diff options
author | Daiki Ueno <ueno@gnu.org> | 2014-12-18 12:17:51 +0900 |
---|---|---|
committer | Daiki Ueno <ueno@gnu.org> | 2014-12-18 12:17:51 +0900 |
commit | ebb5f4402e57fbc15b2800714b45ccf1e05e398b (patch) | |
tree | e7c9c3a6fd85e87037561893c906f84b216c89a8 /gettext-tools/src/x-sh.c | |
parent | 366484db5124a0928679004013143b90e9739283 (diff) | |
download | external_gettext-ebb5f4402e57fbc15b2800714b45ccf1e05e398b.zip external_gettext-ebb5f4402e57fbc15b2800714b45ccf1e05e398b.tar.gz external_gettext-ebb5f4402e57fbc15b2800714b45ccf1e05e398b.tar.bz2 |
sh: Fix handling of Bash ANSI-C quoting
* x-sh.c (read_word): Use phase1 instead of phase2 for Bash ANSI-C
escape sequences. Also handle '\"' and '\E'.
Diffstat (limited to 'gettext-tools/src/x-sh.c')
-rw-r--r-- | gettext-tools/src/x-sh.c | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/gettext-tools/src/x-sh.c b/gettext-tools/src/x-sh.c index 81776d3..9a0614f 100644 --- a/gettext-tools/src/x-sh.c +++ b/gettext-tools/src/x-sh.c @@ -911,32 +911,32 @@ read_word (struct word *wp, int looking_for, flag_context_ty context) if (c2 == '\'' && !open_singlequote) { /* Bash builtin for string with ANSI-C escape sequences. */ - saw_opening_singlequote (); for (;;) { - c = phase2_getc (); + /* We have to use phase1 throughout this loop, + because phase2 does debackslashification, + which is undesirable when parsing ANSI-C + escape sequences. */ + c = phase1_getc (); if (c == EOF) break; if (c == '\'') - { - saw_closing_singlequote (); - break; - } + break; if (c == '\\') { - c = phase2_getc (); + c = phase1_getc (); switch (c) { default: - phase2_ungetc (c); + phase1_ungetc (c); c = '\\'; break; case '\\': break; case '\'': - /* Don't call saw_closing_singlequote () - here. */ + break; + case '"': break; case 'a': @@ -946,6 +946,7 @@ read_word (struct word *wp, int looking_for, flag_context_ty context) c = '\b'; break; case 'e': + case 'E': c = 0x1b; /* ESC */ break; case 'f': @@ -965,7 +966,7 @@ read_word (struct word *wp, int looking_for, flag_context_ty context) break; case 'x': - c = phase2_getc (); + c = phase1_getc (); if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')) @@ -981,7 +982,7 @@ read_word (struct word *wp, int looking_for, flag_context_ty context) else abort (); - c = phase2_getc (); + c = phase1_getc (); if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')) @@ -996,14 +997,14 @@ read_word (struct word *wp, int looking_for, flag_context_ty context) abort (); } else - phase2_ungetc (c); + phase1_ungetc (c); c = n; } else { - phase2_ungetc (c); - phase2_ungetc ('x'); + phase1_ungetc (c); + phase1_ungetc ('x'); c = '\\'; } break; @@ -1013,19 +1014,19 @@ read_word (struct word *wp, int looking_for, flag_context_ty context) { int n = c - '0'; - c = phase2_getc (); + c = phase1_getc (); if (c >= '0' && c <= '7') { n = n * 8 + c - '0'; - c = phase2_getc (); + c = phase1_getc (); if (c >= '0' && c <= '7') n = n * 8 + c - '0'; else - phase2_ungetc (c); + phase1_ungetc (c); } else - phase2_ungetc (c); + phase1_ungetc (c); c = n; } |