]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
xgettext: Support up to 4 format string parsers at the same time.
authorBruno Haible <bruno@clisp.org>
Mon, 5 Jun 2023 10:31:30 +0000 (12:31 +0200)
committerBruno Haible <bruno@clisp.org>
Wed, 7 Jun 2023 15:09:53 +0000 (17:09 +0200)
* gettext-tools/src/xg-arglist-context.h (struct flag_context_ty): Add fields
is_format4, pass_format4.
* gettext-tools/src/xg-arglist-context.c (null_context, passthrough_context,
inherited_context, passthrough_context_circular_list,
flag_context_list_table_add): Update.
* gettext-tools/src/xg-message.c (set_format_flags_from_context,
decide_is_format, remember_a_message_plural): Update.
* gettext-tools/src/xgettext.h (current_formatstring_parser4): New declaration.
* gettext-tools/src/xgettext.c (struct extractor_ty): Add field
formatstring_parser4.
(current_formatstring_parser4): New variable.
(main, extract_from_file, language_to_extractor): Update.

gettext-tools/src/xg-arglist-context.c
gettext-tools/src/xg-arglist-context.h
gettext-tools/src/xg-message.c
gettext-tools/src/xgettext.c
gettext-tools/src/xgettext.h

index f89a4be3d6e268dd9ea30c5998c002cbbd7dcb7a..592e302cb4ba39a6b813093dfbe84adae5fa0515 100644 (file)
@@ -32,6 +32,7 @@
 /* Null context.  */
 flag_context_ty null_context =
   {
+    undecided, false,
     undecided, false,
     undecided, false,
     undecided, false
@@ -40,6 +41,7 @@ flag_context_ty null_context =
 /* Transparent context.  */
 flag_context_ty passthrough_context =
   {
+    undecided, true,
     undecided, true,
     undecided, true,
     undecided, true
@@ -67,6 +69,11 @@ inherited_context (flag_context_ty outer_context,
       result.is_format3 = outer_context.is_format3;
       result.pass_format3 = false;
     }
+  if (result.pass_format4)
+    {
+      result.is_format4 = outer_context.is_format4;
+      result.pass_format4 = false;
+    }
   return result;
 }
 
@@ -78,7 +85,7 @@ flag_context_list_iterator_ty null_context_list_iterator = { 1, NULL };
 static flag_context_list_ty passthrough_context_circular_list =
   {
     1,
-    { undecided, true, undecided, true, undecided, true },
+    { undecided, true, undecided, true, undecided, true, undecided, true },
     &passthrough_context_circular_list
   };
 flag_context_list_iterator_ty passthrough_context_list_iterator =
@@ -172,6 +179,10 @@ flag_context_list_table_add (flag_context_list_table_ty *table,
             list->flags.is_format3 = value;
             list->flags.pass_format3 = pass;
             break;
+          case 3:
+            list->flags.is_format4 = value;
+            list->flags.pass_format4 = pass;
+            break;
           default:
             abort ();
           }
@@ -209,6 +220,10 @@ flag_context_list_table_add (flag_context_list_table_ty *table,
                 list->flags.is_format3 = value;
                 list->flags.pass_format3 = pass;
                 break;
+              case 3:
+                list->flags.is_format4 = value;
+                list->flags.pass_format4 = pass;
+                break;
               default:
                 abort ();
               }
@@ -233,6 +248,10 @@ flag_context_list_table_add (flag_context_list_table_ty *table,
                 list->flags.is_format3 = value;
                 list->flags.pass_format3 = pass;
                 break;
+              case 3:
+                list->flags.is_format4 = value;
+                list->flags.pass_format4 = pass;
+                break;
               default:
                 abort ();
               }
@@ -264,6 +283,10 @@ flag_context_list_table_add (flag_context_list_table_ty *table,
                 list->flags.is_format3 = value;
                 list->flags.pass_format3 = pass;
                 break;
+              case 3:
+                list->flags.is_format4 = value;
+                list->flags.pass_format4 = pass;
+                break;
               default:
                 abort ();
               }
index 6387931e13ad0f3ac7ca319bd398dee703646f9b..c2d3d96e486931e39e54b2e9b73784f931cd0427 100644 (file)
@@ -1,6 +1,6 @@
 /* Keeping track of the flags that apply to a string extracted
    in a certain context.
-   Copyright (C) 2001-2018, 2020 Free Software Foundation, Inc.
+   Copyright (C) 2001-2018, 2020, 2023 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -41,6 +41,9 @@ struct flag_context_ty
   /* Regarding the tertiary formatstring type.  */
   /*enum is_format*/ unsigned int is_format3    : 3;
   /*bool*/           unsigned int pass_format3  : 1;
+  /* Regarding the fourth-ranked formatstring type.  */
+  /*enum is_format*/ unsigned int is_format4    : 3;
+  /*bool*/           unsigned int pass_format4  : 1;
 };
 /* Null context.  */
 extern flag_context_ty null_context;
index 88d215e682a2e7b20ff4397b6f9f4a488ab41e31..d7097f9e2fed0418b9bcc53d1bcef2843b89c6c4 100644 (file)
@@ -54,7 +54,8 @@ set_format_flags_from_context (enum is_format is_format[NFORMATS],
 
   if (context.is_format1 != undecided
       || context.is_format2 != undecided
-      || context.is_format3 != undecided)
+      || context.is_format3 != undecided
+      || context.is_format4 != undecided)
     for (i = 0; i < NFORMATS; i++)
       {
         if (is_format[i] == undecided)
@@ -68,6 +69,9 @@ set_format_flags_from_context (enum is_format is_format[NFORMATS],
             if (formatstring_parsers[i] == current_formatstring_parser3
                 && context.is_format3 != undecided)
               is_format[i] = (enum is_format) context.is_format3;
+            if (formatstring_parsers[i] == current_formatstring_parser4
+                && context.is_format4 != undecided)
+              is_format[i] = (enum is_format) context.is_format4;
           }
         if (possible_format_p (is_format[i]))
           {
@@ -120,7 +124,8 @@ decide_is_format (message_ty *mp)
       if (mp->is_format[i] == undecided
           && (formatstring_parsers[i] == current_formatstring_parser1
               || formatstring_parsers[i] == current_formatstring_parser2
-              || formatstring_parsers[i] == current_formatstring_parser3)
+              || formatstring_parsers[i] == current_formatstring_parser3
+              || formatstring_parsers[i] == current_formatstring_parser4)
           /* But avoid redundancy: objc-format is stronger than c-format.  */
           && !(i == format_c && possible_format_p (mp->is_format[format_objc]))
           && !(i == format_objc && possible_format_p (mp->is_format[format_c]))
@@ -612,7 +617,8 @@ remember_a_message_plural (message_ty *mp, char *string, bool is_utf8,
       for (i = 0; i < NFORMATS; i++)
         if ((formatstring_parsers[i] == current_formatstring_parser1
              || formatstring_parsers[i] == current_formatstring_parser2
-             || formatstring_parsers[i] == current_formatstring_parser3)
+             || formatstring_parsers[i] == current_formatstring_parser3
+             || formatstring_parsers[i] == current_formatstring_parser4)
             && (mp->is_format[i] == undecided || mp->is_format[i] == possible)
             /* But avoid redundancy: objc-format is stronger than c-format.  */
             && !(i == format_c
index dc1215d391799a3fbe7a4e8ffdeb7a67aef6ed3b..d891bb00e82be1ff07baeb54d2852da9aa738c91 100644 (file)
@@ -304,6 +304,7 @@ struct extractor_ty
   struct formatstring_parser *formatstring_parser1;
   struct formatstring_parser *formatstring_parser2;
   struct formatstring_parser *formatstring_parser3;
+  struct formatstring_parser *formatstring_parser4;
 };
 
 
@@ -341,7 +342,7 @@ main (int argc, char *argv[])
   string_list_ty *file_list;
   char *output_file = NULL;
   const char *language = NULL;
-  extractor_ty extractor = { NULL, NULL, NULL, NULL, NULL, NULL };
+  extractor_ty extractor = { NULL, NULL, NULL, NULL, NULL, NULL, NULL };
   int cnt;
   size_t i;
 
@@ -842,7 +843,8 @@ xgettext cannot work without keywords to look for"));
       /* Temporarily reset the directory list to empty, because file_name
          is an output file and therefore should not be searched for.  */
       void *saved_directory_list = dir_list_save_reset ();
-      extractor_ty po_extractor = { extract_po, NULL, NULL, NULL, NULL, NULL };
+      extractor_ty po_extractor =
+        { extract_po, NULL, NULL, NULL, NULL, NULL, NULL };
 
       extract_from_file (file_name, po_extractor, mdlp);
       if (!is_ascii_msgdomain_list (mdlp))
@@ -1873,6 +1875,7 @@ xgettext_open (const char *fn,
 struct formatstring_parser *current_formatstring_parser1;
 struct formatstring_parser *current_formatstring_parser2;
 struct formatstring_parser *current_formatstring_parser3;
+struct formatstring_parser *current_formatstring_parser4;
 
 
 static void
@@ -1885,6 +1888,7 @@ extract_from_file (const char *file_name, extractor_ty extractor,
   current_formatstring_parser1 = extractor.formatstring_parser1;
   current_formatstring_parser2 = extractor.formatstring_parser2;
   current_formatstring_parser3 = extractor.formatstring_parser3;
+  current_formatstring_parser4 = extractor.formatstring_parser4;
 
   if (extractor.extract_from_stream)
     {
@@ -1921,6 +1925,7 @@ extract_from_file (const char *file_name, extractor_ty extractor,
   current_formatstring_parser1 = NULL;
   current_formatstring_parser2 = NULL;
   current_formatstring_parser3 = NULL;
+  current_formatstring_parser4 = NULL;
 }
 
 static message_ty *
@@ -2204,6 +2209,7 @@ language_to_extractor (const char *name)
         result.formatstring_parser1 = tp->formatstring_parser1;
         result.formatstring_parser2 = tp->formatstring_parser2;
         result.formatstring_parser3 = NULL;
+        result.formatstring_parser4 = NULL;
 
         /* Handle --qt.  It's preferrable to handle this facility here rather
            than through an option --language=C++/Qt because the latter would
@@ -2234,7 +2240,7 @@ language_to_extractor (const char *name)
   error (EXIT_FAILURE, 0, _("language '%s' unknown"), name);
   /* NOTREACHED */
   {
-    extractor_ty result = { NULL, NULL, NULL, NULL, NULL, NULL };
+    extractor_ty result = { NULL, NULL, NULL, NULL, NULL, NULL, NULL };
     return result;
   }
 }
index c6c98da558b52b8a395da3e61b2812d74c8f3860..e696f8bed7c1f27c2b69e9d48bd9ec22d88b1dbf 100644 (file)
@@ -1,5 +1,5 @@
 /* xgettext common functions.
-   Copyright (C) 2001-2003, 2005-2006, 2008-2009, 2011, 2013-2014, 2018, 2020 Free Software Foundation, Inc.
+   Copyright (C) 2001-2003, 2005-2006, 2008-2009, 2011, 2013-2014, 2018, 2020, 2023 Free Software Foundation, Inc.
    Written by Peter Miller <millerp@canb.auug.org.au>
    and Bruno Haible <haible@clisp.cons.org>, 2001.
 
@@ -60,6 +60,7 @@ extern enum is_syntax_check default_syntax_check[NSYNTAXCHECKS];
 extern struct formatstring_parser *current_formatstring_parser1;
 extern struct formatstring_parser *current_formatstring_parser2;
 extern struct formatstring_parser *current_formatstring_parser3;
+extern struct formatstring_parser *current_formatstring_parser4;
 
 
 /* Record a flag in the appropriate backend's table.  */