]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
lzmainfo: Use tuklib_mbstr_wrap for --help text
authorLasse Collin <lasse.collin@tukaani.org>
Wed, 29 Jan 2025 18:50:03 +0000 (20:50 +0200)
committerLasse Collin <lasse.collin@tukaani.org>
Wed, 29 Jan 2025 18:59:53 +0000 (20:59 +0200)
Some languages have so long strings that they need to be wrapped.

CMakeLists.txt
src/lzmainfo/Makefile.am
src/lzmainfo/lzmainfo.c

index d24fd9a99786e88bd19855acef44ff1111e0a24f..3de1321fbbd9aa4554d3c01b43663ba080965ac8 100644 (file)
@@ -2016,8 +2016,12 @@ if(XZ_TOOL_LZMAINFO AND HAVE_DECODERS)
         src/common/sysdefs.h
         src/common/tuklib_common.h
         src/common/tuklib_config.h
+        src/common/tuklib_mbstr.h
         src/common/tuklib_mbstr_nonprint.c
         src/common/tuklib_mbstr_nonprint.h
+        src/common/tuklib_mbstr_width.c
+        src/common/tuklib_mbstr_wrap.c
+        src/common/tuklib_mbstr_wrap.h
         src/common/tuklib_exit.c
         src/common/tuklib_exit.h
         src/common/tuklib_gettext.h
index 3b0d22391d9a2a2b7fa12b98169d20f6fac53130..6662ecd5336b1b5ae5e2fc6893ba61d32d442561 100644 (file)
@@ -7,6 +7,8 @@ lzmainfo_SOURCES = \
        lzmainfo.c \
        ../common/tuklib_progname.c \
        ../common/tuklib_mbstr_nonprint.c \
+       ../common/tuklib_mbstr_width.c \
+       ../common/tuklib_mbstr_wrap.c \
        ../common/tuklib_exit.c
 
 if COND_W32
index e94b26fae082f1b425a2bfb3e1469f26f1cfc905..0b0b0d3d09a4d59ac5472b84a26b032f23b93d5d 100644 (file)
@@ -18,6 +18,7 @@
 #include "tuklib_gettext.h"
 #include "tuklib_progname.h"
 #include "tuklib_mbstr_nonprint.h"
+#include "tuklib_mbstr_wrap.h"
 #include "tuklib_exit.h"
 
 #ifdef TUKLIB_DOSLIKE
@@ -30,21 +31,36 @@ tuklib_attr_noreturn
 static void
 help(void)
 {
-       // We don't need automatic word-wrapping here. A few strings are
-       // the same as in xz/message.c but here we need to add the newlines
-       // with putchar('\n'). This way translators won't get two variants
-       // of the same string: one without and another with \n at the end.
+       // A few languages use so long strings that we need automatic
+       // wrapping. A few strings are the same as in xz/message.c and
+       // should be kept in sync.
+       static const struct tuklib_wrap_opt wrap0 = {  0,  0,  0,  0, 79 };
+       int e = 0;
+
        printf(_("Usage: %s [--help] [--version] [FILE]...\n"), progname);
-       puts(_("Show information stored in the .lzma file header."));
-       puts(_("With no FILE, or when FILE is -, read standard input."));
+
+       e |= tuklib_wraps(stdout, &wrap0,
+               W_("Show information stored in the .lzma file header."));
+       e |= tuklib_wraps(stdout, &wrap0,
+               W_("With no FILE, or when FILE is -, read standard input."));
 
        putchar('\n');
 
-       printf(_("Report bugs to <%s> (in English or Finnish)."),
+       e |= tuklib_wrapf(stdout, &wrap0,
+                       W_("Report bugs to <%s> (in English or Finnish)."),
                        PACKAGE_BUGREPORT);
-       putchar('\n');
-       printf(_("%s home page: <%s>"), PACKAGE_NAME, PACKAGE_URL);
-       putchar('\n');
+
+       e |= tuklib_wrapf(stdout, &wrap0,
+                       W_("%s home page: <%s>"), PACKAGE_NAME, PACKAGE_URL);
+
+       if (e != 0) {
+               // Avoid new translatable strings by printing the message
+               // in pieces.
+               fprintf(stderr, _("%s: "), progname);
+               fprintf(stderr, _("Error printing the help text "
+                               "(error code %d)"), e);
+               fprintf(stderr, "\n");
+       }
 
        tuklib_exit(EXIT_SUCCESS, EXIT_FAILURE, true);
 }