From b7953995a8defeb439b90bcb16bed9bc8174775e Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Thu, 5 Oct 2023 23:04:32 +0200 Subject: [PATCH] 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'. --- autogen.sh | 16 ++++++++++++---- gettext-tools/src/x-csharp.c | 6 ++++-- gettext-tools/src/x-javascript.c | 6 ++++-- gettext-tools/src/x-python.c | 6 ++++-- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/autogen.sh b/autogen.sh index 094fe9756..5db7e7c24 100755 --- a/autogen.sh +++ b/autogen.sh @@ -250,6 +250,7 @@ if ! $skip_gnulib; then xmalloca xmemdup0 xsetenv + xstrerror xstriconv xstriconveh xvasprintf @@ -379,19 +380,26 @@ if ! $skip_gnulib; then xstriconv xvasprintf ' - # Module 'fdopen' is enabled in gettext-tools/config.status, because - # it occurs as dependency of some module ('supersede') in + # Module 'fdopen' is enabled in gettext-tools/config.status, + # because it occurs as dependency of some module ('supersede') in # GNULIB_MODULES_TOOLS_FOR_SRC. Therefore on mingw, libgettextpo/stdio.h # contains '#define fdopen rpl_fdopen'. Therefore we need to include # fdopen.lo in libgettextpo.la. - # Module 'realloc-posix' is enabled in gettext-tools/config.status, because - # it occurs as dependency of some module ('read-file') in + # Module 'realloc-posix' is enabled in gettext-tools/config.status, + # because it occurs as dependency of some module ('read-file') in # GNULIB_MODULES_TOOLS_FOR_SRC. Therefore on mingw, libgettextpo/stdlib.h # contains '#define realloc rpl_realloc'. Therefore we need to include # realloc.lo in libgettextpo.la. + # Module 'strerror_r-posix' is enabled in gettext-tools/config.status, + # because it occurs as dependency of some module ('xstrerror') in + # GNULIB_MODULES_TOOLS_FOR_SRC. Therefore gettext-tools/config.h contains + # '#define GNULIB_STRERROR_R_POSIX 1'. Therefore on mingw, + # libgettextpo/error.o references strerror_r. Therefore we need to include + # strerror_r.lo in libgettextpo.la. GNULIB_MODULES_LIBGETTEXTPO_OTHER=' fdopen realloc-posix + strerror_r-posix ' $GNULIB_TOOL --dir=gettext-tools --source-base=libgettextpo --m4-base=libgettextpo/gnulib-m4 --macro-prefix=gtpo --makefile-name=Makefile.gnulib --libtool --local-dir=gnulib-local --local-symlink \ --import --avoid=progname $GNULIB_MODULES_LIBGETTEXTPO $GNULIB_MODULES_LIBGETTEXTPO_OTHER || exit $? diff --git a/gettext-tools/src/x-csharp.c b/gettext-tools/src/x-csharp.c index 81552c93a..9dd385ca6 100644 --- a/gettext-tools/src/x-csharp.c +++ b/gettext-tools/src/x-csharp.c @@ -42,6 +42,7 @@ #include "c-ctype.h" #include "error.h" #include "if-error.h" +#include "xstrerror.h" #include "xalloc.h" #include "xerror.h" #include "xvasprintf.h" @@ -316,8 +317,9 @@ Please specify the correct source encoding through --from-code.\n"), buf[bufcount++] = (unsigned char) c; } else - error (EXIT_FAILURE, errno, _("%s:%d: error: iconv failure"), - real_file_name, line_number); + if_error (IF_SEVERITY_FATAL_ERROR, + real_file_name, line_number, (size_t)(-1), false, + "%s", xstrerror (_("iconv failure"), errno)); } else { diff --git a/gettext-tools/src/x-javascript.c b/gettext-tools/src/x-javascript.c index 644f9db33..8c6883fc2 100644 --- a/gettext-tools/src/x-javascript.c +++ b/gettext-tools/src/x-javascript.c @@ -44,6 +44,7 @@ #include "xg-message.h" #include "error.h" #include "if-error.h" +#include "xstrerror.h" #include "progname.h" #include "xerror.h" #include "xvasprintf.h" @@ -328,8 +329,9 @@ Please specify the correct source encoding through --from-code\n"), buf[bufcount++] = (unsigned char) c; } else - error (EXIT_FAILURE, errno, _("%s:%d: error: iconv failure"), - real_file_name, line_number); + if_error (IF_SEVERITY_FATAL_ERROR, + real_file_name, line_number, (size_t)(-1), false, + "%s", xstrerror (_("iconv failure"), errno)); } else { diff --git a/gettext-tools/src/x-python.c b/gettext-tools/src/x-python.c index 4946b0b77..38f6f82a5 100644 --- a/gettext-tools/src/x-python.c +++ b/gettext-tools/src/x-python.c @@ -43,6 +43,7 @@ #include "xg-message.h" #include "error.h" #include "if-error.h" +#include "xstrerror.h" #include "progname.h" #include "basename-lgpl.h" #include "xerror.h" @@ -355,8 +356,9 @@ comment as specified in https://www.python.org/peps/pep-0263.html.\n"), buf[bufcount++] = (unsigned char) c; } else - error (EXIT_FAILURE, errno, _("%s:%d: error: iconv failure"), - real_file_name, line_number); + if_error (IF_SEVERITY_FATAL_ERROR, + real_file_name, line_number, (size_t)(-1), false, + "%s", xstrerror (_("iconv failure"), errno)); } else { -- 2.47.3