01: /*
02: * GlobalCmd.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: GlobalCmd.java,v 1.5 2006/03/15 23:07:22 mdejong Exp $
12: *
13: */
14:
15: package tcl.lang;
16:
17: /**
18: * This class implements the built-in "global" command in Tcl.
19: */
20:
21: class GlobalCmd implements Command {
22: /**
23: * See Tcl user documentation for details.
24: */
25:
26: public void cmdProc(Interp interp, TclObject[] objv)
27: throws TclException {
28: if (objv.length < 2) {
29: throw new TclNumArgsException(interp, 1, objv,
30: "varName ?varName ...?");
31: }
32:
33: // If we are not executing inside a Tcl procedure, just return.
34:
35: if ((interp.varFrame == null)
36: || !interp.varFrame.isProcCallFrame) {
37: return;
38: }
39:
40: for (int i = 1; i < objv.length; i++) {
41: String varName = objv[i].toString();
42: String varTail = NamespaceCmd.tail(varName);
43:
44: // Link to the variable "varName" in the global :: namespace.
45: // A local link var named varTail is defined.
46:
47: Var.makeUpvar(interp, null, varName, null, TCL.GLOBAL_ONLY,
48: varTail, 0, -1);
49: }
50: }
51: }
|