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 ITRUE: i32 = 1;
const IFALSE: i32 = -1;
const CTRUE: &[u8] = b"T";
const CFALSE: &[u8] = b"F";
const CNAMSZ: i32 = 32;
const CDOFF: i32 = 24;
const CDSCSZ: i32 = 11;
const CLSIDX: i32 = 1;
const TYPIDX: i32 = (CLSIDX + 1);
const LENIDX: i32 = (TYPIDX + 1);
const SIZIDX: i32 = (LENIDX + 1);
const NAMIDX: i32 = (SIZIDX + 1);
const IXTIDX: i32 = (NAMIDX + 1);
const IXPIDX: i32 = (IXTIDX + 1);
const NFLIDX: i32 = (IXPIDX + 1);
const ORDIDX: i32 = (NFLIDX + 1);
const METIDX: i32 = (ORDIDX + 1);
const ENCSIZ: i32 = 5;
const CPSIZE: i32 = 1014;
const CFPIDX: i32 = (CPSIZE + 1);
const CLCIDX: i32 = (CFPIDX + ENCSIZ);
const DPSIZE: i32 = 126;
const DFPIDX: i32 = (DPSIZE + 1);
const DLCIDX: i32 = (DFPIDX + 1);
const IPSIZE: i32 = 254;
const IFPIDX: i32 = (IPSIZE + 1);
const ILCIDX: i32 = (IFPIDX + 1);
const OLD: i32 = 1;
const UPDATE: i32 = (OLD + 1);
const NEW: i32 = (UPDATE + 1);
const DELOLD: i32 = (NEW + 1);
const DELNEW: i32 = (DELOLD + 1);
const DELUPD: i32 = (DELNEW + 1);
const STAIDX: i32 = 1;
const RCPIDX: i32 = (STAIDX + 1);
const DPTBAS: i32 = 2;
const MXRPSZ: i32 = 254;
const UNINIT: i32 = -1;
const NULL: i32 = (UNINIT - 1);
const NOBACK: i32 = (NULL - 1);
const SDSCSZ: i32 = 24;
const EKTIDX: i32 = 1;
const SNOIDX: i32 = (EKTIDX + 1);
const IMDIDX: i32 = (SNOIDX + 1);
const TNMIDX: i32 = (IMDIDX + 1);
const NCIDX: i32 = (TNMIDX + 1);
const NRIDX: i32 = (NCIDX + 1);
const RTIDX: i32 = (NRIDX + 1);
const CPTIDX: i32 = (RTIDX + 1);
const DPTIDX: i32 = (CPTIDX + 1);
const IPTIDX: i32 = (DPTIDX + 1);
const MFLIDX: i32 = (IPTIDX + 1);
const IFLIDX: i32 = (MFLIDX + 1);
const SHDIDX: i32 = (IFLIDX + 1);
const CFHIDX: i32 = (SHDIDX + 1);
const CSNIDX: i32 = (CFHIDX + 1);
const LCPIDX: i32 = (CSNIDX + 1);
const LDPIDX: i32 = (LCPIDX + 1);
const LIPIDX: i32 = (LDPIDX + 1);
const LCWIDX: i32 = (LIPIDX + 1);
const LDWIDX: i32 = (LCWIDX + 1);
const LIWIDX: i32 = (LDWIDX + 1);
const NMLIDX: i32 = (LIWIDX + 1);
const CHR: i32 = 1;
const DP: i32 = 2;
const INT: i32 = 3;
const TIME: i32 = 4;
//$Procedure ZZEKRD06 ( EK, read class 6 column entry elements )
pub fn ZZEKRD06(
HANDLE: i32,
SEGDSC: &[i32],
COLDSC: &[i32],
RECPTR: i32,
BEG: i32,
END: i32,
CVALS: CharArrayMut,
ISNULL: &mut bool,
FOUND: &mut bool,
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let SEGDSC = DummyArray::new(SEGDSC, 1..=SDSCSZ);
let COLDSC = DummyArray::new(COLDSC, 1..=CDSCSZ);
let mut CVALS = DummyCharArrayMut::new(CVALS, None, 1..);
let mut COLUMN = [b' '; CNAMSZ as usize];
let mut AVAIL: i32 = 0;
let mut BASE: i32 = 0;
let mut COLIDX: i32 = 0;
let mut CVLEN: i32 = 0;
let mut D: i32 = 0;
let mut DATPTR: i32 = 0;
let mut DELTA: i32 = 0;
let mut ELTIDX: i32 = 0;
let mut ELTOFF: i32 = 0;
let mut MAXELT: i32 = 0;
let mut NCOLS: i32 = 0;
let mut NELT: i32 = 0;
let mut NREAD: i32 = 0;
let mut NSKIP: i32 = 0;
let mut OFFSET: i32 = 0;
let mut P: i32 = 0;
let mut PAGNUM: i32 = 0;
let mut PG: i32 = 0;
let mut PTRLOC: i32 = 0;
let mut PTROFF: i32 = 0;
let mut RECNO: i32 = 0;
let mut REMAIN: i32 = 0;
let mut START: i32 = 0;
let mut STRLEN: i32 = 0;
//
// SPICELIB functions
//
//
// Non-SPICELIB functions
//
//
// Local variables
//
//
// Use discovery check-in.
//
// Make sure the column exists.
//
NCOLS = SEGDSC[NCIDX];
COLIDX = COLDSC[ORDIDX];
if ((COLIDX < 1) || (COLIDX > NCOLS)) {
CHKIN(b"ZZEKRD06", ctx)?;
SETMSG(b"Column index = #; valid range is 1:#.", ctx);
ERRINT(b"#", COLIDX, ctx);
ERRINT(b"#", NCOLS, ctx);
SIGERR(b"SPICE(INVALIDINDEX)", ctx)?;
CHKOUT(b"ZZEKRD06", ctx)?;
return Ok(());
}
//
// Make sure the output buffer is wide enough to hold the returned
// strings.
//
CVLEN = intrinsics::LEN(&CVALS[1]);
STRLEN = COLDSC[LENIDX];
if (STRLEN > CVLEN) {
//
// We have a string truncation error. Look up the column
// name, record number, and file name before signaling an
// error.
//
ZZEKCNAM(HANDLE, COLDSC.as_slice(), &mut COLUMN, ctx)?;
RECNO = ZZEKRP2N(HANDLE, SEGDSC[SNOIDX], RECPTR, ctx)?;
CHKIN(b"ZZEKRD06", ctx)?;
SETMSG(b"String value has length #; output string can hold only # characters. COLUMN = #; SEGNO = #; RECNO = #; EK = #", ctx);
ERRINT(b"#", STRLEN, ctx);
ERRINT(b"#", CVLEN, ctx);
ERRCH(b"#", &COLUMN, ctx);
ERRINT(b"#", SEGDSC[SNOIDX], ctx);
ERRINT(b"#", RECNO, ctx);
ERRHAN(b"#", HANDLE, ctx)?;
SIGERR(b"SPICE(STRINGTRUNCATED)", ctx)?;
CHKOUT(b"ZZEKRD06", ctx)?;
return Ok(());
}
//
// Compute the data pointer location, and read the pointer.
//
PTRLOC = ((RECPTR + DPTBAS) + COLIDX);
DASRDI(
HANDLE,
PTRLOC,
PTRLOC,
std::slice::from_mut(&mut DATPTR),
ctx,
)?;
if (DATPTR > 0) {
//
// The entry is non-null.
//
*ISNULL = false;
//
// Get the element count. Check for range specifications that
// can't be met.
//
ZZEKGEI(HANDLE, DATPTR, &mut NELT, ctx)?;
if ((BEG < 1) || (BEG > NELT)) {
*FOUND = false;
return Ok(());
} else if ((END < 1) || (END > NELT)) {
*FOUND = false;
return Ok(());
} else if (END < BEG) {
*FOUND = false;
return Ok(());
}
//
// The request is valid, so read the data. The first step is to
// locate the element at index BEG. We'll first decide on which
// page the desired element starts. The first page holds up to
// CPSIZE - ENCSIZ characters; the rest hold CPSIZE characters.
// While we're at it, we'll compute the offset ELTOFF of the
// element from the base of the page on which the element starts.
// We'll use the name OFFSET to represent the character offset
// of the element from the base of the page on which the column
// entry starts.
//
ZZEKPGPG(CHR, DATPTR, &mut P, &mut BASE, ctx)?;
PTROFF = (DATPTR - BASE);
OFFSET = ((PTROFF + ENCSIZ) + (STRLEN * (BEG - 1)));
if (OFFSET <= CPSIZE) {
PAGNUM = 1;
ELTOFF = OFFSET;
} else {
PAGNUM = (((OFFSET + CPSIZE) - 1) / CPSIZE);
ELTOFF = (OFFSET - ((PAGNUM - 1) * CPSIZE));
}
//
// Get the absolute page number and base address of the page
// on which the element starts. If this is not the page on
// which the column entry starts, we'll chain along using
// the page's forward links until we arrive at the correct page.
//
PG = 1;
while (PG < PAGNUM) {
//
// Get the link to the next page, then look up the base
// address of that page.
//
ZZEKGEI(HANDLE, (BASE + CFPIDX), &mut P, ctx)?;
ZZEKPGBS(CHR, P, &mut BASE, ctx)?;
PG = (PG + 1);
}
//
// The desired element starts at address BASE + ELTOFF.
//
DATPTR = (BASE + ELTOFF);
//
// At this point, P is the page on which the element having index
// BEG is located. BASE is the base address of this page.
//
// Read the strings one at a time.
//
ELTIDX = 1;
MAXELT = ((END - BEG) + 1);
while ((ELTIDX <= MAXELT) && !FAILED(ctx)) {
//
// Read the current string. The string may be continued over
// multiple pages. Read only as many characters as will fit
// in the output buffer element CVALS(ELTIDX).
//
REMAIN = intrinsics::MIN0(&[CVLEN, STRLEN]);
START = 1;
while ((REMAIN > 0) && !FAILED(ctx)) {
AVAIL = (((BASE + CPSIZE) - DATPTR) + 1);
NREAD = intrinsics::MIN0(&[REMAIN, AVAIL]);
if (NREAD > 0) {
DASRDC(
HANDLE,
DATPTR,
((DATPTR + NREAD) - 1),
START,
((START + NREAD) - 1),
CVALS.subarray_mut(ELTIDX),
ctx,
)?;
START = (START + NREAD);
REMAIN = (REMAIN - NREAD);
DATPTR = (DATPTR + NREAD);
} else {
//
// Go to the next page for the continuation of the
// current string.
//
ZZEKGEI(HANDLE, (BASE + CFPIDX), &mut P, ctx)?;
ZZEKPGBS(CHR, P, &mut BASE, ctx)?;
DATPTR = (BASE + 1);
}
}
//
// If we did not read all of the current array element,
// we'll need to advance DATPTR past the end of the element.
// If this advance moved DATPTR beyond the last character
// of the current page, the logic above will set DATPTR to
// indicate the first character of the next continuation page.
//
DELTA = (STRLEN - CVLEN);
if (DELTA > 0) {
D = DELTA;
while (D > 0) {
AVAIL = (((BASE + CPSIZE) - DATPTR) + 1);
NSKIP = intrinsics::MIN0(&[D, AVAIL]);
if (NSKIP > 0) {
D = (D - NSKIP);
DATPTR = (DATPTR + NSKIP);
} else {
//
// Go to the next page for the continuation of the
// current string.
//
ZZEKGEI(HANDLE, (BASE + CFPIDX), &mut P, ctx)?;
ZZEKPGBS(CHR, P, &mut BASE, ctx)?;
DATPTR = (BASE + 1);
}
}
}
//
// Blank-pad the output string if necessary.
//
if (CVLEN > STRLEN) {
fstr::assign(
fstr::substr_mut(CVALS.get_mut(ELTIDX), (STRLEN + 1)..),
b" ",
);
}
ELTIDX = (ELTIDX + 1);
}
*FOUND = !FAILED(ctx);
} else if (DATPTR == NULL) {
//
// The value is null.
//
*ISNULL = true;
*FOUND = true;
} else if (DATPTR == UNINIT) {
//
// The data value is absent. This is an error.
//
RECNO = ZZEKRP2N(HANDLE, SEGDSC[SNOIDX], RECPTR, ctx)?;
ZZEKCNAM(HANDLE, COLDSC.as_slice(), &mut COLUMN, ctx)?;
CHKIN(b"ZZEKRD06", ctx)?;
SETMSG(b"Attempted to read uninitialized column entry. SEGNO = #; COLUMN = #; RECNO = #; EK = #", ctx);
ERRINT(b"#", SEGDSC[SNOIDX], ctx);
ERRCH(b"#", &COLUMN, ctx);
ERRINT(b"#", RECNO, ctx);
ERRHAN(b"#", HANDLE, ctx)?;
SIGERR(b"SPICE(UNINITIALIZED)", ctx)?;
CHKOUT(b"ZZEKRD06", ctx)?;
return Ok(());
} else {
//
// The data pointer is corrupted.
//
RECNO = ZZEKRP2N(HANDLE, SEGDSC[SNOIDX], RECPTR, ctx)?;
ZZEKCNAM(HANDLE, COLDSC.as_slice(), &mut COLUMN, ctx)?;
CHKIN(b"ZZEKRD06", ctx)?;
SETMSG(
b"Data pointer is corrupted. SEGNO = #; COLUMN = #; RECNO = #; EK = #",
ctx,
);
ERRINT(b"#", SEGDSC[SNOIDX], ctx);
ERRCH(b"#", &COLUMN, ctx);
ERRINT(b"#", RECNO, ctx);
ERRHAN(b"#", HANDLE, ctx)?;
SIGERR(b"SPICE(BUG)", ctx)?;
CHKOUT(b"ZZEKRD06", ctx)?;
return Ok(());
}
Ok(())
}