wasCSharpSQLite – Blame information for rev 3

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 /*
2 * UpvarCmd.java
3 *
4 * Copyright (c) 1997 Cornell University.
5 * Copyright (c) 1997 Sun Microsystems, Inc.
6 *
7 * See the file "license.terms" for information on usage and
8 * redistribution of this file, and for a DISCLAIMER OF ALL
9 * WARRANTIES.
10 *
11 * Included in SQLite3 port to C# for use in testharness only; 2008 Noah B Hart
12 *
13 * RCS @(#) $Id: UpvarCmd.java,v 1.3 1999/07/12 02:38:53 mo Exp $
14 *
15 */
16 using System;
17 namespace tcl.lang
18 {
19  
20 /// <summary> This class implements the built-in "upvar" command in Tcl.</summary>
21  
22 class UpvarCmd : Command
23 {
24 /// <summary> Tcl_UpvarObjCmd -> UpvarCmd.cmdProc
25 ///
26 /// This procedure is invoked to process the "upvar" Tcl command.
27 /// See the user documentation for details on what it does.
28 /// </summary>
29  
30 public TCL.CompletionCode cmdProc( Interp interp, TclObject[] objv )
31 {
32 CallFrame frame;
33 string frameSpec, otherVarName, myVarName;
34 int p;
35 int objc = objv.Length, objv_index;
36 int result;
37  
38 if ( objv.Length < 3 )
39 {
40 throw new TclNumArgsException( interp, 1, objv, "?level? otherVar localVar ?otherVar localVar ...?" );
41 }
42  
43 // Find the call frame containing each of the "other variables" to be
44 // linked to.
45  
46  
47 frameSpec = objv[1].ToString();
48 // Java does not support passing a reference by refernece so use an array
49 CallFrame[] frameArr = new CallFrame[1];
50 result = CallFrame.getFrame( interp, frameSpec, frameArr );
51 frame = frameArr[0];
52 objc -= ( result + 1 );
53 if ( ( objc & 1 ) != 0 )
54 {
55 throw new TclNumArgsException( interp, 1, objv, "?level? otherVar localVar ?otherVar localVar ...?" );
56 }
57 objv_index = result + 1;
58  
59  
60 // Iterate over each (other variable, local variable) pair.
61 // Divide the other variable name into two parts, then call
62 // MakeUpvar to do all the work of linking it to the local variable.
63  
64 for ( ; objc > 0; objc -= 2, objv_index += 2 )
65 {
66  
67 myVarName = objv[objv_index + 1].ToString();
68  
69 otherVarName = objv[objv_index].ToString();
70  
71 int otherLength = otherVarName.Length;
72 p = otherVarName.IndexOf( (System.Char)'(' );
73 if ( ( p != -1 ) && ( otherVarName[otherLength - 1] == ')' ) )
74 {
75 // This is an array variable name
76 Var.makeUpvar( interp, frame, otherVarName.Substring( 0, ( p ) - ( 0 ) ), otherVarName.Substring( p + 1, ( otherLength - 1 ) - ( p + 1 ) ), 0, myVarName, 0 );
77 }
78 else
79 {
80 // This is a scalar variable name
81 Var.makeUpvar( interp, frame, otherVarName, null, 0, myVarName, 0 );
82 }
83 }
84 interp.resetResult();
85 return TCL.CompletionCode.RETURN;
86 }
87 }
88 }