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
//
// GENERATED FILE
//
use super::*;
use f2rust_std::*;
fn ISQ(L: i32, SQUOTE: i32, DQUOTE: i32, SPCIAL: i32) -> bool {
(((L == SQUOTE) || (L == DQUOTE)) || (L == SPCIAL))
}
fn BLANK(
L: i32,
ODDDQ: bool,
ODDSQ: bool,
ODDSP: bool,
SQUOTE: i32,
DQUOTE: i32,
SPCIAL: i32,
) -> bool {
((((((L == intrinsics::ICHAR(b" ")) || (L == intrinsics::ICHAR(b","))) || ODDDQ) || ODDSQ)
|| ODDSP)
|| ISQ(L, SQUOTE, DQUOTE, SPCIAL))
}
//$Procedure NTHUQT ( N'th unquoted token )
pub fn NTHUQT(STRING: &[u8], N: i32, EQUOTE: &[u8], WORD: &mut [u8], LOC: &mut i32) {
let EQUOTE = &EQUOTE[..1 as usize];
let mut B: i32 = 0;
let mut DQUOTE: i32 = 0;
let mut E: i32 = 0;
let mut L: i32 = 0;
let mut LAST: i32 = 0;
let mut SQUOTE: i32 = 0;
let mut WCOUNT: i32 = 0;
let mut SPCIAL: i32 = 0;
let mut ODDDQ: bool = false;
let mut ODDSQ: bool = false;
let mut ODDSP: bool = false;
let mut INWORD: bool = false;
//
// Spice Functions
//
//
// Local Variables
//
//
// An integer
//
//
// Take care of the dumb cases first.
//
if (N <= 0) {
fstr::assign(WORD, b" ");
*LOC = 0;
return;
}
SQUOTE = intrinsics::ICHAR(b"\'");
DQUOTE = intrinsics::ICHAR(b"\"");
SPCIAL = intrinsics::ICHAR(fstr::substr(EQUOTE, 1..=1));
if (SPCIAL == intrinsics::ICHAR(b" ")) {
SPCIAL = SQUOTE;
}
LAST = spicelib::RTRIM(STRING);
WCOUNT = 0;
ODDDQ = false;
ODDSQ = false;
ODDSP = false;
INWORD = false;
for I in 1..=LAST {
//
// Get the integer value of the I'th character of string.
//
L = intrinsics::ICHAR(fstr::substr(STRING, I..=I));
//
// If this is a quote character, then flip the ODDQ logical
//
if (L == SPCIAL) {
ODDSP = !ODDSP;
}
if (L == SQUOTE) {
ODDSQ = !ODDSQ;
}
if (L == DQUOTE) {
ODDDQ = !ODDDQ;
}
//
// If this is a blank ...
//
if BLANK(L, ODDDQ, ODDSQ, ODDSP, SQUOTE, DQUOTE, SPCIAL) {
//
// if we are in the middle of a word, we are about to
// end it. If the word counter WCOUNT has the same
// value of N then we've found the N'th unquoted word.
// Set the various outputs and return.
//
if (INWORD && (WCOUNT == N)) {
fstr::assign(WORD, fstr::substr(STRING, B..=E));
*LOC = B;
return;
}
//
// If we get to here, we just point out that we are
// not in a word.
//
INWORD = false;
} else {
//
// If this is not a "blank" then ODDDQ, ODDSQ and ODDSP are
// false so we are not inside a quoted string. We are either
// already in a word, or we are just starting one.
//
if INWORD {
//
// We are in a word, just bump the end of this one.
//
E = I;
} else {
//
// We are beginning a word. Up the word counter,
// set the end and beginning of the word.
//
INWORD = true;
WCOUNT = (WCOUNT + 1);
B = I;
E = I;
}
}
//
// Examine the next character.
//
}
if (INWORD && (WCOUNT == N)) {
*LOC = B;
fstr::assign(WORD, fstr::substr(STRING, B..));
} else {
*LOC = 0;
fstr::assign(WORD, b" ");
}
}