]> git.sur5r.net Git - i3/i3/commitdiff
cfgparse: Don’t use asprintf when parsing hex colors
authorMichael Stapelberg <michael@stapelberg.de>
Fri, 21 Oct 2011 22:09:57 +0000 (23:09 +0100)
committerMichael Stapelberg <michael@stapelberg.de>
Fri, 21 Oct 2011 22:09:57 +0000 (23:09 +0100)
src/cfgparse.l
src/cfgparse.y

index 50fbc6caaf154713249735f5c4c958032e01fc33..39e1d3988c15e51fd6e4a910d25b6fca9064aa6e 100644 (file)
@@ -138,7 +138,7 @@ EOL     (\r?\n)
 <WANT_STRING>[^\n]+             { yy_pop_state(); yylval.string = sstrdup(yytext); return STR; }
 <OUTPUT_COND>[a-zA-Z0-9_-]+     { yy_pop_state(); yylval.string = sstrdup(yytext); return OUTPUT; }
 ^[ \t]*#[^\n]*                  { return TOKCOMMENT; }
-<COLOR_COND>[0-9a-fA-F]+        { yy_pop_state(); yylval.string = sstrdup(yytext); return HEX; }
+<COLOR_COND>#[0-9a-fA-F]+       { yy_pop_state(); yylval.string = sstrdup(yytext+1); return HEXCOLOR; }
 <ASSIGN_TARGET_COND>[ \t]*→[ \t]*     { BEGIN(WANT_STRING); }
 <ASSIGN_TARGET_COND>[ \t]+      { BEGIN(WANT_STRING); }
 [0-9]+                          { yylval.number = atoi(yytext); return NUMBER; }
index c9e1eb98f7060a4905be837b7ba474d066661bab..bc4928f632febfb8d1ad35e7f696587ba1a8376c 100644 (file)
@@ -590,7 +590,6 @@ void parse_file(const char *f) {
 %token  <string>        WORD                        "<word>"
 %token  <string>        STR                         "<string>"
 %token  <string>        STR_NG                      "<string (non-greedy)>"
-%token  <string>        HEX                         "<hex>"
 %token  <string>        HEXCOLOR                    "#<hex>"
 %token  <string>        OUTPUT                      "<RandR 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);
     }
     ;