Bruno Haible [Thu, 3 Jul 2025 16:56:11 +0000 (18:56 +0200)]
msgcat, msgen, xgettext: Tweak processing order.
* gettext-tools/src/msgcat.c (main): Sort the list of messages as the last
processing step before writing the PO file.
* gettext-tools/src/msgen.c (main): Likewise.
* gettext-tools/src/xgettext.c (main): Likewise.
Bruno Haible [Thu, 3 Jul 2025 14:56:01 +0000 (16:56 +0200)]
xgettext: Check msgid and msgid_plural for compatibility as format strings.
* gettext-tools/src/if-error.h: Include <stdarg.h>.
(if_verror): New declaration.
* gettext-tools/src/if-error.c (if_verror): New function, extracted from
if_error.
(if_error): Invoke it.
* gettext-tools/src/xg-check.h (xgettext_check_message_list): Renamed from
syntax_check_message_list.
* gettext-tools/src/xg-check.c: Include format.h, if-error.h.
(struct formatstring_error_logger_locals): New type.
(formatstring_error_logger, format_check_message): New functions.
(xgettext_check_message_list): Renamed from syntax_check_message_list. Invoke
also format_check_message.
* gettext-tools/src/xgettext.c (main): Invoke xgettext_check_message_list
instead of syntax_check_message_list.
* gettext-tools/tests/xgettext-19: New file.
* gettext-tools/tests/Makefile.am (TESTS): Add it.
* NEWS: Mention the change.
Bruno Haible [Thu, 3 Jul 2025 10:50:15 +0000 (12:50 +0200)]
xgettext: Fix bug with syntax-checks on messages from Perl source code.
* gettext-tools/src/x-perl.c (extract_perl): Don't free logical_file_name,
because it is referenced by the 'pos' field of the returned messages, and
xg-check.c accesses and prints it.
Bruno Haible [Thu, 3 Jul 2025 06:48:44 +0000 (08:48 +0200)]
msggrep: Add new options -W and -S.
Reported at <https://savannah.gnu.org/bugs/?40489>.
* gettext-tools/src/msggrep.c (workflow_flags, sticky_flags): New variables.
(main): Initialize them. Handle the options -W and -S.
(usage): Document the -W and -S options.
(is_message_selected_no_invert): Return true if one of the specified workflow
flags or one of the specified sticky flags is set.
* gettext-tools/tests/msggrep-12: New file.
* gettext-tools/tests/Makefile.am (TESTS): Add it.
* gettext-tools/doc/msggrep.texi: Document the -W and -S options.
* NEWS: Mention the change.
* gettext-tools/misc/autopoint.in: Instead of failing with "Missing version",
use version 0.23.1. Set omitintl=yes if there is no AM_GNU_GETTEXT invocation.
Bruno Haible [Mon, 30 Jun 2025 11:50:51 +0000 (13:50 +0200)]
Support reading PO files with '#=' lines.
* gettext-tools/src/read-catalog-abstract.c
(catalog_reader_seen_generic_comment): Treat '=' like ','.
* gettext-tools/src/read-catalog.c (default_comment_special): Allow several
calls to this method to make side effects on dcatr.
* gettext-tools/src/read-catalog-special.h: Update comment.
* gettext-tools/src/read-catalog-special.c: Likewise.
* gettext-tools/tests/msgcat-24: New file.
* gettext-tools/tests/Makefile.am (TESTS): Add it.
Bruno Haible [Sun, 29 Jun 2025 07:08:45 +0000 (09:08 +0200)]
examples: Extend the hello-sh example, part 2.
* gettext-tools/examples/hello-sh/hello-2.sh: New file, based on
gettext-tools/examples/hello-sh/hello-1.sh.
* gettext-tools/examples/hello-sh/hello-3.sh: New file, based on
gettext-tools/examples/hello-sh/hello-2.sh.
Bruno Haible [Fri, 27 Jun 2025 21:19:00 +0000 (23:19 +0200)]
Shell: Document two more approaches.
* gettext-tools/doc/lang-sh.texi (sh): Tweaks.
(sh - Three approaches): New subsubsection.
(The gettext.sh approach): New subsubsection, incorporating the "gettext.sh"
subsubsection.
(The printf approach, The printf_gettext approach): New subsubsections.
(Preparing for gettext.sh): Renamed from "Preparing Shell Scripts".
(Preparing for printf, Preparing for printf_gettext): New subsubsections.
* gettext-tools/doc/gettext.texi: Update detailed node list.
* NEWS: Mention the change.
* gettext-tools/src/x-sh.c (init_keywords, init_flag_table_sh): Add knowledge
about printf_gettext and printf_ngettext.
(read_command): Recognize '-c' option of printf_gettext and printf_ngettext.
* gettext-tools/tests/xgettext-sh-1: Add test cases with printf_gettext and
printf_ngettext.
* gettext-tools/doc/xgettext.texi: Document it.
Bruno Haible [Tue, 24 Jun 2025 10:28:21 +0000 (12:28 +0200)]
C++: Add another unit test.
* gettext-tools/tests/lang-c++-boost: New file, based on
gettext-tools/tests/lang-c++26.
* gettext-tools/tests/Makefile.am (TESTS): Add it.
* gettext-tools/doc/lang-c.texi: Mention how to use C++ with the Boost library.
* HACKING: Mention the Boost library.
Bruno Haible [Tue, 24 Jun 2025 05:23:56 +0000 (07:23 +0200)]
Shell: Add another unit test.
* gettext-tools/tests/lang-sh-1: Renamed from gettext-tools/tests/lang-sh.
* gettext-tools/tests/lang-sh-2: New file, based on
gettext-tools/tests/lang-sh-1.
* gettext-tools/tests/Makefile.am (TESTS): Remove lang-sh. Add lang-sh-1,
lang-sh-2.
* gettext-tools/src/format-python-brace.c (struct toplevel_counters): New type.
(parse_directive): Take a 'struct toplevel_counters *' parameter. Allow empty
argument names at the top-level. But reject format strings with both absolute
argument numbers and unnamed arguments at the top-level.
(parse_upto): Take a 'struct toplevel_counters *' parameter.
(format_parse): Pass a 'struct toplevel_counters *' to parse_upto.
* gettext-tools/tests/format-python-brace-1: Update.
* gettext-tools/tests/format-python-brace-2: Add another test case.
* gettext-tools/doc/lang-python.texi: Add more examples of formatting with
positions.
Bruno Haible [Mon, 23 Jun 2025 19:19:56 +0000 (21:19 +0200)]
Add support for Shell printf format strings, part 2.
* gettext-tools/po/POTFILES.in: Add src/format-sh-printf.c.
* gettext-tools/tests/format-sh-printf-1: Use 'printf' instead of 'echo',
because 'echo' processes escape sequences on macOS, OpenBSD, Solaris.
Bruno Haible [Sun, 22 Jun 2025 08:56:33 +0000 (10:56 +0200)]
Add support for Shell printf format strings.
* gettext-tools/src/message.h (enum format_type): Add format_sh_printf.
(NFORMATS): Increment.
* gettext-tools/src/message.c (format_language, format_language_pretty): Add an
entry for format_sh_printf.
* gettext-tools/src/format.h (formatstring_sh_printf): New declaration.
* gettext-tools/src/format.c (formatstring_parsers): Add an entry for
format_sh_printf.
* gettext-tools/src/format-sh-printf.c: New file, based on
gettext-tools/src/format-awk.c.
* gettext-tools/src/FILES: Mention it.
* gettext-tools/src/x-sh.h (SCANNERS_SH): Use formatstring_sh_printf as
secondary format string type.
* gettext-tools/src/xgettext.c (xgettext_record_flag): Update accordingly.
* gettext-tools/src/x-sh.c (init_flag_table_sh): Register gettext, ngettext with
flag 'pass-sh-printf-format'. Register 'printf' with flag 'sh-printf-format'.
* gettext-tools/src/Makefile.am (FORMAT_SOURCE): Add format-sh-printf.c.
* gettext-tools/libgettextpo/Makefile.am (libgettextpo_la_AUXSOURCES): Likewise.
* gettext-tools/doc/gettext.texi (PO Files): Mention sh-printf-format.
(sh-format): Document also the sh-printf-format strings.
* gettext-tools/doc/lang-sh.texi (sh): Mention the coreutils 'printf' command.
* gettext-tools/tests/xgettext-sh-1: Add a test case with a printf invocation.
* gettext-tools/tests/format-sh-printf-1: New file, based on
gettext-tools/tests/format-awk-1.
* gettext-tools/tests/format-sh-printf-2: New file, based on
gettext-tools/tests/format-awk-2.
* gettext-tools/tests/Makefile.am (TESTS): Add them.
* NEWS: Mention the change.
Bruno Haible [Sun, 22 Jun 2025 00:11:33 +0000 (02:11 +0200)]
pascal-format: Accept null precision.
Proof that it's valid:
------------------------- foo.pp -------------------------
program foo;
uses sysutils;
begin
writeln(format('%.f', [3.1415926535]));
end.
----------------------------------------------------------
* gettext-tools/src/format-pascal.c: Fix comment regarding the precision.
(format_parse): Accept a null precision after '.'.
* gettext-tools/tests/format-pascal-1: Add a test case with null precision.
Bruno Haible [Sat, 21 Jun 2025 23:37:58 +0000 (01:37 +0200)]
lua-format: Accept null precision. Limit width and precision to two digits.
Proof that it's valid:
$ lua
print(string.format("%.f", 3.1415926535))
* gettext-tools/src/format-lua.c: Fix comment regarding the width and the
precision.
(format_parse): Recognize at most two digits for the width. Recognize at most
two digits for the precision.
* gettext-tools/tests/format-lua-1: Add test cases with large width, null
precision, and large precision.
Bruno Haible [Sat, 21 Jun 2025 23:20:32 +0000 (01:20 +0200)]
javascript-format: Reject null precision.
Proof that it's invalid:
------------------------------- foo.js -------------------------------
const Format = imports.format;
String.prototype.format = Format.format;
print("%.f".format(3.1415916535));
----------------------------------------------------------------------
$ gjs foo.js
* gettext-tools/src/format-invalid.h (INVALID_PRECISION_MISSING): New macro.
* gettext-tools/src/format-java-printf.c (INVALID_PRECISION_MISSING): Remove
macro.
* gettext-tools/src/format-javascript.c: Fix comment regarding the precision.
(format_parse): Report an error if the precision is null (empty).
* gettext-tools/tests/format-javascript-1: Add a test case with null precision.
Bruno Haible [Sat, 21 Jun 2025 23:08:15 +0000 (01:08 +0200)]
go-format: Accept null precision.
* gettext-tools/src/format-go.c: Clarify comment regarding the precision.
(format_parse): Accept a null precision after '.'.
* gettext-tools/tests/format-go-1: Add a test case with null precision.
Bruno Haible [Sat, 21 Jun 2025 21:49:24 +0000 (23:49 +0200)]
c-format: Accept null precision.
* gettext-tools/src/format-c-parse.h: Fix comment regarding the precision and
the ISO C23 size specifiers.
* gettext-tools/tests/format-c-1: Add a test case with null precision.
Bruno Haible [Sat, 21 Jun 2025 00:53:23 +0000 (02:53 +0200)]
xgettext: Shell: Recognize \u and \U escape sequences in $'...' strings.
* gettext-tools/src/xg-mixed-string.h (mixed_string_remove_prefix,
mixed_string_buffer_equals, mixed_string_buffer_startswith,
mixed_string_buffer_cloned_result): New declarations.
* gettext-tools/src/xg-mixed-string.c (mixed_string_remove_prefix): New
function.
(mixed_string_buffer_is_empty): Also test the absence of utf16_surr.
(mixed_string_buffer_equals, mixed_string_buffer_startswith,
mixed_string_buffer_cloned_result): New functions.
* gettext-tools/src/x-sh.c (struct token): Remove type.
(init_token, free_token, grow_token, string_of_token): Remove functions.
(struct word): Change type of 'token' field.
(free_word): Update.
(string_of_word, substring_of_word): Remove functions.
(read_word): Call mixed_string_buffer_init instead of init_token,
mixed_string_buffer_destroy instead of free_token,
mixed_string_buffer_append_char instead of grow_token. Update accesses to
wp->token. Recognize \u and \U escape sequences in $'...' strings.
(read_command): Call mixed_string_buffer_cloned_result instead of
string_of_word. Update accesses to inner.token.
* gettext-tools/tests/xgettext-sh-7: Use --from-code option.
* gettext-tools/tests/xgettext-sh-9: New file.
* gettext-tools/tests/Makefile.am (TESTS): Add it.
* NEWS: Mention this and the previous change.
Bruno Haible [Thu, 19 Jun 2025 11:36:10 +0000 (13:36 +0200)]
Deprecate the gfc-internal-format flag.
* gettext-tools/src/format-gfc-internal.c: Update comment.
* gettext-tools/doc/gettext.texi (PO Files): Mark gfc-internal-format as
deprecated.
(gfc-internal-format): Mention "up to GCC 14".
Bruno Haible [Thu, 19 Jun 2025 11:35:46 +0000 (13:35 +0200)]
Update gcc-internal-format for GCC 15.
Reported by Roland Illig, Andrew Pinski, Jakub Jelinek in
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119684>.
Also reported by Roland Illig in
<https://savannah.gnu.org/bugs/?50450>, <https://savannah.gnu.org/bugs/?50461>.