From: Bruno Haible Date: Sun, 4 Nov 2018 23:02:54 +0000 (+0100) Subject: xgettext: Simplify calling convention of arglist_parser_remember. X-Git-Tag: v0.20~256 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=604f2b62a0451a5190e55a242dea7e5004e0ce54;p=thirdparty%2Fgettext.git xgettext: Simplify calling convention of arglist_parser_remember. * gettext-tools/src/xg-arglist-parser.h (struct partial_call): Add 'msgid_comment_is_utf8' field. (arglist_parser_remember): Add comment_is_utf8 argument. * gettext-tools/src/xg-arglist-parser.c (arglist_parser_alloc, arglist_parser_clone): Update. (arglist_parser_remember): Add comment_is_utf8 argument. (arglist_parser_done): Pass comment_is_utf8 value down to remember_a_message. * gettext-tools/src/x-c.c (extract_parenthesized): Update callers. Don't set xgettext_current_source_encoding around arglist_parser_remember calls. * gettext-tools/src/x-csharp.c (extract_parenthesized): Likewise. * gettext-tools/src/x-java.c (extract_parenthesized): Likewise. * gettext-tools/src/x-javascript.c (extract_balanced): Likewise. * gettext-tools/src/x-perl.c (extract_balanced): Likewise. * gettext-tools/src/x-python.c (extract_balanced): Likewise. * gettext-tools/src/x-vala.c (extract_balanced): Likewise. * gettext-tools/src/x-awk.c (extract_parenthesized): Update callers. * gettext-tools/src/x-elisp.c (read_object): Likewise. * gettext-tools/src/x-librep.c (read_object): Likewise. * gettext-tools/src/x-lisp.c (read_object): Likewise. * gettext-tools/src/x-lua.c (extract_balanced): Likewise. * gettext-tools/src/x-php.c (extract_balanced): Likewise. * gettext-tools/src/x-scheme.c (read_object): Likewise. * gettext-tools/src/x-sh.c (read_command): Likewise. * gettext-tools/src/x-tcl.c (read_command): Likewise. --- diff --git a/gettext-tools/src/x-awk.c b/gettext-tools/src/x-awk.c index 0cc16186f..da74c0042 100644 --- a/gettext-tools/src/x-awk.c +++ b/gettext-tools/src/x-awk.c @@ -800,7 +800,7 @@ extract_parenthesized (message_list_ty *mlp, arglist_parser_remember (argparser, arg, ms, inner_context, pos.file_name, pos.line_number, - savable_comment); + savable_comment, false); } } next_is_argument = false; diff --git a/gettext-tools/src/x-c.c b/gettext-tools/src/x-c.c index 00f076ffd..0d43fc8d2 100644 --- a/gettext-tools/src/x-c.c +++ b/gettext-tools/src/x-c.c @@ -2304,15 +2304,11 @@ extract_parenthesized (message_list_ty *mlp, &token.pos, NULL, token.comment, false); } else - { - xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_remember (argparser, arg, token.mixed_string, - inner_context, - token.pos.file_name, - token.pos.line_number, - token.comment); - xgettext_current_source_encoding = xgettext_global_source_encoding; - } + arglist_parser_remember (argparser, arg, token.mixed_string, + inner_context, + token.pos.file_name, + token.pos.line_number, + token.comment, false); drop_reference (token.comment); } next_context_iter = null_context_list_iterator; diff --git a/gettext-tools/src/x-csharp.c b/gettext-tools/src/x-csharp.c index 963dda2da..85fb83397 100644 --- a/gettext-tools/src/x-csharp.c +++ b/gettext-tools/src/x-csharp.c @@ -2014,14 +2014,10 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator, &pos, NULL, token.comment, true); } else - { - xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_remember (argparser, arg, token.mixed_string, - inner_context, - pos.file_name, pos.line_number, - token.comment); - xgettext_current_source_encoding = xgettext_global_source_encoding; - } + arglist_parser_remember (argparser, arg, token.mixed_string, + inner_context, + pos.file_name, pos.line_number, + token.comment, true); } drop_reference (token.comment); next_context_iter = null_context_list_iterator; diff --git a/gettext-tools/src/x-elisp.c b/gettext-tools/src/x-elisp.c index b10774061..b661c0c4d 100644 --- a/gettext-tools/src/x-elisp.c +++ b/gettext-tools/src/x-elisp.c @@ -720,7 +720,7 @@ read_object (struct object *op, bool first_in_list, bool new_backquote_flag, inner_context, logical_file_name, inner.line_number_at_start, - savable_comment); + savable_comment, false); } } diff --git a/gettext-tools/src/x-java.c b/gettext-tools/src/x-java.c index cd57c3056..9b7591588 100644 --- a/gettext-tools/src/x-java.c +++ b/gettext-tools/src/x-java.c @@ -1213,14 +1213,10 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator, &pos, NULL, token.comment, true); } else - { - xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_remember (argparser, arg, token.mixed_string, - inner_context, - pos.file_name, pos.line_number, - token.comment); - xgettext_current_source_encoding = xgettext_global_source_encoding; - } + arglist_parser_remember (argparser, arg, token.mixed_string, + inner_context, + pos.file_name, pos.line_number, + token.comment, true); } drop_reference (token.comment); next_context_iter = null_context_list_iterator; diff --git a/gettext-tools/src/x-javascript.c b/gettext-tools/src/x-javascript.c index 27b87d4f7..85c9ad328 100644 --- a/gettext-tools/src/x-javascript.c +++ b/gettext-tools/src/x-javascript.c @@ -1514,14 +1514,10 @@ extract_balanced (message_list_ty *mlp, &pos, NULL, token.comment, true); } else - { - xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_remember (argparser, arg, token.mixed_string, - inner_context, - pos.file_name, pos.line_number, - token.comment); - xgettext_current_source_encoding = xgettext_current_file_source_encoding; - } + arglist_parser_remember (argparser, arg, token.mixed_string, + inner_context, + pos.file_name, pos.line_number, + token.comment, true); } drop_reference (token.comment); next_context_iter = null_context_list_iterator; diff --git a/gettext-tools/src/x-librep.c b/gettext-tools/src/x-librep.c index 1739e6f7c..f660808c7 100644 --- a/gettext-tools/src/x-librep.c +++ b/gettext-tools/src/x-librep.c @@ -694,7 +694,7 @@ read_object (struct object *op, flag_context_ty outer_context) inner_context, logical_file_name, inner.line_number_at_start, - savable_comment); + savable_comment, false); } } diff --git a/gettext-tools/src/x-lisp.c b/gettext-tools/src/x-lisp.c index 41402e24d..7604325f8 100644 --- a/gettext-tools/src/x-lisp.c +++ b/gettext-tools/src/x-lisp.c @@ -1097,7 +1097,7 @@ read_object (struct object *op, flag_context_ty outer_context) inner_context, logical_file_name, inner.line_number_at_start, - savable_comment); + savable_comment, false); } } diff --git a/gettext-tools/src/x-lua.c b/gettext-tools/src/x-lua.c index 55b46ad4a..3a2296f36 100644 --- a/gettext-tools/src/x-lua.c +++ b/gettext-tools/src/x-lua.c @@ -1161,14 +1161,16 @@ extract_balanced (message_list_ty *mlp, token_type_ty delim, tmp_argparser = arglist_parser_alloc (mlp, next_shapes); arglist_parser_remember (tmp_argparser, 1, ms, - inner_context, pos.file_name, - pos.line_number, token.comment); + inner_context, + pos.file_name, pos.line_number, + token.comment, false); arglist_parser_done (tmp_argparser, 1); } else arglist_parser_remember (argparser, arg, ms, - inner_context, pos.file_name, - pos.line_number, token.comment); + inner_context, + pos.file_name, pos.line_number, + token.comment, false); } } drop_reference (token.comment); diff --git a/gettext-tools/src/x-perl.c b/gettext-tools/src/x-perl.c index 818ad27ca..50b87bc12 100644 --- a/gettext-tools/src/x-perl.c +++ b/gettext-tools/src/x-perl.c @@ -3332,11 +3332,9 @@ extract_balanced (message_list_ty *mlp, mixed_string_alloc_utf8 (string, lc_string, logical_file_name, tp->line_number); free (string); - xgettext_current_source_encoding = po_charset_utf8; arglist_parser_remember (argparser, arg, ms, inner_context, logical_file_name, tp->line_number, - tp->comment); - xgettext_current_source_encoding = xgettext_global_source_encoding; + tp->comment, true); } } diff --git a/gettext-tools/src/x-php.c b/gettext-tools/src/x-php.c index ecb689bdb..de9b89f54 100644 --- a/gettext-tools/src/x-php.c +++ b/gettext-tools/src/x-php.c @@ -1542,7 +1542,7 @@ extract_balanced (message_list_ty *mlp, free (token.string); arglist_parser_remember (argparser, arg, ms, inner_context, pos.file_name, pos.line_number, - token.comment); + token.comment, false); } drop_reference (token.comment); } diff --git a/gettext-tools/src/x-python.c b/gettext-tools/src/x-python.c index fb1a4f1d9..a37a1e8b0 100644 --- a/gettext-tools/src/x-python.c +++ b/gettext-tools/src/x-python.c @@ -1629,14 +1629,10 @@ extract_balanced (message_list_ty *mlp, &pos, NULL, token.comment, true); } else - { - xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_remember (argparser, arg, token.mixed_string, - inner_context, - pos.file_name, pos.line_number, - token.comment); - xgettext_current_source_encoding = xgettext_current_file_source_encoding; - } + arglist_parser_remember (argparser, arg, token.mixed_string, + inner_context, + pos.file_name, pos.line_number, + token.comment, true); } drop_reference (token.comment); next_context_iter = null_context_list_iterator; diff --git a/gettext-tools/src/x-scheme.c b/gettext-tools/src/x-scheme.c index 955ca7468..fc4b7853d 100644 --- a/gettext-tools/src/x-scheme.c +++ b/gettext-tools/src/x-scheme.c @@ -801,7 +801,7 @@ read_object (struct object *op, flag_context_ty outer_context) inner_context, logical_file_name, inner.line_number_at_start, - savable_comment); + savable_comment, false); } } diff --git a/gettext-tools/src/x-sh.c b/gettext-tools/src/x-sh.c index 6980a4222..653d8ab6c 100644 --- a/gettext-tools/src/x-sh.c +++ b/gettext-tools/src/x-sh.c @@ -1370,7 +1370,7 @@ read_command (int looking_for, flag_context_ty outer_context) inner_context, logical_file_name, inner.line_number_at_start, - savable_comment); + savable_comment, false); } } diff --git a/gettext-tools/src/x-tcl.c b/gettext-tools/src/x-tcl.c index e67d94a57..8980739fc 100644 --- a/gettext-tools/src/x-tcl.c +++ b/gettext-tools/src/x-tcl.c @@ -942,7 +942,7 @@ read_command (int looking_for, flag_context_ty outer_context) inner_context, logical_file_name, inner.line_number_at_start, - savable_comment); + savable_comment, false); } } diff --git a/gettext-tools/src/x-vala.c b/gettext-tools/src/x-vala.c index 2c5f34509..0fadd6af5 100644 --- a/gettext-tools/src/x-vala.c +++ b/gettext-tools/src/x-vala.c @@ -1335,21 +1335,17 @@ extract_balanced (message_list_ty *mlp, token_type_ty delim, struct arglist_parser *tmp_argparser; tmp_argparser = arglist_parser_alloc (mlp, next_shapes); - xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_remember (tmp_argparser, 1, token.mixed_string, - inner_context, pos.file_name, - pos.line_number, token.comment); - xgettext_current_source_encoding = xgettext_global_source_encoding; + arglist_parser_remember (tmp_argparser, 1, + token.mixed_string, inner_context, + pos.file_name, pos.line_number, + token.comment, false); arglist_parser_done (tmp_argparser, 1); } else - { - xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_remember (argparser, arg, token.mixed_string, - inner_context, pos.file_name, - pos.line_number, token.comment); - xgettext_current_source_encoding = xgettext_global_source_encoding; - } + arglist_parser_remember (argparser, arg, + token.mixed_string, inner_context, + pos.file_name, pos.line_number, + token.comment, false); } } drop_reference (token.comment); diff --git a/gettext-tools/src/xg-arglist-parser.c b/gettext-tools/src/xg-arglist-parser.c index 37647d7e4..a99dc5fc5 100644 --- a/gettext-tools/src/xg-arglist-parser.c +++ b/gettext-tools/src/xg-arglist-parser.c @@ -87,6 +87,7 @@ arglist_parser_alloc (message_list_ty *mlp, const struct callshapes *shapes) ap->alternative[i].msgid_pos.file_name = NULL; ap->alternative[i].msgid_pos.line_number = (size_t)(-1); ap->alternative[i].msgid_comment = NULL; + ap->alternative[i].msgid_comment_is_utf8 = false; ap->alternative[i].msgid_plural = NULL; ap->alternative[i].msgid_plural_context = null_context; ap->alternative[i].msgid_plural_pos.file_name = NULL; @@ -131,6 +132,7 @@ arglist_parser_clone (struct arglist_parser *ap) ccp->msgid_context = cp->msgid_context; ccp->msgid_pos = cp->msgctxt_pos; ccp->msgid_comment = add_reference (cp->msgid_comment); + ccp->msgid_comment_is_utf8 = cp->msgid_comment_is_utf8; ccp->msgid_plural = (cp->msgid_plural != NULL ? mixed_string_clone (cp->msgid_plural) : NULL); ccp->msgid_plural_context = cp->msgid_plural_context; @@ -146,7 +148,8 @@ arglist_parser_remember (struct arglist_parser *ap, int argnum, mixed_string_ty *string, flag_context_ty context, char *file_name, size_t line_number, - refcounted_string_list_ty *comment) + refcounted_string_list_ty *comment, + bool comment_is_utf8) { bool stored_string = false; size_t nalternatives = ap->nalternatives; @@ -176,6 +179,7 @@ arglist_parser_remember (struct arglist_parser *ap, cp->msgid_pos.file_name = file_name; cp->msgid_pos.line_number = line_number; cp->msgid_comment = add_reference (comment); + cp->msgid_comment_is_utf8 = comment_is_utf8; stored_string = true; /* Mark msgid as done. */ cp->argnum1 = 0; @@ -501,7 +505,8 @@ arglist_parser_done (struct arglist_parser *ap, int argnum) mp = remember_a_message (ap->mlp, best_msgctxt, best_msgid, true, msgid_context, &best_cp->msgid_pos, - NULL, best_cp->msgid_comment, false); + NULL, best_cp->msgid_comment, + best_cp->msgid_comment_is_utf8); if (mp != NULL && best_msgid_plural != NULL) remember_a_message_plural (mp, best_msgid_plural, true, msgid_plural_context, diff --git a/gettext-tools/src/xg-arglist-parser.h b/gettext-tools/src/xg-arglist-parser.h index b6d31145c..e2f754e45 100644 --- a/gettext-tools/src/xg-arglist-parser.h +++ b/gettext-tools/src/xg-arglist-parser.h @@ -51,6 +51,7 @@ struct partial_call flag_context_ty msgid_context; lex_pos_ty msgid_pos; refcounted_string_list_ty *msgid_comment; + bool msgid_comment_is_utf8; mixed_string_ty *msgid_plural; /* msgid_plural - owned mixed_string, or NULL */ flag_context_ty msgid_plural_context; lex_pos_ty msgid_plural_pos; @@ -79,12 +80,15 @@ extern struct arglist_parser * arglist_parser_clone (struct arglist_parser *ap); FILE_NAME must be allocated with indefinite extent. COMMENT may be savable_comment, or it may be a saved copy of savable_comment (then add_reference must be used when saving it, and drop_reference while - dropping it). Clear savable_comment. */ + dropping it). Clear savable_comment. + COMMENT_IS_UTF8 must be true if COMMENT has already been converted to UTF-8. + */ extern void arglist_parser_remember (struct arglist_parser *ap, int argnum, mixed_string_ty *string, flag_context_ty context, char *file_name, size_t line_number, - refcounted_string_list_ty *comment); + refcounted_string_list_ty *comment, + bool comment_is_utf8); /* Adds a string argument as msgctxt to an arglist_parser, without incrementing the current argument number. STRING must be a mixed_string; its ownership is passed to the callee.