wasCSharpSQLite – Blame information for rev 3
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /* |
2 | * VariableCmd.java |
||
3 | * |
||
4 | * Copyright (c) 1987-1994 The Regents of the University of California. |
||
5 | * Copyright (c) 1994-1997 Sun Microsystems, Inc. |
||
6 | * Copyright (c) 1998-1999 by Scriptics Corporation. |
||
7 | * Copyright (c) 1999 by Moses DeJong. |
||
8 | * |
||
9 | * See the file "license.terms" for information on usage and |
||
10 | * redistribution of this file, and for a DISCLAIMER OF ALL |
||
11 | * WARRANTIES. |
||
12 | * |
||
13 | * Included in SQLite3 port to C# for use in testharness only; 2008 Noah B Hart |
||
14 | * |
||
15 | * RCS @(#) $Id: VariableCmd.java,v 1.3 1999/06/30 00:13:39 mo Exp $ |
||
16 | */ |
||
17 | using System; |
||
18 | namespace tcl.lang |
||
19 | { |
||
20 | |||
21 | /// <summary> This class implements the built-in "variable" command in Tcl.</summary> |
||
22 | |||
23 | class VariableCmd : Command |
||
24 | { |
||
25 | public TCL.CompletionCode cmdProc( Interp interp, TclObject[] objv ) |
||
26 | { |
||
27 | |||
28 | |||
29 | string varName; |
||
30 | int tail, cp; |
||
31 | Var var, array; |
||
32 | TclObject varValue; |
||
33 | int i; |
||
34 | |||
35 | for ( i = 1; i < objv.Length; i = i + 2 ) |
||
36 | { |
||
37 | // Look up each variable in the current namespace context, creating |
||
38 | // it if necessary. |
||
39 | |||
40 | |||
41 | varName = objv[i].ToString(); |
||
42 | Var[] result = Var.lookupVar( interp, varName, null, ( TCL.VarFlag.NAMESPACE_ONLY | TCL.VarFlag.LEAVE_ERR_MSG ), "define", true, false ); |
||
43 | if ( result == null ) |
||
44 | { |
||
45 | // FIXME: |
||
46 | throw new TclException( interp, "" ); |
||
47 | } |
||
48 | |||
49 | var = result[0]; |
||
50 | array = result[1]; |
||
51 | |||
52 | // Mark the variable as a namespace variable and increment its |
||
53 | // reference count so that it will persist until its namespace is |
||
54 | // destroyed or until the variable is unset. |
||
55 | |||
56 | if ( ( var.flags & VarFlags.NAMESPACE_VAR ) == 0 ) |
||
57 | { |
||
58 | var.flags |= VarFlags.NAMESPACE_VAR; |
||
59 | var.refCount++; |
||
60 | } |
||
61 | |||
62 | // If a value was specified, set the variable to that value. |
||
63 | // Otherwise, if the variable is new, leave it undefined. |
||
64 | // (If the variable already exists and no value was specified, |
||
65 | // leave its value unchanged; just create the local link if |
||
66 | // we're in a Tcl procedure). |
||
67 | |||
68 | if ( i + 1 < objv.Length ) |
||
69 | { |
||
70 | // a value was specified |
||
71 | varValue = Var.setVar( interp, objv[i], null, objv[i + 1], ( TCL.VarFlag.NAMESPACE_ONLY | TCL.VarFlag.LEAVE_ERR_MSG ) ); |
||
72 | |||
73 | if ( varValue == null ) |
||
74 | { |
||
75 | // FIXME: |
||
76 | throw new TclException( interp, "" ); |
||
77 | } |
||
78 | } |
||
79 | |||
80 | |||
81 | |||
82 | // If we are executing inside a Tcl procedure, create a local |
||
83 | // variable linked to the new namespace variable "varName". |
||
84 | |||
85 | if ( ( interp.varFrame != null ) && interp.varFrame.isProcCallFrame ) |
||
86 | { |
||
87 | |||
88 | // varName might have a scope qualifier, but the name for the |
||
89 | // local "link" variable must be the simple name at the tail. |
||
90 | // |
||
91 | // Locate tail in one pass: drop any prefix after two *or more* |
||
92 | // consecutive ":" characters). |
||
93 | |||
94 | int len = varName.Length; |
||
95 | |||
96 | for ( tail = cp = 0; cp < len; ) |
||
97 | { |
||
98 | if ( varName[cp++] == ':' ) |
||
99 | { |
||
100 | while ( ( cp < len ) && ( varName[cp++] == ':' ) ) |
||
101 | { |
||
102 | tail = cp; |
||
103 | } |
||
104 | } |
||
105 | } |
||
106 | |||
107 | // Create a local link "tail" to the variable "varName" in the |
||
108 | // current namespace. |
||
109 | |||
110 | Var.makeUpvar( interp, null, varName, null, TCL.VarFlag.NAMESPACE_ONLY, varName.Substring( tail ), 0 ); |
||
111 | } |
||
112 | } |
||
113 | return TCL.CompletionCode.RETURN; |
||
114 | } |
||
115 | } |
||
116 | } |