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 '210') that turns Puppy into a complete C/C++ compiling environment. Without devx_xxx.sfs, the live-CD already has many languages, including Ash/Bash scripting, Tcl/Tk and PuppyBasic. 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, e2 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. (see also, ML, in Tcl/Tk section below)

Have fun, write a script for Puppy!

Puppy has heaps of support documentation and tools to aid with scripting:

e2, mp,
Geany, Leafpad
Text editors
Ash
Command shell used in Puppy
BusyBox
A suite of basic Unix/Linux console applications, can be used in scripts
Xdialog
A GTK GUI frontend for scripts
xmessage
A very basic X11 GUI dialog frontend for scripts
xcut
A console application for cut-to and paste-from the clipboard
gtk-shell
This is a very flexible, simple, tiny GTK alternative to xmessage and Xdialog. Can display/edit files, display a file-selection dialog, prompt for user input, choice buttons. No documentation. Just type "# gtk-shell -h" for help.
gtkdialog
This is yet another alternative to gtk-shell, 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. This program was introduced with Puppy 0.9.7. I think that gtkdialog is the pick of the bunch!
Note that Puppy currently has two versions of gtkdialog, named gtkdialog and gtkdialog2 -- 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 "gtkdialog2".

Here are some scripts used in Puppy:
/usr/sbin/hardware-probe
/usr/sbin/modem-wizard

Tcl/Tk

Tcl is an interpreted scripting language, similar in concept to Ash scripts as described above, and indeed a Tcl program can just as easily be made into a shell script. However, what really sets Tcl apart is the Tk library, which makes it into a full-blown GUI programming environment. There are many extension libraries for Tcl, and Puppy currently has Tk (the standard extension, provides all the basic widgets), Img (Tcl/Tk only handles gif files, this extends to jpeg, png, etc.), Combobox (a sophisticated widget), BWidget (more sophisticated widgets). Note that you can find all of these in /usr/lib.

There are also some special packages for Tcl, such as FTP and uri (these two are not currently used, but planned to be used if phv, the Puppy HTML viewer is expanded).

Many applications in Puppy (or as PupGet packages) are written in Tcl/Tk, such as Slidedraw, TkZip, CDTAR, XS, snamp, tkpppoe, phv, TkDVD and regexpviewer.

Why Tcl? Why not Perl or Java? For me personally, there are three main reasons: there are a huge number of GUI applications available, Tcl/Tk is fairly small, and it is a very simple easy-to-learn language. That last point is extremely important, as I can actually read code that other people have written, unlike all the languages based on the C syntax, that can have quite obscure code (C++, Java).

Another point to consider is support. The Tcl/Tk community is very active, and their websites have heaps and heaps of docs, tutorials and code examples. Also, Tcl/Tk is pervasive -- every Unix and Linux distro has it. Also it is available for the other operating systems, such as Windows and Mac.

Here are some tools in Puppy to aid Tcl/Tk programming:


ML The console editor MP and the GUI editor Beaver have color syntax highlighting for Tcl/Tk, however Puppy has yet another text editor, called ML, that is especially designed for Tcl/Tk coding. ML has color syntax highlighting and a rapid jump-to-procedure feature.
tkcon This is a console, like rxvt terminal emulator, and in fact capable of doing much the same as rxvt, but with special features to aid Tcl/Tk programming -- CURRENTLY NOT IN PUPPY

I have not placed documentation to teach Tcl/Tk into Puppy: for that, obtain a good book, or study online docs on the Internet. To find out more about Tcl/Tk, here are some links:


www.tcl.tk/advocacy/top10.html Top 10 reasons to choose Tcl
www.tldp.org/HOWTO/Scripting-GUI-TclTk Scripting graphical commands with Tcl/Tk: mini HOWTO
mini.net/tcl/540.html Is Tcl different!
mini.net/tcl/3222 Tcl/Tk is too easy
rsusu1.rnd.runnet.ru/graphics/tcl/tcl-faq comp.lang.tcl newsgroup FAQ
wiki.tcl.tk/969 Arts and crafts of Tcl-Tk programming
hegel.ittc.ukans.edu/topics/tcltk/ Online docs
www.beedub.com/book/ Book extracts "Practical programming in Tcl and Tk"

PuppyBasic

This is an interpreter, and another alternative for developing scripts in Puppy.
PuppyBasic is also known as wxBasicScript, and is derived from a more powerful version called wxBasic.
PuppyBasic has extensions for X programming, in particular to use Xdialog and gtkdialog for creating windows.

Documentation is on the Internet:

Covers wxBasic as well as wxBasicScript (PuppyBasic):
http://noforum.de/wxBasicscript-documentation/index.htm 


wxBasicScript (PuppyBasic) only:
http://noforum.de/wxBasicscript-documentation/wxbasicscript/index.htm

There are PuppyBasic scripts in Puppy, written by Mark Ulrich. Here are some:
/usr/local/Dotpup-downloader-mu05/resource/downloader.wxbs
/usr/sbin/backup_dotpup_menues.wxbs

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.

To use this file is very simple. Download it from the Internet (it is about 55M) and save to /mnt/home (the same place as the "pup_save.3fs" file).

Or, if you have installed Puppy to hard drive, with what we call an "Option 2" installation (Puppy occupying his own partition, no ramdisk), then download the devx_xxx.sfs file to "/" (that is, the top level of the directory hierarchy). ...need to provide more instructions here, see forum.

After downloading devs_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, if you want to do this from a live-CD, fine, but 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, and as Puppy is running in a ramdisk, if it is too small you will be in trouble.
Note that I personally always run Puppy from a live-CD and my PC has 256M RAM and a 400M swap partition -- this gives me an effective ramdisk of about 520M.

(c) Copyright 2004,2005,2006, Barry Kauler