Allow backslashes in quoted strings.
Showing
1 changed file
with
35 additions
and
12 deletions
... | @@ -39,12 +39,13 @@ static list_t string_list; | ... | @@ -39,12 +39,13 @@ static list_t string_list; |
39 | static int number __P ((void)); | 39 | static int number __P ((void)); |
40 | static int string __P ((void)); | 40 | static int string __P ((void)); |
41 | static void multiline_begin __P ((void)); | 41 | static void multiline_begin __P ((void)); |
42 | static void multiline_add __P ((void)); | 42 | static void multiline_add __P ((char *)); |
43 | static void multiline_finish __P ((void)); | 43 | static void multiline_finish __P ((void)); |
44 | static void ident __P((const char *text)); | 44 | static void ident __P((const char *text)); |
45 | static void sieve_include __P((void)); | 45 | static void sieve_include __P((void)); |
46 | static void sieve_searchpath __P((void)); | 46 | static void sieve_searchpath __P((void)); |
47 | 47 | static char *str_escape __P((void)); | |
48 | |||
48 | #ifdef FLEX_SCANNER | 49 | #ifdef FLEX_SCANNER |
49 | #define xinput() (yyin ? getc(yyin) : EOF) | 50 | #define xinput() (yyin ? getc(yyin) : EOF) |
50 | #undef YY_INPUT | 51 | #undef YY_INPUT |
... | @@ -310,7 +311,7 @@ pop_source () | ... | @@ -310,7 +311,7 @@ pop_source () |
310 | return 0; | 311 | return 0; |
311 | } | 312 | } |
312 | %} | 313 | %} |
313 | %x COMMENT ML | 314 | %x COMMENT ML STR |
314 | 315 | ||
315 | WS [ \t][ \t]* | 316 | WS [ \t][ \t]* |
316 | IDENT [a-zA-Z_][a-zA-Z_0-9]+ | 317 | IDENT [a-zA-Z_][a-zA-Z_0-9]+ |
... | @@ -343,15 +344,23 @@ not return NOT; | ... | @@ -343,15 +344,23 @@ not return NOT; |
343 | 0[0-7]*{SIZESUF}* { return number (); } | 344 | 0[0-7]*{SIZESUF}* { return number (); } |
344 | 0x[0-9a-fA-F][0-9a-fA-F]+{SIZESUF}* { return number (); } | 345 | 0x[0-9a-fA-F][0-9a-fA-F]+{SIZESUF}* { return number (); } |
345 | [1-9][0-9]*{SIZESUF}* { return number (); } | 346 | [1-9][0-9]*{SIZESUF}* { return number (); } |
346 | \"[^"\n]*\" { return string (); } | 347 | \"[^\\"\n]*\" { return string (); } |
347 | text: { BEGIN(ML); multiline_begin (); } | 348 | \"[^\\"\n]*\\. { BEGIN(STR); |
349 | multiline_begin (); | ||
350 | multiline_add (str_escape ()); } | ||
351 | <STR>[^\\"\n]*\\. { multiline_add (str_escape ()); } | ||
352 | <STR>[^\\"\n]*\" { BEGIN(INITIAL); | ||
353 | multiline_add (NULL); | ||
354 | multiline_finish (); | ||
355 | return STRING; } | ||
356 | text:[ \t]*#.*\n { BEGIN(ML); multiline_begin (); } | ||
357 | text:[ \t]*\n { BEGIN(ML); multiline_begin (); } | ||
348 | <ML>.[ \t]*\n { BEGIN(INITIAL); | 358 | <ML>.[ \t]*\n { BEGIN(INITIAL); |
349 | sieve_line_num++; | 359 | sieve_line_num++; |
350 | multiline_add (); | ||
351 | multiline_finish (); | 360 | multiline_finish (); |
352 | return MULTILINE; } | 361 | return MULTILINE; } |
353 | <ML>#[ \t]*include.*\n { sieve_include (); } | 362 | <ML>#[ \t]*include.*\n { sieve_include (); } |
354 | <ML>.*\n { sieve_line_num++; multiline_add (); } | 363 | <ML>.*\n { sieve_line_num++; multiline_add (NULL); } |
355 | {WS} ; | 364 | {WS} ; |
356 | \n { sieve_line_num++; } | 365 | \n { sieve_line_num++; } |
357 | . return yytext[0]; | 366 | . return yytext[0]; |
... | @@ -493,7 +502,7 @@ int | ... | @@ -493,7 +502,7 @@ int |
493 | number () | 502 | number () |
494 | { | 503 | { |
495 | char *p; | 504 | char *p; |
496 | yylval.number = strtol (yytext, &p, 0); | 505 | yylval.number = strtoul (yytext, &p, 0); |
497 | switch (*p) | 506 | switch (*p) |
498 | { | 507 | { |
499 | case 'k': | 508 | case 'k': |
... | @@ -523,13 +532,16 @@ string () | ... | @@ -523,13 +532,16 @@ string () |
523 | } | 532 | } |
524 | 533 | ||
525 | void | 534 | void |
526 | multiline_add () | 535 | multiline_add (char *s) |
527 | { | 536 | { |
528 | char *s = strdup (yytext); | ||
529 | if (!s) | 537 | if (!s) |
530 | { | 538 | { |
531 | yyerror ("not enough memory"); | 539 | s = strdup (yytext); |
532 | exit (1); | 540 | if (!s) |
541 | { | ||
542 | yyerror ("not enough memory"); | ||
543 | exit (1); | ||
544 | } | ||
533 | } | 545 | } |
534 | list_append (string_list, s); | 546 | list_append (string_list, s); |
535 | } | 547 | } |
... | @@ -594,3 +606,14 @@ ident (const char *text) | ... | @@ -594,3 +606,14 @@ ident (const char *text) |
594 | exit (1); | 606 | exit (1); |
595 | } | 607 | } |
596 | } | 608 | } |
609 | |||
610 | /* Escapes the last character from yytext */ | ||
611 | char * | ||
612 | str_escape () | ||
613 | { | ||
614 | char *str = sieve_alloc (yyleng - 1); | ||
615 | memcpy (str, yytext, yyleng - 2); | ||
616 | str[yyleng - 2] = yytext[yyleng - 1]; | ||
617 | str[yyleng - 1] = 0; | ||
618 | return str; | ||
619 | } | ... | ... |
-
Please register or sign in to post a comment