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
//
// GENERATED FILE
//
use super::*;
use f2rust_std::*;
//$Procedure MAKSTR (Make String )
pub fn MAKSTR(PATTRN: &[u8], THIS: &[u8], NEXT: &[u8]) {
//
// Spicelib functions
//
//
// Local Varialbes
//
}
//$Procedure FSTSTR ( First string matching a pattern )
pub fn FSTSTR(PATTRN: &[u8], NEXT: &mut [u8], ctx: &mut Context) -> f2rust_std::Result<()> {
let mut I: i32 = 0;
let mut J: i32 = 0;
let mut KEEP: bool = false;
//
// There are two things to handle:
//
// balanced brackets: <>
// balanced braces: {}
//
// We do this in one pass.
//
fstr::assign(NEXT, b" ");
KEEP = true;
J = 1;
{
let m1__: i32 = 1;
let m2__: i32 = spicelib::RTRIM(PATTRN);
let m3__: i32 = 1;
I = m1__;
for _ in 0..((m2__ - m1__ + m3__) / m3__) as i32 {
if fstr::eq(fstr::substr(PATTRN, I..=I), b">") {
KEEP = true;
}
if fstr::eq(fstr::substr(PATTRN, I..=I), b"{") {
fstr::assign(
fstr::substr_mut(NEXT, J..=J),
fstr::substr(PATTRN, (I + 1)..=(I + 1)),
);
J = (J + 1);
KEEP = false;
}
if KEEP {
fstr::assign(fstr::substr_mut(NEXT, J..=J), fstr::substr(PATTRN, I..=I));
J = (J + 1);
}
if fstr::eq(fstr::substr(PATTRN, I..=I), b"<") {
KEEP = false;
}
if fstr::eq(fstr::substr(PATTRN, I..=I), b"}") {
KEEP = true;
}
if (J > intrinsics::LEN(NEXT)) {
spicelib::CHKIN(b"FSTSTR", ctx)?;
spicelib::SETMSG(
b"The string provided for the first name is too short for the input pattern. ",
ctx,
);
spicelib::SIGERR(b"SPICE(OUTPUTTOOLONG)", ctx)?;
spicelib::CHKOUT(b"FSTSTR", ctx)?;
}
I += m3__;
}
}
Ok(())
}
//$Procedure NXTSTR (Next String)
pub fn NXTSTR(PATTRN: &[u8], THIS: &[u8], NEXT: &mut [u8]) {
let mut I: i32 = 0;
let mut J: i32 = 0;
let mut K: i32 = 0;
let mut MAX: i32 = 0;
let mut MIN: i32 = 0;
//
// First copy THIS into NEXT and find the ends of PATTRN and NEXT.
//
fstr::assign(NEXT, THIS);
J = spicelib::RTRIM(PATTRN);
I = spicelib::RTRIM(NEXT);
//
// We work backwards from the right end of the string.
//
while (J > 0) {
//
// If the current character is a right brace we are going
// to assume we are at the end of a restriction token. Use
// the range of the restriction and the current character
// of NEXT to determine the "next" character and whether or
// not we can quit now.
//
if fstr::eq(fstr::substr(PATTRN, J..=J), b"}") {
MAX = intrinsics::ICHAR(fstr::substr(PATTRN, (J - 1)..=(J - 1)));
MIN = intrinsics::ICHAR(fstr::substr(PATTRN, (J - 3)..=(J - 3)));
K = (intrinsics::ICHAR(fstr::substr(NEXT, I..=I)) + 1);
if (K > MAX) {
//
// Roll over the characters, We aren't done we
// need to keep stepping back through the string
//
fstr::assign(fstr::substr_mut(NEXT, I..=I), &intrinsics::CHAR(MIN));
} else if ((K > intrinsics::ICHAR(b"9")) && (K < intrinsics::ICHAR(b"a"))) {
//
// By convention, the first character following '9' is 'a'.
// Since we don't need to "roll over" this character we
// are done at this point.
//
fstr::assign(fstr::substr_mut(NEXT, I..=I), b"a");
return;
} else {
//
// We didn't need to roll over the character so we just
// put in the new one and we can quit now.
//
fstr::assign(fstr::substr_mut(NEXT, I..=I), &intrinsics::CHAR(K));
return;
}
//
// perform the arithmetic needed if we had to roll over the
// character.
//
J = (J - 5);
I = (I - 1);
//
// If the character is '>' we assume we are at the right end
// of an expansion.
//
} else if fstr::eq(fstr::substr(PATTRN, J..=J), b">") {
//
// Skip over the invisible portion of the expansion.
//
while fstr::ne(fstr::substr(PATTRN, J..=J), b"<") {
J = (J - 1);
}
I = (I - 1);
} else {
//
// Nothing to do, just back up to the character to the
// left of the current character.
//
J = (J - 1);
I = (I - 1);
}
}
}