]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
libgettextpo: Remove static variable callback_arg.
authorBruno Haible <bruno@clisp.org>
Sun, 28 Jul 2024 14:08:25 +0000 (16:08 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 28 Jul 2024 14:08:25 +0000 (16:08 +0200)
* gettext-tools/src/read-catalog-abstract.h (po_callback_domain,
po_callback_message, po_callback_comment, po_callback_comment_dot,
po_callback_comment_filepos, po_callback_comment_special,
po_callback_comment_dispatcher): Add a first parameter 'catr'.
* gettext-tools/src/read-catalog-abstract.c (callback_arg): Remove variable.
(parse_start, parse_end): Remove functions.
(catalog_reader_parse): Inline them here.
(po_callback_domain, po_callback_message, po_callback_comment,
po_callback_comment_dot, po_callback_comment_filepos,
po_callback_comment_special, po_parse_comment_filepos,
po_parse_comment_solaris_filepos, po_callback_comment_dispatcher): Add a first
parameter 'catr'.
* gettext-tools/src/po-gram.h: Include read-catalog-abstract.h.
(struct po_parser_state): Add field 'catr'.
* gettext-tools/src/read-po.c (po_parse): Initialize the 'catr' field.
* gettext-tools/src/po-gram-gen.y: Pass ps->catr to po_callback_message,
po_callback_comment_dispatcher, po_callback_domain.
* gettext-tools/src/read-properties.c (properties_parse): Pass catr to
po_callback_comment_dispatcher, po_callback_message.
* gettext-tools/src/read-stringtable.c (special_comment_finish,
comment_line_end, phase4_getc, read_string): Add a first parameter 'catr'.
(stringtable_parse): Pass catr to the functions that need it.

gettext-tools/src/po-gram-gen.y
gettext-tools/src/po-gram.h
gettext-tools/src/read-catalog-abstract.c
gettext-tools/src/read-catalog-abstract.h
gettext-tools/src/read-po.c
gettext-tools/src/read-properties.c
gettext-tools/src/read-stringtable.c

index 35a24d776ff7a1ef35ed25e62a435bdf5d409e34..3ed68859c5d8cbb73b83915cc250c1bc9e89e4f8 100644 (file)
@@ -56,7 +56,8 @@ do_callback_message (struct po_parser_state *ps,
   if (msgctxt == NULL && msgid[0] == '\0' && !obsolete)
     po_lex_charset_set (msgstr, gram_pos.file_name, ps->gram_pot_role);
 
-  po_callback_message (msgctxt,
+  po_callback_message (ps->catr,
+                       msgctxt,
                        msgid, msgid_pos, msgid_plural,
                        msgstr, msgstr_len, msgstr_pos,
                        prev_msgctxt, prev_msgid, prev_msgid_plural,
@@ -139,7 +140,7 @@ po_file
 comment
         : COMMENT
                 {
-                  po_callback_comment_dispatcher ($1.string);
+                  po_callback_comment_dispatcher (ps->catr, $1.string);
                 }
         ;
 
@@ -147,7 +148,7 @@ comment
 domain
         : DOMAIN STRING
                 {
-                   po_callback_domain ($2.string);
+                   po_callback_domain (ps->catr, $2.string);
                 }
         ;
 
index db8acdb8c43cf91059dc2d370dbacafdd7422f59..04271ae0110ace2522bbffb2a02eaf1bd5f3946e 100644 (file)
@@ -1,5 +1,5 @@
 /* GNU gettext - internationalization aids
-   Copyright (C) 1995-2023 Free Software Foundation, Inc.
+   Copyright (C) 1995-2024 Free Software Foundation, Inc.
 
    This file was written by Peter Miller <millerp@canb.auug.org.au>
 
@@ -26,6 +26,8 @@
 # include "unistr.h"
 #endif
 
+#include "read-catalog-abstract.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -77,6 +79,9 @@ struct po_parser_state
 {
   /* ----- Input variables -----  */
 
+  /* The catalog reader that implements the callbacks.  */
+  struct abstract_catalog_reader_ty *catr;
+
   /* Whether the PO file is in the role of a POT file.  */
   bool gram_pot_role;
 
index 036d56870d738b7742b7214d7aba6e8eb6201362..4044950282239dfd9170628bd2da557f8206e6fb 100644 (file)
@@ -36,9 +36,6 @@
 #include "po-xerror.h"
 #include "gettext.h"
 
-/* Local variables.  */
-static abstract_catalog_reader_ty *callback_arg;
-
 
 /* ========================================================================= */
 /* Allocating and freeing instances of abstract_catalog_reader_ty.  */
@@ -148,26 +145,6 @@ call_comment_special (abstract_catalog_reader_ty *catr, const char *s)
 /* Exported functions.  */
 
 
-static inline void
-parse_start (abstract_catalog_reader_ty *catr)
-{
-  /* The parse will call the po_callback_... functions (see below)
-     when the various directive are recognised.  The callback_arg
-     variable is used to tell these functions which instance is to
-     have the relevant method invoked.  */
-  callback_arg = catr;
-
-  call_parse_brief (catr);
-}
-
-static inline void
-parse_end (abstract_catalog_reader_ty *catr)
-{
-  call_parse_debrief (catr);
-  callback_arg = NULL;
-}
-
-
 void
 catalog_reader_parse (abstract_catalog_reader_ty *catr, FILE *fp,
                       const char *real_filename, const char *logical_filename,
@@ -177,9 +154,9 @@ catalog_reader_parse (abstract_catalog_reader_ty *catr, FILE *fp,
   error_message_count = 0;
 
   /* Parse the stream's content.  */
-  parse_start (catr);
+  call_parse_brief (catr);
   input_syntax->parse (catr, fp, real_filename, logical_filename, is_pot_role);
-  parse_end (catr);
+  call_parse_debrief (catr);
 
   if (error_message_count > 0)
     po_xerror (PO_SEVERITY_FATAL_ERROR, NULL,
@@ -199,17 +176,17 @@ catalog_reader_parse (abstract_catalog_reader_ty *catr, FILE *fp,
 /* This function is called by po_gram_lex() whenever a domain directive
    has been seen.  */
 void
-po_callback_domain (char *name)
+po_callback_domain (abstract_catalog_reader_ty *catr, char *name)
 {
-  /* assert(callback_arg); */
-  call_directive_domain (callback_arg, name);
+  call_directive_domain (catr, name);
 }
 
 
 /* This function is called by po_gram_lex() whenever a message has been
    seen.  */
 void
-po_callback_message (char *msgctxt,
+po_callback_message (abstract_catalog_reader_ty *catr,
+                     char *msgctxt,
                      char *msgid, lex_pos_ty *msgid_pos, char *msgid_plural,
                      char *msgstr, size_t msgstr_len, lex_pos_ty *msgstr_pos,
                      char *prev_msgctxt,
@@ -217,8 +194,7 @@ po_callback_message (char *msgctxt,
                      char *prev_msgid_plural,
                      bool force_fuzzy, bool obsolete)
 {
-  /* assert(callback_arg); */
-  call_directive_message (callback_arg, msgctxt,
+  call_directive_message (catr, msgctxt,
                           msgid, msgid_pos, msgid_plural,
                           msgstr, msgstr_len, msgstr_pos,
                           prev_msgctxt, prev_msgid, prev_msgid_plural,
@@ -227,36 +203,33 @@ po_callback_message (char *msgctxt,
 
 
 void
-po_callback_comment (const char *s)
+po_callback_comment (abstract_catalog_reader_ty *catr, const char *s)
 {
-  /* assert(callback_arg); */
-  call_comment (callback_arg, s);
+  call_comment (catr, s);
 }
 
 
 void
-po_callback_comment_dot (const char *s)
+po_callback_comment_dot (abstract_catalog_reader_ty *catr, const char *s)
 {
-  /* assert(callback_arg); */
-  call_comment_dot (callback_arg, s);
+  call_comment_dot (catr, s);
 }
 
 
 /* This function is called by po_parse_comment_filepos(), once for each
    file name.  */
 void
-po_callback_comment_filepos (const char *file_name, size_t line_number)
+po_callback_comment_filepos (abstract_catalog_reader_ty *catr,
+                             const char *file_name, size_t line_number)
 {
-  /* assert(callback_arg); */
-  call_comment_filepos (callback_arg, file_name, line_number);
+  call_comment_filepos (catr, file_name, line_number);
 }
 
 
 void
-po_callback_comment_special (const char *s)
+po_callback_comment_special (abstract_catalog_reader_ty *catr, const char *s)
 {
-  /* assert(callback_arg); */
-  call_comment_special (callback_arg, s);
+  call_comment_special (catr, s);
 }
 
 
@@ -461,7 +434,7 @@ po_parse_comment_special (const char *s,
              U+2068 FILENAME U+2069.
    Call po_callback_comment_filepos for each of them.  */
 static void
-po_parse_comment_filepos (const char *s)
+po_parse_comment_filepos (abstract_catalog_reader_ty *catr, const char *s)
 {
   while (*s != '\0')
     {
@@ -541,7 +514,7 @@ po_parse_comment_filepos (const char *s)
                         memcpy (filename, filename_start, filename_length);
                         filename[filename_length] = '\0';
 
-                        po_callback_comment_filepos (filename, n);
+                        po_callback_comment_filepos (catr, filename, n);
 
                         free (filename);
 
@@ -583,7 +556,7 @@ po_parse_comment_filepos (const char *s)
                       memcpy (filename, filename_start, filename_length);
                       filename[filename_length] = '\0';
 
-                      po_callback_comment_filepos (filename, n);
+                      po_callback_comment_filepos (catr, filename, n);
 
                       free (filename);
 
@@ -637,7 +610,7 @@ po_parse_comment_filepos (const char *s)
                     memcpy (filename, filename_start, filename_length);
                     filename[filename_length] = '\0';
 
-                    po_callback_comment_filepos (filename, n);
+                    po_callback_comment_filepos (catr, filename, n);
 
                     free (filename);
 
@@ -655,7 +628,7 @@ po_parse_comment_filepos (const char *s)
             memcpy (filename, filename_start, filename_length);
             filename[filename_length] = '\0';
 
-            po_callback_comment_filepos (filename, (size_t)(-1));
+            po_callback_comment_filepos (catr, filename, (size_t)(-1));
 
             free (filename);
           }
@@ -678,7 +651,8 @@ po_parse_comment_filepos (const char *s)
      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)
+po_parse_comment_solaris_filepos (abstract_catalog_reader_ty *catr,
+                                  const char *s)
 {
   if (s[0] == ' '
       && (s[1] == 'F' || s[1] == 'f')
@@ -754,7 +728,7 @@ po_parse_comment_solaris_filepos (const char *s)
                               memcpy (string, string_start, string_length);
                               string[string_length] = '\0';
 
-                              po_callback_comment_filepos (string, n);
+                              po_callback_comment_filepos (catr, string, n);
 
                               free (string);
                               return true;
@@ -776,7 +750,7 @@ po_parse_comment_solaris_filepos (const char *s)
    call_comment_filepos (via po_parse_comment_filepos), or
    call_comment_special.  */
 void
-po_callback_comment_dispatcher (const char *s)
+po_callback_comment_dispatcher (abstract_catalog_reader_ty *catr, const char *s)
 {
   if (*s == '.')
     {
@@ -785,25 +759,25 @@ po_callback_comment_dispatcher (const char *s)
          consider it part of the comment, therefore remove it here.  */
       if (*s == ' ')
         s++;
-      po_callback_comment_dot (s);
+      po_callback_comment_dot (catr, s);
     }
   else if (*s == ':')
     {
       /* Parse the file location string.  The appropriate callback will be
          invoked.  */
-      po_parse_comment_filepos (s + 1);
+      po_parse_comment_filepos (catr, s + 1);
     }
   else if (*s == ',' || *s == '!')
     {
       /* Get all entries in the special comment line.  */
-      po_callback_comment_special (s + 1);
+      po_callback_comment_special (catr, s + 1);
     }
   else
     {
       /* It looks like a plain vanilla comment, but Solaris-style file
          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))
+      if (po_parse_comment_solaris_filepos (catr, s))
         /* Do nothing, it is a Sun-style file pos line.  */ ;
       else
         {
@@ -811,7 +785,7 @@ po_callback_comment_dispatcher (const char *s)
              consider it part of the comment, therefore remove it here.  */
           if (*s == ' ')
             s++;
-          po_callback_comment (s);
+          po_callback_comment (catr, s);
         }
     }
 }
index 1cc09572d2887255004acc75743ed8ff6601423e..80927807cb34963a5b94ce09fb74d8b0a0e9f022 100644 (file)
@@ -171,8 +171,9 @@ extern void
 
 /* Callbacks used by po-gram.y or po-lex.c, indirectly from
    catalog_reader_parse.  */
-extern void po_callback_domain (char *name);
-extern void po_callback_message (char *msgctxt,
+extern void po_callback_domain (abstract_catalog_reader_ty *catr, char *name);
+extern void po_callback_message (abstract_catalog_reader_ty *catr,
+                                 char *msgctxt,
                                  char *msgid, lex_pos_ty *msgid_pos,
                                  char *msgid_plural,
                                  char *msgstr, size_t msgstr_len,
@@ -180,12 +181,17 @@ extern void po_callback_message (char *msgctxt,
                                  char *prev_msgctxt,
                                  char *prev_msgid, char *prev_msgid_plural,
                                  bool force_fuzzy, bool obsolete);
-extern void po_callback_comment (const char *s);
-extern void po_callback_comment_dot (const char *s);
-extern void po_callback_comment_filepos (const char *file_name,
+extern void po_callback_comment (abstract_catalog_reader_ty *catr,
+                                 const char *s);
+extern void po_callback_comment_dot (abstract_catalog_reader_ty *catr,
+                                     const char *s);
+extern void po_callback_comment_filepos (abstract_catalog_reader_ty *catr,
+                                         const char *file_name,
                                          size_t line_number);
-extern void po_callback_comment_special (const char *s);
-extern void po_callback_comment_dispatcher (const char *s);
+extern void po_callback_comment_special (abstract_catalog_reader_ty *catr,
+                                         const char *s);
+extern void po_callback_comment_dispatcher (abstract_catalog_reader_ty *catr,
+                                            const char *s);
 
 /* Parse a special comment and put the result in *fuzzyp, formatp, *rangep,
    *wrapp.  */
index c41558137d18c78c0d8f1041eeb4a5f4685e57bc..77ba9dec4ac4409354bac6ce1fd776b4e36718da 100644 (file)
@@ -33,6 +33,7 @@ po_parse (abstract_catalog_reader_ty *catr, FILE *fp,
           bool is_pot_role)
 {
   struct po_parser_state ps;
+  ps.catr = catr;
   ps.gram_pot_role = is_pot_role;
   lex_start (&ps, fp, real_filename, logical_filename);
   po_gram_parse (&ps);
index 1139c57d9c7a8592b2f9ea701ba0be1a0e575808..e0508f1370f9ad67aab011290f60affad6c6b0f9 100644 (file)
@@ -671,6 +671,7 @@ properties_parse (abstract_catalog_reader_ty *catr, FILE *file,
           buffer[buflen] = '\0';
 
           po_callback_comment_dispatcher (
+            catr,
             conv_from_java (
               assume_utf8 ? buffer : conv_from_iso_8859_1 (buffer)));
         }
@@ -700,7 +701,8 @@ properties_parse (abstract_catalog_reader_ty *catr, FILE *file,
                  and if it is not already header/fuzzy/untranslated.  */
               force_fuzzy = (hidden && msgid[0] != '\0' && msgstr[0] != '\0');
 
-              po_callback_message (NULL, msgid, &msgid_pos, NULL,
+              po_callback_message (catr,
+                                   NULL, msgid, &msgid_pos, NULL,
                                    msgstr, strlen (msgstr) + 1, &msgstr_pos,
                                    NULL, NULL, NULL,
                                    force_fuzzy, false);
index 2a4e3d887adc823f0f53f198a3805a5317ffd4d9..e9271fe25f422bb290f4e4ed47f3eaff01c4231a 100644 (file)
@@ -474,11 +474,11 @@ special_comment_add (const char *flag)
 }
 
 static inline void
-special_comment_finish ()
+special_comment_finish (abstract_catalog_reader_ty *catr)
 {
   if (special_comment != NULL)
     {
-      po_callback_comment_special (special_comment);
+      po_callback_comment_special (catr, special_comment);
       free (special_comment);
       special_comment = NULL;
     }
@@ -514,7 +514,8 @@ comment_add (int c)
 }
 
 static void
-comment_line_end (size_t chars_to_remove, bool test_for_fuzzy_msgstr)
+comment_line_end (abstract_catalog_reader_ty *catr,
+                  size_t chars_to_remove, bool test_for_fuzzy_msgstr)
 {
   char *line;
 
@@ -548,7 +549,7 @@ comment_line_end (size_t chars_to_remove, bool test_for_fuzzy_msgstr)
     special_comment_add (line + 6);
   else if (strlen (line) >= 9 && memcmp (line, "Comment: ", 9) == 0)
     /* A comment extracted from the source.  */
-    po_callback_comment_dot (line + 9);
+    po_callback_comment_dot (catr, line + 9);
   else
     {
       char *last_colon;
@@ -562,10 +563,10 @@ comment_line_end (size_t chars_to_remove, bool test_for_fuzzy_msgstr)
         {
           /* A "File: <filename>:<number>" type comment.  */
           *last_colon = '\0';
-          po_callback_comment_filepos (line + 6, number);
+          po_callback_comment_filepos (catr, line + 6, number);
         }
       else
-        po_callback_comment (line);
+        po_callback_comment (catr, line);
     }
 }
 
@@ -574,7 +575,7 @@ comment_line_end (size_t chars_to_remove, bool test_for_fuzzy_msgstr)
    character.  */
 
 static int
-phase4_getc ()
+phase4_getc (abstract_catalog_reader_ty *catr)
 {
   int c;
 
@@ -620,7 +621,7 @@ phase4_getc ()
               {
               case '\n':
                 seen_newline = true;
-                comment_line_end (1, false);
+                comment_line_end (catr, 1, false);
                 comment_start ();
                 last_was_star = false;
                 trailing_stars = 0;
@@ -635,7 +636,7 @@ phase4_getc ()
                 if (last_was_star)
                   {
                     /* Drop additional stars at the end of the comment.  */
-                    comment_line_end (trailing_stars + 1,
+                    comment_line_end (catr, trailing_stars + 1,
                                       expect_fuzzy_msgstr_as_c_comment
                                       && !seen_newline);
                     break;
@@ -664,7 +665,7 @@ phase4_getc ()
           if (!(buflen == 0 && (c == ' ' || c == '\t')))
             comment_add (c);
         }
-      comment_line_end (0, expect_fuzzy_msgstr_as_cxx_comment);
+      comment_line_end (catr, 0, expect_fuzzy_msgstr_as_cxx_comment);
       return '\n';
     }
 }
@@ -708,7 +709,7 @@ is_quotable (int c)
    Return the string in UTF-8 encoding, or NULL if no string is seen.
    Return the start position of the string in *pos.  */
 static char *
-read_string (lex_pos_ty *pos)
+read_string (abstract_catalog_reader_ty *catr, lex_pos_ty *pos)
 {
   static int *buffer;
   static size_t bufmax;
@@ -717,7 +718,7 @@ read_string (lex_pos_ty *pos)
 
   /* Skip whitespace before the string.  */
   do
-    c = phase4_getc ();
+    c = phase4_getc (catr);
   while (is_whitespace (c));
 
   if (c == UEOF)
@@ -809,7 +810,7 @@ read_string (lex_pos_ty *pos)
         po_xerror (PO_SEVERITY_ERROR, NULL,
                    real_file_name, gram_pos.line_number, (size_t)(-1), false,
                    _("warning: syntax error"));
-      for (; c != UEOF && !is_quotable (c); c = phase4_getc ())
+      for (; c != UEOF && !is_quotable (c); c = phase4_getc (catr))
         {
           if (buflen >= bufmax)
             {
@@ -854,15 +855,15 @@ stringtable_parse (abstract_catalog_reader_ty *catr, FILE *file,
       fuzzy_msgstr = NULL;
 
       /* Read the key and all the comments preceding it.  */
-      msgid = read_string (&msgid_pos);
+      msgid = read_string (catr, &msgid_pos);
       if (msgid == NULL)
         break;
 
-      special_comment_finish ();
+      special_comment_finish (catr);
 
       /* Skip whitespace.  */
       do
-        c = phase4_getc ();
+        c = phase4_getc (catr);
       while (is_whitespace (c));
 
       /* Expect a '=' or ';'.  */
@@ -879,7 +880,8 @@ stringtable_parse (abstract_catalog_reader_ty *catr, FILE *file,
              necessarily designate an untranslated entry.  */
           msgstr = xstrdup ("");
           msgstr_pos = msgid_pos;
-          po_callback_message (NULL, msgid, &msgid_pos, NULL,
+          po_callback_message (catr,
+                               NULL, msgid, &msgid_pos, NULL,
                                msgstr, strlen (msgstr) + 1, &msgstr_pos,
                                NULL, NULL, NULL,
                                false, next_is_obsolete);
@@ -887,7 +889,7 @@ stringtable_parse (abstract_catalog_reader_ty *catr, FILE *file,
       else if (c == '=')
         {
           /* Read the value.  */
-          msgstr = read_string (&msgstr_pos);
+          msgstr = read_string (catr, &msgstr_pos);
           if (msgstr == NULL)
             {
               po_xerror (PO_SEVERITY_ERROR, NULL,
@@ -901,7 +903,7 @@ stringtable_parse (abstract_catalog_reader_ty *catr, FILE *file,
           expect_fuzzy_msgstr_as_c_comment = next_is_fuzzy;
           do
             {
-              c = phase4_getc ();
+              c = phase4_getc (catr);
               if (fuzzy_msgstr != NULL)
                 expect_fuzzy_msgstr_as_c_comment = false;
             }
@@ -921,7 +923,7 @@ stringtable_parse (abstract_catalog_reader_ty *catr, FILE *file,
                   phase3_ungetc (c);
 
                   expect_fuzzy_msgstr_as_cxx_comment = true;
-                  c = phase4_getc ();
+                  c = phase4_getc (catr);
                   phase4_ungetc (c);
                   expect_fuzzy_msgstr_as_cxx_comment = false;
                 }
@@ -929,7 +931,8 @@ stringtable_parse (abstract_catalog_reader_ty *catr, FILE *file,
                 msgstr = fuzzy_msgstr;
 
               /* A key/value pair.  */
-              po_callback_message (NULL, msgid, &msgid_pos, NULL,
+              po_callback_message (catr,
+                                   NULL, msgid, &msgid_pos, NULL,
                                    msgstr, strlen (msgstr) + 1, &msgstr_pos,
                                    NULL, NULL, NULL,
                                    false, next_is_obsolete);