|
|
@ -6,6 +6,22 @@ static inline bool isnl(char c) |
|
|
|
return c == '\n' || c == '\r'; |
|
|
|
return c == '\n' || c == '\r'; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const char * strnchr(const char* s, char c, size_t len) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
while (len > 0) { |
|
|
|
|
|
|
|
char x = *s; |
|
|
|
|
|
|
|
if (!x) { |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (x == c) { |
|
|
|
|
|
|
|
return s; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
s++; |
|
|
|
|
|
|
|
len--; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return NULL; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** Process a word read from input */ |
|
|
|
/** Process a word read from input */ |
|
|
|
enum fh_error fh_handle_ascii_word( |
|
|
|
enum fh_error fh_handle_ascii_word( |
|
|
|
struct fh_thread_s *fh, |
|
|
|
struct fh_thread_s *fh, |
|
|
@ -44,7 +60,7 @@ enum fh_error fh_handle_ascii_word( |
|
|
|
|
|
|
|
|
|
|
|
long v = strtol(name, &endptr, base); // if base is 0, this will use auto-detection
|
|
|
|
long v = strtol(name, &endptr, base); // if base is 0, this will use auto-detection
|
|
|
|
if (errno != 0 || (endptr - name) != wordlen) { |
|
|
|
if (errno != 0 || (endptr - name) != wordlen) { |
|
|
|
LOGE("Unknown word and fail to parse as number: \"%.*s\"", (int) wordlen, name); |
|
|
|
LOGE("Unknown word and fail to parse as number: \"%.*s\", len %d", (int) wordlen, name, wordlen); |
|
|
|
return FH_ERR_UNKNOWN_WORD; |
|
|
|
return FH_ERR_UNKNOWN_WORD; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -322,16 +338,17 @@ enum fh_error fh_process_line(struct fh_thread_s *fh) |
|
|
|
|
|
|
|
|
|
|
|
const char *const rp = ReadPtr; |
|
|
|
const char *const rp = ReadPtr; |
|
|
|
|
|
|
|
|
|
|
|
char *end; |
|
|
|
const char *end; |
|
|
|
size_t length; |
|
|
|
size_t length; |
|
|
|
switch (fh->substate) { |
|
|
|
switch (fh->substate) { |
|
|
|
case FH_SUBSTATE_NONE: |
|
|
|
case FH_SUBSTATE_NONE: |
|
|
|
/* try to read a word */ |
|
|
|
/* try to read a word */ |
|
|
|
end = strchr(rp, ' '); |
|
|
|
size_t maxlen = ReadLen - ReadPos; |
|
|
|
|
|
|
|
end = strnchr(rp, ' ', maxlen); |
|
|
|
if (end) { |
|
|
|
if (end) { |
|
|
|
length = end - rp; /* exclude the space */ |
|
|
|
length = end - rp; /* exclude the space */ |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
length = strlen(rp); |
|
|
|
length = strnlen(rp, maxlen); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ReadPos += length + 1; |
|
|
|
ReadPos += length + 1; |
|
|
@ -353,7 +370,7 @@ enum fh_error fh_process_line(struct fh_thread_s *fh) |
|
|
|
} else if (EQ(rp, "[else]", length)) { |
|
|
|
} else if (EQ(rp, "[else]", length)) { |
|
|
|
if (fh->parse_if_level == 1) { |
|
|
|
if (fh->parse_if_level == 1) { |
|
|
|
// we got here by running the [if] branch
|
|
|
|
// we got here by running the [if] branch
|
|
|
|
LOG("\x1b[32m[else] end of false skip\x1b[m"); |
|
|
|
LOG("\x1b[3m[else] end of false skip\x1b[m"); |
|
|
|
fh->parse_if_level--; |
|
|
|
fh->parse_if_level--; |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (EQ(rp, "[then]", length)) { |
|
|
|
} else if (EQ(rp, "[then]", length)) { |
|
|
@ -369,7 +386,7 @@ enum fh_error fh_process_line(struct fh_thread_s *fh) |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (fh->parse_if_level == 0) { |
|
|
|
} else if (fh->parse_if_level == 0) { |
|
|
|
/* eval a word */ |
|
|
|
/* eval a word */ |
|
|
|
//LOG("Handle \"%.*s\"", (int) length, rp);
|
|
|
|
LOG("Handle \"%.*s\", len %d", (int) length, rp, length); |
|
|
|
TRY(fh_handle_ascii_word(fh, rp, length)); |
|
|
|
TRY(fh_handle_ascii_word(fh, rp, length)); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if (EQ(rp, "\\", length)) { |
|
|
|
if (EQ(rp, "\\", length)) { |
|
|
|