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
//
// GENERATED FILE
//
use super::*;
use f2rust_std::*;
//$Procedure FNDNTK ( Find the next token in a string )
pub fn FNDNTK(STRING: &[u8], DELIMS: &[u8], START: i32, BEG: &mut i32, END: &mut i32) {
let mut SPACE: bool = false;
let mut LAST: i32 = 0;
let mut EOL: i32 = 0;
let mut B: i32 = 0;
let mut BLANK: bool = false;
let mut NBR: i32 = 0;
let mut NBL: i32 = 0;
let mut DELIMR: bool = false;
let mut DELIML: bool = false;
let mut NODELM: bool = false;
//
// Local variables
//
//%&END_DECLARATIONS
//
// First we gather some data regarding the input string and
// delimiters
//
SPACE = (intrinsics::INDEX(DELIMS, b" ") != 0);
LAST = intrinsics::LEN(STRING);
EOL = (LAST + 1);
B = intrinsics::MAX0(&[1, START]);
//
// We don't have to do anything if we are starting past the end of
// the string.
//
if (B > EOL) {
*BEG = 0;
*END = 0;
return;
}
//
// Find the first non-blank character at or to the right of where
// we are starting.
//
BLANK = true;
NBR = B;
while BLANK {
if (NBR >= EOL) {
BLANK = false;
} else if fstr::ne(fstr::substr(STRING, NBR..=NBR), b" ") {
BLANK = false;
} else {
NBR = (NBR + 1);
}
}
//
// Find the first non-blank character and first non-blank delimiter
// to the left of the starting point.
//
BLANK = true;
NBL = (B - 1);
while BLANK {
if (NBL <= 0) {
BLANK = false;
} else if fstr::ne(fstr::substr(STRING, NBL..=NBL), b" ") {
BLANK = false;
} else {
NBL = (NBL - 1);
}
}
//
// If both the preceeding non-blank character and the following
// non-blank character are delimiters, we have a null item.
//
if (NBR >= EOL) {
DELIMR = true;
} else {
DELIMR = (intrinsics::INDEX(DELIMS, fstr::substr(STRING, NBR..=NBR)) != 0);
}
if (NBL <= 0) {
DELIML = true;
} else {
DELIML = (intrinsics::INDEX(DELIMS, fstr::substr(STRING, NBL..=NBL)) != 0);
}
if (DELIMR && DELIML) {
*BEG = NBR;
*END = (*BEG - 1);
return;
}
//
// Still here? See if we were past the last delimiter.
//
if ((NBR >= EOL) && !DELIML) {
*BEG = 0;
*END = 0;
return;
}
//
// If the left most non-blank is a delimiter OR a blank is a
// delimiter and the non-blank character to the left is at least
// two characters away from the right non-blank character, then
// we have a token beginning at the right non-blank. We just need
// to find the right boundary.
//
if (DELIML || ((((NBR - NBL) >= 2) && SPACE) && !DELIMR)) {
*BEG = NBR;
*END = *BEG;
//
// Note: DELIMR is already .FALSE. or else we couldn't get to
// this point.
//
while !DELIMR {
if ((*END + 1) >= EOL) {
DELIMR = true;
} else if (intrinsics::INDEX(DELIMS, fstr::substr(STRING, (*END + 1)..=(*END + 1)))
!= 0)
{
DELIMR = true;
} else {
*END = (*END + 1);
}
}
//
// Back up END to the first non-blank that precedes it.
//
while fstr::eq(fstr::substr(STRING, *END..=*END), b" ") {
*END = (*END - 1);
}
return;
}
//
// Still here? In that case we were in the middle of something
// to start with. Move the pointer forward until we reach a
// delimiter.
//
// Keep in mind that DELIMR still has the information as to whether
// or not NBR points to a non-blank delimiter. We are going to use
// this information to determine whether to look for a delimiter
// first or not.
//
if !DELIMR {
NODELM = true;
B = NBR;
while NODELM {
NBR = (NBR + 1);
if (NBR >= EOL) {
NODELM = false;
} else {
NODELM = (intrinsics::INDEX(DELIMS, fstr::substr(STRING, NBR..=NBR)) == 0);
}
}
//
// If a space is a delimiter and we happen to have landed on one,
// we want to continue until we hit a non-blank delimiter or just
// before a non-blank character.
//
if (SPACE && (NBR < EOL)) {
NODELM = fstr::eq(fstr::substr(STRING, NBR..=NBR), b" ");
while NODELM {
NBR = (NBR + 1);
if (NBR == EOL) {
NODELM = false;
} else if (intrinsics::INDEX(DELIMS, fstr::substr(STRING, NBR..=NBR)) != 0) {
NODELM = fstr::eq(fstr::substr(STRING, NBR..=NBR), b" ");
} else if fstr::ne(fstr::substr(STRING, NBR..=NBR), b" ") {
NODELM = false;
//
// Back up one, to just before the non-blank character
//
NBR = (NBR - 1);
}
}
}
//
// Since we did not start on a delimiter if we reached the end of
// the string before hitting one, then there is no token to find
// here.
//
if (NBR >= EOL) {
*BEG = 0;
*END = 0;
return;
}
}
//
// Still here? Then starting at the first character to the right of
// the delimiter, find the next non-blank character, and the next
// right delimiter after that.
//
NBL = NBR;
BLANK = true;
while BLANK {
NBL = (NBL + 1);
if (NBL >= EOL) {
BLANK = false;
} else {
BLANK = fstr::eq(fstr::substr(STRING, NBL..=NBL), b" ");
}
}
//
// Now locate the next delimiter.
//
NBR = (NBL - 1);
DELIMR = false;
while !DELIMR {
NBR = (NBR + 1);
if (NBR >= EOL) {
DELIMR = true;
} else {
DELIMR = (intrinsics::INDEX(DELIMS, fstr::substr(STRING, NBR..=NBR)) != 0);
}
}
*BEG = NBL;
*END = (NBR - 1);
if (*END > *BEG) {
//
// Backup until we are at a non-space.
//
while (fstr::eq(fstr::substr(STRING, *END..=*END), b" ") && (*END > *BEG)) {
*END = (*END - 1);
}
}
}