wasCSharpSQLite – Blame information for rev
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /* |
2 | * ProcCmd.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: ProcCmd.java,v 1.2 1999/08/03 03:04:19 mo Exp $ |
||
14 | * |
||
15 | */ |
||
16 | using System.Text; |
||
17 | namespace tcl.lang |
||
18 | { |
||
19 | |||
20 | /// <summary> This class implements the built-in "proc" command in Tcl.</summary> |
||
21 | |||
22 | class ProcCmd : Command |
||
23 | { |
||
24 | /// <summary> |
||
25 | /// Tcl_ProcObjCmd -> ProcCmd.cmdProc |
||
26 | /// |
||
27 | /// Creates a new Tcl procedure. |
||
28 | /// |
||
29 | /// </summary> |
||
30 | /// <param name="interp">the current interpreter. |
||
31 | /// </param> |
||
32 | /// <param name="objv">command arguments. |
||
33 | /// </param> |
||
34 | /// <exception cref=""> TclException If incorrect number of arguments. |
||
35 | /// </exception> |
||
36 | |||
37 | public TCL.CompletionCode cmdProc( Interp interp, TclObject[] objv ) |
||
38 | { |
||
39 | Procedure proc; |
||
40 | string fullName, procName; |
||
41 | NamespaceCmd.Namespace ns, altNs, cxtNs; |
||
42 | Command cmd; |
||
43 | StringBuilder ds; |
||
44 | |||
45 | if ( objv.Length != 4 ) |
||
46 | { |
||
47 | throw new TclNumArgsException( interp, 1, objv, "name args body" ); |
||
48 | } |
||
49 | |||
50 | // Determine the namespace where the procedure should reside. Unless |
||
51 | // the command name includes namespace qualifiers, this will be the |
||
52 | // current namespace. |
||
53 | |||
54 | |||
55 | fullName = objv[1].ToString(); |
||
56 | |||
57 | // Java does not support passing an address so we pass |
||
58 | // an array of size 1 and then assign arr[0] to the value |
||
59 | NamespaceCmd.Namespace[] nsArr = new NamespaceCmd.Namespace[1]; |
||
60 | NamespaceCmd.Namespace[] altNsArr = new NamespaceCmd.Namespace[1]; |
||
61 | NamespaceCmd.Namespace[] cxtNsArr = new NamespaceCmd.Namespace[1]; |
||
62 | string[] procNameArr = new string[1]; |
||
63 | |||
64 | NamespaceCmd.getNamespaceForQualName( interp, fullName, null, 0, nsArr, altNsArr, cxtNsArr, procNameArr ); |
||
65 | |||
66 | // Get the values out of the arrays |
||
67 | ns = nsArr[0]; |
||
68 | altNs = altNsArr[0]; |
||
69 | cxtNs = cxtNsArr[0]; |
||
70 | procName = procNameArr[0]; |
||
71 | |||
72 | if ( ns == null ) |
||
73 | { |
||
74 | throw new TclException( interp, "can't create procedure \"" + fullName + "\": unknown namespace" ); |
||
75 | } |
||
76 | if ( (System.Object)procName == null ) |
||
77 | { |
||
78 | throw new TclException( interp, "can't create procedure \"" + fullName + "\": bad procedure name" ); |
||
79 | } |
||
80 | // FIXME : could there be a problem with a command named ":command" ? |
||
81 | if ( ( ns != NamespaceCmd.getGlobalNamespace( interp ) ) && ( (System.Object)procName != null ) && ( ( procName.Length > 0 ) && ( procName[0] == ':' ) ) ) |
||
82 | { |
||
83 | throw new TclException( interp, "can't create procedure \"" + procName + "\" in non-global namespace with name starting with \":\"" ); |
||
84 | } |
||
85 | |||
86 | // Create the data structure to represent the procedure. |
||
87 | |||
88 | proc = new Procedure( interp, ns, procName, objv[2], objv[3], interp.ScriptFile, interp.getArgLineNumber( 3 ) ); |
||
89 | |||
90 | // Now create a command for the procedure. This will initially be in |
||
91 | // the current namespace unless the procedure's name included namespace |
||
92 | // qualifiers. To create the new command in the right namespace, we |
||
93 | // generate a fully qualified name for it. |
||
94 | |||
95 | ds = new StringBuilder(); |
||
96 | if ( ns != NamespaceCmd.getGlobalNamespace( interp ) ) |
||
97 | { |
||
98 | ds.Append( ns.fullName ); |
||
99 | ds.Append( "::" ); |
||
100 | } |
||
101 | ds.Append( procName ); |
||
102 | |||
103 | interp.createCommand( ds.ToString(), proc ); |
||
104 | |||
105 | // Now initialize the new procedure's cmdPtr field. This will be used |
||
106 | // later when the procedure is called to determine what namespace the |
||
107 | // procedure will run in. This will be different than the current |
||
108 | // namespace if the proc was renamed into a different namespace. |
||
109 | |||
110 | // FIXME : we do not handle renaming into another namespace correctly yet! |
||
111 | //procPtr->cmdPtr = (Command *) cmd; |
||
112 | |||
113 | return TCL.CompletionCode.RETURN; |
||
114 | } |
||
115 | } |
||
116 | } |