wasCSharpSQLite – Blame information for rev 4
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /* |
2 | * PutsCmd.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: IfCmd.java,v 1.2 2003/02/07 03:41:49 mdejong Exp $ |
||
14 | * |
||
15 | */ |
||
16 | using System; |
||
17 | namespace tcl.lang |
||
18 | { |
||
19 | |||
20 | /// <summary> This class implements the built-in "if" command in Tcl.</summary> |
||
21 | class IfCmd : Command |
||
22 | { |
||
23 | |||
24 | /// <summary> See Tcl user documentation for details.</summary> |
||
25 | /// <exception cref=""> TclException If incorrect number of arguments. |
||
26 | /// </exception> |
||
27 | public TCL.CompletionCode cmdProc( Interp interp, TclObject[] argv ) |
||
28 | { |
||
29 | int i; |
||
30 | bool value; |
||
31 | |||
32 | i = 1; |
||
33 | while ( true ) |
||
34 | { |
||
35 | /* |
||
36 | * At this point in the loop, argv and argc refer to an |
||
37 | * expression to test, either for the main expression or |
||
38 | * an expression following an "elseif". The arguments |
||
39 | * after the expression must be "then" (optional) and a |
||
40 | * script to execute if the expression is true. |
||
41 | */ |
||
42 | |||
43 | if ( i >= argv.Length ) |
||
44 | { |
||
45 | |||
46 | throw new TclException( interp, "wrong # args: no expression after \"" + argv[i - 1] + "\" argument" ); |
||
47 | } |
||
48 | try |
||
49 | { |
||
50 | |||
51 | value = interp.expr.evalBoolean( interp, argv[i].ToString() ); |
||
52 | } |
||
53 | catch ( TclException e ) |
||
54 | { |
||
55 | switch ( e.getCompletionCode() ) |
||
56 | { |
||
57 | |||
58 | case TCL.CompletionCode.ERROR: |
||
59 | interp.addErrorInfo( "\n (\"if\" test expression)" ); |
||
60 | break; |
||
61 | } |
||
62 | throw; |
||
63 | } |
||
64 | |||
65 | i++; |
||
66 | |||
67 | if ( ( i < argv.Length ) && ( argv[i].ToString().Equals( "then" ) ) ) |
||
68 | { |
||
69 | i++; |
||
70 | } |
||
71 | if ( i >= argv.Length ) |
||
72 | { |
||
73 | |||
74 | throw new TclException( interp, "wrong # args: no script following \"" + argv[i - 1] + "\" argument" ); |
||
75 | } |
||
76 | if ( value ) |
||
77 | { |
||
78 | try |
||
79 | { |
||
80 | interp.eval( argv[i], 0 ); |
||
81 | } |
||
82 | catch ( TclException e ) |
||
83 | { |
||
84 | switch ( e.getCompletionCode() ) |
||
85 | { |
||
86 | |||
87 | case TCL.CompletionCode.ERROR: |
||
88 | interp.addErrorInfo( "\n (\"if\" then script line " + interp.errorLine + ")" ); |
||
89 | break; |
||
90 | } |
||
91 | throw; |
||
92 | } |
||
93 | return TCL.CompletionCode.RETURN; |
||
94 | } |
||
95 | |||
96 | /* |
||
97 | * The expression evaluated to false. Skip the command, then |
||
98 | * see if there is an "else" or "elseif" clause. |
||
99 | */ |
||
100 | |||
101 | i++; |
||
102 | if ( i >= argv.Length ) |
||
103 | { |
||
104 | interp.resetResult(); |
||
105 | return TCL.CompletionCode.RETURN; |
||
106 | } |
||
107 | |||
108 | if ( argv[i].ToString().Equals( "elseif" ) ) |
||
109 | { |
||
110 | i++; |
||
111 | continue; |
||
112 | } |
||
113 | break; |
||
114 | } |
||
115 | |||
116 | /* |
||
117 | * Couldn't find a "then" or "elseif" clause to execute. |
||
118 | * Check now for an "else" clause. We know that there's at |
||
119 | * least one more argument when we get here. |
||
120 | */ |
||
121 | |||
122 | |||
123 | if ( argv[i].ToString().Equals( "else" ) ) |
||
124 | { |
||
125 | i++; |
||
126 | if ( i >= argv.Length ) |
||
127 | { |
||
128 | throw new TclException( interp, "wrong # args: no script following \"else\" argument" ); |
||
129 | } |
||
130 | else if ( i != ( argv.Length - 1 ) ) |
||
131 | { |
||
132 | throw new TclException( interp, "wrong # args: extra words after \"else\" clause in " + "\"if\" command" ); |
||
133 | } |
||
134 | } |
||
135 | try |
||
136 | { |
||
137 | interp.eval( argv[i], 0 ); |
||
138 | } |
||
139 | catch ( TclException e ) |
||
140 | { |
||
141 | switch ( e.getCompletionCode() ) |
||
142 | { |
||
143 | |||
144 | case TCL.CompletionCode.ERROR: |
||
145 | interp.addErrorInfo( "\n (\"if\" else script line " + interp.errorLine + ")" ); |
||
146 | break; |
||
147 | } |
||
148 | throw; |
||
149 | } |
||
150 | return TCL.CompletionCode.RETURN; |
||
151 | } |
||
152 | } |
||
153 | } |