MacTcl 7.3
by Ray Johnson
Lockheed Missile & Space Corporation - Artificial Intelligence Center
rjohnson@aic.lockheed.com
This is the source distribution of the Mac port of Tcl 7.3
Read the inclosed README file for information about Tcl.
Other documentation and sample Tcl scripts can be found at
the Tcl ftp site: harbor.ecn.purdue.edu:pub/tcl
The internet news group comp.lang.tcl is also a valuable
source of information about Tcl. A mailing list is also
available (see below).
MacTcl is not a full port. Some items will probably never
be fully supported as they are too tied to the UNIX operating
system. An example is the 'exec' function. Other features
are handled a little differently in the Mac version. Most of
the important differences or extensions of the MacTcl port are
described below. In addition, a few important facts about
compiling the port is also given.
Compiling the Code
Tcl 7.3 is compatible with Think C and MPW. See the file "Notes on Compiling"
for platform specific differences and instructions on compiling Tcl the Tcl
libraries and sample applications.
Unix Commands
Tcl uses Unix to handle many file I/O commands. The are included in
the Mac version for compatibility. Following are a list of Unix functions
included.
- "echo" to print text to stdout
- "ls" to list a directory
- "cd" to change directories
(NOTE: use ":" instead of "/" when making path names)
- "pwd" to display the current directory
- "mkdir" to create new directories
- "rmdir" to remove directories
- "rm" to remove files & folders (will accept lists of files, i.e.. rm [glob *.c] works)
- "cp" to copy a file
- "mv" to change the name of a file or move its location
Macintosh File Names
One of the largest problems you will encounter when porting Unix written Tcl
code to the Mac is the difference in file names and paths between Unix and
the Macintosh. Two major incompatibilities exist.
First the Macintosh allows spaces in file names. Because spaces are element
delimiters in Tcl lists many Unix written scripts to break. Special care is
needed to ensure that a Mac file name or path is always treated as a single
string.
The second problem resides in how paths are constructed. Unix uses the "/"
character to separate directory names. Macintosh on the other had uses the
":" character. Further more, the Unix path "/home/rjohnson/fileName" refers
to an absolute path. While the Macintosh path ":Tcl 7.3:MacTcl Source" refers
to a relative path. That is the special delimiter character means something
different on each platform when placed at the beginning of the path.
Environment Variables
Environment variables may be added to the system via three different mechanisms.
The first is automatic inclusion of system variables. These variables include
things like the system folder path. These variables are determined at startup
time (for the interpreter) but are not changed if the system changes.
The following environment variables are created via this method:
- LOGIN - holds the Chooser name of the Macintosh
- SYS_FOLDER - path to the system directory
- APPLE_M_FOLDER - path to the Apple Menu directory
- CP_FOLDER - path to the control panels directory
- DESK_FOLDER - path to the desk top directory
- EXT_FOLDER - path to the system extensions directory
- PREF_FOLDER - path to the preferences directory
- PRINT_MON_FOLDER - path to the print monitor directory
- SHARED_TRASH_FOLDER - path to the network trash directory
- TRASH_FOLDER - path to the trash directory
- START_UP_FOLDER - path to the start up directory
- PWD - path to the application's default directory
Environment variables may also be placed in a file. A file named
"Tcl Environment Variables" may be placed in the preferences folder.
Each line of this file should be of the form "VAR_NAME=var_data".
For example,
PRINTER=Joe's LW
TCLLIBPATH=Lozoya:System Folder:Tcl Lib
The last alternative is to place environment variables in a 'STR#' resource
named "Tcl Environment Variables" of the application. This is considered
a little more "Mac like" than a Unix style Environment Variable file.
Each entry in the 'STR#' resource has the same format as above.
The source code file "macEnv.c" contains the implementation of the env
mechanisms. This file contains many #define's that allow customization of
the env mechanisms to fit your applications needs.
Auto Load Path
The environment variable TCL_LIBRARY is a special variable that can
be set by the user in the "Tcl Environment Variables" file or the
'STR#' resource named "Tcl Environment Variables".
The variable should contain a full path to a directory that contains
init.tcl and other auto loading tcl scripts. If this variable is
set MacTcl will try to source the file $TCL_LIBRARY:init.tcl on start up.
If the variable of the file does not exist MacTcl will search for
the directory "library" in the default directory (the directory where
the application was started from). If init.tcl exists within the
library directory it will try to source it.
Macintosh Extensions
The MacTcl port also includes a few extensions useful only to Macintosh users.
These include an extension to the source command and the beep command. Look
forward to seeing further extensions as MacTcl evolves.
- Extension to the source command.
- The source command has been extended to allow sourcing of a 'TEXT'
resource in the application or in a seprate file. For example,
the MacTcl command "source -rsrc Init" will source the text found
in the application's 'TEXT' resource named "Init". This extension
allows Tcl code to be included with an application with out requiring
Tcl files to be placed in well known locations on the users machine.
The syntax for the command is:
source [file | [-rsrc name | -rsrcid id] ?-file path?]]
( -rsrc and -rsrcname are equivilent )
( -file and -rsrcfile are equivilent )
- The beep command
- The beep command may take zero or one arguments. If no argument
is given the default Macintosh beep will sound. The command
"beep -list" will return a list of the beep sounds currently
installed in your Mac's system. The command "beep <beepName>"
will sound the named beep. For example, the command "beep Monkey"
sounds the Monkey sound and "beep {Simple Beep}" will play the
basic Macintosh beep sound.
Tcl Documentation
Documentation for Tcl can be found at the ftp site
ftp.aud.alcatel.com.
Macintosh Tcl Mailing List
A Mailing List has been set up to discuss Macintosh related Tcl issues
including (but not limited to) MacTcl. In order to use this Mailing
List you must have access to the internet. To subscribe send a message to:
listserv@aic.lockheed.com
In the body of the message (the subject will be ignored) put:
subscribe mactcl Joe Blow
Replacing Joe Blow with your real name, of course. If you would just like
to receive more information about the list without subscribing put the line:
information mactcl
in the body instead.
The Future
Unfortunately, MacTcl is a part time project. It doesn't generate much
revenue. However, I do plan to continue supporting the port and porting
future Tcl releases. I would also like to extend the port to support more
Macintosh specific features - but I need *your* help. I am very interested
any extensions or enhancements you make to this port. If your work doesn't
alter the Tcl core *too* much and appears to be clean and supportable from
my point of view, I may very well be interested in including it in my release.
The following areas are of the most interest to me:
- The Posix library
- The Posix library included with this port is in sad shape.
If you have the desire to clean it up I know it would be of great
use to anyone porting Posix compliant software to the Mac.
- A Mac specific test suite
- The current test suite is not very useful. Many of them can't
be run as they rely on the exec command. I would also be
interested in tests that test specific Mac enhancements.
- Pure Mac extensions
- Examples of this might include a suite of Tcl commands to display
and manipulate Quick Time Movies or a tcl command that sends
AppleScript commands to Mac applications.
- A better shell
- The current port uses Think C's console package. While very useful
it doesn't support a few desired features including Apple Events,
scrollable window, etc. Such a shell would replace the tclMain.c
file and should support everything it does (like tclAppInit.c).
- Better Unix commands
- I'm very interested in any new Unix-like commands you may create.
Some of the current commands could also be made a bit more robust
(i.e.. the mv command).
- A Mac specific version of init.tcl
- The Unix protocol for handling unknown commands do not work for the
Mac. A better init.tcl that is specific to the Mac would be useful.
Acknowledgments
Many people have helped with this port. Here is a list of people that
have contributed to MacTcl and have supported its continual use. Please
forgive me (and let me know) if I have forgoten anyone.
Patrick Beard
Cecil Coupe
Louis Demers
Tim Endres
Peter Keleher
Duane Murphy
Prag Patel
Bruce Tulloch
The Posix library was taken wholesale from the net - many people contributed
to it. Look in the source of the library for credits.
Of course, we can thank John Ousterhout for the source to Tcl.
If you have comments or Bug reports send them to: Ray Johnson,
rjohnson@aic.lockheed.com
Revision History
- MacTcl7.3
- The source command was extended again to source 'TEXT' resources
from the application and and anyother resource file. Several of
the unix commands were rewiten to be more robust including the
cp, mv, and rm commands. The Posix stat command has been replaced
and the Think C 6.0 stat comand is now over rided by the Posix
stat command.
- MacTcl7.0
- The UNIX command rmdir was added. The source command and beep
commands were extended to better support the Mac. The env mechanism
was rewritten and extended. Support for MPW has been added.
- MacTcl6.7
- The ideas of MacTcl6.1 were used to port 6.7. More complete support
for the env variable was included. Many new Unix commands were
added or extended.
- MacTcl6.1v2
- Port of Tcl 6.1 based on an original port by Prag Patel
November 8, 1994 - Robert Lentz
(ralentz@ralentz.com)