01: /*
02: * TestParsevarCmd.java --
03: *
04: * This procedure implements the "testparsevar" command. It is
05: * used for testing Parser.parseVar.
06: *
07: * Copyright (c) 1997 by Sun Microsystems, Inc.
08: *
09: * See the file "license.terms" for information on usage and redistribution
10: * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11: *
12: * RCS: @(#) $Id: TestParsevarCmd.java,v 1.2 2003/01/09 02:15:40 mdejong Exp $
13: */
14:
15: package tcl.lang;
16:
17: public class TestParsevarCmd implements Command {
18:
19: public void cmdProc(Interp interp, /* Current interpreter. */
20: TclObject objv[]) /* The argument objects. */
21: throws TclException {
22: String name;
23: ParseResult parseResult;
24: TclObject objResult;
25:
26: if (objv.length != 2) {
27: throw new TclNumArgsException(interp, 1, objv, "varName");
28: }
29: name = objv[1].toString();
30: parseResult = Parser.parseVar(interp, name);
31: if (parseResult == null) {
32: throw new TclException(TCL.ERROR);
33: }
34:
35: interp.appendElement(parseResult.value.toString());
36: if ((parseResult.nextIndex > 0)
37: && (parseResult.nextIndex < name.length())) {
38: interp.appendElement(name.substring(parseResult.nextIndex));
39: } else {
40: interp.appendElement("");
41: }
42:
43: parseResult.release();
44: return;
45: }
46: } // end TestParsevarCmd
|