wasCSharpSQLite – Blame information for rev 4
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /* |
2 | * CaseCmd.java |
||
3 | * |
||
4 | * Copyright (c) 1997 Sun Microsystems, Inc. |
||
5 | * |
||
6 | * See the file "license.terms" for information on usage and |
||
7 | * redistribution of this file, and for a DISCLAIMER OF ALL |
||
8 | * WARRANTIES. |
||
9 | * |
||
10 | * Included in SQLite3 port to C# for use in testharness only; 2008 Noah B Hart |
||
11 | * |
||
12 | * RCS @(#) $Id: CaseCmd.java,v 1.2 1999/05/08 23:52:18 dejong Exp $ |
||
13 | * |
||
14 | */ |
||
15 | using System; |
||
16 | namespace tcl.lang |
||
17 | { |
||
18 | |||
19 | /// <summary> This class implements the built-in "case" command in Tcl.</summary> |
||
20 | |||
21 | class CaseCmd : Command |
||
22 | { |
||
23 | /// <summary> Executes a "case" statement. See Tcl user |
||
24 | /// documentation for details. |
||
25 | /// |
||
26 | /// </summary> |
||
27 | /// <param name="interp">the current interpreter. |
||
28 | /// </param> |
||
29 | /// <param name="argv">command arguments. |
||
30 | /// </param> |
||
31 | /// <exception cref=""> TclException If incorrect number of arguments. |
||
32 | /// </exception> |
||
33 | |||
34 | public TCL.CompletionCode cmdProc( Interp interp, TclObject[] argv ) |
||
35 | { |
||
36 | if ( argv.Length < 3 ) |
||
37 | { |
||
38 | throw new TclNumArgsException( interp, 1, argv, "string ?in? patList body ... ?default body?" ); |
||
39 | } |
||
40 | |||
41 | int i; |
||
42 | int body; |
||
43 | TclObject[] caseArgv; |
||
44 | string inString; |
||
45 | |||
46 | |||
47 | inString = argv[1].ToString(); |
||
48 | caseArgv = argv; |
||
49 | body = -1; |
||
50 | |||
51 | |||
52 | if ( argv[2].ToString().Equals( "in" ) ) |
||
53 | { |
||
54 | i = 3; |
||
55 | } |
||
56 | else |
||
57 | { |
||
58 | i = 2; |
||
59 | } |
||
60 | |||
61 | /* |
||
62 | * If all of the pattern/command pairs are lumped into a single |
||
63 | * argument, split them out again. |
||
64 | */ |
||
65 | |||
66 | if ( argv.Length - i == 1 ) |
||
67 | { |
||
68 | caseArgv = TclList.getElements( interp, argv[i] ); |
||
69 | i = 0; |
||
70 | } |
||
71 | |||
72 | { |
||
73 | for ( ; i < caseArgv.Length; i += 2 ) |
||
74 | { |
||
75 | int j; |
||
76 | |||
77 | if ( i == ( caseArgv.Length - 1 ) ) |
||
78 | { |
||
79 | throw new TclException( interp, "extra case pattern with no body" ); |
||
80 | } |
||
81 | |||
82 | /* |
||
83 | * Check for special case of single pattern (no list) with |
||
84 | * no backslash sequences. |
||
85 | */ |
||
86 | |||
87 | |||
88 | string caseString = caseArgv[i].ToString(); |
||
89 | int len = caseString.Length; |
||
90 | for ( j = 0; j < len; j++ ) |
||
91 | { |
||
92 | char c = caseString[j]; |
||
93 | if ( System.Char.IsWhiteSpace( c ) || ( c == '\\' ) ) |
||
94 | { |
||
95 | break; |
||
96 | } |
||
97 | } |
||
98 | if ( j == len ) |
||
99 | { |
||
100 | if ( caseString.Equals( "default" ) ) |
||
101 | { |
||
102 | body = i + 1; |
||
103 | } |
||
104 | if ( Util.stringMatch( inString, caseString ) ) |
||
105 | { |
||
106 | body = i + 1; |
||
107 | goto match_loop_brk; |
||
108 | } |
||
109 | continue; |
||
110 | } |
||
111 | |||
112 | /* |
||
113 | * Break up pattern lists, then check each of the patterns |
||
114 | * in the list. |
||
115 | */ |
||
116 | |||
117 | int numPats = TclList.getLength( interp, caseArgv[i] ); |
||
118 | for ( j = 0; j < numPats; j++ ) |
||
119 | { |
||
120 | |||
121 | if ( Util.stringMatch( inString, TclList.index( interp, caseArgv[i], j ).ToString() ) ) |
||
122 | { |
||
123 | body = i + 1; |
||
124 | goto match_loop_brk; |
||
125 | } |
||
126 | } |
||
127 | } |
||
128 | } |
||
129 | |||
130 | match_loop_brk: |
||
131 | ; |
||
132 | |||
133 | |||
134 | if ( body != -1 ) |
||
135 | { |
||
136 | try |
||
137 | { |
||
138 | interp.eval( caseArgv[body], 0 ); |
||
139 | } |
||
140 | catch ( TclException e ) |
||
141 | { |
||
142 | if ( e.getCompletionCode() == TCL.CompletionCode.ERROR ) |
||
143 | { |
||
144 | |||
145 | interp.addErrorInfo( "\n (\"" + caseArgv[body - 1] + "\" arm line " + interp.errorLine + ")" ); |
||
146 | } |
||
147 | throw; |
||
148 | } |
||
149 | } |
||
150 | return TCL.CompletionCode.RETURN; |
||
151 | } |
||
152 | } |
||
153 | } |