From e350fec2cff20b7e81b3efb453f25c549a82b97c Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 5 Jun 2023 12:31:30 +0200 Subject: [PATCH] xgettext: Support up to 4 format string parsers at the same time. * 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 | 25 ++++++++++++++++++++++++- gettext-tools/src/xg-arglist-context.h | 5 ++++- gettext-tools/src/xg-message.c | 12 +++++++++--- gettext-tools/src/xgettext.c | 12 +++++++++--- gettext-tools/src/xgettext.h | 3 ++- 5 files changed, 48 insertions(+), 9 deletions(-) diff --git a/gettext-tools/src/xg-arglist-context.c b/gettext-tools/src/xg-arglist-context.c index f89a4be3d..592e302cb 100644 --- a/gettext-tools/src/xg-arglist-context.c +++ b/gettext-tools/src/xg-arglist-context.c @@ -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 (); } diff --git a/gettext-tools/src/xg-arglist-context.h b/gettext-tools/src/xg-arglist-context.h index 6387931e1..c2d3d96e4 100644 --- a/gettext-tools/src/xg-arglist-context.h +++ b/gettext-tools/src/xg-arglist-context.h @@ -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; diff --git a/gettext-tools/src/xg-message.c b/gettext-tools/src/xg-message.c index 88d215e68..d7097f9e2 100644 --- a/gettext-tools/src/xg-message.c +++ b/gettext-tools/src/xg-message.c @@ -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 diff --git a/gettext-tools/src/xgettext.c b/gettext-tools/src/xgettext.c index dc1215d39..d891bb00e 100644 --- a/gettext-tools/src/xgettext.c +++ b/gettext-tools/src/xgettext.c @@ -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; } } diff --git a/gettext-tools/src/xgettext.h b/gettext-tools/src/xgettext.h index c6c98da55..e696f8bed 100644 --- a/gettext-tools/src/xgettext.h +++ b/gettext-tools/src/xgettext.h @@ -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 and Bruno Haible , 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. */ -- 2.47.2