From: Bruno Haible Date: Sat, 11 Nov 2023 15:48:27 +0000 (+0100) Subject: libgettextpo: Remove static variable 'plural_counter'. X-Git-Tag: v0.23~307 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6179430a9db06535ff961675892f331a2b61878e;p=thirdparty%2Fgettext.git libgettextpo: Remove static variable 'plural_counter'. * gettext-tools/src/po-gram.h (struct po_parser_state): New type. (po_gram_parse): Add 'struct po_parser_state *ps' parameter. * gettext-tools/src/po-gram-gen.y: Add %parse-param declaration. Access ps->plural_counter instead of plural_counter. (plural_counter): Remove variable. * gettext-tools/src/po-lex.h (po_gram_error): Add 'struct po_parser_state *ps' parameter. * gettext-tools/src/po-lex.c: Include po-gram.h. (po_gram_error): Add 'struct po_parser_state *ps' parameter. (mbfile_getc, control_sequence): Update po_gram_error calls. * gettext-tools/src/read-po.c (po_parse): Pass a 'struct po_parser_state *' to po_gram_parse. --- diff --git a/gettext-tools/src/po-gram-gen.y b/gettext-tools/src/po-gram-gen.y index 07ebdacb1..ccae0d757 100644 --- a/gettext-tools/src/po-gram-gen.y +++ b/gettext-tools/src/po-gram-gen.y @@ -39,8 +39,6 @@ #define _(str) gettext (str) -static long plural_counter; - #define check_obsolete(value1,value2) \ if ((value1).obsolete != (value2).obsolete) \ po_gram_error_at_line (&(value2).pos, _("inconsistent use of #~")); @@ -83,6 +81,8 @@ do_callback_message (char *msgctxt, generated parsers in the same program. */ %define api.prefix {po_gram_} +%parse-param {struct po_parser_state *ps} + %token COMMENT %token DOMAIN %token JUNK @@ -306,7 +306,7 @@ msgid_pluralform : MSGID_PLURAL string_list { check_obsolete ($1, $2); - plural_counter = 0; + ps->plural_counter = 0; $$.string = string_list_concat_destroy (&$2.stringlist); $$.pos = $1.pos; $$.obsolete = $1.obsolete; @@ -350,14 +350,14 @@ pluralform check_obsolete ($1, $3); check_obsolete ($1, $4); check_obsolete ($1, $5); - if ($3.number != plural_counter) + if ($3.number != ps->plural_counter) { - if (plural_counter == 0) + if (ps->plural_counter == 0) po_gram_error_at_line (&$1.pos, _("first plural form has nonzero index")); else po_gram_error_at_line (&$1.pos, _("plural form has wrong index")); } - plural_counter++; + ps->plural_counter++; $$.rhs.msgstr = string_list_concat_destroy (&$5.stringlist); $$.rhs.msgstr_len = strlen ($$.rhs.msgstr) + 1; $$.pos = $1.pos; diff --git a/gettext-tools/src/po-gram.h b/gettext-tools/src/po-gram.h index cf916a984..f2a6c9fda 100644 --- a/gettext-tools/src/po-gram.h +++ b/gettext-tools/src/po-gram.h @@ -1,5 +1,5 @@ /* GNU gettext - internationalization aids - Copyright (C) 1995, 2002-2003, 2006 Free Software Foundation, Inc. + Copyright (C) 1995-2023 Free Software Foundation, Inc. This file was written by Peter Miller @@ -23,7 +23,16 @@ extern "C" { #endif -extern int po_gram_parse (void); +/* Input, output, and local variables of a PO parser instance. */ +struct po_parser_state +{ + /* Input variables. */ + /* Output variables. */ + /* Local variables. */ + long plural_counter; +}; + +extern int po_gram_parse (struct po_parser_state *ps); #ifdef __cplusplus } diff --git a/gettext-tools/src/po-lex.c b/gettext-tools/src/po-lex.c index 0b389a19c..7af1cf739 100644 --- a/gettext-tools/src/po-lex.c +++ b/gettext-tools/src/po-lex.c @@ -49,6 +49,7 @@ #include "pos.h" #include "message.h" #include "str-list.h" +#include "po-gram.h" #include "po-gram-gen.h" #define _(str) gettext(str) @@ -76,7 +77,7 @@ bool gram_pot_role; /* VARARGS1 */ void -po_gram_error (const char *fmt, ...) +po_gram_error (struct po_parser_state *ps, const char *fmt, ...) { va_list ap; char *buffer; @@ -437,7 +438,7 @@ mbfile_getc (mbchar_t mbc, mbfile_t mbf) /* An invalid multibyte sequence was encountered. */ /* Return a single byte. */ if (signal_eilseq) - po_gram_error (_("invalid multibyte sequence")); + po_gram_error (NULL, _("invalid multibyte sequence")); bytes = 1; mbc->uc_valid = false; break; @@ -465,7 +466,7 @@ mbfile_getc (mbchar_t mbc, mbfile_t mbf) if (ferror (mbf->fp)) goto eof; if (signal_eilseq) - po_gram_error (_("incomplete multibyte sequence at end of file")); + po_gram_error (NULL, _("incomplete multibyte sequence at end of file")); bytes = mbf->bufcount; mbc->uc_valid = false; break; @@ -474,7 +475,7 @@ mbfile_getc (mbchar_t mbc, mbfile_t mbf) if (c == '\n') { if (signal_eilseq) - po_gram_error (_("incomplete multibyte sequence at end of line")); + po_gram_error (NULL, _("incomplete multibyte sequence at end of line")); bytes = mbf->bufcount - 1; mbc->uc_valid = false; break; @@ -505,7 +506,7 @@ mbfile_getc (mbchar_t mbc, mbfile_t mbf) /* scratchbuf contains an out-of-range Unicode character (> 0x10ffff). */ if (signal_eilseq) - po_gram_error (_("invalid multibyte sequence")); + po_gram_error (NULL, _("invalid multibyte sequence")); mbc->uc_valid = false; break; } @@ -855,7 +856,7 @@ control_sequence () /* FIXME: \u and \U are not handled. */ } lex_ungetc (mbc); - po_gram_error (_("invalid control sequence")); + po_gram_error (NULL, _("invalid control sequence")); return ' '; } diff --git a/gettext-tools/src/po-lex.h b/gettext-tools/src/po-lex.h index db9e86a3a..6672e4c4a 100644 --- a/gettext-tools/src/po-lex.h +++ b/gettext-tools/src/po-lex.h @@ -85,8 +85,9 @@ extern void po_lex_pass_comments (bool flag); Switch this on or off. */ extern void po_lex_pass_obsolete_entries (bool flag); -extern void po_gram_error (const char *fmt, ...) - __attribute__ ((__format__ (__printf__, 1, 2))); +struct po_parser_state; +extern void po_gram_error (struct po_parser_state *ps, const char *fmt, ...) + __attribute__ ((__format__ (__printf__, 2, 3))); extern void po_gram_error_at_line (const lex_pos_ty *pos, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3))); diff --git a/gettext-tools/src/read-po.c b/gettext-tools/src/read-po.c index 3c54f283f..025cbdf7a 100644 --- a/gettext-tools/src/read-po.c +++ b/gettext-tools/src/read-po.c @@ -37,8 +37,9 @@ po_parse (abstract_catalog_reader_ty *this, FILE *fp, const char *real_filename, const char *logical_filename, bool is_pot_role) { + struct po_parser_state ps; lex_start (fp, real_filename, logical_filename, is_pot_role); - po_gram_parse (); + po_gram_parse (&ps); lex_end (); }