]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
libgettextpo: Remove static variable 'plural_counter'.
authorBruno Haible <bruno@clisp.org>
Sat, 11 Nov 2023 15:48:27 +0000 (16:48 +0100)
committerBruno Haible <bruno@clisp.org>
Sat, 11 Nov 2023 15:48:27 +0000 (16:48 +0100)
* 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.

gettext-tools/src/po-gram-gen.y
gettext-tools/src/po-gram.h
gettext-tools/src/po-lex.c
gettext-tools/src/po-lex.h
gettext-tools/src/read-po.c

index 07ebdacb1e42ff320b4ac097e1e6b1f53dddb79b..ccae0d757b102dc724029e5aa2c55a7f848f823e 100644 (file)
@@ -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;
index cf916a98432c69b749edc2c877648afdfb4f50c7..f2a6c9fda7cc031a4392dfadf406daafa3acea79 100644 (file)
@@ -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 <millerp@canb.auug.org.au>
 
 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
 }
index 0b389a19c8b4b181b314a5522945635666e52b13..7af1cf739bba45b28ccc4b1868b8ccee1b75512d 100644 (file)
@@ -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 ' ';
 }
 
index db9e86a3a98a7fc482ef54b56a0fbfbf576f62c2..6672e4c4a3eb699604a1770ed48c5c67bd9ccb18 100644 (file)
@@ -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)));
 
index 3c54f283fce3f7fb8a7b5ffce12565bfd2c35dd8..025cbdf7aed5cc21705c905c2112c977a8988f16 100644 (file)
@@ -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 ();
 }