From: Bruno Haible Date: Thu, 5 Dec 2002 13:08:42 +0000 (+0000) Subject: Fix bug with filenames starting with a digit. X-Git-Tag: v0.12~1202 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=404857824104635dc22703c00383a187e44fc82e;p=thirdparty%2Fgettext.git Fix bug with filenames starting with a digit. --- diff --git a/src/ChangeLog b/src/ChangeLog index 93d1ee308..e7af82ce2 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ +2002-12-04 Bruno Haible + + Fix handling of references to filenames starting with a digit. + * po-hash-gen.y (last_was_colon): New variable. + (yylex): Update it for each token. Recognize numbers only immediately + after a colon. + (po_hash): Move function. Initialize last_was_colon. + Reported by Yanko Kaneti and + Jordi Mallach . + 2002-11-22 Bruno Haible * msgexec.c (process_string): Change test of full_write return value. diff --git a/src/po-hash-gen.y b/src/po-hash-gen.y index ff611570e..4bdcbc00c 100644 --- a/src/po-hash-gen.y +++ b/src/po-hash-gen.y @@ -36,6 +36,7 @@ #include #include +#include #include #include "xmalloc.h" @@ -109,23 +110,11 @@ %{ -static const char *cur; - - +/* Forward declarations, to avoid gcc warnings. */ void yyerror (char *); int yylex (void); -int -po_hash (const char *s) -{ - extern int yyparse (void); - - cur = s; - return yyparse (); -} - - void yyerror (char *s) { @@ -176,18 +165,26 @@ filepos %% +/* Current position in the pseudo-comment line. */ +static const char *cur; + +/* The NUMBER token must only be recognized after colon. So we have to + remember whether the last token was a colon. */ +static bool last_was_colon; + +/* Returns the next token from the current pseudo-comment line. */ int yylex () { static char *buf; static size_t bufmax; - size_t bufpos; - size_t n; - int c; + + bool look_for_number = last_was_colon; + last_was_colon = false; for (;;) { - c = *cur++; + int c = *cur++; switch (c) { case 0: @@ -200,6 +197,7 @@ yylex () break; case ':': + last_was_colon = true; return COLON; case ',': @@ -215,79 +213,99 @@ yylex () case '7': case '8': case '9': - /* Accumulate a number. */ - n = 0; - for (;;) + if (look_for_number) { - n = n * 10 + c - '0'; - c = *cur++; - switch (c) + /* Accumulate a number. */ + size_t n = 0; + + for (;;) { - default: + n = n * 10 + c - '0'; + c = *cur++; + switch (c) + { + default: + break; + + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + continue; + } break; - - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - continue; } - break; + --cur; + yylval.number = n; + return NUMBER; } - --cur; - yylval.number = n; - return NUMBER; + /* FALLTHROUGH */ default: /* Accumulate a string. */ - bufpos = 0; - for (;;) - { - if (bufpos >= bufmax) - { - bufmax += 100; - buf = xrealloc (buf, bufmax); - } - buf[bufpos++] = c; - - c = *cur++; - switch (c) - { - default: - continue; - - case 0: - case ':': - case ',': - case ' ': - case '\t': - --cur; - break; - } - break; - } - - if (bufpos >= bufmax) - { - bufmax += 100; - buf = xrealloc (buf, bufmax); - } - buf[bufpos] = 0; - - if (strcmp (buf, "file") == 0 || strcmp (buf, "File") == 0) - return FILE_KEYWORD; - if (strcmp (buf, "line") == 0) - return LINE_KEYWORD; - if (strcmp (buf, "number") == 0) - return NUMBER_KEYWORD; - yylval.string = xstrdup (buf); - return STRING; + { + size_t bufpos; + + bufpos = 0; + for (;;) + { + if (bufpos >= bufmax) + { + bufmax += 100; + buf = xrealloc (buf, bufmax); + } + buf[bufpos++] = c; + + c = *cur++; + switch (c) + { + default: + continue; + + case 0: + case ':': + case ',': + case ' ': + case '\t': + --cur; + break; + } + break; + } + + if (bufpos >= bufmax) + { + bufmax += 100; + buf = xrealloc (buf, bufmax); + } + buf[bufpos] = 0; + + if (strcmp (buf, "file") == 0 || strcmp (buf, "File") == 0) + return FILE_KEYWORD; + if (strcmp (buf, "line") == 0) + return LINE_KEYWORD; + if (strcmp (buf, "number") == 0) + return NUMBER_KEYWORD; + yylval.string = xstrdup (buf); + return STRING; + } } } } + + +/* Analyze whether the string (a pseudo-comment line) contains file names + and line numbers. */ +int +po_hash (const char *s) +{ + cur = s; + last_was_colon = false; + return yyparse (); +} diff --git a/tests/ChangeLog b/tests/ChangeLog index 0e3b44a41..e391edca5 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,8 @@ +2002-12-04 Bruno Haible + + * msgmerge-22: New file, from Karl Eichwalder. + * Makefile.am (TESTS): Add it. + 2002-11-13 Bruno Haible Assume ANSI C. diff --git a/tests/Makefile.am b/tests/Makefile.am index 73dfdf899..be4484036 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -39,7 +39,7 @@ TESTS = gettext-1 gettext-2 \ msgmerge-1 msgmerge-2 msgmerge-3 msgmerge-4 msgmerge-5 msgmerge-6 \ msgmerge-7 msgmerge-8 msgmerge-9 msgmerge-10 msgmerge-11 msgmerge-12 \ msgmerge-13 msgmerge-14 msgmerge-15 msgmerge-16 msgmerge-17 \ - msgmerge-18 msgmerge-19 msgmerge-20 msgmerge-21 \ + msgmerge-18 msgmerge-19 msgmerge-20 msgmerge-21 msgmerge-22 \ msgunfmt-1 msgunfmt-2 msgunfmt-3 \ msguniq-1 msguniq-2 msguniq-3 \ xgettext-1 xgettext-2 xgettext-3 xgettext-4 xgettext-5 xgettext-6 \ diff --git a/tests/msgmerge-22 b/tests/msgmerge-22 new file mode 100644 index 000000000..7c39ec6dc --- /dev/null +++ b/tests/msgmerge-22 @@ -0,0 +1,60 @@ +#! /bin/sh + +# Test pseudo-comments containing filenames that start with a digit. + +tmpfiles="" +trap 'rm -fr $tmpfiles' 1 2 3 15 + +tmpfiles="$tmpfiles mm-test22.pot mm-test22.po" +cat <<\EOF > mm-test22.pot +msgid "" +msgstr "" +"Project-Id-Version: GNU gettext 0.11.5\n" +"POT-Creation-Date: 2002-08-20 15:24+0200\n" +"PO-Revision-Date: 2002-12-02 07:05+0100\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: 123.c:134 +#, c-format +msgid "invalid argument `%s' for `%s'" +msgstr "ungültiges Argument »%s« für »%s«" +EOF + +cat <<\EOF > mm-test22.po +#: 123.c:134 +#, c-format +msgid "invalid argument `%s' for `%s'" +msgstr "" +EOF + +tmpfiles="$tmpfiles mm-test22.out" +: ${MSGMERGE=msgmerge} +${MSGMERGE} -q mm-test22.pot mm-test22.po -o mm-test22.out +test $? = 0 || { rm -fr $tmpfiles; exit 1; } + +tmpfiles="$tmpfiles mm-test22.ok" +cat <<\EOF > mm-test22.ok +msgid "" +msgstr "" +"Project-Id-Version: GNU gettext 0.11.5\n" +"POT-Creation-Date: 2002-08-20 15:24+0200\n" +"PO-Revision-Date: 2002-12-02 07:05+0100\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: 123.c:134 +#, c-format +msgid "invalid argument `%s' for `%s'" +msgstr "ungültiges Argument »%s« für »%s«" +EOF + +: ${DIFF=diff} +${DIFF} mm-test22.ok mm-test22.out +result=$? + +rm -fr $tmpfiles + +exit $result