Add support for octal ints
authorJose Luis Tallon <jltallon@adv-solutions.net>
Mon, 28 Dec 2015 18:55:13 +0000 (19:55 +0100)
committerJose Luis Tallon <jltallon@adv-solutions.net>
Wed, 30 Dec 2015 18:15:37 +0000 (19:15 +0100)
lib/scanner.l
lib/wincompat.h

index 54a7dcf..f0f8d51 100644 (file)
@@ -39,6 +39,7 @@
 #endif
 
 #include <stdlib.h>
+#include <errno.h>
 #include <ctype.h>
 #include <string.h>
 #include <limits.h>
@@ -232,7 +233,22 @@ include_dir_open  ^[ \t]*@include_dir[ \t]+\"
 {float}           { yylval->fval = atof(yytext); return(TOK_FLOAT); }
 {integer}         {
                     long long llval;
-                    llval = atoll(yytext);
+                    char *endptr;
+                    int errsave = errno;
+                    errno = 0;
+                    llval = strtoll(yytext, &endptr, 0);       /* base 10 or base 8 */
+                    if( '\0'!=*endptr || 0!=errno )
+                    {
+                      errno = 0;
+                      return(TOK_ERROR);       /* some error occured ... */
+                    }
+                    errno = errsave;
+                    if( '0'==*yytext && '\0'!=*(yytext+1) )
+                    {  // it's octal... so INT we go
+                      yylval->ival=(int)(llval);
+                      return(TOK_INTEGER);
+                    }
+
                     if((llval < INT_MIN) || (llval > INT_MAX))
                     {
                       yylval->llval = llval;
index ddf950f..fe5f5bc 100644 (file)
@@ -40,6 +40,7 @@
 #if !defined(__MINGW32__) && _MSC_VER < 1800
 #define atoll     _atoi64
 #define strtoull  _strtoui64
+#define strtoll   _strtoi64
 #endif
 
 #if !defined(S_ISDIR) && defined(S_IFMT) && defined(S_IFDIR)