From: Bruno Haible Date: Thu, 1 Jun 2006 11:58:56 +0000 (+0000) Subject: Support string concatenation in YCP string extractor. X-Git-Tag: v0.15~118 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ccd9227fe12e0bc51451ffdcbf18b19fe11eb927;p=thirdparty%2Fgettext.git Support string concatenation in YCP string extractor. --- diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index 7b31356af..2c3ba88fa 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,3 +1,13 @@ +2006-05-31 Bruno Haible + + * x-ycp.c (phase5_pushback, phase5_pushback_length): New variables. + (phase5_get): Renamed from x_ycp_lex. + (phase5_unget): New function. + (phase8_get): New function. + (extract_parenthesized): Inside i18n construct, use phase8_get + instead of phase5_get. + Reported by Karl Eichwalder . + 2006-05-22 Bruno Haible * msgfilter.c: Include also on Minix. diff --git a/gettext-tools/src/x-ycp.c b/gettext-tools/src/x-ycp.c index 9ea14e45b..57fc91f19 100644 --- a/gettext-tools/src/x-ycp.c +++ b/gettext-tools/src/x-ycp.c @@ -1,5 +1,5 @@ /* xgettext YCP backend. - Copyright (C) 2001-2003, 2005 Free Software Foundation, Inc. + Copyright (C) 2001-2003, 2005-2006 Free Software Foundation, Inc. This file was written by Bruno Haible , 2001. @@ -41,7 +41,8 @@ /* The YCP syntax is defined in libycp/doc/syntax.html. - See also libycp/src/scanner.ll. */ + See also libycp/src/scanner.ll. + Both are part of the yast2-core package in SuSE Linux distributions. */ void @@ -404,14 +405,22 @@ phase7_getc () /* Combine characters into tokens. Discard whitespace. */ +static token_ty phase5_pushback[1]; +static int phase5_pushback_length; + static void -x_ycp_lex (token_ty *tp) +phase5_get (token_ty *tp) { static char *buffer; static int bufmax; int bufpos; int c; + if (phase5_pushback_length) + { + *tp = phase5_pushback[--phase5_pushback_length]; + return; + } for (;;) { tp->line_number = line_number; @@ -545,6 +554,46 @@ x_ycp_lex (token_ty *tp) } } +/* Supports only one pushback token. */ +static void +phase5_unget (token_ty *tp) +{ + if (tp->type != token_type_eof) + { + if (phase5_pushback_length == SIZEOF (phase5_pushback)) + abort (); + phase5_pushback[phase5_pushback_length++] = *tp; + } +} + + +/* Concatenate adjacent string literals to form single string literals. + (See libycp/src/parser.yy, rule 'string' vs. terminal 'STRING'.) */ + +static void +phase8_get (token_ty *tp) +{ + phase5_get (tp); + if (tp->type != token_type_string_literal) + return; + for (;;) + { + token_ty tmp; + size_t len; + + phase5_get (&tmp); + if (tmp.type != token_type_string_literal) + { + phase5_unget (&tmp); + return; + } + len = strlen (tp->string); + tp->string = xrealloc (tp->string, len + strlen (tmp.string) + 1); + strcpy (tp->string + len, tmp.string); + free (tmp.string); + } +} + /* ========================= Extracting strings. ========================== */ @@ -594,7 +643,11 @@ extract_parenthesized (message_list_ty *mlp, { token_ty token; - x_ycp_lex (&token); + if (in_i18n) + phase8_get (&token); + else + phase5_get (&token); + switch (token.type) { case token_type_i18n: diff --git a/gettext-tools/tests/ChangeLog b/gettext-tools/tests/ChangeLog index af1099ded..8b54fabf6 100644 --- a/gettext-tools/tests/ChangeLog +++ b/gettext-tools/tests/ChangeLog @@ -1,3 +1,8 @@ +2006-05-31 Bruno Haible + + * xgettext-ycp-3: New file, from Karl Eichwalder . + * Makefile.am (TESTS): Add it. + 2006-05-16 Bruno Haible * gettext-4-prg.c: Set the LC_ALL environment variable, not just LANG. diff --git a/gettext-tools/tests/Makefile.am b/gettext-tools/tests/Makefile.am index 568b72725..8b6529ee5 100644 --- a/gettext-tools/tests/Makefile.am +++ b/gettext-tools/tests/Makefile.am @@ -88,7 +88,7 @@ TESTS = gettext-1 gettext-2 gettext-3 gettext-4 gettext-5 gettext-6 gettext-7 \ xgettext-smalltalk-1 \ xgettext-stringtable-1 \ xgettext-tcl-1 xgettext-tcl-2 \ - xgettext-ycp-1 xgettext-ycp-2 \ + xgettext-ycp-1 xgettext-ycp-2 xgettext-ycp-3 \ format-awk-1 format-awk-2 \ format-boost-1 format-boost-2 \ format-c-1 format-c-2 format-c-3 format-c-4 format-c-5 \