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
//
// GENERATED FILE
//
use super::*;
use f2rust_std::*;
//$Procedure FNDPTK ( Find the previous token in a string )
pub fn FNDPTK(
STRING: &[u8],
DELIMS: &[u8],
START: i32,
BEG: &mut i32,
END: &mut i32,
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let mut LAST: i32 = 0;
let mut EOL: i32 = 0;
let mut B: i32 = 0;
let mut ATDELM: bool = false;
let mut ONSPCE: bool = false;
//
// SPICE funtions.
//
//
// Local variables
//
//%&END_DECLARATIONS
//
// Standard SPICE error handling
//
if spicelib::RETURN(ctx) {
return Ok(());
} else {
spicelib::CHKIN(b"FNDPTK", ctx)?;
}
//
// First we gather some data regarding the input string and
// delimiters
//
LAST = intrinsics::LEN(STRING);
EOL = (LAST + 1);
B = intrinsics::MIN0(&[(EOL + 1), START]);
//
// We don't have to do anything if we are starting past the end of
// the string.
//
if (B < 1) {
*BEG = 0;
*END = 0;
spicelib::CHKOUT(b"FNDPTK", ctx)?;
return Ok(());
}
if (B < EOL) {
ONSPCE = fstr::eq(fstr::substr(STRING, B..=B), b" ");
} else {
ONSPCE = false;
}
//
// Are we currently pointing at a delimiter?
//
if (B > EOL) {
ATDELM = false;
} else if (B == EOL) {
ATDELM = true;
} else if (intrinsics::INDEX(DELIMS, fstr::substr(STRING, B..=B)) != 0) {
ATDELM = true;
} else {
ATDELM = false;
}
if ATDELM {
//
// Yes. Move left to a non-blank character
//
B = spicelib::NCPOSR(STRING, b" ", (B - 1));
//
// If we didn't find a non-blank, then there is not a previous
// token.
//
if (B == 0) {
*BEG = 0;
*END = 0;
spicelib::CHKOUT(b"FNDPTK", ctx)?;
return Ok(());
}
//
// Still here? Are we currently pointing at a delimiter?
//
if (intrinsics::INDEX(DELIMS, fstr::substr(STRING, B..=B)) != 0) {
//
// Yes. Move left to a non-blank.
//
B = spicelib::NCPOSR(STRING, b" ", (B - 1));
}
//
// Move left to a delimiter, then Move right 1
//
B = (spicelib::CPOSR(STRING, DELIMS, B) + 1);
//
// Are we on a space?
//
} else if ONSPCE {
//
// Yes. (note: space is not a delimiter ) Find the next
// non-blank to the right.
//
B = spicelib::NCPOS(STRING, b" ", B);
//
// Is this a delimiter?
//
if (B == 0) {
//
// it was all blanks to the end of the string. Make the
// B point to the end + 1, that is a delimiter
//
B = EOL;
B = spicelib::CPOSR(STRING, DELIMS, B);
} else if (intrinsics::INDEX(DELIMS, fstr::substr(STRING, B..=B)) == 0) {
//
// No. Move left to the first delimiter.
//
B = spicelib::CPOSR(STRING, DELIMS, B);
//
// If we ran off the front of the string without hitting a
// delimiter, there isn't a previous token. Checkout and
// head for home.
//
if (B == 0) {
*BEG = 0;
*END = 0;
spicelib::CHKOUT(b"FNDPTK", ctx)?;
return Ok(());
}
}
//
// Move left to the first delimiter.
// Move right 1
//
B = (spicelib::CPOSR(STRING, DELIMS, (B - 1)) + 1);
} else {
//
// Otherwise
//
// Move left to the first delimiter.
//
if (B > EOL) {
B = EOL;
} else {
B = spicelib::CPOSR(STRING, DELIMS, B);
//
// B is now pointing at a delimiter.
//
}
//----------
if (B == 0) {
*BEG = 0;
*END = 0;
spicelib::CHKOUT(b"FNDPTK", ctx)?;
return Ok(());
}
//
// Move left to the first non-blank (here or to the left)
//
if (B < EOL) {
B = spicelib::NCPOSR(STRING, b" ", B);
//
// B is now pointing to the first non-blank character to the
// left of the token we started in.
//
if (((intrinsics::INDEX(DELIMS, fstr::substr(STRING, B..=B)) != 0)
&& (intrinsics::INDEX(DELIMS, b" ") != 0))
&& fstr::eq(fstr::substr(STRING, (B - 1)..=(B - 1)), b" "))
{
//
// Move backwards to the true delimiter for the token
// that ends here.
//
B = (spicelib::NCPOSR(STRING, b" ", (B - 1)) + 1);
}
} else {
//
// If we were at or beyond the EOL position, we need to
// know if backing up to a non-blank puts us on a delimiter
// or not. If it does reset B to EOL.
//
B = spicelib::NCPOSR(STRING, b" ", B);
if (intrinsics::INDEX(DELIMS, fstr::substr(STRING, B..=B)) != 0) {
B = EOL;
}
}
//
// Move left to the first deliter, and then move right 1.
//
B = (spicelib::CPOSR(STRING, DELIMS, (B - 1)) + 1);
}
FNDNTK(STRING, DELIMS, B, BEG, END);
spicelib::CHKOUT(b"FNDPTK", ctx)?;
Ok(())
}