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
//
// GENERATED FILE
//
use super::*;
use f2rust_std::*;
const FILEN: i32 = 127;
const MAXTRY: i32 = 20;
//$Procedure TSTFIL ( Open a new file on the specified port )
//
pub fn TSTFIL(
PATTRN: &[u8],
PORT: &[u8],
FILE: &mut [u8],
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let mut FNAME = [b' '; FILEN as usize];
let mut NAME = [b' '; FILEN as usize];
let mut THIS = [b' '; FILEN as usize];
let mut BADOPN: i32 = 0;
let mut MORE: bool = false;
//
//
//
// Spicelib routines.
//
//
// Local Parameters
//
spicelib::CHKIN(b"TSTFIL", ctx)?;
fstr::assign(&mut FNAME, b" ");
fstr::assign(&mut NAME, b" ");
fstr::assign(&mut THIS, b" ");
support::FSTSTR(PATTRN, &mut FNAME, ctx)?;
fstr::assign(&mut NAME, &FNAME);
MORE = true;
BADOPN = 0;
while (BADOPN < MAXTRY) {
//
// Look for a file name that does not already exist.
//
while (spicelib::EXISTS(&NAME, ctx)? && MORE) {
fstr::assign(&mut THIS, &NAME);
fstr::assign(&mut NAME, b" ");
support::NXTSTR(PATTRN, &THIS, &mut NAME);
MORE = fstr::ne(&NAME, &FNAME);
}
if !MORE {
fstr::assign(FILE, b" ");
spicelib::SETMSG(b"It was not possible to create a # file as specified. All appropriately named files already exist.", ctx);
spicelib::ERRCH(b"#", PORT, ctx);
spicelib::SIGERR(b"CMLOOP(CANNOTMAKEFILE)", ctx)?;
spicelib::CHKOUT(b"TSTFIL", ctx)?;
return Ok(());
} else {
fstr::assign(FILE, &NAME);
}
//
// Ok. We've got a good candidate, try to attach it to the
// specified port.
//
TSTOPN(PORT, FILE, ctx)?;
if spicelib::FAILED(ctx) {
BADOPN = (BADOPN + 1);
//
// We will try a few more times on the off chance that
// some other program used the same name first. This
// is not likely, file protection problems or PATTRN
// specifications are a more probable cause of the trouble,
// but we try anyway.
//
if (BADOPN < MAXTRY) {
spicelib::RESET(ctx);
}
} else {
//
// We were successful in opening the port with the
// specified name. We can quit now.
//
TSTSLF(FILE, ctx);
spicelib::CHKOUT(b"TSTFIL", ctx)?;
return Ok(());
}
}
//
// If you get to this point, a file was not succesfully
// attached to PORT. But TSTIO has already diagnosed
// the problem as much as we're going to. Just set FILE
// to a blank and return.
//
fstr::assign(FILE, b" ");
spicelib::CHKOUT(b"TSTFIL", ctx)?;
Ok(())
}