]> git.draconx.ca Git - cdecl99.git/blobdiff - src/scan.l
libcdecl: Combine identifier and struct allocation.
[cdecl99.git] / src / scan.l
index 29dd33da4374060ea6a9428e7e297a34e0ee6190..7549e6f7baee99cafb40a46d72f2211f10d511ce 100644 (file)
 #define STRTOUMAX strtoul
 #endif
 
-#define dup_token() do { \
-       yylval->strval = malloc(yyleng+1); \
-       if (!yylval->strval) { \
-               cdecl__errmsg(CDECL__ENOMEM); \
-               return T_LEX_ERROR; \
-       } \
-       memcpy(yylval->strval, yytext, yyleng); \
-       yylval->strval[yyleng] = 0; \
-} while(0)
-
 static char *to_octal(char *dst, unsigned val)
 {
        unsigned i;
@@ -188,7 +178,9 @@ INTEGER 0x[[:xdigit:]]+|0[0-7]+|[[:digit:]]+
 #else
                yyless(strcspn(yytext, "-"));
 #endif
-               dup_token();
+               if (!(yylval->item = cdecl__alloc_item(yyleng+1)))
+                       return T_LEX_ERROR; \
+               memcpy(yylval->item->s, yytext, yyleng+1);
        }
        return UNPACK_TOKEN(tok);
 }