001: /*
002: * ReturnCmd.java --
003: *
004: * This file implements the Tcl "return" 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: ReturnCmd.java,v 1.1.1.1 1998/10/14 21:09:19 cvsadmin Exp $
014: *
015: */
016:
017: package tcl.lang;
018:
019: /*
020: * This class implements the built-in "return" command in Tcl.
021: */
022:
023: class ReturnCmd implements Command {
024:
025: /*
026: *----------------------------------------------------------------------
027: *
028: * cmdProc --
029: *
030: * This procedure is invoked as part of the Command interface to
031: * process the "return" 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 argv[]) // Argument list.
045: throws TclException // A standard Tcl exception.
046: {
047: interp.errorCode = null;
048: interp.errorInfo = null;
049: int returnCode, i;
050:
051: /*
052: * Note: returnCode is the value given by the -code option. Don't
053: * confuse this value with the compCode variable of the
054: * TclException thrown by this method, which is always TCL.RETURN.
055: */
056:
057: returnCode = TCL.OK;
058: for (i = 1; i < argv.length - 1; i += 2) {
059: if (argv[i].toString().equals("-code")) {
060: if (argv[i + 1].toString().equals("ok")) {
061: returnCode = TCL.OK;
062: } else if (argv[i + 1].toString().equals("error")) {
063: returnCode = TCL.ERROR;
064: } else if (argv[i + 1].toString().equals("return")) {
065: returnCode = TCL.RETURN;
066: } else if (argv[i + 1].toString().equals("break")) {
067: returnCode = TCL.BREAK;
068: } else if (argv[i + 1].toString().equals("continue")) {
069: returnCode = TCL.CONTINUE;
070: } else {
071: try {
072: returnCode = TclInteger
073: .get(interp, argv[i + 1]);
074: } catch (TclException e) {
075: throw new TclException(
076: interp,
077: "bad completion code \""
078: + argv[i + 1]
079: + "\": must be ok, error, return, break, "
080: + "continue, or an integer");
081: }
082: }
083: } else if (argv[i].toString().equals("-errorcode")) {
084: interp.errorCode = argv[i + 1].toString();
085: } else if (argv[i].toString().equals("-errorinfo")) {
086: interp.errorInfo = argv[i + 1].toString();
087: } else {
088: throw new TclException(
089: interp,
090: "bad option \""
091: + argv[i]
092: + "\": must be -code, -errorcode, or -errorinfo");
093: }
094: }
095: if (i != argv.length) {
096: interp.setResult(argv[argv.length - 1]);
097: }
098:
099: interp.returnCode = returnCode;
100: throw new TclException(TCL.RETURN);
101: }
102:
103: } // end ReturnCmd
|