]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - tc/emp_ematch.l
Replace open-coded instances of print_nl()
[mirror_iproute2.git] / tc / emp_ematch.l
index 70cdb9a615f8de0ee72dee2a79d265418064858e..2f4926d43d5b2a9eb55253ac2eb26d2e4c86c1aa 100644 (file)
@@ -1,5 +1,6 @@
+/* SPDX-License-Identifier: GPL-2.0 */
 %{
- #include "emp_ematch.yacc.h"
+ #include "emp_ematch.tab.h"
  #include "m_ematch.h"
 
  extern int ematch_argc;
  static void __attribute__ ((unused)) yy_push_state (int  new_state );
  static void __attribute__ ((unused)) yy_pop_state  (void);
  static int  __attribute__ ((unused)) yy_top_state (void );
-%}
-
-%x str
 
-%option 8bit stack warn noyywrap prefix="ematch_"
-%%
-
- static unsigned char *strbuf;
+ static char *strbuf;
  static unsigned int strbuf_size;
  static unsigned int strbuf_index;
 
        strbuf = realloc(strbuf, strbuf_size);
  }
 
- static void strbuf_append_char(unsigned char c)
+ static void strbuf_append_char(char c)
  {
        while (strbuf_index >= strbuf_size)
                strbuf_enlarge();
        strbuf[strbuf_index++] = c;
  }
 
- static void strbuf_append_charp(unsigned char *s)
+ static void strbuf_append_charp(char *s)
  {
        while (strbuf_index >= strbuf_size)
                strbuf_enlarge();
        strbuf_index += strlen(s);
  }
 
+%}
+
+%x lexstr
+
+%option 8bit stack warn noyywrap prefix="ematch_"
+%%
 [ \t\r\n]+
 
 \"                                     {
                                                                return ERROR;
                                                }
                                                strbuf_index = 0;
-                                               
-                                               BEGIN(str);
+
+                                               BEGIN(lexstr);
                                        }
 
-<str>\"                                        {
+<lexstr>\"                                     {
                                                BEGIN(INITIAL);
                                                yylval.b = bstr_new(strbuf, strbuf_index);
                                                yylval.b->quoted = 1;
                                                return ATTRIBUTE;
                                        }
 
-<str>\\[0-7]{1,3}                      { /* octal escape sequence */
+<lexstr>\\[0-7]{1,3}                   { /* octal escape sequence */
                                                int res;
-                                               
+
                                                sscanf(yytext + 1, "%o", &res);
                                                if (res > 0xFF) {
                                                        fprintf(stderr, "error: octal escape sequence" \
                                                strbuf_append_char((unsigned char) res);
                                        }
 
-<str>\\[0-9]+                          { /* catch wrong octal escape seq. */
+<lexstr>\\[0-9]+                               { /* catch wrong octal escape seq. */
                                                fprintf(stderr, "error: invalid octale escape sequence\n");
                                                return ERROR;
                                        }
 
-<str>\\x[0-9a-fA-F]{1,2}               {
+<lexstr>\\x[0-9a-fA-F]{1,2}            {
                                                int res;
-                                               
+
                                                sscanf(yytext + 2, "%x", &res);
-                                               
+
                                                if (res > 0xFF) {
                                                        fprintf(stderr, "error: hexadecimal escape " \
                                                        "sequence out of range\n");
                                                strbuf_append_char((unsigned char) res);
                                        }
 
-<str>\\n                               strbuf_append_char('\n');
-<str>\\r                               strbuf_append_char('\r');
-<str>\\t                               strbuf_append_char('\t');
-<str>\\v                               strbuf_append_char('\v');
-<str>\\b                               strbuf_append_char('\b');
-<str>\\f                               strbuf_append_char('\f');
-<str>\\a                               strbuf_append_char('\a');
+<lexstr>\\n                            strbuf_append_char('\n');
+<lexstr>\\r                            strbuf_append_char('\r');
+<lexstr>\\t                            strbuf_append_char('\t');
+<lexstr>\\v                            strbuf_append_char('\v');
+<lexstr>\\b                            strbuf_append_char('\b');
+<lexstr>\\f                            strbuf_append_char('\f');
+<lexstr>\\a                            strbuf_append_char('\a');
 
-<str>\\(.|\n)                          strbuf_append_char(yytext[1]);
-<str>[^\\\n\"]+                                strbuf_append_charp(yytext);
+<lexstr>\\(.|\n)                       strbuf_append_char(yytext[1]);
+<lexstr>[^\\\n\"]+                     strbuf_append_charp(yytext);
 
 [aA][nN][dD]                           return AND;
 [oO][rR]                               return OR;
 ")"                                    {
                                                return yylval.i = *yytext;
                                        }
-[^ \t\r\n()]+                          {
+[^" \t\r\n()][^ \t\r\n()]*             {
                                                yylval.b = bstr_alloc(yytext);
                                                if (yylval.b == NULL)
                                                        return ERROR;