HOWTO: Write programs

Puppy is a tiny distribution, but there is a wide choice of programming languages. The default live-CD is not setup for compiling C or C++ programs, however there is an add-on file named 'devx_xxx.sfs' (where 'xxx' is the Puppy version number, for example '430' for version 4.3) that turns Puppy into a complete C/C++ compiling environment (Vala/Genie compiler also). The 'devx' file also provides Python. Without devx_430.sfs, the live-CD already has Ash/Bash and Perl scripting languages. This page has a summary of the programming options in Puppy...

Ash/Bash scripts

A language that is all ready for action in Puppy is command-shell scripting. Unix and Linux shell command-scripting has been around for ages and is going to be around for a long time to come. What I mean by the "command shell" is the user interface that you use when at the commandline. When you are running X, the commandline will be in a terminal window, but you can also exit from X and be back at a commandline.

The actual program that is running and doing the interacting with you is known as the command-shell, and for Linux it is usually what is known as the Bash shell. In Puppy, you have a choice of two shells, Bash or Ash.
Note that when a terminal window is opened in X, Bash is running. If you exit from X to the commandline, Ash is running. You can explicitly choose either Bash or Ash in a script by placing "#!/bin/bash" or "#!/bin/sh" (or "#!/bin/ash") on the first line.

A shell script is an executable program, except that it is a text file and does not have to be compiled. Shell scripts can be very sophisticated, and there are lots of them in Puppy.

This page is not a tutorial on how to program with Ash/Bash scripts --there are plenty of books on the subject and also on the Internet. There are a couple of Bash scripting HOWTOs to be found here:

"Advanced Bash-Scripting Guide": http://www.tldp.org/LDP/abs/html/index.html
"Bash Programming - Introduction HOWTO": http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html

To write a Ash/Bash script, all you need is a text editor, and Puppy has two console editors, e3 and MP, and two GUI editors, Geany and NicoEdit. Geany, NicoEdit and MP have color syntax highlighting for Bash/Ash scripts.

Have fun, write a script for Puppy!

Here is an overview of tools to aid with scripting, with links to online docs:

e3, mp,
Geany
Text editors
Ash , Bash
Command shells used in Puppy
BusyBox
A suite of basic Unix/Linux console applications, can be used in scripts. Puppy uses many of these, although in many cases the "full" program is used as the Busybox applet lacks the required functionality.
Xdialog
A GTK GUI frontend for scripts
xmessage
A very basic X11 GUI dialog frontend for scripts
xclip
A console application for cut-to and paste-from the clipboard or X-selections (primary or secondary). Can be used in scripts.
gtkdialog3
This is yet another alternative to xmessage and Xdialog. Gtkdialog is a GTK2 application and reads an XML file that describes the dialog format and user interaction, allowing incredible sophisticated GUIs. I think that gtkdialog is the pick of the bunch!
Note that Puppy currently has two versions of gtkdialog, named gtkdialog2 and gtkdialog3 -- it is preferred that you use the latter as this will eventually be the only one in Puppy -- in other words, always execute the binary "gtkdialog3".
Note, the user manual for gtkdialog3 is rudimentary, but the 'devx' module has many example programs at /usr/share/doc/gtkdialog3/examples.

Here are some scripts used in Puppy:
/usr/sbin/pmount
/usr/sbin/timezone-set

C/C++ programming

All of the tools for compiling C/C++ applications are to be found in an add-on file named devx_xxx.sfs. This is what we call an SFS file, and you can read an overview of these online in this page: http://puppylinux.com/development/package-management.htm

To use this file is very simple. Download it from the Internet (it is about 90MB) and save to /mnt/home (the same place as the "pupsave.2fs" file).

Or, if you have installed Puppy to hard drive with what we call a "full" installation (Puppy occupying his own partition, no ramdisk), then download the devx_xxx.sfs file ...then some manual steps are required, see here: http://www.puppylinux.com/hard-puppy.htm.

After downloading devx_xxx.sfs and placing it in the right place, reboot Puppy, and that's it, you're ready to go.
All of the normal compiling tools work, such as "configure" and "make".

Note, it is necessary that the PC have either a Linux swap partition and/or a lot of RAM. C/C++ compiling needs a lot of temporary space.

It is also recommended that you place the source package in a mounted Linux partition, not in /root. This is in the case of running from a live-CD or a frugal install, in which '/' is actually a layered filesystem. A layered filesystem sometimes causes problems with compiling, so it is recommended to mount a hard drive partition for the purpose -- a Linux partition, not a DOS/Windows partition!

If you compile a package and would like to make it available for others to use, it is very easy to create a PET package -- read this: http://www.puppylinux.com/development/createpet.htm

If you want to write GTK applications, the 'devx' file also has 'glade-3'. This is a visual GUI-builder. Find out more about Glade here: http://glade.gnome.org/ The 'glade-3' program generates an XML file, and Puppy has 'libglade', a library that an application uses to read the XML file and generate the GUI.

Note, gtkdialog3 is also able to load a Glade XML file. See the gtkdialog3 examples at /usr/share/doc/gtkdialog/examples, provided by the 'devx' file. So, even a Bash script can utilise Glade.

Vala/Genie programming

This is the future. Vala and Genie are languages in every respect superior to C/C++. Vala has a C#-like syntax, Genie has a Python-like syntax. It is actually the same compiler, it just accepts two alternative syntaxes.

Vala/Genie is a true compiler environment and generates extremely efficient executables. They are particularly nice for writing GTK applications. I have placed the Vala/Genie compiler, with documentation and the ValaIDE, in the 'devx' SFS file.

Online documentation on Vala/Genie is here:
http://puppylinux.com/genie/index.html

The ValaIDE is an Integrated Development Environment, with a text editor that has colour syntax highlghting for both Vala and Genie. If the 'devx' SFS file is loaded, you will find an entry for ValaIDE in the 'Utility' menu.

Note that the NicoEdit text editor also has syntax highlighting for Vala and Genie. The Geany text editor has syntax highlighting for Vala but not Genie.

Also if the 'devx' sfs file is loaded you will find the Vala Reference Manual at /usr/share/devhelp/books/vala/index.html.

We are standardising on Vala/Genie for future application development in Puppy, particularly Genie due to its friendly syntax. You can find some exciting new applications on the Puppy forum, that are gradually finding their way into the official Puppy live-CD.

Nicholas's NicoEdit text editor is one example, a GTK application written in Genie. It doesn't stop there, Mark has written PuppyBrowser, EmbeddedBookmarks and Pictureviewer in Genie, and I have even included the source code in Puppy:

/usr/local/PuppyBrowser
/usr/local/EmbeddedBookmarks
/usr/local/Pictureviewer

(c) Copyright 2004,2005,2006,2007,2008,2009 Barry Kauler