5 #include <string.h> /* memcmp */
7 /*******************************************************************************/
9 bool memstrcmp(const uint8_t *start, const uint8_t *end, const char *str)
11 uint32_t len = strlen(str);
16 return memcmp(start, str, len) == 0;
21 static uint8_t digit_to_int(uint8_t ch)
42 // parse binary, hex and decimal numbers
43 bool parse_number(const uint8_t *str, uint8_t len, uint32_t *result)
58 if ((i == 0 || i == 1) && c == 'b') // 0b/b for binary
66 if (i==0 && c == 'h') // h for hex
74 if (i == 1 && c == 'x') // 0x for hex
83 digit = digit_to_int(c);
86 *result = (*result) * base + digit;
93 /*******************************************************************************/
95 // find the next token in the buffer given by *tok_start to line_end
96 // on success, returns true, *tok_start points at first byte of found token, *tok_end points at first character after end of token
97 bool tok(uint8_t const **tok_start, uint8_t const **tok_end, const uint8_t *line_end)
99 // skip whitespace on front
100 while(*tok_start != line_end)
102 if (**tok_start == ' ' || **tok_start == '\t')
107 // *tok_start is now first non-whitespace character in token
109 *tok_end = *tok_start;
110 // skip to end of token
111 while(*tok_end != line_end)
113 if (**tok_end == ' ' || **tok_end == '\t')
118 // *tok_end is now first whitespace character after token or line_end
120 return *tok_end != *tok_start;
123 // advance tok_start/tok_end to next token and read number value into i
124 bool tok_num(const uint8_t **tok_start, const uint8_t **tok_end, const uint8_t *line_end, uint32_t *i)
126 if (tok(tok_start, tok_end, line_end))
128 if (parse_number(*tok_start, (*tok_end)-(*tok_start), i))
130 *tok_start = *tok_end; // skip past token
135 // *tok_start = *tok_end; // skip past token
142 /*******************************************************************************/