Bruno Haible [Wed, 13 Aug 2025 20:19:19 +0000 (22:19 +0200)]
its: Improve libxml error handling.
When there is a non-fatal error, the previous code would just print a message
to stderr and continue the operation, without affecting the exit code.
* gettext-tools/src/its.c: Include <setjmp.h>, <stdarg.h>.
(xml_error_exit): New variable.
(structured_error): Longjmp to xml_error_exit.
(generic_error): New function.
(its_rule_list_add_from_file, its_rule_list_add_from_string,
its_rule_list_extract, its_merge_context_merge, its_merge_context_alloc,
its_merge_context_write): Invoke also xmlSetGenericErrorFunc. Use setjmp to
abort the operation when a non-fatal error occurs.
Bruno Haible [Sun, 3 Aug 2025 18:02:26 +0000 (20:02 +0200)]
libcroco: Fix double-free and free-after-use bug.
Reported by Coverity.
* libtextstyle/gnulib-local/lib/libcroco/cr-sel-eng.c
(cr_sel_eng_unregister_pseudo_class_sel_handler): Don't access or free 'elem'
after it has been freed. Remove always-NULL variable.
Bruno Haible [Fri, 1 Aug 2025 13:17:31 +0000 (15:17 +0200)]
gettext.m4: Fix build on Cygwin with gcc 13 or newer.
This gcc version links with -lintl -liconv by default, making it appear as if
gettext() et al. were defined in libc. But GNU gettext still needs to build a
new libintl.
* gettext-runtime/m4/gettext.m4 (AM_GNU_GETTEXT): On Cygwin, set
USE_INCLUDED_LIBINTL=yes regardless of the gcc version.
Bruno Haible [Sun, 27 Jul 2025 22:07:10 +0000 (00:07 +0200)]
OCaml support: Add OCaml support in the tools.
This implements several improvements, compared to
"ocaml-gettext --action extract ...":
- Comments are extracted.
- '#, ocaml-format' annotation on f_ arguments.
- Recognizes concatenated strings, such as ("abc" ^ "def").
- Supports (s_ "").
* autopull.sh: Check out tree-sitter-ocaml. Set TREE_SITTER_OCAML_VERSION.
* gettext-tools/build-aux/tree-sitter-ocaml-portability.diff: New file.
* gettext-tools/configure.ac: Set TREE_SITTER_OCAML_VERSION.
* gettext-tools/Makefile.am (EXTRA_DIST): Add the tree-sitter-ocaml source code
and patch.
* gettext-tools/doc/gettext.texi (PO Files): Mention ocaml-format.
(Translators for other Languages): New subsection "OCaml Format Strings".
* gettext-tools/doc/lang-ocaml.texi: Mention all the supported *gettext
functions. Mention format strings with positions.
* gettext-tools/doc/xgettext.texi: Document the OCaml support in more places.
* gettext-tools/src/message.h (format_ocaml): New enum value.
(NFORMATS): Increment.
* gettext-tools/src/message.c (format_language, format_language_pretty): Add an
entry for format_ocaml.
* gettext-tools/src/format-ocaml.c: New file, based on
gettext-tools/src/format-awk.c.
* gettext-tools/src/format.h (formatstring_ocaml): New declaration.
* gettext-tools/src/format.c (formatstring_parsers): Add formatstring_ocaml.
* gettext-tools/src/x-ocaml.h (SCANNERS_OCAML): Reference flag_table_ocaml and
formatstring_ocaml.
(extract_ocaml): Declare with first argument of type 'FILE *'.
* gettext-tools/src/x-ocaml.c: Completely rewritten.
* gettext-tools/src/xgettext.c (flag_table_ocaml): New variable.
(usage): Document the OCaml support in more places.
(xgettext_record_flag): Support format_ocaml.
* gettext-tools/src/FILES: Mention format-ocaml.c.
* gettext-tools/src/Makefile.am (FORMAT_SOURCE): Add format-ocaml.c.
(LIBXGETTEXTTS): Add libxgettextts5.a.
(libxgettextts5_a_*): New variables.
* gettext-tools/libgettextpo/Makefile.am (libgettextpo_la_AUXSOURCES): Add
format-ocaml.c.
* gettext-tools/po/POTFILES.in: Add src/format-ocaml.c.
* gettext-tools/tests/format-ocaml-1: New file.
* gettext-tools/tests/format-ocaml-2: New file.
* gettext-tools/tests/xgettext-ocaml-1: New file.
* gettext-tools/tests/xgettext-ocaml-2: New file.
* gettext-tools/tests/Makefile.am (TESTS): Add the new tests.
* NEWS: Mention the OCaml support.
Bruno Haible [Sun, 20 Jul 2025 15:56:37 +0000 (17:56 +0200)]
examples: Make 'check-example' more maintainable.
Some examples require specific sets of environment variables.
E.g. hello-go requires a PATH which uses GCC 13 or 14, not GCC 15,
due to <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119098>.
* gettext-tools/examples/check-examples: Rewrite to use one top-level function
per sample, instead of one top-level function for each check.
Bruno Haible [Sat, 19 Jul 2025 16:10:30 +0000 (18:10 +0200)]
examples: Use infrastructure from gettext version 0.26.
* gettext-tools/examples/hello-*/configure.ac: Use AM_GNU_GETTEXT_VERSION with
version 0.26.
* gettext-tools/examples/hello-c++-kde/configure.in.in: Likewise.
Bruno Haible [Fri, 18 Jul 2025 19:38:32 +0000 (21:38 +0200)]
msginit: Fix encoding of second title line, part 2.
Reported by Matilin Torre <watilin@protonmail.com> in
<https://lists.gnu.org/archive/html/bug-gettext/2025-07/msg00024.html>.
To reproduce the problem:
$ LC_ALL=de_DE.ISO-8859-1 msginit -l fr_FR.ISO-8859-1 -i some_utf-8.pot -o fr.po
* gettext-tools/src/msginit.c (output_charset): New variable.
(content_type): Use output_charset.
(get_title): Use output_charset instead of ignoring was_utf8.
(fill_header): Initialize output_charset. Moved logic from content_type()
to here.
Bruno Haible [Fri, 18 Jul 2025 19:34:55 +0000 (21:34 +0200)]
msginit: Fix encoding of second title line, part 1.
Reported by Matilin Torre <watilin@protonmail.com> in
<https://lists.gnu.org/archive/html/bug-gettext/2025-07/msg00024.html>.
* gettext-tools/src/msginit.c: Include xstriconv.h.
(get_title): Don't set OUTPUT_CHARSET; this does not work any more since 2005,
when an optimization was made in dcigettext.c. Instead, use xstr_iconv().
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.