diff options
Diffstat (limited to 'libmu_sieve/sieve-lex.l')
-rw-r--r-- | libmu_sieve/sieve-lex.l | 48 |
1 files changed, 16 insertions, 32 deletions
diff --git a/libmu_sieve/sieve-lex.l b/libmu_sieve/sieve-lex.l index 306aaf92b..c2f4de3fc 100644 --- a/libmu_sieve/sieve-lex.l +++ b/libmu_sieve/sieve-lex.l @@ -1,6 +1,6 @@ %top { /* GNU Mailutils -- a suite of utilities for electronic mail - Copyright (C) 1999-2019 Free Software Foundation, Inc. + Copyright (C) 1999-2024 Free Software Foundation, Inc. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -41,7 +41,6 @@ static int number (void); static int string (void); static void line_begin (void); static void line_add (char const *text, size_t len); -static void line_addz (char const *text); static void line_finish (void); static void multiline_begin (void); static void multiline_add (void); @@ -50,7 +49,6 @@ static char *multiline_strip_tabs (char *text); static void ident (const char *text); static void sieve_include (void); static void sieve_searchpath (void); -static char *str_unescape (char *text, size_t len); static int isemptystr (char *text); static mu_linetrack_t trk; @@ -155,12 +153,12 @@ push_source (const char *name) if (yylloc.beg.mu_file && st.st_ino == sieve_source_inode) { - yyerror (_("recursive inclusion")); + mu_sieve_yyerror (_("recursive inclusion")); return 1; } if ((ctx = ctx_lookup (st.st_ino))) { - yyerror (_("recursive inclusion")); + mu_sieve_yyerror (_("recursive inclusion")); if (ctx->prev) { mu_diag_at_locus_range (MU_LOG_ERROR, &ctx->incl_range, @@ -234,6 +232,7 @@ pop_source () } %} +%option prefix="mu_sieve_yy" %option nounput %option noinput @@ -274,13 +273,15 @@ true return TRUE; 0x[0-9a-fA-F][0-9a-fA-F]+{SIZESUF}* { return number (); } [1-9][0-9]*{SIZESUF}* { return number (); } /* Quoted strings */ -\"[^\\"\n]*\" { return string (); } -\"[^\\"\n]*\\. { BEGIN(STR); +\"[^\\"]*\" { return string (); } +\"[^\\"]*\\. { BEGIN(STR); line_begin (); - line_addz (str_unescape (yytext + 1, yyleng - 1)); } -<STR>[^\\"\n]*\\. { line_addz (str_unescape (yytext, yyleng)); } -<STR>[^\\"\n]*\" { BEGIN(INITIAL); - if (yyleng > 1) + line_add (yytext + 1, yyleng - 3); + line_add (yytext + yyleng - 1, 1); } +<STR>[^\\"]*\\. { line_add (yytext, yyleng - 2); + line_add (yytext + yyleng - 1, 1); } +<STR>[^\\"]*\" { BEGIN(INITIAL); + if (yyleng > 1) line_add (yytext, yyleng - 1); line_finish (); return STRING; } @@ -344,7 +345,7 @@ get_file_name (char *p, char *endp, int *usepath) break; default: - yyerror (_("preprocessor syntax")); + mu_sieve_yyerror (_("preprocessor syntax")); return NULL; } @@ -353,7 +354,7 @@ get_file_name (char *p, char *endp, int *usepath) if (*p != exp) { - yyerror (_("missing closing quote in preprocessor statement")); + mu_sieve_yyerror (_("missing closing quote in preprocessor statement")); return NULL; } @@ -523,12 +524,6 @@ line_add (char const *text, size_t len) } static void -line_addz (char const *text) -{ - mu_opool_appendz (mu_sieve_machine->string_pool, text); -} - -static void multiline_add (void) { mu_opool_appendz (mu_sieve_machine->string_pool, @@ -573,7 +568,7 @@ multiline_begin (void) multiline_delimiter = strdup ("."); if (!multiline_delimiter) { - yyerror (_("not enough memory")); + mu_sieve_yyerror (_("not enough memory")); exit (1); } } @@ -593,21 +588,10 @@ ident (const char *text) yylval.string = strdup (text); if (!yylval.string) { - yyerror (_("not enough memory")); + mu_sieve_yyerror (_("not enough memory")); exit (1); } } - -/* Escapes the last character from yytext */ -static char * -str_unescape (char *text, size_t len) -{ - char *str = mu_sieve_malloc (mu_sieve_machine, len); - memcpy (str, text, len - 2); - str[len - 2] = mu_wordsplit_c_unquote_char (text[len - 1]); - str[len - 1] = 0; - return str; -} static mu_i_sv_interp_t string_interpreter; |