adapt to simplified opt_funccall interface
[cparser] / lexer.c
diff --git a/lexer.c b/lexer.c
index 111bc6d..8e0567e 100644 (file)
--- a/lexer.c
+++ b/lexer.c
@@ -87,7 +87,9 @@ static size_t read_block(unsigned char *const read_buf, size_t const n)
 {
        size_t const s = fread(read_buf, 1, n, input);
        if (s == 0) {
-               if (ferror(input))
+               /* on OS/X ferror appears to return true on eof as well when running
+                * the application in gdb... */
+               if (!feof(input) && ferror(input))
                        parse_error("read from input failed");
                buf[MAX_PUTBACK] = EOF;
                bufpos           = buf + MAX_PUTBACK;
@@ -333,10 +335,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 +770,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);
                }