1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
//
// GENERATED FILE
//
use super::*;
use f2rust_std::*;
const MAXFNM: i32 = 80;
const MAXCNM: i32 = 1000;
const LNGSTR: i32 = 1200;
const WDSIZE: i32 = 32;
const MAXPLC: i32 = 7;
struct SaveVars {
SUCCES: bool,
CASEOK: bool,
CASENO: i32,
NFAIL: i32,
DESCR: Vec<u8>,
MYNAME: Vec<u8>,
MYACT: Vec<u8>,
TRACE: Vec<u8>,
RNAME: Vec<u8>,
DIGIT: ActualCharArray2D,
D: StackArray<i32, 7>,
J: i32,
INCR: bool,
ANYBAD: bool,
}
impl SaveInit for SaveVars {
fn new() -> Self {
let mut SUCCES: bool = false;
let mut CASEOK: bool = false;
let mut CASENO: i32 = 0;
let mut NFAIL: i32 = 0;
let mut DESCR = vec![b' '; MAXCNM as usize];
let mut MYNAME = vec![b' '; MAXCNM as usize];
let mut MYACT = vec![b' '; WDSIZE as usize];
let mut TRACE = vec![b' '; LNGSTR as usize];
let mut RNAME = vec![b' '; MAXFNM as usize];
let mut DIGIT = ActualCharArray2D::new(1, 1..=10, 1..=MAXPLC);
let mut D = StackArray::<i32, 7>::new(1..=MAXPLC);
let mut J: i32 = 0;
let mut INCR: bool = false;
let mut ANYBAD: bool = false;
ANYBAD = false;
SUCCES = true;
CASEOK = true;
CASENO = 0;
NFAIL = 0;
fstr::assign(&mut MYNAME, b" ");
fstr::assign(&mut DESCR, b" ");
fstr::assign(&mut RNAME, b" ");
Self {
SUCCES,
CASEOK,
CASENO,
NFAIL,
DESCR,
MYNAME,
MYACT,
TRACE,
RNAME,
DIGIT,
D,
J,
INCR,
ANYBAD,
}
}
}
//$Procedure T_STAT ( Test Status )
pub fn T_STAT(ACT: &[u8], NAME: &[u8], OK: bool, NUMBER: i32) {
//
// Local parameters
//
//
// Local Variables
//
//
// We enough digits to have unique text versions of case numbers
// for 10**7 cases.
//
//
// Saved variables
//
//
// Initial values
//
}
//$Procedure T_BEGIN ( Initialize test case family )
pub fn T_BEGIN(NAME: &[u8], ctx: &mut Context) {
let save = ctx.get_vars::<SaveVars>();
let save = &mut *save.borrow_mut();
//
// Until something goes wrong. All tests are assumed to pass.
// Store the name and current case number.
//
save.SUCCES = true;
fstr::assign(&mut save.RNAME, NAME);
save.CASENO = 0;
save.NFAIL = 0;
//
// Set up the "odometer" for the case counter. Note we put
// blanks instead of zeros for every digit but the least
// significant digit.
//
// Here's the idea. At each test case, we increment CASENO
// and flip over one digit on the case odometer. When we
// reach the 10 on any digit, we flip back to zero and
// cause the digit to the left to increment. The actual
// text version for the current case number will be:
//
// DIGIT(D(1),1)//DIGIT(D(2),2)// ... //DIGIT(D(MAXPLC),MAXPLC).
//
for I in 1..=MAXPLC {
fstr::assign(save.DIGIT.get_mut([1, I]), b" ");
fstr::assign(save.DIGIT.get_mut([2, I]), b"1");
fstr::assign(save.DIGIT.get_mut([3, I]), b"2");
fstr::assign(save.DIGIT.get_mut([4, I]), b"3");
fstr::assign(save.DIGIT.get_mut([5, I]), b"4");
fstr::assign(save.DIGIT.get_mut([6, I]), b"5");
fstr::assign(save.DIGIT.get_mut([7, I]), b"6");
fstr::assign(save.DIGIT.get_mut([8, I]), b"7");
fstr::assign(save.DIGIT.get_mut([9, I]), b"8");
fstr::assign(save.DIGIT.get_mut([10, I]), b"9");
save.D[I] = 1;
}
fstr::assign(save.DIGIT.get_mut([1, MAXPLC]), b"0");
}
//$Procedure T_NAME ( Return the name of the current family of tests )
pub fn T_NAME(NAME: &mut [u8], ctx: &mut Context) {
let save = ctx.get_vars::<SaveVars>();
let save = &mut *save.borrow_mut();
fstr::assign(NAME, &save.RNAME);
}
//$Procedure T_SUCCESS ( Return information on overall status of tests )
pub fn T_SUCCESS(OK: &mut bool, ctx: &mut Context) {
let save = ctx.get_vars::<SaveVars>();
let save = &mut *save.borrow_mut();
*OK = save.SUCCES;
}
//$Procedure T_FCOUNT ( Number of failed test cases )
pub fn T_FCOUNT(NUMBER: &mut i32, ctx: &mut Context) {
let save = ctx.get_vars::<SaveVars>();
let save = &mut *save.borrow_mut();
*NUMBER = save.NFAIL;
}
//$Procedure T_CASE ( Set up for the next test case )
pub fn T_CASE(NAME: &[u8], ctx: &mut Context) {
let save = ctx.get_vars::<SaveVars>();
let save = &mut *save.borrow_mut();
//
// Store the name, set this case success value to .TRUE. and
// increment the case number.
//
fstr::assign(&mut save.DESCR, NAME);
save.CASEOK = true;
save.CASENO = (save.CASENO + 1);
//
// Reset the error handling.
//
spicelib::RESET(ctx);
//
// Next we increment the odometer. We always increment the least
// significant digit.
//
save.INCR = true;
for I in intrinsics::range(MAXPLC, 1, -1) {
if save.INCR {
//
// If we incremented this digit, we will never want to use
// a blank (while in this test case) for this digit again.
// Set the first digit to zero "0".
//
save.D[I] = (save.D[I] + 1);
fstr::assign(save.DIGIT.get_mut([1, I]), b"0");
//
// If the current digit is not greater than 10, we need
// to set it back to 1 and cascade up to the next digit.
// That is, make sure INCR stays .TRUE.
//
if (save.D[I] > 10) {
save.D[I] = 1;
} else {
//
// In this case we do not need to increment any digit
// that is more significant than the current digit.
//
save.INCR = false;
}
}
}
}
//$Procedure T_CFAIL ( Records some aspects of failed test case )
pub fn T_CFAIL(ctx: &mut Context) {
let save = ctx.get_vars::<SaveVars>();
let save = &mut *save.borrow_mut();
if save.CASEOK {
save.NFAIL = (save.NFAIL + 1);
}
save.ANYBAD = true;
save.CASEOK = false;
save.SUCCES = false;
}
//$Procedure T_CPASS ( Return status of current test case )
pub fn T_CPASS(OK: &mut bool, ctx: &mut Context) {
let save = ctx.get_vars::<SaveVars>();
let save = &mut *save.borrow_mut();
*OK = save.CASEOK;
}
//$Procedure T_CNUM ( Number of current test case )
pub fn T_CNUM(NUMBER: &mut i32, ctx: &mut Context) {
let save = ctx.get_vars::<SaveVars>();
let save = &mut *save.borrow_mut();
*NUMBER = save.CASENO;
}
//$Procedure T_CNAME ( Return the name of the current test case )
pub fn T_CNAME(NAME: &mut [u8], ctx: &mut Context) {
let save = ctx.get_vars::<SaveVars>();
let save = &mut *save.borrow_mut();
fstr::assign(&mut save.MYNAME, b"Test Case ");
save.J = 10;
//
// Append each non-blank digit (starting with the most
// significant) to the current value of MYNAME.
//
for I in 1..=MAXPLC {
if fstr::ne(save.DIGIT.get([save.D[I], I]), b" ") {
save.J = (save.J + 1);
fstr::assign(
fstr::substr_mut(&mut save.MYNAME, save.J..=save.J),
save.DIGIT.get([save.D[I], I]),
);
}
}
//
// Place a period after the case number.
//
save.J = (save.J + 1);
fstr::assign(fstr::substr_mut(&mut save.MYNAME, save.J..=save.J), b".");
//
// Follow that up with the case description.
//
save.J = (save.J + 2);
fstr::assign(fstr::substr_mut(&mut save.MYNAME, save.J..), &save.DESCR);
fstr::assign(NAME, &save.MYNAME);
}
//$Procedure T_ANYBAD ( Was there any failed case? )
pub fn T_ANYBAD(OK: &mut bool, ctx: &mut Context) {
let save = ctx.get_vars::<SaveVars>();
let save = &mut *save.borrow_mut();
*OK = save.ANYBAD;
}
//$Procedure T_TRACE ( Set or get the last stored value of traceback )
pub fn T_TRACE(ACT: &[u8], NAME: &mut [u8], ctx: &mut Context) {
let save = ctx.get_vars::<SaveVars>();
let save = &mut *save.borrow_mut();
spicelib::LJUST(ACT, &mut save.MYACT);
spicelib::UCASE(&save.MYACT.to_vec(), &mut save.MYACT, ctx);
if fstr::eq(&save.MYACT, b"SET") {
fstr::assign(&mut save.TRACE, NAME);
} else if fstr::eq(&save.MYACT, b"GET") {
fstr::assign(NAME, &save.TRACE);
}
}