]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Fix bug with filenames starting with a digit.
authorBruno Haible <bruno@clisp.org>
Thu, 5 Dec 2002 13:08:42 +0000 (13:08 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:08:52 +0000 (12:08 +0200)
src/ChangeLog
src/po-hash-gen.y
tests/ChangeLog
tests/Makefile.am
tests/msgmerge-22 [new file with mode: 0644]

index 93d1ee30847cd8e57594e5bd7aec9e63fc4a924b..e7af82ce2d513d2ec08d159bf5e7239e26d141ba 100644 (file)
@@ -1,3 +1,13 @@
+2002-12-04  Bruno Haible  <bruno@clisp.org>
+
+       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 <yaneti@declera.com> and
+       Jordi Mallach <jordi@sindominio.net>.
+
 2002-11-22  Bruno Haible  <bruno@clisp.org>
 
        * msgexec.c (process_string): Change test of full_write return value.
index ff611570e85776507e8510760b4620ef879e108d..4bdcbc00c2c61b9130b49aaaf2f5c22321c9fc13 100644 (file)
@@ -36,6 +36,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdbool.h>
 #include <string.h>
 
 #include "xmalloc.h"
 
 %{
 
-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 ();
+}
index 0e3b44a41e54b8d294c9a4ca7b426408bd8272be..e391edca524307d983789b454ff5fd2b129dd445 100644 (file)
@@ -1,3 +1,8 @@
+2002-12-04  Bruno Haible  <bruno@clisp.org>
+
+       * msgmerge-22: New file, from Karl Eichwalder.
+       * Makefile.am (TESTS): Add it.
+
 2002-11-13  Bruno Haible  <bruno@clisp.org>
 
        Assume ANSI C.
index 73dfdf899d2997354814e24c540e345b3de10c20..be448403635bd9a80b00e4a373437c88f61f90f3 100644 (file)
@@ -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 (file)
index 0000000..7c39ec6
--- /dev/null
@@ -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