From 3523d1d2753e1a5af64fffe777123c200fae40b1 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 17 Sep 2023 11:54:45 +0200 Subject: [PATCH] xgettext: Avoid a warning 'Charset "CHARSET" is not a portable encoding name'. * gettext-tools/src/po-charset.h (po_lex_charset_set): Add is_pot_role parameter. * gettext-tools/src/po-charset.c (po_lex_charset_set): Likewise. * gettext-tools/src/po-lex.h (gram_pot_role): New declaration. (lex_start): Add is_pot_role parameter. * gettext-tools/src/po-lex.c (gram_pot_role): New variable. (lex_start): Add is_pot_role parameter. (lex_end): Update. * gettext-tools/src/po-gram-gen.y (do_callback_message): Pass gram_pot_role to po_lex_charset_set. * gettext-tools/src/read-catalog-abstract.h (struct catalog_input_format): Add is_pot_role parameter to the 'parse' member. (catalog_reader_parse): Add is_pot_role parameter. * gettext-tools/src/read-po.c (po_parse): Add is_pot_role parameter. * gettext-tools/src/read-properties.c (properties_parse): Likewise. * gettext-tools/src/read-stringtable.c (stringtable_parse): Likewise. * gettext-tools/src/read-catalog-abstract.c (catalog_reader_parse): Add is_pot_role parameter. * gettext-tools/src/x-po.c (extract): Pass is_pot_role as true. * gettext-tools/src/xgettext.c (read_exclusion_file): Likewise. * gettext-tools/src/read-catalog.c (read_catalog_stream): Pass is_pot_role as false. * gettext-tools/src/msgfmt.c (read_catalog_file_msgfmt): Likewise. --- gettext-tools/src/msgfmt.c | 2 +- gettext-tools/src/po-charset.c | 12 +++++++----- gettext-tools/src/po-charset.h | 8 +++++--- gettext-tools/src/po-gram-gen.y | 5 ++--- gettext-tools/src/po-lex.c | 10 ++++++++-- gettext-tools/src/po-lex.h | 5 ++++- gettext-tools/src/read-catalog-abstract.c | 3 ++- gettext-tools/src/read-catalog-abstract.h | 7 ++++--- gettext-tools/src/read-catalog.c | 2 +- gettext-tools/src/read-po.c | 7 ++++--- gettext-tools/src/read-properties.c | 3 ++- gettext-tools/src/read-stringtable.c | 3 ++- gettext-tools/src/x-po.c | 2 +- gettext-tools/src/xgettext.c | 2 +- 14 files changed, 44 insertions(+), 27 deletions(-) diff --git a/gettext-tools/src/msgfmt.c b/gettext-tools/src/msgfmt.c index 2ea831cc3..e14c96209 100644 --- a/gettext-tools/src/msgfmt.c +++ b/gettext-tools/src/msgfmt.c @@ -1401,7 +1401,7 @@ read_catalog_file_msgfmt (char *filename, catalog_input_format_ty input_syntax) } po_lex_pass_obsolete_entries (true); catalog_reader_parse ((abstract_catalog_reader_ty *) pop, fp, real_filename, - filename, input_syntax); + filename, false, input_syntax); catalog_reader_free ((abstract_catalog_reader_ty *) pop); if (fp != stdin) diff --git a/gettext-tools/src/po-charset.c b/gettext-tools/src/po-charset.c index db95cf040..c4faeffd2 100644 --- a/gettext-tools/src/po-charset.c +++ b/gettext-tools/src/po-charset.c @@ -1,5 +1,5 @@ /* Charset handling while reading PO files. - Copyright (C) 2001-2007, 2010, 2019-2021 Free Software Foundation, Inc. + Copyright (C) 2001-2007, 2010, 2019-2021, 2023 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify @@ -464,7 +464,8 @@ po_lex_charset_init () } void -po_lex_charset_set (const char *header_entry, const char *filename) +po_lex_charset_set (const char *header_entry, + const char *filename, bool is_pot_role) { /* Verify the validity of CHARSET. It is necessary 1. for the correct treatment of multibyte characters containing @@ -492,9 +493,10 @@ po_lex_charset_set (const char *header_entry, const char *filename) only ASCII msgids. */ size_t filenamelen = strlen (filename); - if (!(filenamelen >= 4 - && memcmp (filename + filenamelen - 4, ".pot", 4) == 0 - && strcmp (charset, "CHARSET") == 0)) + if (!(strcmp (charset, "CHARSET") == 0 + && ((filenamelen >= 4 + && memcmp (filename + filenamelen - 4, ".pot", 4) == 0) + || is_pot_role))) { char *warning_message = xasprintf (_("\ diff --git a/gettext-tools/src/po-charset.h b/gettext-tools/src/po-charset.h index 0ab49bd6d..ed0db85a8 100644 --- a/gettext-tools/src/po-charset.h +++ b/gettext-tools/src/po-charset.h @@ -1,5 +1,5 @@ /* Charset handling while reading PO files. - Copyright (C) 2001-2003, 2006, 2021 Free Software Foundation, Inc. + Copyright (C) 2001-2003, 2006, 2021, 2023 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify @@ -85,9 +85,11 @@ extern DLL_VARIABLE bool po_lex_weird_cjk; /* Initialize the PO file's encoding. */ extern void po_lex_charset_init (void); -/* Set the PO file's encoding from the header entry. */ +/* Set the PO file's encoding from the header entry. + If is_pot_role is true, "charset=CHARSET" is expected and does not deserve + a warning. */ extern void po_lex_charset_set (const char *header_entry, - const char *filename); + const char *filename, bool is_pot_role); /* Finish up with the PO file's encoding. */ extern void po_lex_charset_close (void); diff --git a/gettext-tools/src/po-gram-gen.y b/gettext-tools/src/po-gram-gen.y index 5f6b2e409..43c842d11 100644 --- a/gettext-tools/src/po-gram-gen.y +++ b/gettext-tools/src/po-gram-gen.y @@ -1,6 +1,5 @@ /* GNU gettext - internationalization aids - Copyright (C) 1995-1996, 1998, 2000-2001, 2003, 2005-2006, 2012-2013, 2016, 2020 - Free Software Foundation, Inc. + Copyright (C) 1995-1996, 1998, 2000-2001, 2003, 2005-2006, 2012-2013, 2016, 2020, 2023 Free Software Foundation, Inc. This file was written by Peter Miller @@ -56,7 +55,7 @@ do_callback_message (char *msgctxt, { /* Test for header entry. Ignore fuzziness of the header entry. */ if (msgctxt == NULL && msgid[0] == '\0' && !obsolete) - po_lex_charset_set (msgstr, gram_pos.file_name); + po_lex_charset_set (msgstr, gram_pos.file_name, gram_pot_role); po_callback_message (msgctxt, msgid, msgid_pos, msgid_plural, diff --git a/gettext-tools/src/po-lex.c b/gettext-tools/src/po-lex.c index 934829eae..22d088492 100644 --- a/gettext-tools/src/po-lex.c +++ b/gettext-tools/src/po-lex.c @@ -1,5 +1,5 @@ /* GNU gettext - internationalization aids - Copyright (C) 1995-2009, 2011, 2019 Free Software Foundation, Inc. + Copyright (C) 1995-2009, 2011, 2019, 2023 Free Software Foundation, Inc. This file was written by Peter Miller . Multibyte character handling by Bruno Haible . @@ -67,6 +67,9 @@ lex_pos_ty gram_pos; int gram_pos_column; +/* Whether the PO file is in the role of a POT file. */ +bool gram_pot_role; + /* Error handling during the parsing of a PO file. These functions can access gram_pos and gram_pos_column. */ @@ -604,7 +607,8 @@ bool pass_obsolete_entries = false; /* Prepare lexical analysis. */ void -lex_start (FILE *fp, const char *real_filename, const char *logical_filename) +lex_start (FILE *fp, const char *real_filename, const char *logical_filename, + bool is_pot_role) { /* Ignore the logical_filename, because PO file entries already have their file names attached. But use real_filename for error messages. */ @@ -614,6 +618,7 @@ lex_start (FILE *fp, const char *real_filename, const char *logical_filename) gram_pos.line_number = 1; gram_pos_column = 0; + gram_pot_role = is_pot_role; signal_eilseq = true; po_lex_obsolete = false; po_lex_previous = false; @@ -628,6 +633,7 @@ lex_end () gram_pos.file_name = NULL; gram_pos.line_number = 0; gram_pos_column = 0; + gram_pot_role = false; signal_eilseq = false; po_lex_obsolete = false; po_lex_previous = false; diff --git a/gettext-tools/src/po-lex.h b/gettext-tools/src/po-lex.h index 99af2566e..2f6df0d6a 100644 --- a/gettext-tools/src/po-lex.h +++ b/gettext-tools/src/po-lex.h @@ -55,6 +55,9 @@ extern "C" { extern DLL_VARIABLE lex_pos_ty gram_pos; extern DLL_VARIABLE int gram_pos_column; +/* Whether the PO file is in the role of a POT file. */ +extern DLL_VARIABLE bool gram_pot_role; + /* Number of parse errors within a PO file that cause the program to terminate. Cf. error_message_count, declared in . */ extern DLL_VARIABLE unsigned int gram_max_allowed_errors; @@ -65,7 +68,7 @@ extern DLL_VARIABLE bool pass_obsolete_entries; /* Prepare lexical analysis. */ extern void lex_start (FILE *fp, const char *real_filename, - const char *logical_filename); + const char *logical_filename, bool is_pot_role); /* Terminate lexical analysis. */ extern void lex_end (void); diff --git a/gettext-tools/src/read-catalog-abstract.c b/gettext-tools/src/read-catalog-abstract.c index 17ed4602e..c1956b29f 100644 --- a/gettext-tools/src/read-catalog-abstract.c +++ b/gettext-tools/src/read-catalog-abstract.c @@ -171,13 +171,14 @@ parse_end (abstract_catalog_reader_ty *pop) void catalog_reader_parse (abstract_catalog_reader_ty *pop, FILE *fp, const char *real_filename, const char *logical_filename, + bool is_pot_role, catalog_input_format_ty input_syntax) { error_message_count = 0; /* Parse the stream's content. */ parse_start (pop); - input_syntax->parse (pop, fp, real_filename, logical_filename); + input_syntax->parse (pop, fp, real_filename, logical_filename, is_pot_role); parse_end (pop); if (error_message_count > 0) diff --git a/gettext-tools/src/read-catalog-abstract.h b/gettext-tools/src/read-catalog-abstract.h index 01df62709..91d487c7c 100644 --- a/gettext-tools/src/read-catalog-abstract.h +++ b/gettext-tools/src/read-catalog-abstract.h @@ -1,6 +1,5 @@ /* Reading PO files, abstract class. - Copyright (C) 1995-1996, 1998, 2000-2003, 2005-2006, 2008-2009, 2012, - 2015 Free Software Foundation, Inc. + Copyright (C) 1995-1996, 1998, 2000-2003, 2005-2006, 2008-2009, 2012, 2015, 2023 Free Software Foundation, Inc. This file was written by Peter Miller @@ -134,7 +133,8 @@ struct catalog_input_format { /* Parses the contents of FP, invoking the appropriate callbacks. */ void (*parse) (abstract_catalog_reader_ty *pop, FILE *fp, - const char *real_filename, const char *logical_filename); + const char *real_filename, const char *logical_filename, + bool is_pot_role); /* Whether the parse function always produces messages encoded in UTF-8 encoding. */ @@ -155,6 +155,7 @@ extern void catalog_reader_parse (abstract_catalog_reader_ty *pop, FILE *fp, const char *real_filename, const char *logical_filename, + bool is_pot_role, catalog_input_format_ty input_syntax); /* Call the destructor and deallocate a abstract_catalog_reader_ty (or derived diff --git a/gettext-tools/src/read-catalog.c b/gettext-tools/src/read-catalog.c index c593ca98e..2dd3bd66a 100644 --- a/gettext-tools/src/read-catalog.c +++ b/gettext-tools/src/read-catalog.c @@ -479,7 +479,7 @@ read_catalog_stream (FILE *fp, const char *real_filename, pop->mdlp->encoding = po_charset_utf8; po_lex_pass_obsolete_entries (true); catalog_reader_parse ((abstract_catalog_reader_ty *) pop, fp, real_filename, - logical_filename, input_syntax); + logical_filename, false, input_syntax); mdlp = pop->mdlp; catalog_reader_free ((abstract_catalog_reader_ty *) pop); return mdlp; diff --git a/gettext-tools/src/read-po.c b/gettext-tools/src/read-po.c index 1bc42ca4a..3c54f283f 100644 --- a/gettext-tools/src/read-po.c +++ b/gettext-tools/src/read-po.c @@ -1,5 +1,5 @@ /* Reading PO files. - Copyright (C) 1995-1996, 1998, 2000-2006 Free Software Foundation, Inc. + Copyright (C) 1995-1996, 1998, 2000-2006, 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 @@ -34,9 +34,10 @@ abstract_catalog_reader_class_ty methods. */ static void po_parse (abstract_catalog_reader_ty *this, FILE *fp, - const char *real_filename, const char *logical_filename) + const char *real_filename, const char *logical_filename, + bool is_pot_role) { - lex_start (fp, real_filename, logical_filename); + lex_start (fp, real_filename, logical_filename, is_pot_role); po_gram_parse (); lex_end (); } diff --git a/gettext-tools/src/read-properties.c b/gettext-tools/src/read-properties.c index c5ef74cad..20518939a 100644 --- a/gettext-tools/src/read-properties.c +++ b/gettext-tools/src/read-properties.c @@ -597,7 +597,8 @@ read_escaped_string (bool in_key) abstract_catalog_reader_class_ty methods. */ static void properties_parse (abstract_catalog_reader_ty *this, FILE *file, - const char *real_filename, const char *logical_filename) + const char *real_filename, const char *logical_filename, + bool is_pot_role) { /* Read the file into memory. */ contents = fread_file (file, 0, &contents_length); diff --git a/gettext-tools/src/read-stringtable.c b/gettext-tools/src/read-stringtable.c index 5a87c0de6..0b8b3f752 100644 --- a/gettext-tools/src/read-stringtable.c +++ b/gettext-tools/src/read-stringtable.c @@ -828,7 +828,8 @@ read_string (lex_pos_ty *pos) abstract_catalog_reader_class_ty methods. */ static void stringtable_parse (abstract_catalog_reader_ty *pop, FILE *file, - const char *real_filename, const char *logical_filename) + const char *real_filename, const char *logical_filename, + bool is_pot_role) { fp = file; real_file_name = real_filename; diff --git a/gettext-tools/src/x-po.c b/gettext-tools/src/x-po.c index fd6b517a0..740aa3d89 100644 --- a/gettext-tools/src/x-po.c +++ b/gettext-tools/src/x-po.c @@ -165,7 +165,7 @@ extract (FILE *fp, pop->mdlp = NULL; pop->mlp = mdlp->item[0]->messages; catalog_reader_parse ((abstract_catalog_reader_ty *) pop, fp, real_filename, - logical_filename, input_syntax); + logical_filename, true, input_syntax); catalog_reader_free ((abstract_catalog_reader_ty *) pop); if (header_charset != NULL) diff --git a/gettext-tools/src/xgettext.c b/gettext-tools/src/xgettext.c index 9fc61ab3e..d44721e50 100644 --- a/gettext-tools/src/xgettext.c +++ b/gettext-tools/src/xgettext.c @@ -1341,7 +1341,7 @@ read_exclusion_file (char *filename) abstract_catalog_reader_ty *pop; pop = catalog_reader_alloc (&exclude_methods); - catalog_reader_parse (pop, fp, real_filename, filename, &input_format_po); + catalog_reader_parse (pop, fp, real_filename, filename, true, &input_format_po); catalog_reader_free (pop); if (fp != stdin) -- 2.47.3