From: Bruno Haible Date: Sun, 4 Nov 2018 22:28:58 +0000 (+0100) Subject: xgettext: Delay calls to from_current_source_encoding, part 2. X-Git-Tag: v0.20~257 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2a88aedeb5fdbade69ce60f61e7b3cf41d7c6bcb;p=thirdparty%2Fgettext.git xgettext: Delay calls to from_current_source_encoding, part 2. * gettext-tools/src/xg-arglist-parser.h: Include xg-mixed-string.h. (struct partial_call): Change type of fields msgctxt, msgid, msgid_plural to 'mixed_string_ty *'. (arglist_parser_remember, arglist_parser_remember_msgctxt): Take a 'mixed_string_ty *' argument instead of a 'char *' argument. * gettext-tools/src/xg-arglist-parser.c (arglist_parser_clone): Update accordingly. (arglist_parser_remember, arglist_parser_remember_msgctxt): Take a 'mixed_string_ty *' argument. (arglist_parser_done): Convert the mixed_string to UTF-8 encoded 'char *' here. This is where from_current_source_encoding gets invoked now: immediately before invoking remember_a_message, that is, only when we really need to know the --from-source encoding. * gettext-tools/src/x-c.c (extract_parenthesized): Pass the mixed_string to arglist_parser_remember. Don't set xgettext_current_source_encoding around arglist_parser_done 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-python.c (extract_balanced): Likewise. * gettext-tools/src/x-vala.c (extract_balanced): Likewise. * gettext-tools/src/x-lisp.c: Include xg-mixed-string.h. (read_object): Convert the string to a mixed_string_ty before passing it to arglist_parser_remember. * gettext-tools/src/x-elisp.c: Likewise. * gettext-tools/src/x-librep.c: Likewise. * gettext-tools/src/x-scheme.c: Likewise. * gettext-tools/src/x-awk.c: Include xg-mixed-string.h. (extract_parenthesized): Convert the string to a mixed_string_ty before passing it to arglist_parser_remember. * gettext-tools/src/x-lua.c: Include xg-mixed-string.h. (extract_balanced): Convert the string to a mixed_string_ty before passing it to arglist_parser_remember. * gettext-tools/src/x-php.c: Include xg-mixed-string.h. (extract_balanced): Convert the string to a mixed_string_ty before passing it to arglist_parser_remember. * gettext-tools/src/x-sh.c: Include xg-mixed-string.h. (read_command): Convert the string to a mixed_string_ty before passing it to arglist_parser_remember. * gettext-tools/src/x-tcl.c: Include xg-mixed-string.h. (read_command): Convert the string to a mixed_string_ty before passing it to arglist_parser_remember. * gettext-tools/src/x-perl.c (extract_balanced): Convert the string to a mixed_string_ty before passing it to arglist_parser_remember. Don't set xgettext_current_source_encoding around arglist_parser_done calls. --- diff --git a/gettext-tools/src/x-awk.c b/gettext-tools/src/x-awk.c index 993aa3aab..0cc16186f 100644 --- a/gettext-tools/src/x-awk.c +++ b/gettext-tools/src/x-awk.c @@ -32,6 +32,7 @@ #include "message.h" #include "xgettext.h" #include "xg-pos.h" +#include "xg-mixed-string.h" #include "xg-arglist-context.h" #include "xg-arglist-callshape.h" #include "xg-arglist-parser.h" @@ -791,10 +792,16 @@ extract_parenthesized (message_list_ty *mlp, remember_a_message (mlp, NULL, token.string, false, inner_context, &pos, NULL, savable_comment, false); else - arglist_parser_remember (argparser, arg, token.string, - inner_context, - pos.file_name, pos.line_number, - savable_comment); + { + mixed_string_ty *ms = + mixed_string_alloc_simple (token.string, lc_string, + pos.file_name, pos.line_number); + free (token.string); + arglist_parser_remember (argparser, arg, ms, + inner_context, + pos.file_name, pos.line_number, + savable_comment); + } } next_is_argument = false; next_context_iter = null_context_list_iterator; diff --git a/gettext-tools/src/x-c.c b/gettext-tools/src/x-c.c index 09f474c24..00f076ffd 100644 --- a/gettext-tools/src/x-c.c +++ b/gettext-tools/src/x-c.c @@ -2252,10 +2252,7 @@ extract_parenthesized (message_list_ty *mlp, arglist_parser_alloc (mlp, state ? next_shapes : NULL))) { - xgettext_current_source_encoding = po_charset_utf8; arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = - xgettext_global_source_encoding; return true; } next_context_iter = null_context_list_iterator; @@ -2264,9 +2261,7 @@ extract_parenthesized (message_list_ty *mlp, continue; case xgettext_token_type_rparen: - xgettext_current_source_encoding = po_charset_utf8; arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; return false; case xgettext_token_type_comma: @@ -2301,15 +2296,17 @@ extract_parenthesized (message_list_ty *mlp, case xgettext_token_type_string_literal: { - char *string = mixed_string_contents (token.mixed_string); - mixed_string_free (token.mixed_string); if (extract_all) - remember_a_message (mlp, NULL, string, true, inner_context, - &token.pos, NULL, token.comment, false); + { + char *string = mixed_string_contents (token.mixed_string); + mixed_string_free (token.mixed_string); + remember_a_message (mlp, NULL, string, true, inner_context, + &token.pos, NULL, token.comment, false); + } else { xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_remember (argparser, arg, string, + arglist_parser_remember (argparser, arg, token.mixed_string, inner_context, token.pos.file_name, token.pos.line_number, @@ -2330,9 +2327,7 @@ extract_parenthesized (message_list_ty *mlp, continue; case xgettext_token_type_eof: - xgettext_current_source_encoding = po_charset_utf8; arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; return true; default: diff --git a/gettext-tools/src/x-csharp.c b/gettext-tools/src/x-csharp.c index cfa6ea622..963dda2da 100644 --- a/gettext-tools/src/x-csharp.c +++ b/gettext-tools/src/x-csharp.c @@ -1934,9 +1934,7 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator, arglist_parser_alloc (mlp, state ? next_shapes : NULL))) { - xgettext_current_source_encoding = po_charset_utf8; arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; return true; } next_context_iter = null_context_list_iterator; @@ -1946,9 +1944,7 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator, case token_type_rparen: if (terminator == token_type_rparen) { - xgettext_current_source_encoding = po_charset_utf8; arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; return false; } if (terminator == token_type_rbrace) @@ -1968,9 +1964,7 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator, null_context, null_context_list_iterator, arglist_parser_alloc (mlp, NULL))) { - xgettext_current_source_encoding = po_charset_utf8; arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; return true; } next_context_iter = null_context_list_iterator; @@ -1980,9 +1974,7 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator, case token_type_rbrace: if (terminator == token_type_rbrace) { - xgettext_current_source_encoding = po_charset_utf8; arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; return false; } if (terminator == token_type_rparen) @@ -2009,22 +2001,22 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator, case token_type_string_literal: { - char *string; lex_pos_ty pos; - string = mixed_string_contents (token.mixed_string); - mixed_string_free (token.mixed_string); - pos.file_name = logical_file_name; pos.line_number = token.line_number; if (extract_all) - remember_a_message (mlp, NULL, string, true, inner_context, - &pos, NULL, token.comment, true); + { + char *string = mixed_string_contents (token.mixed_string); + mixed_string_free (token.mixed_string); + remember_a_message (mlp, NULL, string, true, inner_context, + &pos, NULL, token.comment, true); + } else { xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_remember (argparser, arg, string, + arglist_parser_remember (argparser, arg, token.mixed_string, inner_context, pos.file_name, pos.line_number, token.comment); @@ -2037,9 +2029,7 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator, continue; case token_type_eof: - xgettext_current_source_encoding = po_charset_utf8; arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; return true; case token_type_dot: diff --git a/gettext-tools/src/x-elisp.c b/gettext-tools/src/x-elisp.c index 3fff84f90..b10774061 100644 --- a/gettext-tools/src/x-elisp.c +++ b/gettext-tools/src/x-elisp.c @@ -32,6 +32,7 @@ #include "message.h" #include "xgettext.h" #include "xg-pos.h" +#include "xg-mixed-string.h" #include "xg-arglist-context.h" #include "xg-arglist-callshape.h" #include "xg-arglist-parser.h" @@ -708,12 +709,19 @@ read_object (struct object *op, bool first_in_list, bool new_backquote_flag, { /* These are the argument positions. */ if (argparser != NULL && inner.type == t_string) - arglist_parser_remember (argparser, arg, - string_of_object (&inner), - inner_context, - logical_file_name, - inner.line_number_at_start, - savable_comment); + { + char *s = string_of_object (&inner); + mixed_string_ty *ms = + mixed_string_alloc_simple (s, lc_string, + logical_file_name, + inner.line_number_at_start); + free (s); + arglist_parser_remember (argparser, arg, ms, + inner_context, + logical_file_name, + inner.line_number_at_start, + savable_comment); + } } free_object (&inner); diff --git a/gettext-tools/src/x-java.c b/gettext-tools/src/x-java.c index e019f4e5a..cd57c3056 100644 --- a/gettext-tools/src/x-java.c +++ b/gettext-tools/src/x-java.c @@ -1133,9 +1133,7 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator, arglist_parser_alloc (mlp, state ? next_shapes : NULL))) { - xgettext_current_source_encoding = po_charset_utf8; arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; return true; } next_context_iter = null_context_list_iterator; @@ -1145,9 +1143,7 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator, case token_type_rparen: if (terminator == token_type_rparen) { - xgettext_current_source_encoding = po_charset_utf8; arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; return false; } if (terminator == token_type_rbrace) @@ -1167,9 +1163,7 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator, null_context, null_context_list_iterator, arglist_parser_alloc (mlp, NULL))) { - xgettext_current_source_encoding = po_charset_utf8; arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; return true; } next_context_iter = null_context_list_iterator; @@ -1179,9 +1173,7 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator, case token_type_rbrace: if (terminator == token_type_rbrace) { - xgettext_current_source_encoding = po_charset_utf8; arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; return false; } if (terminator == token_type_rparen) @@ -1208,22 +1200,22 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator, case token_type_string_literal: { - char *string; lex_pos_ty pos; - string = mixed_string_contents (token.mixed_string); - mixed_string_free (token.mixed_string); - pos.file_name = logical_file_name; pos.line_number = token.line_number; if (extract_all) - remember_a_message (mlp, NULL, string, true, inner_context, - &pos, NULL, token.comment, true); + { + char *string = mixed_string_contents (token.mixed_string); + mixed_string_free (token.mixed_string); + remember_a_message (mlp, NULL, string, true, inner_context, + &pos, NULL, token.comment, true); + } else { xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_remember (argparser, arg, string, + arglist_parser_remember (argparser, arg, token.mixed_string, inner_context, pos.file_name, pos.line_number, token.comment); @@ -1236,9 +1228,7 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator, continue; case token_type_eof: - xgettext_current_source_encoding = po_charset_utf8; arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; return true; case token_type_dot: diff --git a/gettext-tools/src/x-javascript.c b/gettext-tools/src/x-javascript.c index 0dea9c079..27b87d4f7 100644 --- a/gettext-tools/src/x-javascript.c +++ b/gettext-tools/src/x-javascript.c @@ -1450,9 +1450,7 @@ extract_balanced (message_list_ty *mlp, arglist_parser_alloc (mlp, state ? next_shapes : NULL))) { - xgettext_current_source_encoding = po_charset_utf8; arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_current_file_source_encoding; return true; } next_context_iter = null_context_list_iterator; @@ -1462,9 +1460,7 @@ extract_balanced (message_list_ty *mlp, case token_type_rparen: if (delim == token_type_rparen || delim == token_type_eof) { - xgettext_current_source_encoding = po_charset_utf8; arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_current_file_source_encoding; return false; } next_context_iter = null_context_list_iterator; @@ -1486,9 +1482,7 @@ extract_balanced (message_list_ty *mlp, null_context, null_context_list_iterator, arglist_parser_alloc (mlp, NULL))) { - xgettext_current_source_encoding = po_charset_utf8; arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_current_file_source_encoding; return true; } next_context_iter = null_context_list_iterator; @@ -1498,9 +1492,7 @@ extract_balanced (message_list_ty *mlp, case token_type_rbracket: if (delim == token_type_rbracket || delim == token_type_eof) { - xgettext_current_source_encoding = po_charset_utf8; arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_current_file_source_encoding; return false; } next_context_iter = null_context_list_iterator; @@ -1509,22 +1501,22 @@ extract_balanced (message_list_ty *mlp, case token_type_string: { - char *string; lex_pos_ty pos; - string = mixed_string_contents (token.mixed_string); - mixed_string_free (token.mixed_string); - pos.file_name = logical_file_name; pos.line_number = token.line_number; if (extract_all) - remember_a_message (mlp, NULL, string, true, inner_context, - &pos, NULL, token.comment, true); + { + char *string = mixed_string_contents (token.mixed_string); + mixed_string_free (token.mixed_string); + remember_a_message (mlp, NULL, string, true, inner_context, + &pos, NULL, token.comment, true); + } else { xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_remember (argparser, arg, string, + arglist_parser_remember (argparser, arg, token.mixed_string, inner_context, pos.file_name, pos.line_number, token.comment); @@ -1537,9 +1529,7 @@ extract_balanced (message_list_ty *mlp, continue; case token_type_eof: - xgettext_current_source_encoding = po_charset_utf8; arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_current_file_source_encoding; return true; case token_type_keyword: diff --git a/gettext-tools/src/x-librep.c b/gettext-tools/src/x-librep.c index 552e58beb..1739e6f7c 100644 --- a/gettext-tools/src/x-librep.c +++ b/gettext-tools/src/x-librep.c @@ -33,6 +33,7 @@ #include "message.h" #include "xgettext.h" #include "xg-pos.h" +#include "xg-mixed-string.h" #include "xg-arglist-context.h" #include "xg-arglist-callshape.h" #include "xg-arglist-parser.h" @@ -682,12 +683,19 @@ read_object (struct object *op, flag_context_ty outer_context) { /* These are the argument positions. */ if (argparser != NULL && inner.type == t_string) - arglist_parser_remember (argparser, arg, - string_of_object (&inner), - inner_context, - logical_file_name, - inner.line_number_at_start, - savable_comment); + { + char *s = string_of_object (&inner); + mixed_string_ty *ms = + mixed_string_alloc_simple (s, lc_string, + logical_file_name, + inner.line_number_at_start); + free (s); + arglist_parser_remember (argparser, arg, ms, + inner_context, + logical_file_name, + inner.line_number_at_start, + savable_comment); + } } free_object (&inner); diff --git a/gettext-tools/src/x-lisp.c b/gettext-tools/src/x-lisp.c index 0680c17dc..41402e24d 100644 --- a/gettext-tools/src/x-lisp.c +++ b/gettext-tools/src/x-lisp.c @@ -32,6 +32,7 @@ #include "message.h" #include "xgettext.h" #include "xg-pos.h" +#include "xg-mixed-string.h" #include "xg-arglist-context.h" #include "xg-arglist-callshape.h" #include "xg-arglist-parser.h" @@ -1085,12 +1086,19 @@ read_object (struct object *op, flag_context_ty outer_context) { /* These are the argument positions. */ if (argparser != NULL && inner.type == t_string) - arglist_parser_remember (argparser, arg, - string_of_object (&inner), - inner_context, - logical_file_name, - inner.line_number_at_start, - savable_comment); + { + char *s = string_of_object (&inner); + mixed_string_ty *ms = + mixed_string_alloc_simple (s, lc_string, + logical_file_name, + inner.line_number_at_start); + free (s); + arglist_parser_remember (argparser, arg, ms, + inner_context, + logical_file_name, + inner.line_number_at_start, + savable_comment); + } } free_object (&inner); diff --git a/gettext-tools/src/x-lua.c b/gettext-tools/src/x-lua.c index f45d3e029..55b46ad4a 100644 --- a/gettext-tools/src/x-lua.c +++ b/gettext-tools/src/x-lua.c @@ -32,6 +32,7 @@ #include "rc-str-list.h" #include "xgettext.h" #include "xg-pos.h" +#include "xg-mixed-string.h" #include "xg-arglist-context.h" #include "xg-arglist-callshape.h" #include "xg-arglist-parser.h" @@ -1149,19 +1150,23 @@ extract_balanced (message_list_ty *mlp, token_type_ty delim, &pos, NULL, token.comment, false); else { + mixed_string_ty *ms = + mixed_string_alloc_simple (token.string, lc_string, + pos.file_name, pos.line_number); + free (token.string); /* A string immediately after a symbol means a function call. */ if (state) { struct arglist_parser *tmp_argparser; tmp_argparser = arglist_parser_alloc (mlp, next_shapes); - arglist_parser_remember (tmp_argparser, 1, token.string, + arglist_parser_remember (tmp_argparser, 1, ms, inner_context, pos.file_name, pos.line_number, token.comment); arglist_parser_done (tmp_argparser, 1); } else - arglist_parser_remember (argparser, arg, token.string, + arglist_parser_remember (argparser, arg, ms, inner_context, pos.file_name, pos.line_number, token.comment); } diff --git a/gettext-tools/src/x-perl.c b/gettext-tools/src/x-perl.c index f2b4365f0..818ad27ca 100644 --- a/gettext-tools/src/x-perl.c +++ b/gettext-tools/src/x-perl.c @@ -34,6 +34,7 @@ #include "xgettext.h" #include "xg-pos.h" #include "xg-encoding.h" +#include "xg-mixed-string.h" #include "xg-arglist-context.h" #include "xg-arglist-callshape.h" #include "xg-arglist-parser.h" @@ -3066,9 +3067,7 @@ extract_balanced (message_list_ty *mlp, if (delim == tp->type) { - xgettext_current_source_encoding = po_charset_utf8; arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; if (next_argparser != NULL) free (next_argparser); #if DEBUG_PERL @@ -3085,9 +3084,7 @@ extract_balanced (message_list_ty *mlp, if (comma_delim && tp->type == token_type_comma) { - xgettext_current_source_encoding = po_charset_utf8; arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; if (next_argparser != NULL) free (next_argparser); #if DEBUG_PERL @@ -3137,9 +3134,7 @@ extract_balanced (message_list_ty *mlp, inner_context, next_context_iter, 1, next_argparser)) { - xgettext_current_source_encoding = po_charset_utf8; arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; return true; } @@ -3223,9 +3218,7 @@ extract_balanced (message_list_ty *mlp, inner_context, next_context_iter, 1, next_argparser)) { - xgettext_current_source_encoding = po_charset_utf8; arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; return true; } next_is_argument = false; @@ -3238,9 +3231,7 @@ extract_balanced (message_list_ty *mlp, inner_context, next_context_iter, arg, arglist_parser_clone (argparser))) { - xgettext_current_source_encoding = po_charset_utf8; arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; if (next_argparser != NULL) free (next_argparser); free_token (tp); @@ -3277,9 +3268,7 @@ extract_balanced (message_list_ty *mlp, if (arglist_parser_decidedp (argparser, arg)) { /* We have missed the argument. */ - xgettext_current_source_encoding = po_charset_utf8; arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; argparser = arglist_parser_alloc (mlp, NULL); arg = 0; } @@ -3339,10 +3328,12 @@ extract_balanced (message_list_ty *mlp, if (must_collect) { char *string = collect_message (mlp, tp, EXIT_FAILURE); - + mixed_string_ty *ms = + 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, - string, inner_context, + arglist_parser_remember (argparser, arg, ms, inner_context, logical_file_name, tp->line_number, tp->comment); xgettext_current_source_encoding = xgettext_global_source_encoding; @@ -3351,9 +3342,7 @@ extract_balanced (message_list_ty *mlp, if (arglist_parser_decidedp (argparser, arg)) { - xgettext_current_source_encoding = po_charset_utf8; arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; argparser = arglist_parser_alloc (mlp, NULL); } @@ -3381,9 +3370,7 @@ extract_balanced (message_list_ty *mlp, fprintf (stderr, "%s:%d: type EOF (%d)\n", logical_file_name, tp->line_number, nesting_level); #endif - xgettext_current_source_encoding = po_charset_utf8; arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; if (next_argparser != NULL) free (next_argparser); next_argparser = NULL; @@ -3399,9 +3386,7 @@ extract_balanced (message_list_ty *mlp, null_context, null_context_list_iterator, 1, arglist_parser_alloc (mlp, NULL))) { - xgettext_current_source_encoding = po_charset_utf8; arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; if (next_argparser != NULL) free (next_argparser); free_token (tp); @@ -3435,9 +3420,7 @@ extract_balanced (message_list_ty *mlp, null_context, null_context_list_iterator, 1, arglist_parser_alloc (mlp, NULL))) { - xgettext_current_source_encoding = po_charset_utf8; arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; if (next_argparser != NULL) free (next_argparser); free_token (tp); @@ -3469,9 +3452,7 @@ extract_balanced (message_list_ty *mlp, #endif /* The ultimate sign. */ - xgettext_current_source_encoding = po_charset_utf8; arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; argparser = arglist_parser_alloc (mlp, NULL); /* FIXME: Instead of resetting outer_context here, it may be better diff --git a/gettext-tools/src/x-php.c b/gettext-tools/src/x-php.c index 1c5b1092f..ecb689bdb 100644 --- a/gettext-tools/src/x-php.c +++ b/gettext-tools/src/x-php.c @@ -32,6 +32,7 @@ #include "rc-str-list.h" #include "xgettext.h" #include "xg-pos.h" +#include "xg-mixed-string.h" #include "xg-arglist-context.h" #include "xg-arglist-callshape.h" #include "xg-arglist-parser.h" @@ -1534,10 +1535,15 @@ extract_balanced (message_list_ty *mlp, remember_a_message (mlp, NULL, token.string, false, inner_context, &pos, NULL, token.comment, false); else - arglist_parser_remember (argparser, arg, token.string, - inner_context, - pos.file_name, pos.line_number, - token.comment); + { + mixed_string_ty *ms = + mixed_string_alloc_simple (token.string, lc_string, + pos.file_name, pos.line_number); + free (token.string); + arglist_parser_remember (argparser, arg, ms, inner_context, + pos.file_name, pos.line_number, + token.comment); + } drop_reference (token.comment); } next_context_iter = null_context_list_iterator; diff --git a/gettext-tools/src/x-python.c b/gettext-tools/src/x-python.c index 19f584678..fb1a4f1d9 100644 --- a/gettext-tools/src/x-python.c +++ b/gettext-tools/src/x-python.c @@ -1565,9 +1565,7 @@ extract_balanced (message_list_ty *mlp, arglist_parser_alloc (mlp, state ? next_shapes : NULL))) { - xgettext_current_source_encoding = po_charset_utf8; arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_current_file_source_encoding; return true; } next_context_iter = null_context_list_iterator; @@ -1577,9 +1575,7 @@ extract_balanced (message_list_ty *mlp, case token_type_rparen: if (delim == token_type_rparen || delim == token_type_eof) { - xgettext_current_source_encoding = po_charset_utf8; arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_current_file_source_encoding; return false; } next_context_iter = null_context_list_iterator; @@ -1601,9 +1597,7 @@ extract_balanced (message_list_ty *mlp, null_context, null_context_list_iterator, arglist_parser_alloc (mlp, NULL))) { - xgettext_current_source_encoding = po_charset_utf8; arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_current_file_source_encoding; return true; } next_context_iter = null_context_list_iterator; @@ -1613,9 +1607,7 @@ extract_balanced (message_list_ty *mlp, case token_type_rbracket: if (delim == token_type_rbracket || delim == token_type_eof) { - xgettext_current_source_encoding = po_charset_utf8; arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_current_file_source_encoding; return false; } next_context_iter = null_context_list_iterator; @@ -1624,22 +1616,22 @@ extract_balanced (message_list_ty *mlp, case token_type_string: { - char *string; lex_pos_ty pos; - string = mixed_string_contents (token.mixed_string); - mixed_string_free (token.mixed_string); - pos.file_name = logical_file_name; pos.line_number = token.line_number; if (extract_all) - remember_a_message (mlp, NULL, string, true, inner_context, - &pos, NULL, token.comment, true); + { + char *string = mixed_string_contents (token.mixed_string); + mixed_string_free (token.mixed_string); + remember_a_message (mlp, NULL, string, true, inner_context, + &pos, NULL, token.comment, true); + } else { xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_remember (argparser, arg, string, + arglist_parser_remember (argparser, arg, token.mixed_string, inner_context, pos.file_name, pos.line_number, token.comment); @@ -1652,9 +1644,7 @@ extract_balanced (message_list_ty *mlp, continue; case token_type_eof: - xgettext_current_source_encoding = po_charset_utf8; arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_current_file_source_encoding; return true; case token_type_plus: diff --git a/gettext-tools/src/x-scheme.c b/gettext-tools/src/x-scheme.c index 2856b6a80..955ca7468 100644 --- a/gettext-tools/src/x-scheme.c +++ b/gettext-tools/src/x-scheme.c @@ -32,6 +32,7 @@ #include "message.h" #include "xgettext.h" #include "xg-pos.h" +#include "xg-mixed-string.h" #include "xg-arglist-context.h" #include "xg-arglist-callshape.h" #include "xg-arglist-parser.h" @@ -789,12 +790,19 @@ read_object (struct object *op, flag_context_ty outer_context) { /* These are the argument positions. */ if (argparser != NULL && inner.type == t_string) - arglist_parser_remember (argparser, arg, - string_of_object (&inner), - inner_context, - logical_file_name, - inner.line_number_at_start, - savable_comment); + { + char *s = string_of_object (&inner); + mixed_string_ty *ms = + mixed_string_alloc_simple (s, lc_string, + logical_file_name, + inner.line_number_at_start); + free (s); + arglist_parser_remember (argparser, arg, ms, + inner_context, + logical_file_name, + inner.line_number_at_start, + savable_comment); + } } free_object (&inner); diff --git a/gettext-tools/src/x-sh.c b/gettext-tools/src/x-sh.c index 75f170816..6980a4222 100644 --- a/gettext-tools/src/x-sh.c +++ b/gettext-tools/src/x-sh.c @@ -32,6 +32,7 @@ #include "message.h" #include "xgettext.h" #include "xg-pos.h" +#include "xg-mixed-string.h" #include "xg-arglist-context.h" #include "xg-arglist-callshape.h" #include "xg-arglist-parser.h" @@ -1318,9 +1319,14 @@ read_command (int looking_for, flag_context_ty outer_context) && memcmp (argparser->keyword, "ngettext", 8) == 0)); if (accepts_context && argparser->next_is_msgctxt) { + char *s = string_of_word (&inner); + mixed_string_ty *ms = + mixed_string_alloc_simple (s, lc_string, + logical_file_name, + inner.line_number_at_start); + free (s); argparser->next_is_msgctxt = false; - arglist_parser_remember_msgctxt (argparser, - string_of_word (&inner), + arglist_parser_remember_msgctxt (argparser, ms, inner_context, logical_file_name, inner.line_number_at_start); @@ -1339,9 +1345,14 @@ read_command (int looking_for, flag_context_ty outer_context) && (inner.token->charcount >= 10 && memcmp (inner.token->chars, "--context=", 10) == 0)) { + char *s = substring_of_word (&inner, 10); + mixed_string_ty *ms = + mixed_string_alloc_simple (s, lc_string, + logical_file_name, + inner.line_number_at_start); + free (s); argparser->next_is_msgctxt = false; - arglist_parser_remember_msgctxt (argparser, - substring_of_word (&inner, 10), + arglist_parser_remember_msgctxt (argparser, ms, inner_context, logical_file_name, inner.line_number_at_start); @@ -1349,8 +1360,13 @@ read_command (int looking_for, flag_context_ty outer_context) } else { - arglist_parser_remember (argparser, arg, - string_of_word (&inner), + char *s = string_of_word (&inner); + mixed_string_ty *ms = + mixed_string_alloc_simple (s, lc_string, + logical_file_name, + inner.line_number_at_start); + free (s); + arglist_parser_remember (argparser, arg, ms, inner_context, logical_file_name, inner.line_number_at_start, diff --git a/gettext-tools/src/x-tcl.c b/gettext-tools/src/x-tcl.c index 43704c7d0..e67d94a57 100644 --- a/gettext-tools/src/x-tcl.c +++ b/gettext-tools/src/x-tcl.c @@ -35,6 +35,7 @@ #include "xgettext.h" #include "xg-pos.h" #include "xg-encoding.h" +#include "xg-mixed-string.h" #include "xg-arglist-context.h" #include "xg-arglist-callshape.h" #include "xg-arglist-parser.h" @@ -930,12 +931,19 @@ read_command (int looking_for, flag_context_ty outer_context) { /* These are the argument positions. */ if (argparser != NULL && inner.type == t_string) - arglist_parser_remember (argparser, arg, - string_of_word (&inner), - inner_context, - logical_file_name, - inner.line_number_at_start, - savable_comment); + { + char *s = string_of_word (&inner); + mixed_string_ty *ms = + mixed_string_alloc_simple (s, lc_string, + logical_file_name, + inner.line_number_at_start); + free (s); + arglist_parser_remember (argparser, arg, ms, + inner_context, + logical_file_name, + inner.line_number_at_start, + savable_comment); + } } free_word (&inner); diff --git a/gettext-tools/src/x-vala.c b/gettext-tools/src/x-vala.c index c0347693e..2c5f34509 100644 --- a/gettext-tools/src/x-vala.c +++ b/gettext-tools/src/x-vala.c @@ -1281,9 +1281,7 @@ extract_balanced (message_list_ty *mlp, token_type_ty delim, arglist_parser_alloc (mlp, state ? next_shapes : NULL))) { - xgettext_current_source_encoding = po_charset_utf8; arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; return true; } next_context_iter = null_context_list_iterator; @@ -1293,9 +1291,7 @@ extract_balanced (message_list_ty *mlp, token_type_ty delim, case token_type_rparen: if (delim == token_type_rparen || delim == token_type_eof) { - xgettext_current_source_encoding = po_charset_utf8; arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; return false; } @@ -1314,44 +1310,46 @@ extract_balanced (message_list_ty *mlp, token_type_ty delim, continue; case token_type_eof: - xgettext_current_source_encoding = po_charset_utf8; arglist_parser_done (argparser, arg); - xgettext_current_source_encoding = xgettext_global_source_encoding; return true; case token_type_string_literal: { - char *string; lex_pos_ty pos; - string = mixed_string_contents (token.mixed_string); - mixed_string_free (token.mixed_string); - pos.file_name = logical_file_name; pos.line_number = token.line_number; if (extract_all) - remember_a_message (mlp, NULL, string, true, inner_context, - &pos, NULL, token.comment, false); + { + char *string = mixed_string_contents (token.mixed_string); + mixed_string_free (token.mixed_string); + remember_a_message (mlp, NULL, string, true, inner_context, + &pos, NULL, token.comment, false); + } else { - xgettext_current_source_encoding = po_charset_utf8; /* A string immediately after a symbol means a function call. */ if (state) { struct arglist_parser *tmp_argparser; tmp_argparser = arglist_parser_alloc (mlp, next_shapes); - arglist_parser_remember (tmp_argparser, 1, string, + 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_done (tmp_argparser, 1); } else - arglist_parser_remember (argparser, arg, string, - inner_context, pos.file_name, - pos.line_number, token.comment); - xgettext_current_source_encoding = xgettext_global_source_encoding; + { + 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; + } } } drop_reference (token.comment); diff --git a/gettext-tools/src/xg-arglist-parser.c b/gettext-tools/src/xg-arglist-parser.c index f15eee713..37647d7e4 100644 --- a/gettext-tools/src/xg-arglist-parser.c +++ b/gettext-tools/src/xg-arglist-parser.c @@ -124,14 +124,15 @@ arglist_parser_clone (struct arglist_parser *ap) ccp->argnum2_glib_context = cp->argnum2_glib_context; ccp->argtotal = cp->argtotal; ccp->xcomments = cp->xcomments; - ccp->msgctxt = (cp->msgctxt != NULL ? xstrdup (cp->msgctxt) : NULL); + ccp->msgctxt = + (cp->msgctxt != NULL ? mixed_string_clone (cp->msgctxt) : NULL); ccp->msgctxt_pos = cp->msgctxt_pos; - ccp->msgid = (cp->msgid != NULL ? xstrdup (cp->msgid) : NULL); + ccp->msgid = (cp->msgid != NULL ? mixed_string_clone (cp->msgid) : NULL); ccp->msgid_context = cp->msgid_context; ccp->msgid_pos = cp->msgctxt_pos; ccp->msgid_comment = add_reference (cp->msgid_comment); ccp->msgid_plural = - (cp->msgid_plural != NULL ? xstrdup (cp->msgid_plural) : NULL); + (cp->msgid_plural != NULL ? mixed_string_clone (cp->msgid_plural) : NULL); ccp->msgid_plural_context = cp->msgid_plural_context; ccp->msgid_plural_pos = cp->msgid_plural_pos; } @@ -142,7 +143,7 @@ arglist_parser_clone (struct arglist_parser *ap) void arglist_parser_remember (struct arglist_parser *ap, - int argnum, char *string, + int argnum, mixed_string_ty *string, flag_context_ty context, char *file_name, size_t line_number, refcounted_string_list_ty *comment) @@ -194,13 +195,13 @@ arglist_parser_remember (struct arglist_parser *ap, /* Note: There is a memory leak here: When string was stored but is later not used by arglist_parser_done, we don't free it. */ if (!stored_string) - free (string); + mixed_string_free (string); } void arglist_parser_remember_msgctxt (struct arglist_parser *ap, - char *string, + mixed_string_ty *string, flag_context_ty context, char *file_name, size_t line_number) { @@ -222,7 +223,7 @@ arglist_parser_remember_msgctxt (struct arglist_parser *ap, /* Note: There is a memory leak here: When string was stored but is later not used by arglist_parser_done, we don't free it. */ if (!stored_string) - free (string); + mixed_string_free (string); } @@ -389,17 +390,52 @@ arglist_parser_done (struct arglist_parser *ap, int argnum) { /* best_cp indicates the best found complete call. Now call remember_a_message. */ + flag_context_ty msgid_context; + flag_context_ty msgid_plural_context; + char *best_msgctxt; + char *best_msgid; + char *best_msgid_plural; message_ty *mp; + msgid_context = best_cp->msgid_context; + msgid_plural_context = best_cp->msgid_plural_context; + + /* Special support for the 3-argument tr operator in Qt: + When --qt and --keyword=tr:1,1,2c,3t are specified, add to the + context the information that the argument is expected to be a + qt-plural-format. */ + if (recognize_qt_formatstrings () + && best_cp->msgid_plural == best_cp->msgid) + { + msgid_context.is_format3 = yes_according_to_context; + msgid_plural_context.is_format3 = yes_according_to_context; + } + + best_msgctxt = + (best_cp->msgctxt != NULL + ? mixed_string_contents_free1 (best_cp->msgctxt) + : NULL); + best_msgid = + (best_cp->msgid != NULL + ? mixed_string_contents_free1 (best_cp->msgid) + : NULL); + best_msgid_plural = + (best_cp->msgid_plural != NULL + ? /* Special support for the 3-argument tr operator in Qt. */ + (best_cp->msgid_plural == best_cp->msgid + ? xstrdup (best_msgid) + : mixed_string_contents_free1 (best_cp->msgid_plural)) + : NULL); + /* Split strings in the GNOME glib syntax "msgctxt|msgid". */ if (best_cp->argnum1_glib_context || best_cp->argnum2_glib_context) /* split_keywordspec should not allow the context to be specified in two different ways. */ - if (best_cp->msgctxt != NULL) + if (best_msgctxt != NULL) abort (); if (best_cp->argnum1_glib_context) { - const char *separator = strchr (best_cp->msgid, '|'); + const char *separator = strchr (best_msgid, '|'); if (separator == NULL) { @@ -413,18 +449,18 @@ arglist_parser_done (struct arglist_parser *ap, int argnum) } else { - size_t ctxt_len = separator - best_cp->msgid; + size_t ctxt_len = separator - best_msgid; char *ctxt = XNMALLOC (ctxt_len + 1, char); - memcpy (ctxt, best_cp->msgid, ctxt_len); + memcpy (ctxt, best_msgid, ctxt_len); ctxt[ctxt_len] = '\0'; - best_cp->msgctxt = ctxt; - best_cp->msgid = xstrdup (separator + 1); + best_msgctxt = ctxt; + best_msgid = xstrdup (separator + 1); } } - if (best_cp->msgid_plural != NULL && best_cp->argnum2_glib_context) + if (best_msgid_plural != NULL && best_cp->argnum2_glib_context) { - const char *separator = strchr (best_cp->msgid_plural, '|'); + const char *separator = strchr (best_msgid_plural, '|'); if (separator == NULL) { @@ -438,16 +474,16 @@ arglist_parser_done (struct arglist_parser *ap, int argnum) } else { - size_t ctxt_len = separator - best_cp->msgid_plural; + size_t ctxt_len = separator - best_msgid_plural; char *ctxt = XNMALLOC (ctxt_len + 1, char); - memcpy (ctxt, best_cp->msgid_plural, ctxt_len); + memcpy (ctxt, best_msgid_plural, ctxt_len); ctxt[ctxt_len] = '\0'; - if (best_cp->msgctxt == NULL) - best_cp->msgctxt = ctxt; + if (best_msgctxt == NULL) + best_msgctxt = ctxt; else { - if (strcmp (ctxt, best_cp->msgctxt) != 0) + if (strcmp (ctxt, best_msgctxt) != 0) { error_with_progname = false; error_at_line (0, 0, @@ -458,35 +494,19 @@ arglist_parser_done (struct arglist_parser *ap, int argnum) } free (ctxt); } - best_cp->msgid_plural = xstrdup (separator + 1); + best_msgid_plural = xstrdup (separator + 1); } } - { - flag_context_ty msgid_context = best_cp->msgid_context; - flag_context_ty msgid_plural_context = best_cp->msgid_plural_context; - - /* Special support for the 3-argument tr operator in Qt: - When --qt and --keyword=tr:1,1,2c,3t are specified, add to the - context the information that the argument is expected to be a - qt-plural-format. */ - if (recognize_qt_formatstrings () - && best_cp->msgid_plural == best_cp->msgid) - { - msgid_context.is_format3 = yes_according_to_context; - msgid_plural_context.is_format3 = yes_according_to_context; - } - - mp = remember_a_message (ap->mlp, best_cp->msgctxt, best_cp->msgid, - false, msgid_context, - &best_cp->msgid_pos, - NULL, best_cp->msgid_comment, false); - if (mp != NULL && best_cp->msgid_plural != NULL) - remember_a_message_plural (mp, best_cp->msgid_plural, false, - msgid_plural_context, - &best_cp->msgid_plural_pos, - NULL, false); - } + mp = remember_a_message (ap->mlp, best_msgctxt, best_msgid, true, + msgid_context, + &best_cp->msgid_pos, + NULL, best_cp->msgid_comment, false); + if (mp != NULL && best_msgid_plural != NULL) + remember_a_message_plural (mp, best_msgid_plural, true, + msgid_plural_context, + &best_cp->msgid_plural_pos, + NULL, false); if (best_cp->xcomments.nitems > 0) { diff --git a/gettext-tools/src/xg-arglist-parser.h b/gettext-tools/src/xg-arglist-parser.h index bad14fcad..b6d31145c 100644 --- a/gettext-tools/src/xg-arglist-parser.h +++ b/gettext-tools/src/xg-arglist-parser.h @@ -25,6 +25,7 @@ #include "rc-str-list.h" #include "str-list.h" +#include "xg-mixed-string.h" #include "xg-arglist-context.h" #include "xg-arglist-callshape.h" @@ -44,13 +45,13 @@ struct partial_call bool argnum2_glib_context; /* argument argnum2 has the syntax "ctxt|msgid" */ int argtotal; /* total number of arguments, 0 if unspecified */ string_list_ty xcomments; /* auto-extracted comments */ - char *msgctxt; /* context - owned string, or NULL */ + mixed_string_ty *msgctxt; /* context - owned mixed_string, or NULL */ lex_pos_ty msgctxt_pos; - char *msgid; /* msgid - owned string, or NULL */ + mixed_string_ty *msgid; /* msgid - owned mixed_string, or NULL */ flag_context_ty msgid_context; lex_pos_ty msgid_pos; refcounted_string_list_ty *msgid_comment; - char *msgid_plural; /* msgid_plural - owned string, or NULL */ + mixed_string_ty *msgid_plural; /* msgid_plural - owned mixed_string, or NULL */ flag_context_ty msgid_plural_context; lex_pos_ty msgid_plural_pos; }; @@ -74,22 +75,22 @@ extern struct arglist_parser * arglist_parser_alloc (message_list_ty *mlp, /* Clones an arglist_parser. */ extern struct arglist_parser * arglist_parser_clone (struct arglist_parser *ap); /* Adds a string argument to an arglist_parser. ARGNUM must be > 0. - STRING must be malloc()ed string; its ownership is passed to the callee. + STRING must be a mixed_string; its ownership is passed to the callee. 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. */ extern void arglist_parser_remember (struct arglist_parser *ap, - int argnum, char *string, + int argnum, mixed_string_ty *string, flag_context_ty context, char *file_name, size_t line_number, refcounted_string_list_ty *comment); /* Adds a string argument as msgctxt to an arglist_parser, without incrementing the current argument number. - STRING must be malloc()ed string; its ownership is passed to the callee. + STRING must be a mixed_string; its ownership is passed to the callee. FILE_NAME must be allocated with indefinite extent. */ extern void arglist_parser_remember_msgctxt (struct arglist_parser *ap, - char *string, + mixed_string_ty *string, flag_context_ty context, char *file_name, size_t line_number); /* Tests whether an arglist_parser has is not waiting for more arguments after