Dave wrote:
> . So, is anything but option #1 viable or even possible?
Best answer would be to change the question.
> . /*
> . * Replace standard "exit" and "catch" commands.
> . *
> . * This is a design flaw in Tcl - the standard "exit" command just calls
> . * exit() and kills the application.
That's correct, at least in this context.
It should return TCL_EXIT to the
> . * app, which then decides if it wants to terminate or not. In our case,
> . * we just delete the Tcl interpreter (and create a new one with the next
> . * :tcl command).
But that's not really a good solution.
Better solution is to replace [exit] with a command that deletes
the interp. No use of a custom return code, and thus, no need to
replace [catch] to enable special treatment of the custom return
code. Note that with the addition of [try] in later Tcl releases,
modifying [catch] is no longer sufficient anyway, to say nothing
of the other places where a custom return code might be encountered.
> . */
> . #define TCL_EXIT 5
> .
> . static int
> . exitcmd(dummy, interp, objc, objv)
> . ClientData dummy UNUSED;
> . Tcl_Interp *interp;
> . int objc;
> . Tcl_Obj *CONST objv[];
> . {
> . int value = 0;
> .
> . switch (objc)
> . {
> . case 2:
> . if (Tcl_GetIntFromObj(interp, objv[1], &value) != TCL_OK)
> . break;
> . /* FALLTHROUGH */
> . case 1:
> . Tcl_SetObjResult(interp, Tcl_NewIntObj(value));
Tcl_DeleteInterp(interp);
break;
> . default:
> . Tcl_WrongNumArgs(interp, 1, objv, "?returnCode?");
> . }
> . return TCL_ERROR;
--
| Don Porter Applied and Computational Mathematics Division |
|
donald...@nist.gov Information Technology Laboratory |
|
http://math.nist.gov/~DPorter/ NIST |
|______________________________________________________________________|