From 1a51c8981750865412b53f01fbae8305d85f4a50 Mon Sep 17 00:00:00 2001 From: Jose Luis Tallon Date: Mon, 28 Dec 2015 19:55:13 +0100 Subject: [PATCH] Add support for octal ints --- lib/scanner.l | 18 +++++++++++++++++- lib/wincompat.h | 1 + 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/scanner.l b/lib/scanner.l index 54a7dcf..f0f8d51 100644 --- a/lib/scanner.l +++ b/lib/scanner.l @@ -39,6 +39,7 @@ #endif #include +#include #include #include #include @@ -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; diff --git a/lib/wincompat.h b/lib/wincompat.h index ddf950f..fe5f5bc 100644 --- a/lib/wincompat.h +++ b/lib/wincompat.h @@ -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) -- 2.7.4