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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
//
// GENERATED FILE
//
use super::*;
use f2rust_std::*;
const FTSIZE: i32 = 5000;
const RSVUNT: i32 = 2;
const SCRUNT: i32 = 1;
const UTSIZE: i32 = ((20 + SCRUNT) + RSVUNT);
const READ: i32 = 1;
const WRITE: i32 = 2;
const SCRTCH: i32 = 3;
const NEW: i32 = 4;
const NUMAMH: i32 = 4;
const BIGI3E: i32 = 1;
const LTLI3E: i32 = 2;
const VAXGFL: i32 = 3;
const VAXDFL: i32 = 4;
const NUMBFF: i32 = 4;
const STRSIZ: i32 = 8;
const STRLEN: i32 = ((STRSIZ + 1) * NUMBFF);
const DAF: i32 = 1;
const DAS: i32 = 2;
const NUMARC: i32 = 2;
const RECL: i32 = 1024;
const FILEN: i32 = 255;
const CBFSIZ: i32 = 1024;
const SIZSTR: i32 = 16;
const SIZEXP: i32 = (3 * SIZSTR);
const SIZEND: i32 = 6;
const SIZFTP: i32 = (SIZSTR + (2 * SIZEND));
const SIZDLM: i32 = 1;
const NUMTST: i32 = 6;
const RECLEN: i32 = 1024;
const DASBIL: i32 = 85;
const DASFTP: i32 = 700;
const DAFFTP: i32 = 700;
//$Procedure T_CPTFIL ( Create Partial Test Files )
pub fn T_CPTFIL(
NAME: &[u8],
ARCH: i32,
FDREC: i32,
BFFID: &[u8],
CNI: &[u8],
CFDREC: &[u8],
CNSUM: &[u8],
ADDFTP: bool,
BRKFTP: bool,
NEWIDW: &[u8],
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let mut RECORD = [b' '; RECLEN as usize];
let mut DELIM = [b' '; SIZDLM as usize];
let mut FTPSTR = [b' '; SIZFTP as usize];
let mut LFTBKT = [b' '; SIZEND as usize];
let mut RGTBKT = [b' '; SIZEND as usize];
let mut TSTSTR = [b' '; SIZSTR as usize];
let mut LUN: i32 = 0;
let mut IOSTAT: i32 = 0;
//
// SPICELIB Functions
//
//
// Local Parameters
//
//
// Local Variables
//
//
// Standard SPICE error handling
//
if spicelib::RETURN(ctx) {
return Ok(());
} else {
spicelib::CHKIN(b"T_CPTFIL", ctx)?;
}
//
// Fetch the logical unit we're going to use to create the
// file.
//
spicelib::GETLUN(&mut LUN, ctx)?;
//
// Open the file we are about to construct.
//
{
use f2rust_std::io;
let specs = io::OpenSpecs {
unit: Some(LUN),
file: Some(NAME),
access: Some(b"DIRECT"),
recl: Some(RECL),
status: Some(b"NEW"),
..Default::default()
};
IOSTAT = io::capture_iostat(|| ctx.open(specs))?;
}
//
// Check IOSTAT for trouble.
//
//
if (IOSTAT != 0) {
{
use f2rust_std::io;
let specs = io::CloseSpecs {
unit: Some(LUN),
..Default::default()
};
ctx.close(specs)?;
}
spicelib::SETMSG(b"Attempt to open file, \'#\', failed. IOSTAT was $.", ctx);
spicelib::ERRCH(b"#", NAME, ctx);
spicelib::ERRINT(b"$", IOSTAT, ctx);
spicelib::SIGERR(b"SPICE(FILEOPENFAILED)", ctx)?;
spicelib::CHKOUT(b"T_CPTFIL", ctx)?;
return Ok(());
}
//
// Initialize RECORD to be a blank string.
//
fstr::assign(&mut RECORD, b" ");
//
// Do the absolute minimum to produce the necessary test file.
// In this regard we will be placing only the patterns necessary
// to exercise the logic of ZZDDHIFF and not focusing on the creation
// of legitmate DAF and DAS files.
//
if (ARCH == DAF) {
//
// Assemble the file record.
//
fstr::assign(fstr::substr_mut(&mut RECORD, 1..=8), b"DAF/TEST");
fstr::assign(fstr::substr_mut(&mut RECORD, 13..=16), CNI);
fstr::assign(fstr::substr_mut(&mut RECORD, 77..=80), CFDREC);
fstr::assign(fstr::substr_mut(&mut RECORD, 89..=96), BFFID);
//
// Before going any further, check to see if we are to replace
// the ID word with NEWIDW.
//
if fstr::ne(NEWIDW, b" ") {
fstr::assign(
fstr::substr_mut(&mut RECORD, 1..=8),
fstr::substr(NEWIDW, 1..=8),
);
}
if ADDFTP {
//
// Get the FTP string.
//
spicelib::ZZFTPSTR(&mut TSTSTR, &mut LFTBKT, &mut RGTBKT, &mut DELIM, ctx);
fstr::assign(
&mut FTPSTR,
&fstr::concat(
&fstr::concat(
fstr::substr(&LFTBKT, 1..=spicelib::RTRIM(&LFTBKT)),
fstr::substr(&TSTSTR, 1..=spicelib::RTRIM(&TSTSTR)),
),
fstr::substr(&RGTBKT, 1..=spicelib::RTRIM(&RGTBKT)),
),
);
//
// Check to see if we are to "break" the FTP string.
//
if BRKFTP {
//
// Replace the "<13>" in the first cluster with
// "<10>" to generate the error.
//
fstr::assign(
fstr::substr_mut(
&mut FTPSTR,
(spicelib::RTRIM(&LFTBKT) + 2)..=(spicelib::RTRIM(&LFTBKT) + 2),
),
&intrinsics::CHAR(10),
);
}
//
// Add the FTP string at position DASFTP.
//
fstr::assign(fstr::substr_mut(&mut RECORD, DAFFTP..), &FTPSTR);
}
//
// Write the record.
//
{
use f2rust_std::{
data::Val,
io::{self, Writer},
};
let mut writer = io::UnformattedWriter::new(ctx.io_unit(LUN)?, Some(1))?;
IOSTAT = io::capture_iostat(|| {
writer.start()?;
writer.write_str(&RECORD)?;
writer.finish()?;
Ok(())
})?;
}
//
// Now create the first descriptor record.
//
fstr::assign(fstr::substr_mut(&mut RECORD, 1..=16), b" ");
fstr::assign(fstr::substr_mut(&mut RECORD, 17..=24), CNSUM);
fstr::assign(fstr::substr_mut(&mut RECORD, 25..=42), b" ");
{
use f2rust_std::{
data::Val,
io::{self, Writer},
};
let mut writer = io::UnformattedWriter::new(ctx.io_unit(LUN)?, Some(FDREC))?;
IOSTAT = io::capture_iostat(|| {
writer.start()?;
writer.write_str(&RECORD)?;
writer.finish()?;
Ok(())
})?;
}
//
// Check IOSTAT for trouble.
//
if (IOSTAT != 0) {
spicelib::SETMSG(b"Attempt to write file \'#\' failed. Value of IOSTAT was #. The file has been deleted.", ctx);
spicelib::ERRFNM(b"#", LUN, ctx)?;
spicelib::ERRINT(b"#", IOSTAT, ctx);
{
use f2rust_std::io;
let specs = io::CloseSpecs {
unit: Some(LUN),
status: Some(b"DELETE"),
..Default::default()
};
ctx.close(specs)?;
}
spicelib::SIGERR(b"SPICE(WRITEFAILURE)", ctx)?;
spicelib::CHKOUT(b"T_CPTFIL", ctx)?;
return Ok(());
}
//
// We've created the test file, close the UNIT since we will be
// re-opening it from the test code driver.
//
{
use f2rust_std::io;
let specs = io::CloseSpecs {
unit: Some(LUN),
..Default::default()
};
ctx.close(specs)?;
}
} else if (ARCH == DAS) {
//
// We need only to place the BFF ID string in the appropriate
// place in the file record along with the DAS indentifier.
//
fstr::assign(fstr::substr_mut(&mut RECORD, 1..=8), b"DAS/TEST");
fstr::assign(fstr::substr_mut(&mut RECORD, DASBIL..=(DASBIL + 7)), BFFID);
//
// Before going any further, check to see if we are to replace
// the ID word with NEWIDW.
//
if fstr::ne(NEWIDW, b" ") {
fstr::assign(
fstr::substr_mut(&mut RECORD, 1..=8),
fstr::substr(NEWIDW, 1..=8),
);
}
if ADDFTP {
//
// Get the FTP string.
//
spicelib::ZZFTPSTR(&mut TSTSTR, &mut LFTBKT, &mut RGTBKT, &mut DELIM, ctx);
fstr::assign(
&mut FTPSTR,
&fstr::concat(
&fstr::concat(
fstr::substr(&LFTBKT, 1..=spicelib::RTRIM(&LFTBKT)),
fstr::substr(&TSTSTR, 1..=spicelib::RTRIM(&TSTSTR)),
),
fstr::substr(&RGTBKT, 1..=spicelib::RTRIM(&RGTBKT)),
),
);
//
// Check to see if we are to "break" the FTP string.
//
if BRKFTP {
//
// Replace the "<13>" in the first cluster with
// "<10>" to generate the error.
//
fstr::assign(
fstr::substr_mut(
&mut FTPSTR,
(spicelib::RTRIM(&LFTBKT) + 2)..=(spicelib::RTRIM(&LFTBKT) + 2),
),
&intrinsics::CHAR(10),
);
}
//
// Add the FTP string at position DASFTP.
//
fstr::assign(fstr::substr_mut(&mut RECORD, DASFTP..), &FTPSTR);
}
//
// Write the record.
//
{
use f2rust_std::{
data::Val,
io::{self, Writer},
};
let mut writer = io::UnformattedWriter::new(ctx.io_unit(LUN)?, Some(1))?;
IOSTAT = io::capture_iostat(|| {
writer.start()?;
writer.write_str(&RECORD)?;
writer.finish()?;
Ok(())
})?;
}
//
// Check IOSTAT for trouble.
//
if (IOSTAT != 0) {
spicelib::SETMSG(b"Attempt to write file \'#\' failed. Value of IOSTAT was #. The file has been deleted.", ctx);
spicelib::ERRFNM(b"#", LUN, ctx)?;
spicelib::ERRINT(b"#", IOSTAT, ctx);
{
use f2rust_std::io;
let specs = io::CloseSpecs {
unit: Some(LUN),
status: Some(b"DELETE"),
..Default::default()
};
ctx.close(specs)?;
}
spicelib::SIGERR(b"SPICE(WRITEFAILURE)", ctx)?;
spicelib::CHKOUT(b"T_CPTFIL", ctx)?;
return Ok(());
}
//
// We've created the test file, close the UNIT since we will be
// re-opening it from the test code driver.
//
{
use f2rust_std::io;
let specs = io::CloseSpecs {
unit: Some(LUN),
..Default::default()
};
ctx.close(specs)?;
}
} else {
spicelib::SETMSG(b"Unknown architecture code.", ctx);
spicelib::SIGERR(b"SPICE(BUG)", ctx)?;
spicelib::CHKOUT(b"T_CPTFIL", ctx)?;
return Ok(());
}
spicelib::CHKOUT(b"T_CPTFIL", ctx)?;
Ok(())
}