X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=lexer.c;h=08774997babc8a675f78d843463a3f2593aba6bc;hb=8100b4a9336172bceb7d67992aed642b26a4508e;hp=99dd4e67b228aa15a4d312ee6ca6049bf967979c;hpb=3415b6eed2f921a4281a7068919eda93c6b26099;p=cparser diff --git a/lexer.c b/lexer.c index 99dd4e6..0877499 100644 --- a/lexer.c +++ b/lexer.c @@ -333,10 +333,20 @@ static named_decoder_t const decoders[] = { { NULL, NULL } }; +/** strcasecmp is not part of C99 so we need our own implementation here */ +static int my_strcasecmp(const char *s1, const char *s2) +{ + for ( ; *s1 != 0; ++s1, ++s2) { + if (tolower(*s1) != tolower(*s2)) + break; + } + return (unsigned char)*s1 - (unsigned char)*s2; +} + void select_input_encoding(char const* const encoding) { for (named_decoder_t const *i = decoders; i->name != NULL; ++i) { - if (strcasecmp(encoding, i->name) != 0) + if (my_strcasecmp(encoding, i->name) != 0) continue; decoder = i->decoder; return; @@ -758,7 +768,7 @@ static void parse_number(void) /* check for invalid octal digits */ for (size_t i= 0; i < size; ++i) { char t = string[i]; - if (t == '8' || t == '9') + if (t >= '8') errorf(&lexer_token.source_position, "invalid digit '%c' in octal number", t); } @@ -1657,15 +1667,15 @@ void lexer_open_buffer(const char *buffer, size_t len, const char *input_name) #if 0 // TODO bufpos = buffer; bufend = buffer + len; + + /* place a virtual \n at the beginning so the lexer knows that we're + * at the beginning of a line */ + c = '\n'; #else (void)buffer; (void)len; panic("builtin lexing not done yet"); #endif - - /* place a virtual \n at the beginning so the lexer knows that we're - * at the beginning of a line */ - c = '\n'; } void exit_lexer(void)