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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
//
// GENERATED FILE
//
use super::*;
use f2rust_std::*;
const RECLEN: i32 = 32;
const SHRT: i32 = (RECLEN / 2);
//$Procedure F_ZZASC1 ( Family of tests for ZZASCII )
pub fn F_ZZASC1(OK: &mut bool, ctx: &mut Context) -> f2rust_std::Result<()> {
let mut FAIL = StackArray::<i32, 2>::new(1..=2);
let mut NATIVE: i32 = 0;
let mut IOSTAT: i32 = 0;
let mut NUMBER: i32 = 0;
let mut REC: i32 = 0;
let mut LINE = ActualCharArray::new(RECLEN, 1..=3);
let mut FILES = ActualCharArray::new(12, 1..=3);
let mut TERMIN = ActualCharArray::new(2, 1..=3);
let mut EXPECT = ActualCharArray::new(5, 1..=3);
let mut OUTTRM = [b' '; 5 as usize];
let mut WORD = [b' '; 5 as usize];
let mut WRKLIN = [b' '; 50 as usize];
let mut SHRTLN = [b' '; SHRT as usize];
let mut XSHRTL = [b' '; 2 as usize];
//
// Write ascii text containing line terminators
// for each platform, Macintosh classic, Unix,
// and DOS.
//
//
// SPICELIB functions.
//
//
// Open the test family.
//
testutil::TOPEN(b"F_ZZASC1", ctx)?;
//
// Define the data to write to test files. ID the
// file as an LSK kernel, with a begin text block - thus
// we don't risk damaging any kernel pool variable
// assignments. The third line contains the data to write.
// Thirty-two characters written forty times.
//
fstr::assign(LINE.get_mut(1), b"KPL/LSK ");
fstr::assign(LINE.get_mut(2), b"\\begintext ");
fstr::assign(LINE.get_mut(3), b"12345678901234567890123456789012");
//
// Initialize the file names and the corresponding line
// terminators.
//
fstr::assign(FILES.get_mut(1), b"mac.ker");
fstr::assign(FILES.get_mut(2), b"unix.ker");
fstr::assign(FILES.get_mut(3), b"dos.ker");
fstr::assign(
fstr::substr_mut(TERMIN.get_mut(1), 1..=2),
&intrinsics::CHAR(13),
);
fstr::assign(
fstr::substr_mut(TERMIN.get_mut(2), 1..=2),
&intrinsics::CHAR(10),
);
fstr::assign(
fstr::substr_mut(TERMIN.get_mut(3), 1..=2),
&fstr::concat(&intrinsics::CHAR(13), &intrinsics::CHAR(10)),
);
fstr::assign(EXPECT.get_mut(1), b"CR");
fstr::assign(EXPECT.get_mut(2), b"LF");
fstr::assign(EXPECT.get_mut(3), b"CR-LF");
//
// Initialize the REC marker value. Start from the
// beginning of the file.
//
REC = 1;
//
// Loop over the three terminator types. Create
// a test file with an appropriate name for the terminator
// character.
//
for I in 1..=3 {
//
// If the test file exists, delete it.
//
if spicelib::EXISTS(&FILES[I], ctx)? {
testutil::KILFIL(&FILES[I], ctx)?;
}
//
// Find a free logical unit for file access.
//
spicelib::GETLUN(&mut NUMBER, ctx)?;
//
// Open the file as direct access thus suppressing the print
// of a native line terminator.
//
{
use f2rust_std::io;
let specs = io::OpenSpecs {
unit: Some(NUMBER),
file: Some(FILES.get(I)),
access: Some(b"DIRECT"),
status: Some(b"NEW"),
recl: Some(RECLEN),
..Default::default()
};
IOSTAT = io::capture_iostat(|| ctx.open(specs))?;
}
//
// Add the terminator to the first line.
//
fstr::assign(fstr::substr_mut(LINE.get_mut(1), 31..=32), TERMIN.get(I));
//
// Write the line to record REC then increment REC.
//
{
use f2rust_std::{
data::Val,
io::{self, Writer},
};
let mut writer = io::UnformattedWriter::new(ctx.io_unit(NUMBER)?, Some(REC))?;
writer.start()?;
writer.write_str(fstr::substr(LINE.get(1), 1..=32))?;
writer.finish()?;
}
REC = (REC + 1);
//
// Add the terminator to the second line.
//
fstr::assign(fstr::substr_mut(LINE.get_mut(2), 31..=32), TERMIN.get(I));
//
// Write the line to record REC then increment REC.
//
{
use f2rust_std::{
data::Val,
io::{self, Writer},
};
let mut writer = io::UnformattedWriter::new(ctx.io_unit(NUMBER)?, Some(REC))?;
writer.start()?;
writer.write_str(fstr::substr(LINE.get(2), 1..=32))?;
writer.finish()?;
}
REC = (REC + 1);
//
// Add the terminator to the third data line. We
// write this line 40 times to create a kernel file
// larger than 1032 (the record size read by GETFAT).
//
fstr::assign(fstr::substr_mut(LINE.get_mut(3), 31..=32), TERMIN.get(I));
//
// Write the line, incrementing the record counter each
// pass.
//
for J in 1..=40 {
{
use f2rust_std::{
data::Val,
io::{self, Writer},
};
let mut writer = io::UnformattedWriter::new(ctx.io_unit(NUMBER)?, Some(REC))?;
writer.start()?;
writer.write_str(fstr::substr(LINE.get(3), 1..=32))?;
writer.finish()?;
}
REC = (REC + 1);
}
//
// Finished. Close this file, reset the REC marker for the
// next file.
//
{
use f2rust_std::io;
let specs = io::CloseSpecs {
unit: Some(NUMBER),
..Default::default()
};
ctx.close(specs)?;
}
REC = 1;
}
//
// Case 1
//
testutil::TCASE(b"Check for correct terminator ID", ctx)?;
//
// Start tests. Check the correct response for each file.
// Note, the length of WRKLIN must exceed the declared length of
// the LINE variable for the test to succeed.
//
for I in 1..=3 {
spicelib::ZZASCII(&FILES[I], &mut WRKLIN, false, &mut OUTTRM, ctx)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
testutil::CHCKSC(b"Terminator", &OUTTRM, b"=", &EXPECT[I], OK, ctx)?;
}
//
// Case 2
//
testutil::TCASE(b"Check for failure for short line", ctx)?;
//
// Test that a scan fails when using a line length shorter than
// the line length of the first line in the file of interest.
// In this case we know the test kernels have line
// lengths of thirty-two.
//
for I in 1..=3 {
spicelib::ZZASCII(&FILES[I], &mut SHRTLN, false, &mut OUTTRM, ctx)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
testutil::CHCKSC(b"Terminator", &OUTTRM, b"=", b"?", OK, ctx)?;
}
//
// Retrieve the proper line terminator for the platform.
//
spicelib::ZZPLATFM(b"TEXT_FORMAT", &mut WORD, ctx);
//
// Set the index for the native terminator.
//
if spicelib::EQSTR(&WORD, &EXPECT[1]) {
NATIVE = 1;
FAIL[1] = 2;
FAIL[2] = 3;
} else if spicelib::EQSTR(&WORD, &EXPECT[2]) {
NATIVE = 2;
FAIL[1] = 1;
FAIL[2] = 3;
} else if spicelib::EQSTR(&WORD, &EXPECT[3]) {
NATIVE = 3;
FAIL[1] = 1;
FAIL[2] = 2;
} else {
//
// BAD BUG! This block should never execute.
//
testutil::CHCKXC(true, b"UNKNOWNLINETERMINATOR", OK, ctx)?;
//
// Clean-up. Delete files.
//
for I in 1..=3 {
testutil::KILFIL(&FILES[I], ctx)?;
}
//
// Close out the test family.
//
testutil::T_SUCCESS(OK, ctx);
return Ok(());
}
//
// Case 3
//
testutil::TCASE(b"Check for correct FURNSH response, native.", ctx)?;
//
// Check a native file passes through a FURNSH call without
// an error signal.
//
spicelib::FURNSH(&FILES[NATIVE], ctx)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
//
// Unload the kernel so we don't mess-up another kernel
// test family.
//
spicelib::UNLOAD(&FILES[NATIVE], ctx)?;
//
// Case 4
//
testutil::TCASE(b"Check for correct FURNSH response, non-native.", ctx)?;
//
// Check a non-native file causes an error signal when used in a
// FURNSH call.
//
spicelib::FURNSH(&FILES[FAIL[1]], ctx)?;
testutil::CHCKXC(true, b"SPICE(INCOMPATIBLEEOL)", OK, ctx)?;
spicelib::FURNSH(&FILES[FAIL[2]], ctx)?;
testutil::CHCKXC(true, b"SPICE(INCOMPATIBLEEOL)", OK, ctx)?;
//
// Case 5
//
testutil::TCASE(b"Check for ZZASCII short work line signal.", ctx)?;
//
// Ensure ZZASCII signals an error for work line lengths
// below the 3 character threshold.
//
spicelib::ZZASCII(&FILES[NATIVE], &mut XSHRTL, false, &mut OUTTRM, ctx)?;
testutil::CHCKXC(true, b"SPICE(STRINGTOOSHORT)", OK, ctx)?;
//
// Clean-up. Delete files.
//
for I in 1..=3 {
testutil::KILFIL(&FILES[I], ctx)?;
}
//
// Close out the test family.
//
testutil::T_SUCCESS(OK, ctx);
Ok(())
}