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
//
// 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 IDWLEN: i32 = 8;
const IFNLEN: i32 = 60;
const NWC: i32 = 1024;
const BEGIDW: i32 = 1;
const ENDIDW: i32 = 8;
const BEGIFN: i32 = 9;
const ENDIFN: i32 = 68;
const BEGNRR: i32 = 69;
const ENDNRR: i32 = 72;
const BEGNRC: i32 = 73;
const ENDNRC: i32 = 76;
const BEGNCR: i32 = 77;
const ENDNCR: i32 = 80;
const BEGNCC: i32 = 81;
const ENDNCC: i32 = 84;
struct SaveVars {
NATBFF: i32,
FIRST: bool,
}
impl SaveInit for SaveVars {
fn new() -> Self {
let mut NATBFF: i32 = 0;
let mut FIRST: bool = false;
FIRST = true;
NATBFF = -1;
Self { NATBFF, FIRST }
}
}
//$Procedure ZZDASRFR ( DAS, read file record )
pub fn ZZDASRFR(
HANDLE: i32,
IDWORD: &mut [u8],
IFNAME: &mut [u8],
NRESVR: &mut i32,
NRESVC: &mut i32,
NCOMR: &mut i32,
NCOMC: &mut i32,
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let save = ctx.get_vars::<SaveVars>();
let save = &mut *save.borrow_mut();
let mut CHRBUF = [b' '; NWC as usize];
let mut TMPIDW = [b' '; IDWLEN as usize];
let mut TMPIFN = [b' '; IFNLEN as usize];
let mut IBFF: i32 = 0;
let mut IOSTAT: i32 = 0;
let mut UNIT: i32 = 0;
//
// SPICELIB functions
//
//
// Local parameters
//
//
// Parameters for positions of file record elements:
//
//
// ID word begin and end:
//
//
// Internal file name begin and end:
//
//
// Reserved record count begin and end:
//
//
// Reserved record character count begin and end:
//
//
// Comment area record count begin and end:
//
//
// Comment area character count begin and end:
//
//
// Local variables
//
//
// Saved variables
//
//
// Initial values
//
//
// Standard SPICE error handling.
//
if RETURN(ctx) {
return Ok(());
}
CHKIN(b"ZZDASRFR", ctx)?;
//
// On the first pass through this routine, get the integer code of
// the host system's native binary file format.
//
if save.FIRST {
ZZDDHNFC(&mut save.NATBFF, ctx)?;
if FAILED(ctx) {
CHKOUT(b"ZZDASRFR", ctx)?;
return Ok(());
}
save.FIRST = false;
}
//
// Get a logical unit for this DAS file.
//
ZZDDHHLU(HANDLE, b"DAS", false, &mut UNIT, ctx)?;
//
// Get the integer code for the file's binary format.
//
ZZDDHPPF(UNIT, DAS, &mut IBFF, ctx)?;
if FAILED(ctx) {
CHKOUT(b"ZZDASRFR", ctx)?;
return Ok(());
}
if (IBFF == save.NATBFF) {
//
// We're looking at a native file. Just read the file record.
//
{
use f2rust_std::{
data::Val,
io::{self, Reader},
};
let mut reader = io::UnformattedReader::new(ctx.io_unit(UNIT)?, Some(1))?;
IOSTAT = io::capture_iostat(|| {
reader.start()?;
reader.read_str(&mut TMPIDW)?;
reader.read_str(&mut TMPIFN)?;
*NRESVR = reader.read_i32()?;
*NRESVC = reader.read_i32()?;
*NCOMR = reader.read_i32()?;
*NCOMC = reader.read_i32()?;
reader.finish()?;
Ok(())
})?;
}
if (IOSTAT != 0) {
SETMSG(
b"Could not DAS read file record. File was #. IOSTAT was #.",
ctx,
);
ERRFNM(b"#", UNIT, ctx)?;
ERRINT(b"#", IOSTAT, ctx);
SIGERR(b"SPICE(DASFILEREADFAILED)", ctx)?;
CHKOUT(b"ZZDASRFR", ctx)?;
return Ok(());
}
fstr::assign(IDWORD, &TMPIDW);
fstr::assign(IFNAME, &TMPIFN);
} else {
//
// The file is non-native.
//
// We don't check the access mode of the file, because we're
// not going to reject files that are open for writing.
//
// We'll read the file record as a character string and then
// pick it apart.
//
{
use f2rust_std::{
data::Val,
io::{self, Reader},
};
let mut reader = io::UnformattedReader::new(ctx.io_unit(UNIT)?, Some(1))?;
IOSTAT = io::capture_iostat(|| {
reader.start()?;
reader.read_str(&mut CHRBUF)?;
reader.finish()?;
Ok(())
})?;
}
if (IOSTAT != 0) {
SETMSG(b"Could not read DAS file record. File is #. IOSTAT was #. File\'s BFF integer code is #.", ctx);
ERRFNM(b"#", UNIT, ctx)?;
ERRINT(b"#", IOSTAT, ctx);
ERRINT(b"#", IBFF, ctx);
SIGERR(b"SPICE(DASFILEREADFAILED)", ctx)?;
CHKOUT(b"ZZDASRFR", ctx)?;
return Ok(());
}
//
// Set the string output arguments.
//
fstr::assign(IDWORD, fstr::substr(&CHRBUF, BEGIDW..=ENDIDW));
fstr::assign(IFNAME, fstr::substr(&CHRBUF, BEGIFN..=ENDIFN));
//
// The integer output arguments require translation.
//
ZZXLATEI(
IBFF,
fstr::substr(&CHRBUF, BEGNRR..=ENDNRR),
1,
std::slice::from_mut(NRESVR),
ctx,
)?;
ZZXLATEI(
IBFF,
fstr::substr(&CHRBUF, BEGNRC..=ENDNRC),
1,
std::slice::from_mut(NRESVC),
ctx,
)?;
ZZXLATEI(
IBFF,
fstr::substr(&CHRBUF, BEGNCR..=ENDNCR),
1,
std::slice::from_mut(NCOMR),
ctx,
)?;
ZZXLATEI(
IBFF,
fstr::substr(&CHRBUF, BEGNCC..=ENDNCC),
1,
std::slice::from_mut(NCOMC),
ctx,
)?;
}
CHKOUT(b"ZZDASRFR", ctx)?;
Ok(())
}