From: Bruno Haible Date: Mon, 7 Feb 2005 11:48:32 +0000 (+0000) Subject: Leave #: lines with unknown syntax alone instead of turning them into X-Git-Tag: v0.14.2~95 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e4b738e3d574ae49e229fb3db82f6c42ac411d9;p=thirdparty%2Fgettext.git Leave #: lines with unknown syntax alone instead of turning them into plain comments. --- diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index a1388ab2e..457faf44e 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,3 +1,25 @@ +2005-02-06 Bruno Haible + + 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 . + 2005-02-04 Bruno Haible * plural-table.c (plural_table): Add an entry about Vietnamese. diff --git a/gettext-tools/src/FILES b/gettext-tools/src/FILES index c42f0df0b..ceee7cb16 100644 --- a/gettext-tools/src/FILES +++ b/gettext-tools/src/FILES @@ -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}. diff --git a/gettext-tools/src/Makefile.am b/gettext-tools/src/Makefile.am index 01bebb819..b61968dc5 100644 --- a/gettext-tools/src/Makefile.am +++ b/gettext-tools/src/Makefile.am @@ -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 diff --git a/gettext-tools/src/Makefile.msvc b/gettext-tools/src/Makefile.msvc index 893d45aa5..d16bbdc80 100644 --- a/gettext-tools/src/Makefile.msvc +++ b/gettext-tools/src/Makefile.msvc @@ -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 diff --git a/gettext-tools/src/Makefile.vms b/gettext-tools/src/Makefile.vms index 38a2e27bd..6b41a2fda 100644 --- a/gettext-tools/src/Makefile.vms +++ b/gettext-tools/src/Makefile.vms @@ -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 diff --git a/gettext-tools/src/read-po-abstract.c b/gettext-tools/src/read-po-abstract.c index 1230a951b..01e0a7882 100644 --- a/gettext-tools/src/read-po-abstract.c +++ b/gettext-tools/src/read-po-abstract.c @@ -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 @@ -29,7 +29,6 @@ #include #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); diff --git a/gettext-tools/src/read-po-abstract.h b/gettext-tools/src/read-po-abstract.h index 0c076f026..62a43204e 100644 --- a/gettext-tools/src/read-po-abstract.h +++ b/gettext-tools/src/read-po-abstract.h @@ -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 @@ -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, diff --git a/gettext-tools/src/read-stringtable.c b/gettext-tools/src/read-stringtable.c index 137167d75..b96d036b7 100644 --- a/gettext-tools/src/read-stringtable.c +++ b/gettext-tools/src/read-stringtable.c @@ -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 , 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" diff --git a/gettext-tools/tests/ChangeLog b/gettext-tools/tests/ChangeLog index 9747ab2d3..ba17cfb7f 100644 --- a/gettext-tools/tests/ChangeLog +++ b/gettext-tools/tests/ChangeLog @@ -1,3 +1,8 @@ +2005-02-06 Bruno Haible + + * msgcat-11: New file. + * Makefile.am (TESTS): Add it. + 2005-01-29 Bruno Haible * Makefile.am (LDADD_yes): Add INTL_MACOSX_LIBS. diff --git a/gettext-tools/tests/Makefile.am b/gettext-tools/tests/Makefile.am index 44454c42c..c75266062 100644 --- a/gettext-tools/tests/Makefile.am +++ b/gettext-tools/tests/Makefile.am @@ -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 index 000000000..29c14f596 --- /dev/null +++ b/gettext-tools/tests/msgcat-11 @@ -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