<div dir="ltr">From e40c908b95aff31a5527abbd0690cc61f5f50bd4 Mon Sep 17 00:00:00 2001<br>From: Adeniyi Mayokun <<a href="mailto:adeniyimayokun17@gmail.com">adeniyimayokun17@gmail.com</a>><br>Date: Sat, 24 Mar 2018 11:07:17 +0100<br>Subject: [PATCH 2/2] Fixed wrc gives parse error if resource nameID has quoted<br> & Updated parse.l file<br> <br> Signed-off-by: Adeniyi Mayokun <<a href="mailto:adeniyimayokun17@gmail.com">adeniyimayokun17@gmail.com</a>><br><br>---<br> tools/wrc/parser.l | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++--<br> 1 file changed, 99 insertions(+), 3 deletions(-)<br><br>diff --git a/tools/wrc/parser.l b/tools/wrc/parser.l<br>index 32a231b5a2..dfcefc069e 100644<br>--- a/tools/wrc/parser.l<br>+++ b/tools/wrc/parser.l<br>@@ -66,7 +66,10 @@<br>  *            - Rebuild string processing so that it may contain<br>  *              escaped '\0'.<br>  */<br>-<br>+/* Exclusive double-quoted nameID handling */<br>+%x tkid_dbl<br>+/* Exclusive single-quoted nameID handling */<br>+%x tkid_sgl<br> /* Exclusive string handling */<br> %x tkstr<br> /* Exclusive unicode string handling */<br>@@ -122,6 +125,7 @@ ws    [ \f\t\r]<br> #define YY_USER_ACTION    char_number+=yyleng; wanted_id = want_id; want_id = 0;<br> <br> #define YY_USER_INIT current_codepage = -1;<br>+id_initial = 1;<br> <br> static void addcchar(char c);<br> static void addwchar(WCHAR s);<br>@@ -138,6 +142,13 @@ static int wbufalloc = 0;<br> <br> static int current_codepage = -1;  /* use language default */<br> <br>+/* Used for differentiating between single- and double-quoted nameID's */<br>+static int id_dblquote = 0;<br>+/* Used for catching first (quoted) nameID before wanted_id is set.<br>+ * This variable is reset to 0 once the first ID (quoted or not), string or<br>+ * data has been encountered */<br>+static int id_initial = 1;<br>+<br> /*<br>  * This one is a bit tricky.<br>  * We set 'want_id' in the parser to get the first<br>@@ -402,8 +413,46 @@ static unsigned long xstrtoul(const char *nptr, char **endptr, int base)<br> 0[oO][0-7]+[lL]?    { parser_lval.num = xstrtoul(yytext+2, 0, 8);<br>                           return (yytext[yyleng-1] == 'L' || yytext[yyleng-1] == 'l') ? tLNUMBER : tNUMBER; }<br> <br>+<tkid_dbl>{A-Za-z_0-9./\\\']+\"<br>+|<br>+<tkid_sgl>[A-Za-z_0-9./\\\"]+\'<br>+{<br>+<br>+char *tmp;<br>+<br>+size_t len;<br>+<br>+/* Plus 1 for the initial double quote that we missed and plus 1 for a trailing NUL */<br>+<br>+len = strlen(yytext) +2;<br>+<br>+tmp = xmalloc(len);<br>+<br>+/* Put the quote character that was missed */<br>+<br>+tmp[0] = id_dblquote ? '\"' : '\'';<br>+<br>+id_dlquote = 0;<br>+<br>+strcpy(tmp + 1, yytext);<br>+<br>+/* Make sure we have a NUL at the end */<br>+<br>+tmp[len-1] = '\0';<br>+<br>+parser_lval.str = make_string(tmp);<br>+<br>+free(tmp);<br>+<br>+yy_pop_state();<br>+<br>+return tIDENT;<br>+}<br>+<br>+<br> [A-Za-z_0-9./\\]+    {<br>                 struct keyword *tok = iskeyword(yytext);<br>+                id_initial = 0;<br> <br>                 if(tok)<br>                 {<br>@@ -427,6 +476,9 @@ static unsigned long xstrtoul(const char *nptr, char **endptr, int base)<br>      */<br> L\"            {<br>                 yy_push_state(tklstr);<br>+<br>+                id_initial = 0;<br>+                <br>                 wbufidx = 0;<br>                 if(!win32)<br>                     parser_warning("16bit resource contains unicode strings\n");<br>@@ -483,7 +535,29 @@ L\"            {<br>     /*<br>      * Normal string scanning<br>      */<br>-\"            yy_push_state(tkstr); cbufidx = 0;<br>+\" {<br>+<br>+<br>+if (wanted_id || id_initial)<br>+<br>+{<br>+<br>+yy_push_state(tkid_dbl);<br>+<br>+id_dblquote = 1;<br>+<br>+id_initial = 0;<br>+<br>+}<br>+<br>+else<br>+<br>+{<br>+<br>+            yy_push_state(tkstr); cbufidx = 0;<br>+<br>+}<br>+    }<br> <tkstr>\"{ws}+    |<br> <tkstr>\"        {<br>                 yy_pop_state();<br>@@ -528,7 +602,29 @@ L\"            {<br>     /*<br>      * Raw data scanning<br>      */<br>-\'            yy_push_state(tkrcd); cbufidx = 0;<br>+\' {<br>+<br>+if (wanted_id || id_initial)<br>+<br>+{<br>+<br>+yy_push_state(tkid_sgl);<br>+<br>+id_initial = 0;<br>+<br>+id_dblquote = 0;<br>+<br>+}<br>+<br>+else<br>+<br>+{<br>+<br>+<br>+            yy_push_state(tkrcd); cbufidx = 0;<br>+<br>+}<br>+    }<br> <tkrcd>\'        {<br>                 yy_pop_state();<br>                 parser_lval.raw = new_raw_data();<br>-- <br>2.14.1<br><br><br></div>