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
//
// GENERATED FILE
//
use super::*;
use f2rust_std::*;
//$Procedure MATCHE ( Match two words, allowing for common errors )
pub fn MATCHE(
WORD: &[u8],
GUESS: &[u8],
TRANSF: &mut [u8],
LOC: &mut i32,
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let mut COPY = [b' '; 65 as usize];
let mut TEMPL = [b' '; 65 as usize];
let mut MYGUES = [b' '; 65 as usize];
let mut CLEN: i32 = 0;
//
// SPICELIB functions
//
//
// Local variables
//
//
// Save a copy of the first 64 significant characters in a buffer,
// from which we may construct templates.
//
fstr::assign(&mut COPY, b" ");
spicelib::LJUST(WORD, fstr::substr_mut(&mut COPY, 1..=64));
spicelib::LJUST(GUESS, &mut MYGUES);
CLEN = QRTRIM(©);
//
// Apply the transformations one at a time, in the order most
// likely to succeed:
//
// Removal
// Transposition
// Replacement
// Insertion
//
// Quit as soon as a possible match is found.
//
// Actually, we need to check for identity first. Otherwise,
// we're likely to find a transposition that yields the same
// word: for example, transposing the second and third letters
// of APPLE yields APPLE.
//
if spicelib::EQSTR(WORD, &MYGUES) {
fstr::assign(TRANSF, b"IDENTITY");
*LOC = 0;
return Ok(());
}
//
// Removal
// -------
//
// Remove the character at each location, and check against MYGUES.
//
for I in 1..=CLEN {
spicelib::REMSUB(©, I, I, &mut TEMPL, ctx)?;
if spicelib::EQSTR(&TEMPL, &MYGUES) {
fstr::assign(TRANSF, b"REMOVE");
*LOC = I;
return Ok(());
}
}
//
// Transposition
// -------------
//
// Transpose each pair of characters, and check against MYGUES.
//
for I in 1..=(CLEN - 1) {
fstr::assign(&mut TEMPL, ©);
fstr::assign(
fstr::substr_mut(&mut TEMPL, I..=I),
fstr::substr(©, (I + 1)..=(I + 1)),
);
fstr::assign(
fstr::substr_mut(&mut TEMPL, (I + 1)..=(I + 1)),
fstr::substr(©, I..=I),
);
if spicelib::EQSTR(&TEMPL, &MYGUES) {
fstr::assign(TRANSF, b"TRANSPOSE");
*LOC = I;
return Ok(());
}
}
//
// Replacement
// -----------
//
// Replace each character with a wild character, and check
// against MYGUES.
//
for I in 1..=CLEN {
fstr::assign(&mut TEMPL, ©);
fstr::assign(
fstr::substr_mut(&mut TEMPL, I..=I),
fstr::substr(&MYGUES, I..=I),
);
if spicelib::EQSTR(&TEMPL, &MYGUES) {
fstr::assign(TRANSF, b"REPLACE");
*LOC = I;
return Ok(());
}
}
//
// Insertion
// ---------
//
// Insert a wild character at each location, and check against
// MYGUES.
//
for I in 1..=(CLEN + 1) {
if (I == 1) {
fstr::assign(
fstr::substr_mut(&mut TEMPL, 1..=1),
fstr::substr(&MYGUES, 1..=1),
);
fstr::assign(fstr::substr_mut(&mut TEMPL, 2..), ©);
} else if (I == (CLEN + 1)) {
fstr::assign(&mut TEMPL, ©);
fstr::assign(
fstr::substr_mut(&mut TEMPL, I..=I),
fstr::substr(&MYGUES, I..=I),
);
} else {
fstr::assign(
fstr::substr_mut(&mut TEMPL, 1..=(I - 1)),
fstr::substr(©, 1..=(I - 1)),
);
fstr::assign(
fstr::substr_mut(&mut TEMPL, I..=I),
fstr::substr(&MYGUES, I..=I),
);
fstr::assign(
fstr::substr_mut(&mut TEMPL, (I + 1)..),
fstr::substr(©, I..),
);
}
if spicelib::EQSTR(&TEMPL, &MYGUES) {
fstr::assign(TRANSF, b"INSERT");
*LOC = I;
return Ok(());
}
}
//
// None of these transformations work.
//
fstr::assign(TRANSF, b"NONE");
*LOC = 0;
Ok(())
}