01: /*
02: * ExprCmd.java
03: *
04: * Copyright (c) 1997 Cornell University.
05: * Copyright (c) 1997 Sun Microsystems, Inc.
06: *
07: * See the file "license.terms" for information on usage and
08: * redistribution of this file, and for a DISCLAIMER OF ALL
09: * WARRANTIES.
10: *
11: * RCS: @(#) $Id: ExprCmd.java,v 1.3 2005/09/30 02:12:17 mdejong Exp $
12: *
13: */
14:
15: package tcl.lang;
16:
17: /**
18: * This class implements the built-in "expr" command in Tcl.
19: */
20:
21: class ExprCmd implements Command {
22: /**
23: * Evaluates a Tcl expression. See Tcl user documentation for
24: * details.
25: * @exception TclException If malformed expression.
26: */
27:
28: public void cmdProc(Interp interp, TclObject argv[])
29: throws TclException {
30: if (argv.length < 2) {
31: throw new TclNumArgsException(interp, 1, argv,
32: "arg ?arg ...?");
33: }
34:
35: if (argv.length == 2) {
36: interp.expr.evalSetResult(interp, argv[1].toString());
37: } else {
38: StringBuffer sbuf = new StringBuffer();
39: sbuf.append(argv[1].toString());
40: for (int i = 2; i < argv.length; i++) {
41: sbuf.append(' ');
42: sbuf.append(argv[i].toString());
43: }
44: interp.expr.evalSetResult(interp, sbuf.toString());
45: }
46: }
47: }
|