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
//
// GENERATED FILE
//
use super::*;
use f2rust_std::*;
const MAXCOM: i32 = 20;
const FILEN: i32 = 128;
const COMSIZ: i32 = 1024;
const ERRSIZ: i32 = 1760;
const STYSIZ: i32 = 120;
const NONE: i32 = 0;
const COMBUF: i32 = (NONE + 1);
const KEYBRD: i32 = (COMBUF + 1);
const INPFIL: i32 = (KEYBRD + 1);
const WDSIZE: i32 = 32;
struct SaveVars {
SAVDLM: Vec<u8>,
SAVPMT: Vec<u8>,
WORD: Vec<u8>,
ERROR: Vec<u8>,
LNGMSG: Vec<u8>,
BUFFER: ActualCharArray,
FILE: Vec<u8>,
REST: Vec<u8>,
EXIT: Vec<u8>,
SHTMSG: Vec<u8>,
START: Vec<u8>,
STOP: Vec<u8>,
BUFFED: i32,
BUFSRC: StackArray<i32, 20>,
FIRST: bool,
NOCOM: bool,
READNG: bool,
}
impl SaveInit for SaveVars {
fn new() -> Self {
let mut SAVDLM = vec![b' '; 1 as usize];
let mut SAVPMT = vec![b' '; 80 as usize];
let mut WORD = vec![b' '; 80 as usize];
let mut ERROR = vec![b' '; 300 as usize];
let mut LNGMSG = vec![b' '; 300 as usize];
let mut BUFFER = ActualCharArray::new(COMSIZ, 1..=MAXCOM);
let mut FILE = vec![b' '; FILEN as usize];
let mut REST = vec![b' '; FILEN as usize];
let mut EXIT = vec![b' '; WDSIZE as usize];
let mut SHTMSG = vec![b' '; WDSIZE as usize];
let mut START = vec![b' '; WDSIZE as usize];
let mut STOP = vec![b' '; WDSIZE as usize];
let mut BUFFED: i32 = 0;
let mut BUFSRC = StackArray::<i32, 20>::new(1..=MAXCOM);
let mut FIRST: bool = false;
let mut NOCOM: bool = false;
let mut READNG: bool = false;
BUFFED = 0;
FIRST = true;
READNG = false;
fstr::assign(&mut SAVDLM, b";");
fstr::assign(&mut SAVPMT, b" ");
Self {
SAVDLM,
SAVPMT,
WORD,
ERROR,
LNGMSG,
BUFFER,
FILE,
REST,
EXIT,
SHTMSG,
START,
STOP,
BUFFED,
BUFSRC,
FIRST,
NOCOM,
READNG,
}
}
}
//$Procedure NXTCOM ( Next command )
pub fn NXTCOM(
PROMPT: &[u8],
DELIM: &[u8],
COMMND: &[u8],
SOURCE: i32,
ctx: &mut Context,
) -> f2rust_std::Result<()> {
if spicelib::RETURN(ctx) {
return Ok(());
} else {
spicelib::CHKIN(b"NXTCOM", ctx)?;
}
spicelib::SETMSG(b"NXTCOM: You have called an entry which performs no run-time function. This may indicate a bug. Please check the documentation for the subroutine NXTCOM.", ctx);
spicelib::SIGERR(b"SPICE(BOGUSENTRY)", ctx)?;
spicelib::CHKOUT(b"NXTCOM", ctx)?;
Ok(())
}
pub fn GETCOM(COMMND: &mut [u8], SOURCE: &mut i32, ctx: &mut Context) -> f2rust_std::Result<()> {
let save = ctx.get_vars::<SaveVars>();
let save = &mut *save.borrow_mut();
//
// Standard SPICE error handling.
//
if spicelib::RETURN(ctx) {
return Ok(());
} else {
spicelib::CHKIN(b"GETCOM", ctx)?;
}
if save.FIRST {
TRNLAT(b"STOP", &mut save.STOP, ctx);
TRNLAT(b"EXIT", &mut save.EXIT, ctx);
TRNLAT(b"START", &mut save.START, ctx);
TRNLAT(b"DEFPROMPT", &mut save.SAVPMT, ctx);
save.FIRST = false;
}
//
// While we don't have a command, try to get one. We look
// in the command buffer first.
//
//
// We don't have a command yet.
//
save.NOCOM = true;
while save.NOCOM {
if (save.BUFFED > 0) {
fstr::assign(COMMND, save.BUFFER.get(save.BUFFED));
*SOURCE = save.BUFSRC[save.BUFFED];
save.BUFFED = (save.BUFFED - 1);
} else {
//
// If we're already reading from a file then just let PRREAD
// take care of obtaining the command. If PRREAD reaches the
// end of the current file, the previous file is popped off
// the stack, and the next command from this file is read
// instead. (If no files remain to be read, DELIM is returned.)
// In that case we are no longer reading from files.
//
if save.READNG {
PRREAD(&save.SAVDLM, COMMND, ctx)?;
*SOURCE = INPFIL;
if fstr::eq(COMMND, &save.SAVDLM) {
save.READNG = false;
}
}
//
// If we're not reading from a file, get the command from the
// keyboard. ( If the command was terminated by a blank line,
// the command is returned as a blank. )
//
if !save.READNG {
if BATCH(ctx) {
fstr::assign(COMMND, &save.EXIT);
} else {
RDSTMT(&save.SAVPMT, &save.SAVDLM, COMMND, ctx)?;
}
*SOURCE = KEYBRD;
}
}
//
// We must have a command at this point.
//
save.NOCOM = false;
//
// We need to check to see if what we have is a control word.
//
spicelib::NEXTWD(COMMND, &mut save.WORD, &mut save.REST);
spicelib::UCASE(&save.WORD.to_vec(), &mut save.WORD, ctx);
//
// If the control word is 'START', we know that we will be
// reading from a file. Let PRSTRT take care of keeping track of
// the files being read from. If there's a problem in PRSTRT we
// need to signal an error here due to PRSTRT's error handling.
// Bail out if there's a problem. If all goes well in PRSTR,
// we will read the first command in the file the next pass
// through the DO LOOP.
//
if fstr::eq(&save.WORD, &save.START) {
//
// We need to log this command commented out so that anyone
// using the resulting log file, will not have to worry
// about starting a file twice.
//
NSPLOG(COMMND, true, ctx)?;
fstr::assign(&mut save.FILE, b" ");
spicelib::NEXTWD(&save.REST.to_vec(), &mut save.FILE, &mut save.REST);
if fstr::eq(&save.FILE, b" ") {
*SOURCE = NONE;
TRNLAT(b"MISSINGFILELONG", &mut save.LNGMSG, ctx);
TRNLAT(b"MISSINGFILESHORT", &mut save.SHTMSG, ctx);
spicelib::SETMSG(&save.LNGMSG, ctx);
spicelib::SIGERR(&save.SHTMSG, ctx)?;
spicelib::CHKOUT(b"GETCOM", ctx)?;
return Ok(());
}
PRSTRT(&save.FILE, &mut save.ERROR, ctx)?;
//
// If an error occurs in PRSTRT we're in trouble. Signal an
// error and bail. If there's no problem, we're now reading
// from a file.
//
if fstr::ne(&save.ERROR, b" ") {
*SOURCE = NONE;
TRNLAT(b"MISSINGFILESHORT", &mut save.SHTMSG, ctx);
spicelib::SETMSG(&save.ERROR, ctx);
spicelib::SIGERR(&save.SHTMSG, ctx)?;
spicelib::CHKOUT(b"GETCOM", ctx)?;
return Ok(());
} else {
save.READNG = true;
save.NOCOM = true;
}
//
// If the control word is 'STOP', clear the stack of files.
// If we were reading commands from files, we won't be anymore.
// If we were reading commands from the keyboard, the command to
// return is 'STOP'.
//
} else if fstr::eq(&save.WORD, &save.STOP) {
if save.READNG {
PRCLR(ctx)?;
NSPLOG(COMMND, true, ctx)?;
save.READNG = false;
save.NOCOM = true;
} else {
fstr::assign(COMMND, &save.WORD);
}
//
// If the control word is 'EXIT', and we're reading from a file,
// we need to remove that file from the stack. If we're reading
// commands from the keyboard, we'll return the command 'EXIT'.
//
} else if fstr::eq(&save.WORD, &save.EXIT) {
if save.READNG {
PREXIT(ctx)?;
NSPLOG(COMMND, true, ctx)?;
save.NOCOM = true;
} else {
fstr::assign(COMMND, &save.WORD);
}
}
}
spicelib::CHKOUT(b"GETCOM", ctx)?;
Ok(())
}
//$Procedure SETDAP ( Set the delimeter and prompt values )
pub fn SETDAP(DELIM: &[u8], PROMPT: &[u8], ctx: &mut Context) -> f2rust_std::Result<()> {
let save = ctx.get_vars::<SaveVars>();
let save = &mut *save.borrow_mut();
//
// Standard SPICE error handling.
//
if spicelib::RETURN(ctx) {
return Ok(());
} else {
spicelib::CHKIN(b"SETDAP", ctx)?;
}
//
// Set the values of the delimeter and prompt.
//
fstr::assign(&mut save.SAVDLM, DELIM);
fstr::assign(&mut save.SAVPMT, PROMPT);
TRNLAT(b"STOP", &mut save.STOP, ctx);
TRNLAT(b"EXIT", &mut save.EXIT, ctx);
TRNLAT(b"START", &mut save.START, ctx);
if fstr::eq(&save.SAVPMT, b" ") {
TRNLAT(b"DEFPROMPT", &mut save.SAVPMT, ctx);
}
save.FIRST = false;
spicelib::CHKOUT(b"SETDAP", ctx)?;
Ok(())
}
//
pub fn PUTCOM(COMMND: &[u8], SOURCE: i32, ctx: &mut Context) -> f2rust_std::Result<()> {
let save = ctx.get_vars::<SaveVars>();
let save = &mut *save.borrow_mut();
if (save.BUFFED < MAXCOM) {
save.BUFFED = (save.BUFFED + 1);
fstr::assign(save.BUFFER.get_mut(save.BUFFED), COMMND);
save.BUFSRC[save.BUFFED] = spicelib::BRCKTI(SOURCE, NONE, INPFIL);
return Ok(());
}
spicelib::CHKIN(b"PUTCOM", ctx)?;
TRNLAT(b"COMBUFFULLLNG", &mut save.LNGMSG, ctx);
TRNLAT(b"COMBUFFULLSHT", &mut save.SHTMSG, ctx);
spicelib::SETMSG(&save.LNGMSG, ctx);
spicelib::SIGERR(&save.SHTMSG, ctx)?;
spicelib::CHKOUT(b"PUTCOM", ctx)?;
Ok(())
}