Tcl (``Tool Control Language'') is
a shell interpreter. It was made to be embedded
inside a C program. The usual stand-alone
interpreter is ``tclsh
''
Tk basically adds the X11 interface to Tcl..
It provides a set of widets. It has
a stand-alone interpreter called ``wish
''
A major ftp site for all sorts of Tcl/Tk goodies is
ftp://ftp.aud.alcatel.com/tcl/
.
ftp://ftp.sterling.com/programming/languages/tcl/
ftp://ftp.cs.columbia.edu/archives/tcl/
ftp://sunsite.unc.edu/pub/languages/tcl/
Tcl/Tk CD-ROMs are available from Info-Magic (1-800-800-6613) and Walnut Creek (1-800-786-9907).
Tcl and Tk were written mainly by John Ousterhout. He also wrote a book Tcl and the Tk Toolkit (Addison-Wesley, 1994, ISBN: 0-201-63337-X).
Another book, Practical Programming in Tcl and Tk ,
by Brent Welch is due in this spring (1995).
A review draft is available for a while
in the directory
ftp://parcftp.xerox.com/pub/sprite/welch/
D. Richard Hipp has written a toolkit for embedding
Tcl/Tk scripts into a C program. It is available
as et1_1.tar.gz
in the ftp archive:
ftp://ftp.std.com/pub/drh/
This directory also contains a paper describing
the toolkit (notes.ps.gz
).
Most of my talk is stolen from the above three sources.
# example from D. Richard Hipp # Change the name of every file in the working directory # to all lower-case letters foreach file [glob -nocomplain *] { set newname [string tolower $file] if {"$file"!="$newname"} { exec mv $file $newname } }
Tcl is a line oriented shell language.
Commands are are seperated by a newline or ``;
''.
Unless you are careful, Tcl will forget what
happened on the previous line. You can continue
a new line with a backslash ``\
''.
You can also nest a set of commands in curly
braces ``{
'' and ``}
''.
If the first character of a command is ``#
'',
then it is a comment; remember that ``;
''
can seperate commands.
Like UNIX shells, Tcl does variable substitutions
using the dollar sign; i.e. for variable blah
,
the substitution occurs for $blah
.
Square brackets do command substitution -- [command]
The backslash ``\
'' is the basic escape character.
Most command and word delimiters are disabled
within the regular "
double-quote"
.
You can quote literals inside curly
braces ``{
'' and ``}
''.
A ``}
'' needs to be seperated
by at least one whitespace from the next ``{
''.
catch
eval
expr
foreach
global
history
if
else
and elseif
incr
lindex
list
proc
set
source
while
There ``C''-like operators
like ``+
'', ``-
'', ``&&
'', ``||
''
and functions like sin
and pow
. In script
files, command-line arguments ( except for the file name)
are stored in argv
as one character string
and the number of arguments is in argc
;
note that argv0
is the name of the script file.
Tcl has ``regular expression'' matching.
There is a Tcl extension called expect
for controlling interactive programs (without any modifications
to the interactive program!). If you are curious, try
playing around with scripts like kibitz
, ftp-rfc
,
and weather
. The program can be obtained from:
ftp://ftp.cme.nist.gov/pub/expect.tar.Z
# everyone's favorite ;-) button .b -text "Hello, World!" -command exit pack .b
button entry listbox message scrollbar canvas frame menu radiobutton text checkbutton label menubutton scale toplevel
The general purpose graphics widget is canvas
. It has
a bunch of useful items like rectangles, circles,
lines, polygons, Bézier curves, text. Even other
widgets can be embedded in a canvas.
Similarly, the general purpose text widget is text
.
It have several hooks for indexing, marking and tagging text.
Generally the frame
widget is useful for dividing
up a window into (hopefully logical) section.
The widget toplevel
is similar to a frame,
but the frame is new top-level window; a top-level window
could even be put on another host's display.
After a widget is created, you need to tell the geometry
manager to display; pack
is the most common command
for this purpose.
Tcl uses bind
to bind X events to Tcl commands.
Key
KeyRelease
Button
ButtonRelease
Enter
Leave
Motion
Various keyboard modifiers are Control
, Shift
,
Lock
, Meta
, Alt
.
Mouse clicks can be modified by Double
and Triple
.
hello.c
int main(int argc, char **argv) { Et_Init(&argc,argv); ET( button .b -text {Hello, World!} -command exit ); ET( pack .b ); Et_MainLoop(); return 0; }
First compile the et2c
preprocessor and the et.o
library files. The include paths may vary from system to system.
cc -o et2c -I/usr/include/tcl et2c.c et2c -I/usr/lib/tcl -I/usr/lib/tk et.c >et_.c cc -o et.o -c et_.c rm et_.cThis step need be done only once. Next compile the program.
et2c hello.c >hello_.c cc -o hello hello_.c et.o -ltcl -ltk -lX11 -lm rm hello_.c
Et_Init
Et_ReadStdin
Et_MainLoop
ET
ET_STR
ET_DBL
ET_INT
ET_OK
ET_ERROR
ET_INCLUDE
ET_PROC
ET_INSTALL_COMMANDS
Et_Interp
Et_MainWindow
Et_Display
cmd_name
cmd_dir