01: /*
02: * TestEvalExCmd.java
03: *
04: * |>Description.<|
05: *
06: * Copyright (c) 1997 by Sun Microsystems, Inc.
07: *
08: * See the file "license.terms" for information on usage and redistribution
09: * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
10: *
11: * RCS: @(#) $Id: TestEvalExCmd.java,v 1.2 2006/03/11 22:35:54 mdejong Exp $
12: */
13: package tcl.lang;
14:
15: public class TestEvalExCmd implements Command {
16:
17: /*
18: *----------------------------------------------------------------------
19: *
20: * TestevalexObjCmd -> cmdProc
21: *
22: * This procedure implements the "testevalex" command. It is
23: * used to test Tcl_EvalEx.
24: *
25: * Results:
26: * A standard Tcl result.
27: *
28: * Side effects:
29: * None.
30: *
31: *----------------------------------------------------------------------
32: */
33:
34: public void cmdProc(Interp interp, // Current interpreter.
35: TclObject[] objv) // The argument objects.
36: throws TclException {
37: int code, oldFlags, length, flags;
38: CharPointer script;
39: String string;
40:
41: if (objv.length == 1) {
42: // The command was invoked with no arguments, so just toggle
43: // the flag that determines whether we use Tcl_EvalEx.
44:
45: if ((interp.flags & Parser.USE_EVAL_DIRECT) != 0) {
46: interp.flags &= ~Parser.USE_EVAL_DIRECT;
47: interp.setResult("disabling direct evaluation");
48: } else {
49: interp.flags |= Parser.USE_EVAL_DIRECT;
50: interp.setResult("enabling direct evaluation");
51: }
52: return;
53: }
54:
55: flags = 0;
56: if (objv.length == 3) {
57: string = objv[2].toString();
58: if (!string.equals("global")) {
59: interp.setResult("bad value \"" + string
60: + "\": must be global");
61: throw new TclException(TCL.ERROR);
62: }
63: flags |= TCL.EVAL_GLOBAL;
64: } else if (objv.length != 2) {
65: throw new TclNumArgsException(interp, 1, objv,
66: "script ?global?");
67: }
68: interp.setResult("xxx");
69:
70: // Note, we have to set the USE_EVAL_DIRECT flag in the interpreter
71: // in addition to calling Tcl_EvalEx. This is needed so that even nested
72: // commands are evaluated directly.
73:
74: oldFlags = interp.flags;
75: interp.flags |= Parser.USE_EVAL_DIRECT;
76: string = objv[1].toString();
77: script = new CharPointer(string);
78: Parser.eval2(interp, script.array, script.index, script
79: .length(), flags);
80: interp.flags = (interp.flags & ~Parser.USE_EVAL_DIRECT)
81: | (oldFlags & Parser.USE_EVAL_DIRECT);
82: return;
83: }
84: } // end TestEvalExCmd
|