]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Leave #: lines with unknown syntax alone instead of turning them into
authorBruno Haible <bruno@clisp.org>
Mon, 7 Feb 2005 11:48:32 +0000 (11:48 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:12:09 +0000 (12:12 +0200)
plain comments.

gettext-tools/src/ChangeLog
gettext-tools/src/FILES
gettext-tools/src/Makefile.am
gettext-tools/src/Makefile.msvc
gettext-tools/src/Makefile.vms
gettext-tools/src/read-po-abstract.c
gettext-tools/src/read-po-abstract.h
gettext-tools/src/read-stringtable.c
gettext-tools/tests/ChangeLog
gettext-tools/tests/Makefile.am
gettext-tools/tests/msgcat-11 [new file with mode: 0755]

index a1388ab2eddb40483c7c54fc3ebc48ea6550e42d..457faf44ec0a674b10dda83b555444847c088859 100644 (file)
@@ -1,3 +1,25 @@
+2005-02-06  Bruno Haible  <bruno@clisp.org>
+
+       Leave #: lines with unknown syntax alone instead of turning them into
+       plain comments.
+       * po-hash.h: Remove file.
+       * po-hash-gen.y: Remove file.
+       * read-po-abstract.c: Don't include po-hash.h.
+       (po_parse_comment_filepos, po_parse_comment_solaris_filepos): New
+       functions.
+       (po_callback_comment_dispatcher): Call them instead of the old
+       po_parse_comment_filepos.
+       * read-stringtable.c: Don't include po-hash.h.
+       * Makefile.am (noinst_HEADERS): Remove po-hash.h, po-hash-gen.h.
+       (COMMON_SOURCE): Remove po-hash-gen.y.
+       (BUILT_SOURCES): Remove po-hash-gen.c, po-hash-gen.h.
+       * Makefile.msvc (OBJECTS): Remove po-hash-gen.obj.
+       (po-hash-gen.obj): Remove rule.
+       * Makefile.vms (OBJECTS): Remove po-hash-gen.obj.
+       (po-hash-gen.obj): Remove rule.
+       * FILES: Update.
+       Reported by David Fraser <davidf@sjsoft.com>.
+
 2005-02-04  Bruno Haible  <bruno@clisp.org>
 
        * plural-table.c (plural_table): Add an entry about Vietnamese.
index c42f0df0b5aa14608181036c19ad9dbcab0b2655..ceee7cb16c7366baec05884805a09c787133a14e 100644 (file)
@@ -61,8 +61,6 @@ write-stringtable.c
 |               Lexical analysis of PO files.
 |
 | read-po-abstract.h
-| po-hash.h
-| po-hash-gen.y
 | po-gram.h
 | po-gram-gen.y
 | read-properties.h
@@ -74,10 +72,6 @@ write-stringtable.c
 |              .strings files.
 |         read-po-abstract.h
 |                       General parser structure.
-|         po-hash.h
-|         po-hash-gen.y
-|                       Lexical analysis and parsing of pseudo-comments in
-|                       PO files, introduced by "#:" and "#".
 |         po-gram.h
 |         po-gram-gen.y
 |                       Parsing of PO files, based on po-lex.{h,c}.
index 01bebb819241fe228e377620cdbfe1aa2ac24e1a..b61968dc58655e34a1e63bdc927b2e72a9aed637 100644 (file)
@@ -34,12 +34,12 @@ lib_LTLIBRARIES = libgettextsrc.la libgettextpo.la
 
 include_HEADERS = gettext-po.h
 
-noinst_HEADERS = pos.h message.h po-error.h po-gram.h po-hash.h po-charset.h \
+noinst_HEADERS = pos.h message.h po-error.h po-gram.h po-charset.h \
 po-lex.h open-po.h \
 read-po-abstract.h read-po.h read-properties.h read-stringtable.h \
 str-list.h \
 write-po.h write-properties.h write-stringtable.h \
-dir-list.h file-list.h po-gram-gen.h po-gram-gen2.h po-hash-gen.h \
+dir-list.h file-list.h po-gram-gen.h po-gram-gen2.h \
 msgl-charset.h msgl-equal.h msgl-iconv.h msgl-ascii.h msgl-cat.h \
 msgl-english.h msgfmt.h msgunfmt.h plural-count.h \
 read-mo.h write-mo.h \
@@ -94,12 +94,12 @@ CSHARPCOMPFLAGS = -O -g
 # All programs must read PO files. (msgunfmt also, for read-java.c,
 # read-csharp.c and read-resources.c.)
 # message.c -> str-list.c.
-# (read-po-abstract.c <--> po-hash-gen.y <--> po-gram-gen.y <--> po-lex.c) -> str-list.c.
-# (read-po-abstract.c <--> po-hash-gen.y <--> po-gram-gen.y <--> po-lex.c) -> open-po.c -> dir-list.c -> str-list.c.
-# (read-po-abstract.c <--> po-hash-gen.y <--> po-gram-gen.y <--> po-lex.c) -> po-charset.c.
-# (read-po-abstract.c <--> po-hash-gen.y <--> po-gram-gen.y <--> po-lex.c) -> message.c -> str-list.c.
+# (read-po-abstract.c <--> po-gram-gen.y <--> po-lex.c) -> str-list.c.
+# (read-po-abstract.c <--> po-gram-gen.y <--> po-lex.c) -> open-po.c -> dir-list.c -> str-list.c.
+# (read-po-abstract.c <--> po-gram-gen.y <--> po-lex.c) -> po-charset.c.
+# (read-po-abstract.c <--> po-gram-gen.y <--> po-lex.c) -> message.c -> str-list.c.
 COMMON_SOURCE = message.c po-error.c \
-read-po-abstract.c po-lex.c po-gram-gen.y po-hash-gen.y po-charset.c \
+read-po-abstract.c po-lex.c po-gram-gen.y po-charset.c \
 read-properties.c read-stringtable.c open-po.c dir-list.c str-list.c
 
 # xgettext and msgfmt deal with format strings.
@@ -243,8 +243,7 @@ endif
 # Special rules for bison and flex generated files.
 
 BUILT_SOURCES = \
-  po-gram-gen.c po-gram-gen.h po-gram-gen2.h \
-  po-hash-gen.c po-hash-gen.h
+  po-gram-gen.c po-gram-gen.h po-gram-gen2.h
 
 po-lex.o po-lex.lo: po-gram-gen2.h
 po-gram-gen2.h: po-gram-gen.h
index 893d45aa5abd2f719e8b79b716aa5d97c7863501..d16bbdc804bb9a542e9006e2de5a06cccb655b9f 100644 (file)
@@ -110,7 +110,6 @@ OBJECTS = \
   read-po-abstract.obj \
   po-lex.obj \
   po-gram-gen.obj \
-  po-hash-gen.obj \
   po-charset.obj \
   read-properties.obj \
   read-stringtable.obj \
@@ -189,9 +188,6 @@ po-lex.obj : po-lex.c
 po-gram-gen.obj : po-gram-gen.c
        $(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c po-gram-gen.c
 
-po-hash-gen.obj : po-hash-gen.c
-       $(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c po-hash-gen.c
-
 po-charset.obj : po-charset.c
        $(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c po-charset.c
 
index 38a2e27bd330aa0e0b248707e9f58c3bea6d4706..6b41a2fdaa4cdbded20a84665e04528127ce04fa 100644 (file)
@@ -56,7 +56,6 @@ OBJECTS = \
   read-po-abstract.obj, \
   po-lex.obj, \
   po-gram-gen.obj, \
-  po-hash-gen.obj, \
   po-charset.obj, \
   read-properties.obj, \
   read-stringtable.obj, \
@@ -133,9 +132,6 @@ po-lex.obj : po-lex.c
 po-gram-gen.obj : po-gram-gen.c
        $(CC) $(INCLUDES) $(CFLAGS) /define=($(DEFS)) po-gram-gen.c
 
-po-hash-gen.obj : po-hash-gen.c
-       $(CC) $(INCLUDES) $(CFLAGS) /define=($(DEFS)) po-hash-gen.c
-
 po-charset.obj : po-charset.c
        $(CC) $(INCLUDES) $(CFLAGS) /define=($(DEFS)) po-charset.c
 
index 1230a951b6dcdcfd036988fd763ea7184ece2ef6..01e0a7882bcdd12dc756e6f131e6076d67f80439 100644 (file)
@@ -1,5 +1,5 @@
 /* Reading PO files, abstract class.
-   Copyright (C) 1995-1996, 1998, 2000-2004 Free Software Foundation, Inc.
+   Copyright (C) 1995-1996, 1998, 2000-2005 Free Software Foundation, Inc.
 
    This file was written by Peter Miller <millerp@canb.auug.org.au>
 
@@ -29,7 +29,6 @@
 #include <string.h>
 
 #include "po-gram.h"
-#include "po-hash.h"
 #include "read-properties.h"
 #include "read-stringtable.h"
 #include "xalloc.h"
@@ -197,8 +196,7 @@ po_scan (abstract_po_reader_ty *pop, FILE *fp,
 
 
 /* ========================================================================= */
-/* Callbacks used by po-gram.y or po-hash.y or po-lex.c, indirectly
-   from po_scan.  */
+/* Callbacks used by po-gram.y or po-lex.c, indirectly from po_scan.  */
 
 
 /* This function is called by po_gram_lex() whenever a domain directive
@@ -356,6 +354,295 @@ po_parse_comment_special (const char *s,
 }
 
 
+/* Parse a GNU style file comment.
+   Syntax: an arbitrary number of
+             STRING COLON NUMBER
+           or
+             STRING
+   The latter style, without line number, occurs in PO files converted e.g.
+   from Pascal .rst files or from OpenOffice resource files.
+   Call po_callback_comment_filepos for each of them.  */
+static void
+po_parse_comment_filepos (const char *s)
+{
+  while (*s != '\0')
+    {
+      while (*s == ' ' || *s == '\t' || *s == '\n')
+       s++;
+      if (*s != '\0')
+       {
+         const char *string_start = s;
+
+         do
+           s++;
+         while (!(*s == '\0' || *s == ' ' || *s == '\t' || *s == '\n'));
+
+         /* See if there is a COLON and NUMBER after the STRING, separated
+            through optional spaces.  */
+         {
+           const char *p = s;
+
+           while (*p == ' ' || *p == '\t' || *p == '\n')
+             p++;
+
+           if (*p == ':')
+             {
+               p++;
+
+               while (*p == ' ' || *p == '\t' || *p == '\n')
+                 p++;
+
+               if (*p >= '0' && *p <= '9')
+                 {
+                   /* Accumulate a number.  */
+                   size_t n = 0;
+
+                   do
+                     {
+                       n = n * 10 + (*p - '0');
+                       p++;
+                     }
+                   while (*p >= '0' && *p <= '9');
+
+                   if (*p == '\0' || *p == ' ' || *p == '\t' || *p == '\n')
+                     {
+                       /* Parsed a GNU style file comment with spaces.  */
+                       const char *string_end = s;
+                       size_t string_length = string_end - string_start;
+                       char *string = (char *) xmalloc (string_length + 1);
+
+                       memcpy (string, string_start, string_length);
+                       string[string_length] = '\0';
+
+                       po_callback_comment_filepos (string, n);
+
+                       free (string);
+
+                       s = p;
+                       continue;
+                     }
+                 }
+             }
+         }
+
+         /* See if there is a COLON at the end of STRING and a NUMBER after
+            it, separated through optional spaces.  */
+         if (s[-1] == ':')
+           {
+             const char *p = s;
+
+             while (*p == ' ' || *p == '\t' || *p == '\n')
+               p++;
+
+             if (*p >= '0' && *p <= '9')
+               {
+                 /* Accumulate a number.  */
+                 size_t n = 0;
+
+                 do
+                   {
+                     n = n * 10 + (*p - '0');
+                     p++;
+                   }
+                 while (*p >= '0' && *p <= '9');
+
+                 if (*p == '\0' || *p == ' ' || *p == '\t' || *p == '\n')
+                   {
+                     /* Parsed a GNU style file comment with spaces.  */
+                     const char *string_end = s - 1;
+                     size_t string_length = string_end - string_start;
+                     char *string = (char *) xmalloc (string_length + 1);
+
+                     memcpy (string, string_start, string_length);
+                     string[string_length] = '\0';
+
+                     po_callback_comment_filepos (string, n);
+
+                     free (string);
+
+                     s = p;
+                     continue;
+                   }
+               }
+           }
+
+         /* See if there is a COLON and NUMBER at the end of the STRING,
+            without separating spaces.  */
+         {
+           const char *p = s;
+
+           while (p > string_start)
+             {
+               p--;
+               if (!(*p >= '0' && *p <= '9'))
+                 {
+                   p++;
+                   break;
+                 }
+             }
+
+           /* p now points to the beginning of the trailing digits segment
+              at the end of STRING.  */
+
+           if (p < s
+               && p > string_start + 1
+               && p[-1] == ':')
+             {
+               /* Parsed a GNU style file comment without spaces.  */
+               const char *string_end = p - 1;
+
+               /* Accumulate a number.  */
+               {
+                 size_t n = 0;
+
+                 do
+                   {
+                     n = n * 10 + (*p - '0');
+                     p++;
+                   }
+                 while (p < s);
+
+                 {
+                   size_t string_length = string_end - string_start;
+                   char *string = (char *) xmalloc (string_length + 1);
+
+                   memcpy (string, string_start, string_length);
+                   string[string_length] = '\0';
+
+                   po_callback_comment_filepos (string, n);
+
+                   free (string);
+
+                   continue;
+                 }
+               }
+             }
+         }
+
+         /* Parsed a file comment without line number.  */
+         {
+           const char *string_end = s;
+           size_t string_length = string_end - string_start;
+           char *string = (char *) xmalloc (string_length + 1);
+
+           memcpy (string, string_start, string_length);
+           string[string_length] = '\0';
+
+           po_callback_comment_filepos (string, (size_t)(-1));
+
+           free (string);
+         }
+       }
+    }
+}
+
+
+/* Parse a SunOS or Solaris style file comment.
+   Syntax of SunOS style:
+     FILE_KEYWORD COLON STRING COMMA LINE_KEYWORD COLON NUMBER
+   Syntax of Solaris style:
+     FILE_KEYWORD COLON STRING COMMA LINE_KEYWORD NUMBER_KEYWORD COLON NUMBER
+   where
+     FILE_KEYWORD ::= "file" | "File"
+     COLON ::= ":"
+     COMMA ::= ","
+     LINE_KEYWORD ::= "line"
+     NUMBER_KEYWORD ::= "number"
+     NUMBER ::= [0-9]+
+   Return true if parsed, false if not a comment of this form. */
+static bool
+po_parse_comment_solaris_filepos (const char *s)
+{
+  if (s[0] == ' '
+      && (s[1] == 'F' || s[1] == 'f')
+      && s[2] == 'i' && s[3] == 'l' && s[4] == 'e'
+      && s[5] == ':')
+    {
+      const char *string_start;
+      const char *string_end;
+
+      {
+       const char *p = s + 6;
+
+       while (*p == ' ' || *p == '\t')
+         p++;
+       string_start = p;
+      }
+
+      for (string_end = string_start; *string_end != '\0'; string_end++)
+       {
+         const char *p = string_end;
+
+         while (*p == ' ' || *p == '\t')
+           p++;
+
+         if (*p == ',')
+           {
+             p++;
+
+             while (*p == ' ' || *p == '\t')
+               p++;
+
+             if (p[0] == 'l' && p[1] == 'i' && p[2] == 'n' && p[3] == 'e')
+               {
+                 p += 4;
+
+                 while (*p == ' ' || *p == '\t')
+                   p++;
+
+                 if (p[0] == 'n' && p[1] == 'u' && p[2] == 'm'
+                     && p[3] == 'b' && p[4] == 'e' && p[5] == 'r')
+                   {
+                     p += 6;
+                     while (*p == ' ' || *p == '\t')
+                       p++;
+                   }
+
+                 if (*p == ':')
+                   {
+                     p++;
+
+                     if (*p >= '0' && *p <= '9')
+                       {
+                         /* Accumulate a number.  */
+                         size_t n = 0;
+
+                         do
+                           {
+                             n = n * 10 + (*p - '0');
+                             p++;
+                           }
+                         while (*p >= '0' && *p <= '9');
+
+                         while (*p == ' ' || *p == '\t' || *p == '\n')
+                           p++;
+
+                         if (*p == '\0')
+                           {
+                             /* Parsed a Sun style file comment.  */
+                             size_t string_length = string_end - string_start;
+                             char *string =
+                               (char *) xmalloc (string_length + 1);
+
+                             memcpy (string, string_start, string_length);
+                             string[string_length] = '\0';
+
+                             po_callback_comment_filepos (string, n);
+
+                             free (string);
+                             return true;
+                           }
+                       }
+                   }
+               }
+           }
+       }
+    }
+
+  return false;
+}
+
+
 /* This function is called by po_gram_lex() whenever a comment is
    seen.  It analyzes the comment to see what sort it is, and then
    dispatches it to the appropriate method: call_comment, call_comment_dot,
@@ -368,14 +655,9 @@ po_callback_comment_dispatcher (const char *s)
     po_callback_comment_dot (s + 1);
   else if (*s == ':')
     {
-      /* Parse the file location string.  If the parse succeeds, the
-        appropriate callback will be invoked.  If the parse fails,
-        the po_parse_comment_filepos function will return non-zero - so
-        pretend it was a normal comment.  */
-      if (po_parse_comment_filepos (s + 1) == 0)
-       /* Do nothing, it is a GNU-style file pos line.  */ ;
-      else
-       po_callback_comment (s + 1);
+      /* Parse the file location string.  The appropriate callback will be
+        invoked.  */
+      po_parse_comment_filepos (s + 1);
     }
   else if (*s == ',' || *s == '!')
     {
@@ -385,13 +667,9 @@ po_callback_comment_dispatcher (const char *s)
   else
     {
       /* It looks like a plain vanilla comment, but Solaris-style file
-        position lines do, too.  Rather than parse the lot, only look
-        at lines that could start with "# File..." This minimizes
-        memory leaks on failed parses.  If the parse succeeds, the
-        appropriate callback will be invoked.  */
-      if (s[0] == ' ' && (s[1] == 'F' || s[1] == 'f') && s[2] == 'i'
-         && s[3] == 'l' && s[4] == 'e' && s[5] == ':'
-         && po_parse_comment_filepos (s) == 0)
+        position lines do, too.  Try to parse the lot.  If the parse
+        succeeds, the appropriate callback will be invoked.  */
+      if (po_parse_comment_solaris_filepos (s))
        /* Do nothing, it is a Sun-style file pos line.  */ ;
       else
        po_callback_comment (s);
index 0c076f0262bbad8b25d38f35190f02598166dd45..62a43204e8c812e5459aa19ef8f745b5a149b3a3 100644 (file)
@@ -1,5 +1,5 @@
 /* Reading PO files, abstract class.
-   Copyright (C) 1995-1996, 1998, 2000-2003 Free Software Foundation, Inc.
+   Copyright (C) 1995-1996, 1998, 2000-2003, 2005 Free Software Foundation, Inc.
 
    This file was written by Peter Miller <millerp@canb.auug.org.au>
 
@@ -151,8 +151,7 @@ extern void
        po_reader_free (abstract_po_reader_ty *pop);
 
 
-/* Callbacks used by po-gram.y or po-hash.y or po-lex.c, indirectly
-   from po_scan.  */
+/* Callbacks used by po-gram.y or po-lex.c, indirectly from po_scan.  */
 extern void po_callback_domain (char *name);
 extern void po_callback_message (char *msgid, lex_pos_ty *msgid_pos,
                                 char *msgid_plural,
index 137167d7587955c240784342ef249d212bb446e6..b96d036b75e576965dd348ef28bbab58b76af355 100644 (file)
@@ -1,5 +1,5 @@
 /* Reading NeXTstep/GNUstep .strings files.
-   Copyright (C) 2003 Free Software Foundation, Inc.
+   Copyright (C) 2003, 2005 Free Software Foundation, Inc.
    Written by Bruno Haible <bruno@clisp.org>, 2003.
 
    This program is free software; you can redistribute it and/or modify
@@ -33,7 +33,6 @@
 #include "error.h"
 #include "error-progname.h"
 #include "read-po-abstract.h"
-#include "po-hash.h"
 #include "xalloc.h"
 #include "exit.h"
 #include "utf8-ucs4.h"
index 9747ab2d3306e020c6f463b75b9993f227c8751c..ba17cfb7fa50e0b3edaaa50593f0799dc987a072 100644 (file)
@@ -1,3 +1,8 @@
+2005-02-06  Bruno Haible  <bruno@clisp.org>
+
+       * msgcat-11: New file.
+       * Makefile.am (TESTS): Add it.
+
 2005-01-29  Bruno Haible  <bruno@clisp.org>
 
        * Makefile.am (LDADD_yes): Add INTL_MACOSX_LIBS.
index 44454c42c4fa30f5cb75f39924ed5e95db540568..c752660628b3775f122b88935d9c54addad1291d 100644 (file)
@@ -26,7 +26,7 @@ TESTS = gettext-1 gettext-2 \
        msgattrib-11 msgattrib-12 msgattrib-13 msgattrib-14 \
        msgattrib-properties-1 \
        msgcat-1 msgcat-2 msgcat-3 msgcat-4 msgcat-5 msgcat-6 msgcat-7 \
-       msgcat-8 msgcat-9 msgcat-10 \
+       msgcat-8 msgcat-9 msgcat-10 msgcat-11 \
        msgcat-properties-1 msgcat-properties-2 \
        msgcat-stringtable-1 \
        msgcmp-1 msgcmp-2 msgcmp-3 \
diff --git a/gettext-tools/tests/msgcat-11 b/gettext-tools/tests/msgcat-11
new file mode 100755 (executable)
index 0000000..29c14f5
--- /dev/null
@@ -0,0 +1,47 @@
+#! /bin/sh
+
+# Verify that msgcat leaves #: lines in place even if they have a bizarre
+# syntax.
+
+tmpfiles=""
+trap 'rm -fr $tmpfiles' 1 2 3 15
+
+tmpfiles="$tmpfiles mcat-test11.in"
+cat <<\EOF > mcat-test11.in
+#: basctl/source\basicide\basidesh.src#RID_STR_NOMODULE.text
+msgid "Simple"
+msgstr "Einfach"
+
+#: basctl/source\basicide\basidesh.src:RID_STR_NOMODULE.text
+msgid "Different"
+msgstr "Anders"
+
+#: file:4
+msgid "where"
+msgstr "wo"
+
+#: line:4
+msgid "what"
+msgstr "was"
+
+#: number:4
+msgid "who"
+msgstr "wer"
+
+#: foobar:4a
+msgid "whenever"
+msgstr "immer"
+EOF
+
+tmpfiles="$tmpfiles mcat-test11.out"
+: ${MSGCAT=msgcat}
+${MSGCAT} mcat-test11.in -o mcat-test11.out
+test $? = 0 || { rm -fr $tmpfiles; exit 1; }
+
+: ${DIFF=diff}
+${DIFF} mcat-test11.in mcat-test11.out
+result=$?
+
+rm -fr $tmpfiles
+
+exit $result