Bruno Haible [Mon, 8 Jan 2024 05:51:40 +0000 (06:51 +0100)]
intl: Fix the Windows MUI code, so that it works on Windows 10.
Reported by <lrn1986@gmail.com> at <https://savannah.gnu.org/bugs/?65128>.
* gettext-runtime/intl/langprefs.c (_nl_language_preferences_win32_mui): Make
GetUserPreferredUILanguages prototype with Microsoft's current documentation.
Allow the first GetUserPreferredUILanguages call to succeed.
Bruno Haible [Tue, 5 Dec 2023 15:07:38 +0000 (16:07 +0100)]
xgettext: Java: Flag strings on which the method 'formatted' is used as java-printf-format.
* gettext-tools/src/x-java.c (token_type_semicolon): New enum item.
(phase5_get): Recognize semicolon tokens.
(extract_parenthesized): Handle method invocation .formatted. Return when a
semicolon was seen.
* gettext-tools/tests/xgettext-java-8: New file, based on
gettext-tools/tests/xgettext-vala-6.
* gettext-tools/tests/xgettext-java-9: New file, based on
gettext-tools/tests/xgettext-vala-7.
* gettext-tools/tests/Makefile.am (TESTS): Add them.
* NEWS: Mention the change.
Bruno Haible [Tue, 5 Dec 2023 13:15:42 +0000 (14:15 +0100)]
xgettext: Python: Add support for f-strings.
Reported by Ben <gnu@mail.qoben.com>
at <https://savannah.gnu.org/bugs/?61596>.
* gettext-tools/src/x-python.c (P7_498_START_OF_EXPRESSION): New macro.
(token_type_498, token_type_l498, token_type_m498, token_type_r498): New enum
items.
(free_token): Treat token_type_498 like token_type_string.
(phase7_getuc): Accept an f_string parameter. Use it to combine {{ to { and
}} to }.
(f_string_depth): New variable.
(struct f_string_level): New type.
(f_string_stack, f_string_stack_alloc): New variables.
(new_f_string_level): New function.
(open_pb): Renamed from open_pbb.
(phase5_get): Consider also the f_string_stack. Accept f"...", fr"...", rf"..."
syntax. Recognize tokens of type token_type_498, token_type_l498,
token_type_m498, token_type_r498.
(x_python_lex): Treat token_type_498 like token_type_string.
(extract_balanced): Handle the new token types.
(extract_python): Initialize f_string_depth and the f_string_stack.
* gettext-tools/tests/xgettext-python-1: Test also the backslash handling in
f-strings.
* gettext-tools/tests/xgettext-python-8: New file.
* gettext-tools/tests/Makefile.am (TESTS): Add it.
* gettext-tools/doc/lang-python.texi (Python): Explain the limitations of
f-string support.
* NEWS: Mention the change.
Bruno Haible [Thu, 30 Nov 2023 16:16:36 +0000 (17:16 +0100)]
xgettext: Vala: Flag strings on which the method 'printf' is used as c-format.
* gettext-tools/src/x-vala.c (token_type_semicolon): New enum item.
(phase3_get): Recognize semicolon tokens.
(phase4_pushback, phase4_pushback_length): New variables.
(phase4_get): Renamed from x_vala_lex. Handle pushback.
(phase4_unget, x_vala_lex, x_vala_unlex): New functions.
(extract_balanced): Handle method invocations .printf and .vprintf. Return when
a semicolon was seen.
(extract_vala): Initialize phase4_pushback_length.
* gettext-tools/tests/xgettext-vala-6: Add tests for printf used as method.
* gettext-tools/tests/xgettext-vala-7: New file.
* gettext-tools/tests/Makefile.am (TESTS): Add it.
* NEWS: Mention the change.
Bruno Haible [Thu, 30 Nov 2023 15:55:42 +0000 (16:55 +0100)]
xgettext: Vala: Don't flag printf arguments as c-format.
Reported by Anders Jonsson <anders.jonsson@norsjovallen.se>
at <https://savannah.gnu.org/bugs/?64921>.
* gettext-tools/src/xgettext.c (xgettext_record_flag: Recognize also
"undecided-...-format".
* gettext-tools/src/x-vala.c (init_flag_table_vala): Flag the printf function as
'undecided-c-format', not 'c-format'.
* gettext-tools/tests/xgettext-vala-5: Use vprintf instead of printf.
* gettext-tools/tests/xgettext-vala-6: New file.
* gettext-tools/tests/Makefile.am (TESTS): Add it.
Bruno Haible [Thu, 30 Nov 2023 07:43:16 +0000 (08:43 +0100)]
xgettext: Refactor the formatstring code.
* gettext-tools/src/xg-formatstring.h (NXFORMATS, XFORMAT_PRIMARY,
XFORMAT_SECONDARY, XFORMAT_TERTIARY, XFORMAT_FOURTH): New macros.
(current_formatstring_parser1, current_formatstring_parser2,
current_formatstring_parser3, current_formatstring_parser4): Remove
declarations.
(current_formatstring_parser): New declaration.
* gettext-tools/src/xg-formatstring.c (current_formatstring_parser1,
current_formatstring_parser2, current_formatstring_parser3,
current_formatstring_parser4): Remove variables.
(current_formatstring_parser): New variable.
* gettext-tools/src/xg-arglist-context.h: Include xg-formatstring.h.
(struct formatstring_context_ty): New type.
(struct flag_context_ty): Replace individual fields with an array.
(flag_context_list_table_add): Rename parameter 'index' to 'fi'.
* gettext-tools/src/xg-arglist-context.c (null_context, passthrough_context):
Update.
(inherited_context): Loop over the four formatstring types.
(passthrough_context_circular_list): Update.
(set_flags_for_formatstring_type): Simplify.
(flag_context_list_table_add): Rename parameter 'index' to 'fi'.
* gettext-tools/src/xg-arglist-parser.c (arglist_parser_done): Update.
* gettext-tools/src/xg-message.c (set_format_flags_from_context): Loop over the
four formatstring types.
(is_relevant): New function.
(decide_is_format, remember_a_message_plural): Use it.
* gettext-tools/src/xgettext.c (struct extractor_ty): Replace individual fields
with an array.
(main): Update.
(flag_context_list_table_insert): Rename parameter 'index' to 'fi'.
(xgettext_record_flag): Use XFORMAT_* macros.
(extract_from_file): Loop over the four formatstring types.
(recognize_qt_formatstrings): Update.
(language_to_extractor): Use XFORMAT_* macros and a loop.
Bruno Haible [Thu, 30 Nov 2023 07:24:18 +0000 (08:24 +0100)]
Fix clang -Wunused-function warnings.
* gettext-runtime/src/envsubst.c: Include attribute.h.
(string_list_member, string_list_destroy): Mark as MAYBE_UNUSED.
* gettext-tools/src/format-scheme.c: Include attribute.h.
(II): Mark as MAYBE_UNUSED.
* gettext-tools/src/msgl-fsearch.c: Include attribute.h.
(add_index): Mark as MAYBE_UNUSED.
* gettext-tools/src/po-lex.c: Include attribute.h.
(mb_isnul, mb_cmp, mb_equal, mb_isascii, mb_putc, mb_setascii): Mark as
MAYBE_UNUSED.
* gettext-tools/src/write-qt.c: Include attribute.h.
(write_u16): Mark as MAYBE_UNUSED.
* gettext-tools/src/x-awk.c (free_token): Mark as MAYBE_UNUSED.
* gettext-tools/src/x-python.c (phase0_ungetc): Mark as MAYBE_UNUSED.
Bruno Haible [Fri, 17 Nov 2023 11:46:18 +0000 (12:46 +0100)]
gettext.m4: Recognize a statically built libintl on macOS and AIX.
Reported by David Edelsohn <dje.gcc@gmail.com> in
<https://gcc.gnu.org/pipermail/gcc-patches/2023-November/636558.html>.
* gettext-runtime/m4/gettext.m4 (AM_GNU_GETTEXT): In the
"checking for GNU gettext in libintl..." test, add also the special
system library dependencies needed on macOS and AIX.
Bruno Haible [Fri, 17 Nov 2023 11:40:54 +0000 (12:40 +0100)]
build: Fix a build issue on AIX.
How to reproduce:
$ cd gettext-20231111
$ ~/build-64-gcc --disable-shared
$ (cd build-64-gcc && gmake install)
$ cd ..
$ cd gettext-0.22.3
$ ~/build-64-gcc
=> Fails with "ERROR: Undefined symbol: .syntax_check_message_list"
because the link uses $PREFIX/lib/libgettextsrc.a, which is a non-shared
library that does not export 'syntax_check_message_list'.
* gettext-tools/configure.ac (INSTALL_PRIVATE_LIBRARIES): New conditional.
* gettext-tools/src/Makefile.am (noinst_LTLIBRARIES): Define as alternative to
lib_LTLIBRARIES.
(install-exec-clean): Remove rule.
* gettext-tools/gnulib-lib/Makefile.am (lib_LTLIBRARIES): Initialize.
* gnulib-local/modules/gettext-tools-misc (Makefile.am): Define
noinst_LTLIBRARIES as alternative to lib_LTLIBRARIES. Remove
'install-exec-clean' rule.
* gettext-tools/src/po-gram-gen.y: Request a pure parser.
* gettext-tools/src/po-lex.h (po_gram_lex): Add lval parameter.
* gettext-tools/src/po-lex.c (po_gram_lex): Add lval parameter. Store the result
in *lval instead of in po_gram_lval.
* gettext-tools/woe32dll/gettextsrc-exports.c: Remove po_gram_lval.
Bruno Haible [Sat, 11 Nov 2023 15:48:16 +0000 (16:48 +0100)]
libgettextpo: Remove static variable 'width.0'.
* gnulib-local/lib/xerror.h: Include <stddef.h>.
(multiline_warning, multiline_error): Change return type to size_t. Don't
suggest to pass a NULL prefix.
(multiline_append): New declaration.
* gnulib-local/lib/xerror.c (multiline_internal): New function, extracted from
multiline_warning.
(multiline_warning, multiline_error): Reject a NULL prefix. Call
multiline_internal.
(multiline_append): New function.
* gettext-tools/src/msgl-charset.c (compare_po_locale_charsets): Invoke
multiline_append instead of multiline_warning with NULL argument.
* gettext-tools/src/msgfmt.c (msgfmt_parse_debrief): Invoke multiline_append
instead of multiline_error with NULL argument.
* gettext-tools/src/po-error.c (void_multiline_warning, void_multiline_error):
New functions.
(po_multiline_warning, po_multiline_error): Use them as initializer.
* gettext-tools/libgettextpo/gettext-po.c (void_multiline_warning,
void_multiline_error): New functions.
(po_file_read_v2, po_file_write): Use them as defaults for po_multiline_warning,
po_multiline_error.
Bruno Haible [Sat, 11 Nov 2023 15:48:13 +0000 (16:48 +0100)]
libgettextpo: Remove static variable 'result.0'.
* gettext-tools/src/write-po.h (make_format_description_string): Change return
type to 'char *'.
* gettext-tools/src/write-po.c (make_format_description_string): Return a
freshly allocated string.
(message_print_comment_flags, message_print_obsolete): Free the result of
make_format_description_string when done.
* gettext-tools/src/write-stringtable.c (write_message): Likewise.
Bruno Haible [Thu, 5 Oct 2023 21:04:32 +0000 (23:04 +0200)]
xgettext: Simplify code that emits diagnostics with error number.
* autogen.sh (GNULIB_MODULES_TOOLS_FOR_SRC): Add xstrerror.
(GNULIB_MODULES_LIBGETTEXTPO_OTHER): Add strerror_r-posix.
* gettext-tools/src/x-csharp.c: Include xstrerror.h.
(phase2_getc): Invoke 'xstrerror' and 'if_error' instead of 'error'.
* gettext-tools/src/x-javascript.c: Include xstrerror.h.
(phase2_getc): Invoke 'xstrerror' and 'if_error' instead of 'error'.
* gettext-tools/src/x-python.c: Include xstrerror.h.
(phase2_getc): Invoke 'xstrerror' and 'if_error' instead of 'error'.
Bruno Haible [Sun, 1 Oct 2023 18:18:12 +0000 (20:18 +0200)]
Avoid crash by stack overflow during plural expression evaluation.
* gettext-runtime/intl/plural-exp.h (enum eval_status, struct eval_result): New
types.
(plural_eval): Change return type to 'struct eval_result'.
* gettext-runtime/intl/eval-plural.h (EVAL_MAXDEPTH, OK): New macros.
(plural_eval_recurse): New function, extracted from plural_eval.
(plural_eval): Change return type to 'struct eval_result'. Invoke
plural_eval_recurse.
* gettext-runtime/intl/dcigettext.c (plural_lookup): Update.
* gettext-tools/src/plural-eval.h: Update comment.
* gettext-tools/src/msgl-check.c (plural_expression_histogram): Update.
(check_plural_eval): Update. Fail with an error message if the plural expression
evaluation produced a stack overflow.
* gettext-tools/tests/plural-3: Update.
Bruno Haible [Sun, 1 Oct 2023 18:18:02 +0000 (20:18 +0200)]
tests: Add option --thread to tstgettext, tstngettext.
* gettext-tools/tests/tstgettext.c: Include glthread/thread.h.
(inhibit_added_newline, do_expand): Remove variables.
(long_options): Add --thread option.
(struct worker_context): New type.
(main): Move some local variables into a context. Recognize option --thread.
At the end, invoke worker_thread.
(worker_thread): New function, extracted from main.
* gettext-tools/tests/tstngettext.c: Include glthread/thread.h.
(long_options): Add --thread option.
(struct worker_context): New type.
(main): Move some local variables into a context. Recognize option --thread.
At the end, invoke worker_thread.
(worker_thread): New function, extracted from main.
* gettext-tools/tests/Makefile.am (tstgettext_LDADD, tstngettext_LDADD): Add
gnulib-lib/libtestsgnu.a and $(LIBMULTITHREAD).
Bruno Haible [Sun, 1 Oct 2023 18:16:36 +0000 (20:16 +0200)]
build: Remove redundant -I options from AM_CPPFLAGS.
https://www.gnu.org/software/automake/manual/html_node/Program-Variables.html
documents that -I. -I$(srcdir) and -I$(top_builddir) (for config.h)
are already part of Automake's $(DEFAULT_INCLUDES), which is used
before $(AM_CPPFLAGS).
Bruno Haible [Sat, 30 Sep 2023 18:03:47 +0000 (20:03 +0200)]
intl: Remove use of alloca() for wdirname handling.
* autogen.sh (GNULIB_MODULES_LIBINTL): Add wgetcwd-lgpl.
* gettext-runtime/intl/dcigettext.c: Include <wchar.h>.
(DCIGETTEXT): Allocate resolved_wdirname through malloc() instead of through
alloca().
Bruno Haible [Sat, 30 Sep 2023 13:08:26 +0000 (15:08 +0200)]
intl: Merge from glibc.
Apply commits
2017-06-21 Florian Weimer <fweimer@redhat.com>
DCIGETTEXT: Use getcwd, asprintf to construct absolute pathname
and
2018-12-21 Florian Weimer <fweimer@redhat.com>
intl: Do not return NULL on asprintf failure in gettext [BZ #24018]
Bruno Haible [Wed, 20 Sep 2023 09:03:35 +0000 (11:03 +0200)]
Fix intl-7 test failure on Solaris 11.
* gettext-tools/tests/init.cfg (prepare_locale_): Preserve the existing contents
of "$2".
* gettext-tools/tests/intl-7: While calling prepare_locale_, ensure that fr_FR
has higher priority than fr.
Bruno Haible [Mon, 18 Sep 2023 19:28:25 +0000 (21:28 +0200)]
libgettextpo: Fix compilation error on FreeBSD (regression 2023-09-16).
* gettext-tools/libgettextpo/gettext-po.c (po_file_write, po_error_logger,
po_message_check_format): Use orig_error, orig_error_at_line instead of the
error, error_at_line symbols.
* gettext-tools/src/x-perl.c: Ensure the top-level extract_balanced call returns
when a closing paren or bracket is seen.
(token_type_r_any): New enum item.
(prefer_regexp_over_division, extract_balanced): Handle it.
(extract_perl): Pass token_type_r_any instead of token_type_rbrace.
Bruno Haible [Mon, 18 Sep 2023 18:26:48 +0000 (20:26 +0200)]
xgettext: Perl: Add test against unbounded nesting_depth growth.
Reported by Gavin D. Smith <gavinsmith0123@gmail.com> at
<https://lists.gnu.org/archive/html/bug-gettext/2023-07/msg00008.html>
and <https://savannah.gnu.org/bugs/?64552>.
* gettext-tools/tests/xgettext-perl-stackovfl-5: New file.
* gettext-tools/tests/testdata/xg-pl-so-5.pl: New file, taken from
https://git.savannah.gnu.org/gitweb/?p=texinfo.git;a=blob;f=tp/Texinfo/Convert/HTML.pm;hb=c8d9edd94d9b1a3e675e811208d9e66eaf9a7daa
* gettext-tools/tests/Makefile.am (TESTS): Add xgettext-perl-stackovfl-5.
(EXTRA_DIST): Add testdata/xg-pl-so-5.pl.