diff --git a/ChangeLog b/ChangeLog index 54a64509c..61e5b7c12 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2012-02-25 Vladimir Serbinenko + + $"..." support in scripts. + + * grub-core/script/execute.c (grub_script_arglist_to_argv): Handle + GRUB_SCRIPT_ARG_TYPE_GETTEXT. + * grub-core/script/yylex.l: Likewise. + * include/grub/script_sh.h (GRUB_SCRIPT_ARG_TYPE_GETTEXT): New enum + value. + 2012-02-25 Vladimir Serbinenko * gentpl.py: Remove obsolete pkglib_DATA handling. diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c index 466c3cfe7..cddc7ad4c 100644 --- a/grub-core/script/execute.c +++ b/grub-core/script/execute.c @@ -328,8 +328,8 @@ grub_script_arglist_to_argv (struct grub_script_arglist *arglist, struct grub_script_arg *arg = 0; struct grub_script_argv result = { 0, 0, 0 }; - auto int append (char *s, int escape_type); - int append (char *s, int escape_type) + auto int append (const char *s, int escape_type); + int append (const char *s, int escape_type) { int r; char *p = 0; @@ -395,12 +395,20 @@ grub_script_arglist_to_argv (struct grub_script_arglist *arglist, break; case GRUB_SCRIPT_ARG_TYPE_TEXT: - if (grub_strlen (arg->str) && + if (arg->str[0] && grub_script_argv_append (&result, arg->str, grub_strlen (arg->str))) goto fail; break; + case GRUB_SCRIPT_ARG_TYPE_GETTEXT: + { + const char *t = _(arg->str); + if (grub_script_argv_append (&result, t, grub_strlen (t))) + goto fail; + } + break; + case GRUB_SCRIPT_ARG_TYPE_DQSTR: case GRUB_SCRIPT_ARG_TYPE_SQSTR: if (append (arg->str, 1)) diff --git a/grub-core/script/yylex.l b/grub-core/script/yylex.l index 55188b79b..85314ef70 100644 --- a/grub-core/script/yylex.l +++ b/grub-core/script/yylex.l @@ -133,15 +133,17 @@ ESC \\(.|\n) SQCHR [^\'] DQCHR {ESC}|[^\\\"] DQSTR \"{DQCHR}*\" +I18NSTR \$\"{DQCHR}*\" SQSTR \'{SQCHR}*\' SPECIAL \?|\#|\*|\@ VARIABLE ${NAME}|$\{{NAME}\}|${DIGITS}|$\{{DIGITS}\}|${SPECIAL}|$\{{SPECIAL}\} -WORD ({CHAR}|{DQSTR}|{SQSTR}|{ESC}|{VARIABLE})+ +WORD ({CHAR}|{DQSTR}|{SQSTR}|{ESC}|{VARIABLE}|{I18NSTR})+ MULTILINE {WORD}?((\"{DQCHR}*)|(\'{SQCHR}*)|(\\\n)) %x SPLIT %x DQUOTE +%x I18NQUOTE %x SQUOTE %x VAR @@ -217,6 +219,10 @@ MULTILINE {WORD}?((\"{DQCHR}*)|(\'{SQCHR}*)|(\\\n)) yy_push_state (SQUOTE, yyscanner); ARG (GRUB_SCRIPT_ARG_TYPE_TEXT); } + "\$\"" { + yy_push_state (I18NQUOTE, yyscanner); + ARG (GRUB_SCRIPT_ARG_TYPE_GETTEXT); + } \$ { yy_push_state (VAR, yyscanner); ARG (GRUB_SCRIPT_ARG_TYPE_TEXT); @@ -282,6 +288,18 @@ MULTILINE {WORD}?((\"{DQCHR}*)|(\'{SQCHR}*)|(\\\n)) (.|\n) { COPY (yytext, yyleng); } } +{ + \\\\ { COPY ("\\", 1); } + \\\" { COPY ("\"", 1); } + \\\n { /* ignore */ } + [^\"\\\n]+ { COPY (yytext, yyleng); } + \" { + yy_pop_state (yyscanner); + ARG (GRUB_SCRIPT_ARG_TYPE_GETTEXT); + } + (.|\n) { COPY (yytext, yyleng); } +} + <> { yypop_buffer_state (yyscanner); yyextra->lexerstate->eof = 1; diff --git a/include/grub/script_sh.h b/include/grub/script_sh.h index fdccaca8d..b4c3f40ef 100644 --- a/include/grub/script_sh.h +++ b/include/grub/script_sh.h @@ -53,6 +53,7 @@ typedef enum { GRUB_SCRIPT_ARG_TYPE_VAR, GRUB_SCRIPT_ARG_TYPE_TEXT, + GRUB_SCRIPT_ARG_TYPE_GETTEXT, GRUB_SCRIPT_ARG_TYPE_DQVAR, GRUB_SCRIPT_ARG_TYPE_DQSTR, GRUB_SCRIPT_ARG_TYPE_SQSTR,