From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1S6XV2-0000rC-9N for mharc-grub-devel@gnu.org; Sat, 10 Mar 2012 20:23:04 -0500 Received: from eggs.gnu.org ([208.118.235.92]:53372) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S6XUx-0000oG-Bu for grub-devel@gnu.org; Sat, 10 Mar 2012 20:23:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S6XUv-00074r-4J for grub-devel@gnu.org; Sat, 10 Mar 2012 20:22:58 -0500 Received: from mail-we0-f169.google.com ([74.125.82.169]:61392) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S6XUu-00074e-Nq for grub-devel@gnu.org; Sat, 10 Mar 2012 20:22:57 -0500 Received: by werj55 with SMTP id j55so2705324wer.0 for ; Sat, 10 Mar 2012 17:22:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:x-enigmail-version:content-type; bh=ch3kURqWterX0IbMIUFCVJvWrolJUXaCwYTGMfkCdCM=; b=qJeTgXs1ZhCeGHPAuTLiP56/Iw7K3PXxwYos/3xUZ3yIP5tQdUJ0XJvByW/2NxkkyZ pNN1Ij609cs2HUUrsiAyT1+3zb49Q46zYpJTJwWonuVw1KmTOMOx89X0Lgqi8aj0Z+O2 3zwiEpgA/dqbdOu+5isLZjNfwLriZPjtGWTvx9YwHRxEcBx/jei1FTwpxS9JfqRUbk/x 4BePiMjOKDLc9dZlSHY6WG3vQXpqu+S6UwXnYi5u/vprSD3HNDpnrdAqppY91MRwBD9o 2zns7vMVpWfqYa0UoAoAHeB8A3fYUe3AKnpcJ8UdeD1OJt0p1XrODRrVvYoRAhjNtbqa 3Lvg== Received: by 10.216.136.72 with SMTP id v50mr4343107wei.73.1331428974707; Sat, 10 Mar 2012 17:22:54 -0800 (PST) Received: from fedora.x201.phnet (207-116.62-81.cust.bluewin.ch. [81.62.116.207]) by mx.google.com with ESMTPS id p10sm20693854wic.0.2012.03.10.17.22.52 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 10 Mar 2012 17:22:53 -0800 (PST) Message-ID: <4F5BFE6A.90301@gmail.com> Date: Sun, 11 Mar 2012 02:22:50 +0100 From: =?UTF-8?B?VmxhZGltaXIgJ8+GLWNvZGVyL3BoY29kZXInIFNlcmJpbmVua28=?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20120131 Thunderbird/10.0 MIME-Version: 1.0 To: The development of GRUB 2 Subject: Re: gettext $"..." References: <4F5BFB64.5060101@gmail.com> In-Reply-To: <4F5BFB64.5060101@gmail.com> X-Enigmail-Version: 1.3.5 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="------------enig607EF518FD73D2213688512C" X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 74.125.82.169 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 11 Mar 2012 01:23:01 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig607EF518FD73D2213688512C Content-Type: multipart/mixed; boundary="------------060004030302060309020807" This is a multi-part message in MIME format. --------------060004030302060309020807 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Update to fix escaping. $"" as long as doesn't contain $* or $@ in absence of gettext should behave the same as "" On 11.03.2012 02:09, Vladimir '=CF=86-coder/phcoder' Serbinenko wrote: > Hello, all. Following discussion with Jordan Uggla it was found out tha= t > current syntax of $"..." without variable expansion isn't enough for a > meaningful i18n and committing ourselves to it by releasing a version > with it would be counter-productive as later we'll need something bette= r > but won't be able to remove something mostly useless. Since the bash > behaviour is unsafe due to variable expansion in translated strings. Bu= t > it's the very feature that is interesting for translation. There is > however a compromise by allowing in translated string only same > variables as in the original.This allows translator to rearrange > variables as he sees fit but in the same time makes it safe (basically > it's printf with reduced syntax and named tokens and without ability to= > run over the end). Fortunately only betas were released with $"..." > feature and no project has used it for i18n yet. Attached patch > implements the described behaviour. > Variables $* and $@ can't be used inside $"...". > Can someone have a look, comment on approach and/or provide tests? > --=20 Regards Vladimir '=CF=86-coder/phcoder' Serbinenko --------------060004030302060309020807 Content-Type: text/x-diff; name="gettext.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="gettext.diff" =3D=3D=3D modified file 'grub-core/script/execute.c' --- grub-core/script/execute.c 2012-03-10 12:19:46 +0000 +++ grub-core/script/execute.c 2012-03-11 01:18:47 +0000 @@ -321,6 +321,196 @@ return grub_env_set (name, val); } =20 +static int +parse_string (const char *str, + int (*hook) (const char *var, grub_size_t varlen), + char **put) +{ + const char *ptr; + int escaped =3D 0; + const char *optr; + + for (ptr =3D str; ptr && *ptr; ) + switch (*ptr) + { + case '\\': + escaped =3D !escaped; + if (!escaped && put) + *((*put)++) =3D '\\'; + ptr++; + break; + case '$': + if (escaped) + { + escaped =3D 0; + if (put) + *((*put)++) =3D *ptr; + ptr++; + break; + } + + ptr++; + switch (*ptr) + { + case '{': + { + optr =3D ptr + 1; + ptr =3D grub_strchr (optr, '}'); + if (!ptr) + break; + if (hook (optr, ptr - optr)) + return 1; + ptr++; + break; + } + case '0' ... '9': + optr =3D ptr; + while (*ptr >=3D '0' && *ptr <=3D '9') + ptr++; + if (hook (optr, ptr - optr)) + return 1; + break; + case 'a' ... 'z': + case 'A' ... 'Z': + case '_': + optr =3D ptr; + while ((*ptr >=3D '0' && *ptr <=3D '9') + || (*ptr >=3D 'a' && *ptr <=3D 'z') + || (*ptr >=3D 'A' && *ptr <=3D 'Z')) + ptr++; + if (hook (optr, ptr - optr)) + return 1; + break; + case '?': + case '#': + if (hook (ptr, 1)) + return 1; + ptr++; + break; + } + break; + default: + if (escaped && put) + *((*put)++) =3D '\\'; + escaped =3D 0; + if (put) + *((*put)++) =3D *ptr; + ptr++; + break; + } + return 0; +} + +static int +gettext_append (struct grub_script_argv *result, const char *orig_str) +{ + const char *template; + char *res =3D 0, *ptr; + char **allowed_strings; + grub_size_t nallowed_strings =3D 0; + grub_size_t additional_len =3D 1; + int rval =3D 1; + const char *iptr; + + auto int save_allow (const char *str, grub_size_t len); + int save_allow (const char *str, grub_size_t len) + { + allowed_strings[nallowed_strings++] =3D grub_strndup (str, len); + if (!allowed_strings[nallowed_strings - 1]) + return 1; + return 0; + } + + auto int getlen (const char *str, grub_size_t len); + int getlen (const char *str, grub_size_t len) + { + const char *var; + grub_size_t i; + + for (i =3D 0; i < nallowed_strings; i++) + if (grub_strncmp (allowed_strings[i], str, len) =3D=3D 0 + && allowed_strings[i][len] =3D=3D 0) + break; + if (i =3D=3D nallowed_strings) + return 0; + + /* Enough for any number. */ + if (len =3D=3D 1 && str[0] =3D=3D '#') + { + additional_len +=3D 30; + return 0; + } + var =3D grub_env_get (allowed_strings[i]); + if (var) + additional_len +=3D grub_strlen (var); + return 0; + } + + auto int putvar (const char *str, grub_size_t len); + int putvar (const char *str, grub_size_t len) + { + const char *var; + grub_size_t i; + + for (i =3D 0; i < nallowed_strings; i++) + if (grub_strncmp (allowed_strings[i], str, len) =3D=3D 0 + && allowed_strings[i][len] =3D=3D 0) + { + break; + } + if (i =3D=3D nallowed_strings) + return 0; + + /* Enough for any number. */ + if (len =3D=3D 1 && str[0] =3D=3D '#') + { + grub_snprintf (ptr, 30, "%u", scope->argv.argc); + ptr +=3D grub_strlen (ptr); + return 0; + } + var =3D grub_env_get (allowed_strings[i]); + if (var) + ptr =3D grub_stpcpy (ptr, var); + return 0; + } + + grub_size_t dollar_cnt =3D 0; + + for (iptr =3D orig_str; *iptr; iptr++) + if (*iptr =3D=3D '$') + dollar_cnt++; + allowed_strings =3D grub_malloc (sizeof (allowed_strings[0]) * dollar_= cnt); + + if (parse_string (orig_str, save_allow, 0)) + goto fail; + + template =3D _(orig_str); + + if (parse_string (template, getlen, 0)) + goto fail; + + res =3D grub_malloc (grub_strlen (template) + additional_len); + if (!res) + goto fail; + ptr =3D res; + + if (parse_string (template, putvar, &ptr)) + goto fail; + + if (grub_script_argv_append (result, res, ptr - res)) + goto fail; + rval =3D 0; + fail: + grub_free (res); + { + grub_size_t i; + for (i =3D 0; i < nallowed_strings; i++) + grub_free (allowed_strings[i]); + } + grub_free (allowed_strings); + return rval; +} + /* Convert arguments in ARGLIST into ARGV form. */ static int grub_script_arglist_to_argv (struct grub_script_arglist *arglist, @@ -406,8 +596,7 @@ =20 case GRUB_SCRIPT_ARG_TYPE_GETTEXT: { - const char *t =3D _(arg->str); - if (grub_script_argv_append (&result, t, grub_strlen (t))) + if (gettext_append (&result, arg->str)) goto fail; } break; =3D=3D=3D modified file 'grub-core/script/yylex.l' --- grub-core/script/yylex.l 2012-02-26 18:02:46 +0000 +++ grub-core/script/yylex.l 2012-03-11 01:16:17 +0000 @@ -289,7 +289,7 @@ } =20 { - \\\\ { COPY ("\\", 1); } + \\\\ { COPY ("\\\\", 2); } \\\" { COPY ("\"", 1); } \\\n { /* ignore */ } [^\"\\\n]+ { COPY (yytext, yyleng); } @@ -297,6 +297,7 @@ yy_pop_state (yyscanner); ARG (GRUB_SCRIPT_ARG_TYPE_GETTEXT); } + \\ { COPY ("\\", 1); } (.|\n) { COPY (yytext, yyleng); } } =20 --------------060004030302060309020807-- --------------enig607EF518FD73D2213688512C Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iF4EAREKAAYFAk9b/msACgkQNak7dOguQglYOgD9HqnHqb9uk5z+HZl9008iIM60 okYq3Nvvg1G+LoDNYHwA+wa4ZzbXqoIV5enxTyXYtLcmIZuwfPLMCVk5e2mNrhf1 =FaEb -----END PGP SIGNATURE----- --------------enig607EF518FD73D2213688512C--