001: /*
002: * UplevelCmd.java --
003: *
004: * Implements the "uplevel" command.
005: *
006: * Copyright (c) 1997 Cornell University.
007: * Copyright (c) 1997 Sun Microsystems, Inc.
008: *
009: * See the file "license.terms" for information on usage and
010: * redistribution of this file, and for a DISCLAIMER OF ALL
011: * WARRANTIES.
012: *
013: * RCS: @(#) $Id: UplevelCmd.java,v 1.5 2005/11/16 21:08:11 mdejong Exp $
014: *
015: */
016:
017: package tcl.lang;
018:
019: /*
020: * This class implements the built-in "uplevel" command in Tcl.
021: */
022:
023: class UplevelCmd implements Command {
024:
025: /*
026: *----------------------------------------------------------------------
027: *
028: * Tcl_UplevelObjCmd -> UplevelCmd.cmdProc
029: *
030: * This procedure is invoked as part of the Command interface to
031: * process the "uplevel" Tcl command. See the user documentation
032: * for details on what it does.
033: *
034: * Results:
035: * None.
036: *
037: * Side effects:
038: * See the user documentation.
039: *
040: *----------------------------------------------------------------------
041: */
042:
043: public void cmdProc(Interp interp, // Current interpreter.
044: TclObject[] objv) // Argument list.
045: throws TclException // A standard Tcl exception.
046: {
047: String optLevel;
048: int result;
049: CallFrame savedVarFrame, frame;
050: int objc = objv.length;
051: int objv_index;
052: TclObject cmd;
053:
054: if (objv.length < 2) {
055: throw new TclNumArgsException(interp, 1, objv,
056: "?level? command ?arg ...?");
057: }
058:
059: // Find the level to use for executing the command.
060:
061: optLevel = objv[1].toString();
062: // Java does not support passing a reference by refernece so use an array
063: CallFrame[] frameArr = new CallFrame[1];
064: result = CallFrame.getFrame(interp, optLevel, frameArr);
065: frame = frameArr[0];
066:
067: objc -= (result + 1);
068: if (objc == 0) {
069: throw new TclNumArgsException(interp, 1, objv,
070: "?level? command ?arg ...?");
071: }
072: objv_index = (result + 1);
073:
074: // Modify the interpreter state to execute in the given frame.
075:
076: savedVarFrame = interp.varFrame;
077: interp.varFrame = frame;
078:
079: // Execute the residual arguments as a command.
080:
081: if (objc == 1) {
082: cmd = objv[objv_index];
083: } else {
084: cmd = Util.concat(objv_index, objv.length - 1, objv);
085: }
086:
087: try {
088: interp.eval(cmd, 0);
089: } catch (TclException e) {
090: if (e.getCompletionCode() == TCL.ERROR) {
091: interp.addErrorInfo("\n (\"uplevel\" body line "
092: + interp.errorLine + ")");
093: }
094: throw e;
095: } finally {
096: interp.varFrame = savedVarFrame;
097: }
098: }
099:
100: } // end UplevelCmd
|