01: /*
02: * IncrCmd.java
03: *
04: * Copyright (c) 1997 Cornell University.
05: * Copyright (c) 1997-1998 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: IncrCmd.java,v 1.3 2006/01/11 21:24:50 mdejong Exp $
12: *
13: */
14:
15: package tcl.lang;
16:
17: /**
18: * This class implements the built-in "incr" command in Tcl.
19: */
20: class IncrCmd implements Command {
21: /**
22: * This procedure is invoked to process the "incr" Tcl command.
23: * See the user documentation for details on what it does.
24: * @exception TclException if wrong # of args or increment is not an
25: * integer.
26: */
27:
28: public void cmdProc(Interp interp, TclObject objv[])
29: throws TclException {
30: int incrAmount;
31: TclObject newValue;
32:
33: if ((objv.length != 2) && (objv.length != 3)) {
34: throw new TclNumArgsException(interp, 1, objv,
35: "varName ?increment?");
36: }
37:
38: // Calculate the amount to increment by.
39:
40: if (objv.length == 2) {
41: incrAmount = 1;
42: } else {
43: try {
44: incrAmount = TclInteger.get(interp, objv[2]);
45: } catch (TclException e) {
46: interp.addErrorInfo("\n (reading increment)");
47: throw e;
48: }
49: }
50:
51: // Increment the variable's value.
52:
53: newValue = Var.incrVar(interp, objv[1].toString(), null,
54: incrAmount, TCL.LEAVE_ERR_MSG);
55:
56: // FIXME: we need to look at this exception throwing problem again
57: /*
58: if (newValue == null) {
59: return TCL_ERROR;
60: }
61: */
62:
63: // Set the interpreter's object result to refer to the variable's new
64: // value object.
65: interp.setResult(newValue);
66: return;
67: }
68: }
|