From 77961ad9c84ade490da8d79578be764a4e77053c Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Fri, 21 Oct 2011 23:09:57 +0100 Subject: [PATCH] =?UTF-8?q?cfgparse:=20Don=E2=80=99t=20use=20asprintf=20wh?= =?UTF-8?q?en=20parsing=20hex=20colors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cfgparse.l | 2 +- src/cfgparse.y | 11 +++-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/cfgparse.l b/src/cfgparse.l index 50fbc6ca..39e1d398 100644 --- a/src/cfgparse.l +++ b/src/cfgparse.l @@ -138,7 +138,7 @@ EOL (\r?\n) [^\n]+ { yy_pop_state(); yylval.string = sstrdup(yytext); return STR; } [a-zA-Z0-9_-]+ { yy_pop_state(); yylval.string = sstrdup(yytext); return OUTPUT; } ^[ \t]*#[^\n]* { return TOKCOMMENT; } -[0-9a-fA-F]+ { yy_pop_state(); yylval.string = sstrdup(yytext); return HEX; } +#[0-9a-fA-F]+ { yy_pop_state(); yylval.string = sstrdup(yytext+1); return HEXCOLOR; } [ \t]*→[ \t]* { BEGIN(WANT_STRING); } [ \t]+ { BEGIN(WANT_STRING); } [0-9]+ { yylval.number = atoi(yytext); return NUMBER; } diff --git a/src/cfgparse.y b/src/cfgparse.y index c9e1eb98..bc4928f6 100644 --- a/src/cfgparse.y +++ b/src/cfgparse.y @@ -590,7 +590,6 @@ void parse_file(const char *f) { %token WORD "" %token STR "" %token STR_NG "" -%token HEX "" %token HEXCOLOR "#" %token OUTPUT "" %token TOKBINDCODE @@ -1506,14 +1505,10 @@ color: ; colorpixel: - '#' HEX + HEXCOLOR { - char *hex; - if (asprintf(&hex, "#%s", $2) == -1) - die("asprintf()"); - free($2); - $$ = get_colorpixel(hex); - free(hex); + $$ = get_colorpixel($1); + free($1); } ;