01: /*
02: * SetCmd.java --
03: *
04: * Implements the built-in "set" Tcl command.
05: *
06: * Copyright (c) 1997 Cornell University.
07: * Copyright (c) 1997 Sun Microsystems, Inc.
08: *
09: * See the file "license.terms" for information on usage and
10: * redistribution of this file, and for a DISCLAIMER OF ALL
11: * WARRANTIES.
12: *
13: * RCS: @(#) $Id: SetCmd.java,v 1.2 1999/05/09 01:23:19 dejong Exp $
14: *
15: */
16:
17: package tcl.lang;
18:
19: /*
20: * This class implements the built-in "set" command in Tcl.
21: */
22:
23: class SetCmd implements Command {
24:
25: /*
26: *----------------------------------------------------------------------
27: *
28: * cmdProc --
29: *
30: * This procedure is invoked as part of the Command interface to
31: * process the "set" Tcl command. See the user documentation
32: * for details on what it does.
33: *
34: * Results:
35: * None.
36: *
37: * Side effects:
38: * See the user documentation.
39: *
40: *----------------------------------------------------------------------
41: */
42:
43: public void cmdProc(Interp interp, // Current interpreter.
44: TclObject argv[]) // Argument list.
45: throws TclException // A standard Tcl exception.
46: {
47: final boolean debug = false;
48:
49: if (argv.length == 2) {
50: if (debug) {
51: System.out.println("getting value of \""
52: + argv[1].toString() + "\"");
53: System.out.flush();
54: }
55: interp.setResult(interp.getVar(argv[1], 0));
56: } else if (argv.length == 3) {
57: if (debug) {
58: System.out.println("setting value of \""
59: + argv[1].toString() + "\" to \""
60: + argv[2].toString() + "\"");
61: System.out.flush();
62: }
63: interp.setResult(interp.setVar(argv[1], argv[2], 0));
64: } else {
65: throw new TclNumArgsException(interp, 1, argv,
66: "varName ?newValue?");
67: }
68: }
69:
70: } // end SetCmd
|