🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.amiga.tech
Article #13964

Re: Tcl - Tool command language

#13964
From: Peter da Silva
Date: Thu, 01 Mar 1990 14:40
66 lines
2456 bytes
In article <132344@sun.Eng.Sun.COM> cmcmanis@sun.UUCP (Chuck McManis) writes:
> Ok Karl, sounds like Dr. Ousterhout has re-invented REXX.

To a certain extent, yes. But there are some big differences between REXX
and TCL. First of all, the source to TCL is freely available. Secondly, the
TCL-C interface is a lit simpler and cleaner than the REXX-C one, and you
get TCL messages already parsed... to add a REXX interface to a program
requires that you implement your own command language first. On the down
side TCL is newer and hasn't been library-ised yet.

REXX is a baby-PL/I. TCL is a string-oriented language with some similarity
to lisp. On UNIX, I have integrated TCL and my UNIX version of Browse... here's
part of the startup file for browse:

proc key_'d' {} {
	if { [string compare d [get key -d-]] == 0 } {
		set file [target]
		set prompt [concat Delete $file {? }]
		if { [string match {[yY]} [get key $prompt]] } {
			if { ![eval [concat browse delete $file]] } {
				perror
			}
		}
	}
}

proc key_'r' {} {
	set file [get file .]
	set prompt [concat Rename $file {to }]
	set new_file [get response $prompt $file]
	if { ![browse rename $file $new_file] } {
		perror
	}
}

Here's how you add a command to TCL, from the example code:

int
cmdSleep(clientData, interp, argc, argv)
    ClientData clientData;		/* Not used. */
    Tcl_Interp *interp;
    int argc;
    int *argv;
{
    int count;
    if (argc != 2) {
	sprintf(interp->result, "wrong # args:  should be \"%.50s seconds\"",
		argv[0]);
	return TCL_ERROR;
    }
    count = atoi(argv[1]);
    sleep(count);
    return TCL_OK;
}

main()
{
    interp = Tcl_CreateInterp();

    Tcl_CreateCommand(interp, "sleep", cmdSleep, (ClientData) "sleep", NULL);
    ...
-- 
 _--_|\  Peter da Silva <peter@sugar.hackercorp.com>.
/      \
\_.--._/ I haven't lost my mind, it's backed up on tape somewhere!
      v  "Have you hugged your wolf today?" `-_-'
Technical Details
Message-ID: <5224@sugar.hackercorp.com>
Path: arc1-ca.pugleaf.net!utzoo!censor!geac!torsqnt!jarvis.csri.toronto.edu!cs.utexas.edu!wuarchive!texbell!sugar!peter
References: <5213@sugar.hackercorp.com> <132344@sun.Eng.Sun.COM>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!censor!geac!torsqnt!jarvis.csri.toronto.edu!cs.utexas.edu!wuarchive!texbell!sugar!peter
From: peter@sugar.hackercorp.com (Peter da Silva)
Newsgroups: comp.sys.amiga.tech
Subject: Re: Tcl - Tool command language
Message-ID: <5224@sugar.hackercorp.com>
Date: 1 Mar 90 14:40:46 GMT
References: <5213@sugar.hackercorp.com> <132344@sun.Eng.Sun.COM>
Reply-To: peter@sugar.hackercorp.com (Peter da Silva)
Organization: Sugar Land Unix - Houston
Lines: 66