|
|
|
@ -57,34 +57,26 @@ static Error parseword(const char *start, const char *end)
|
|
|
|
|
static Error parseSource()
|
|
|
|
|
{
|
|
|
|
|
auto result = Error::none;
|
|
|
|
|
char *start = nullptr;
|
|
|
|
|
char *end;
|
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
|
|
while (result == Error::none && haskey()) {
|
|
|
|
|
s = (char *)DICT[DIdxSource];
|
|
|
|
|
|
|
|
|
|
++DICT[DIdxSource];
|
|
|
|
|
--DICT[DIdxSrcLen];
|
|
|
|
|
|
|
|
|
|
if (isspace(*s)) {
|
|
|
|
|
if (start) {
|
|
|
|
|
result = parseword(start, end + 1);
|
|
|
|
|
start = nullptr;
|
|
|
|
|
}
|
|
|
|
|
char *start = (char *)DICT[DIdxSource];
|
|
|
|
|
char *end = start;
|
|
|
|
|
auto& i = *((char *)&DICT[DIdxInBuf]);
|
|
|
|
|
|
|
|
|
|
while (result == Error::none && i < DICT[DIdxSrcLen]) {
|
|
|
|
|
if (isspace(*end) || *end == '\0') {
|
|
|
|
|
if (end - start < 1) {
|
|
|
|
|
start = ++end;
|
|
|
|
|
++i;
|
|
|
|
|
} else {
|
|
|
|
|
if (!start) {
|
|
|
|
|
start = s;
|
|
|
|
|
++i; // discard the space
|
|
|
|
|
result = parseword(start, end);
|
|
|
|
|
start = (char *)DICT[DIdxSource] + i;
|
|
|
|
|
end = start;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
++end;
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Parse the final word if it is non-empty.
|
|
|
|
|
if (start)
|
|
|
|
|
result = parseword(start, s + 1);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
@ -93,9 +85,11 @@ static Error parseSource()
|
|
|
|
|
Error parse()
|
|
|
|
|
{
|
|
|
|
|
// Reset source buffer and try to fill it with getinput().
|
|
|
|
|
DICT[DIdxSource] = (Cell)&DICT[DIdxBegin];
|
|
|
|
|
DICT[DIdxSource] = (Cell)&DICT[DIdxInBuf] + 1;
|
|
|
|
|
DICT[DIdxSrcLen] = 0;
|
|
|
|
|
*((char *)&DICT[DIdxInBuf]) = 0;
|
|
|
|
|
getinput();
|
|
|
|
|
addkey('\0');
|
|
|
|
|
|
|
|
|
|
return parseSource();
|
|
|
|
|
}
|
|
|
|
|