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
//
// GENERATED FILE
//
use super::*;
use f2rust_std::*;
const MAXLEN: i32 = 255;
//$Procedure EXPFNM_1 ( Expand a filename )
pub fn EXPFNM_1(INFIL: &[u8], OUTFIL: &mut [u8], ctx: &mut Context) -> f2rust_std::Result<()> {
let mut BLANK: i32 = 0;
let mut SLASH: i32 = 0;
let mut WORD = [b' '; MAXLEN as usize];
let mut DIR = [b' '; MAXLEN as usize];
let mut INLEN: i32 = 0;
let mut WRDLEN: i32 = 0;
let mut DIRLEN: i32 = 0;
let mut OUTLEN: i32 = 0;
let mut KEEP: i32 = 0;
let mut NEED: i32 = 0;
//
// SPICELIB functions
//
//
// Parameters
//
//
// Local variables
//
//
// Standard SPICE error handling.
//
if spicelib::RETURN(ctx) {
return Ok(());
} else {
spicelib::CHKIN(b"EXPFNM_1", ctx)?;
}
//
// If the input filename is blank, that's an error.
//
if fstr::eq(INFIL, b" ") {
spicelib::SETMSG(b"The input filename \'#\' was blank.", ctx);
spicelib::ERRCH(b"#", INFIL, ctx);
spicelib::SIGERR(b"SPICE(BADFILENAME)", ctx)?;
spicelib::CHKOUT(b"EXPFNM_1", ctx)?;
return Ok(());
}
//
// If there are blanks anywhere in the filename, SPICELIB
// considers the filename to be invalid.
//
BLANK = spicelib::POS(fstr::substr(INFIL, 1..=spicelib::RTRIM(INFIL)), b" ", 1);
if (BLANK != 0) {
spicelib::SETMSG(b"The input filename \'#\' had blank characters in it.", ctx);
spicelib::ERRCH(b"#", INFIL, ctx);
spicelib::SIGERR(b"SPICE(BADFILENAME)", ctx)?;
spicelib::CHKOUT(b"EXPFNM_1", ctx)?;
return Ok(());
}
//
// Look for a slash in the filename.
//
SLASH = spicelib::POS(INFIL, b"/", 1);
//
// If we found a slash in a position other than the first
// character position, we want to examine the word that
// comes before it just in case it is an environment
// variable.
//
if (SLASH > 1) {
fstr::assign(&mut WORD, fstr::substr(INFIL, 1..=(SLASH - 1)));
ctx.getenv(&WORD, &mut DIR);
//
// If the word was an environment variable, then construct
// the expanded filename. If it wasn't, just return the original
// input filename.
//
if fstr::ne(&DIR, b" ") {
fstr::assign(OUTFIL, INFIL);
INLEN = spicelib::RTRIM(INFIL);
WRDLEN = spicelib::RTRIM(&WORD);
DIRLEN = spicelib::RTRIM(&DIR);
OUTLEN = intrinsics::LEN(OUTFIL);
KEEP = (INLEN - WRDLEN);
NEED = (KEEP + DIRLEN);
//
// If the output filename length is not long enough for
// the substitution, signal an error. Otherwise, substitute
// in the new value.
//
if (NEED > OUTLEN) {
spicelib::SETMSG(b"The expanded filename for the input filename \'#\' exceeded the length of the output filename. The expanded name was # characters too long.", ctx);
spicelib::ERRCH(b"#", INFIL, ctx);
spicelib::ERRINT(b"#", (NEED - OUTLEN), ctx);
spicelib::SIGERR(b"SPICE(STRINGTOOSMALL)", ctx)?;
spicelib::CHKOUT(b"EXPFNM_1", ctx)?;
return Ok(());
} else {
spicelib::REPSUB(
INFIL,
1,
(SLASH - 1),
fstr::substr(&DIR, 1..=spicelib::RTRIM(&DIR)),
OUTFIL,
ctx,
)?;
}
} else {
fstr::assign(OUTFIL, INFIL);
}
} else {
//
// No slashes are in the filename, so it's just an easy case.
//
// It's possible that the entire filename is an environment
// variable. If it's not, then just return the input filename.
//
ctx.getenv(INFIL, OUTFIL);
if fstr::eq(OUTFIL, b" ") {
fstr::assign(OUTFIL, INFIL);
}
}
spicelib::CHKOUT(b"EXPFNM_1", ctx)?;
Ok(())
}