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 '401' for version 4.01) that turns
Puppy into a complete C/C++ compiling environment (FreeBASIC compiler also). Without
devx_xxx.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 Leafpad. Geany and MP are particularly interesting as they 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, Leafpad
|
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 70M) and save to /mnt/home (the same place as the "pup_save.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.
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.
FreeBASIC programming
If you want the simplicity of Basic and the
efficiency of a compiler, then take a look at FreeBASIC. Unlike some
other free compilers (such as FreePascal), FreeBASIC generates very
small executables, on a par with those generated by C programming. You
can also use all the shared libraries in Puppy, including the GTK
libraries -- and the the FreeBASIC package includes all the GTK
tutorial examples taken from the online tutorial at www.gtk.org.
FreeBASIC is available in the 'devx' module, so install that as described above, and you're in business!
After installing the 'devx' module, the FreeBASIC examples are to be
found at /usr/share/doc/freebasic. Binaries and include files are to be
found in /usr/share/freebasic. The compiler 'fbc' is in the path at
/usr/bin/fbc.
All documentation for FreeBASIC is to be found online at: http://freebasic.net/,
however the 'devx' module also has it as the User Manual as a CHM file
(Microsoft Help format) and recent releases of Puppy have 'ChmSee', a
reader for this file-format. The CHM help file is to be found at
/usr/share/doc/freebasic.
The best editor for writing FreeBASIC programs is Geany (the default text editor in Puppy), as it has color syntax highlighting.
FreeBASIC can also use Glade XML files. There is an application
'glade2bas' that will generate a skeleton FreeBASIC application for a
particular Glade XML file. A HOWTO is at
/usr/share/doc/freebasic/howto_glade_freebasic.pdf. This is all
provided in the 'devx' file.
(c) Copyright 2004,2005,2006,2007,2008 Barry Kauler