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
//
// GENERATED FILE
//
use super::*;
use f2rust_std::*;
//$Procedure MATCHM ( Match string against multiple wildcard templates )
pub fn MATCHM(
STRING: &[u8],
TEMPL: &[u8],
WSTR: &[u8],
WCHR: &[u8],
NOTCHR: &[u8],
ORCHR: &[u8],
ctx: &mut Context,
) -> f2rust_std::Result<bool> {
let WSTR = &WSTR[..1];
let WCHR = &WCHR[..1];
let NOTCHR = &NOTCHR[..1];
let ORCHR = &ORCHR[..1];
let mut MATCHM: bool = false;
let mut BEG: i32 = 0;
let mut END: i32 = 0;
let mut B: i32 = 0;
let mut E: i32 = 0;
let mut MATCH: bool = false;
let mut NEGATE: bool = false;
let mut LOOP: bool = false;
//
// SPICELIB functions
//
//
// Local variables
//
//
// Give the function an initial value.
//
MATCHM = false;
//
// Standard SPICE error handling
//
if spicelib::RETURN(ctx) {
return Ok(MATCHM);
} else {
spicelib::CHKIN(b"MATCHM", ctx)?;
}
//
// Reject bad inputs.
//
if (((fstr::eq(WSTR, b" ") || fstr::eq(WCHR, b" ")) || fstr::eq(NOTCHR, b" "))
|| fstr::eq(ORCHR, b" "))
{
spicelib::SIGERR(b"SPICE(ILLEGTEMPL)", ctx)?;
spicelib::CHKOUT(b"MATCHM", ctx)?;
return Ok(MATCHM);
} else if (((((fstr::eq(WSTR, WCHR) || fstr::eq(WSTR, NOTCHR)) || fstr::eq(WSTR, ORCHR))
|| fstr::eq(WCHR, NOTCHR))
|| fstr::eq(WCHR, ORCHR))
|| fstr::eq(NOTCHR, ORCHR))
{
spicelib::SIGERR(b"SPICE(AMBIGTEMPL)", ctx)?;
spicelib::CHKOUT(b"MATCHM", ctx)?;
return Ok(MATCHM);
}
//
// Ignore leading and trailing spaces in the collection.
//
BEG = spicelib::FRSTNB(TEMPL);
END = QLSTNB(TEMPL);
//
// A blank collection matches ONLY a blank string.
//
if (BEG == 0) {
MATCHM = fstr::eq(STRING, b" ");
spicelib::CHKOUT(b"MATCHM", ctx)?;
return Ok(MATCHM);
}
//
// If the first template is the NOT character, the entire collection
// is negated, and we can begin with the next template. Otherwise,
// just start at the beginning again.
//
B = BEG;
E = UPTO(fstr::substr(TEMPL, 1..=END), ORCHR, B);
if (E >= intrinsics::LEN(TEMPL)) {
NEGATE = false;
BEG = B;
} else if (fstr::eq(fstr::substr(TEMPL, B..=E), NOTCHR)
&& fstr::eq(fstr::substr(TEMPL, (E + 1)..=(E + 1)), ORCHR))
{
NEGATE = true;
BEG = (E + 2);
} else {
NEGATE = false;
BEG = B;
}
//
// Grab one template at a time, comparing them against the string
// until a match has occured or until no templates remain.
//
MATCH = false;
while ((BEG <= END) && !MATCH) {
B = BEG;
E = UPTO(fstr::substr(TEMPL, 1..=END), ORCHR, B);
//
// If we started on an OR character, then either we are
// at the beginning of a string that starts with one,
// or we just passed one and found another either next to
// it, or separated by nothing but spaces. By convention,
// either case is interpreted as a blank template.
//
if fstr::eq(fstr::substr(TEMPL, B..=B), ORCHR) {
MATCH = fstr::eq(STRING, b" ");
BEG = (BEG + 1);
//
// If this is a negated template, negate the results.
// Remember that a NOT character by itself does not
// matches anything.
//
} else if fstr::eq(fstr::substr(TEMPL, B..=B), NOTCHR) {
if fstr::eq(fstr::substr(TEMPL, B..=E), NOTCHR) {
MATCH = false;
} else {
MATCH =
!spicelib::MATCHI(STRING, fstr::substr(TEMPL, (B + 1)..=E), WSTR, WCHR, ctx);
}
BEG = (E + 2);
//
// Or a normal one?
//
} else {
MATCH = spicelib::MATCHI(STRING, fstr::substr(TEMPL, B..=E), WSTR, WCHR, ctx);
BEG = (E + 2);
}
//
// Skip any blanks before the next template.
// The logic ensures no evaluation of TEMPL(BEG:BEG)
// if BEG > LEN(TEMPL).
//
LOOP = (BEG < END);
if LOOP {
LOOP = (LOOP && fstr::eq(fstr::substr(TEMPL, BEG..=BEG), b" "));
}
while LOOP {
BEG = (BEG + 1);
if (BEG >= END) {
LOOP = false;
} else if fstr::ne(fstr::substr(TEMPL, BEG..=BEG), b" ") {
LOOP = false;
} else {
LOOP = true;
}
}
}
//
// It doesn't happen often, but occasionally a template ends with
// the OR character. This implies a blank template at the end of
// the collection.
//
if fstr::eq(fstr::substr(TEMPL, END..=END), ORCHR) {
if !MATCH {
MATCH = fstr::eq(STRING, b" ");
}
}
//
// Negate the results, if appropriate.
//
if NEGATE {
MATCHM = !MATCH;
} else {
MATCHM = MATCH;
}
spicelib::CHKOUT(b"MATCHM", ctx)?;
Ok(MATCHM)
}