+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.
#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)
{
%%
+/* 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:
break;
case ':':
+ last_was_colon = true;
return COLON;
case ',':
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 ();
+}
+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.
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 \
--- /dev/null
+#! /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