1 // SPDX-License-Identifier: 0BSD
3 ///////////////////////////////////////////////////////////////////////////////
6 /// \brief Printing messages
8 // Authors: Lasse Collin
11 ///////////////////////////////////////////////////////////////////////////////
18 /// Number of the current file
19 static unsigned int files_pos
= 0;
21 /// Total number of input files; zero if unknown.
22 static unsigned int files_total
;
25 static enum message_verbosity verbosity
= V_WARNING
;
27 /// Filename which we will print with the verbose messages
28 static const char *filename
;
30 /// True once the a filename has been printed to stderr as part of progress
31 /// message. If automatic progress updating isn't enabled, this becomes true
32 /// after the first progress message has been printed due to user sending
33 /// SIGINFO, SIGUSR1, or SIGALRM. Once this variable is true, we will print
34 /// an empty line before the next filename to make the output more readable.
35 static bool first_filename_printed
= false;
37 /// This is set to true when we have printed the current filename to stderr
38 /// as part of a progress message. This variable is useful only if not
39 /// updating progress automatically: if user sends many SIGINFO, SIGUSR1, or
40 /// SIGALRM signals, we won't print the name of the same file multiple times.
41 static bool current_filename_printed
= false;
43 /// True if we should print progress indicator and update it automatically
44 /// if also verbose >= V_VERBOSE.
45 static bool progress_automatic
= false;
47 /// True if message_progress_start() has been called but
48 /// message_progress_end() hasn't been called yet.
49 static bool progress_started
= false;
51 /// This is true when a progress message was printed and the cursor is still
52 /// on the same line with the progress message. In that case, a newline has
53 /// to be printed before any error messages.
54 static bool progress_active
= false;
56 /// Pointer to lzma_stream used to do the encoding or decoding.
57 static lzma_stream
*progress_strm
;
59 /// This is true if we are in passthru mode (not actually compressing or
60 /// decompressing) and thus cannot use lzma_get_progress(progress_strm, ...).
61 /// That is, we are using coder_passthru() in coder.c.
62 static bool progress_is_from_passthru
;
64 /// Expected size of the input stream is needed to show completion percentage
65 /// and estimate remaining time.
66 static uint64_t expected_in_size
;
69 // Use alarm() and SIGALRM when they are supported. This has two minor
70 // advantages over the alternative of polling gettimeofday():
71 // - It is possible for the user to send SIGINFO, SIGUSR1, or SIGALRM to
72 // get intermediate progress information even when --verbose wasn't used
73 // or stderr is not a terminal.
74 // - alarm() + SIGALRM seems to have slightly less overhead than polling
78 const int message_progress_sigs
[] = {
89 /// The signal handler for SIGALRM sets this to true. It is set back to false
90 /// once the progress message has been updated.
91 static volatile sig_atomic_t progress_needs_updating
= false;
93 /// Signal handler for SIGALRM
95 progress_signal_handler(int sig
lzma_attribute((__unused__
)))
97 progress_needs_updating
= true;
103 /// This is true when progress message printing is wanted. Using the same
104 /// variable name as above to avoid some ifdefs.
105 static bool progress_needs_updating
= false;
107 /// Elapsed time when the next progress message update should be done.
108 static uint64_t progress_next_update
;
116 // If --verbose is used, we use a progress indicator if and only
117 // if stderr is a terminal. If stderr is not a terminal, we print
118 // verbose information only after finishing the file. As a special
119 // exception, even if --verbose was not used, user can send SIGALRM
120 // to make us print progress information once without automatic
122 progress_automatic
= is_tty(STDERR_FILENO
);
125 // Establish the signal handlers which set a flag to tell us that
126 // progress info should be updated.
128 sigemptyset(&sa
.sa_mask
);
130 sa
.sa_handler
= &progress_signal_handler
;
132 for (size_t i
= 0; message_progress_sigs
[i
] != 0; ++i
)
133 if (sigaction(message_progress_sigs
[i
], &sa
, NULL
))
134 message_signal_handler();
142 message_verbosity_increase(void)
144 if (verbosity
< V_DEBUG
)
152 message_verbosity_decrease(void)
154 if (verbosity
> V_SILENT
)
161 extern enum message_verbosity
162 message_verbosity_get(void)
169 message_set_files(unsigned int files
)
176 /// Prints the name of the current file if it hasn't been printed already,
177 /// except if we are processing exactly one stream from stdin to stdout.
178 /// I think it looks nicer to not print "(stdin)" when --verbose is used
179 /// in a pipe and no other files are processed.
183 if (!opt_robot
&& (files_total
!= 1 || filename
!= stdin_filename
)) {
186 FILE *file
= opt_mode
== MODE_LIST
? stdout
: stderr
;
188 // If a file was already processed, put an empty line
189 // before the next filename to improve readability.
190 if (first_filename_printed
)
193 first_filename_printed
= true;
194 current_filename_printed
= true;
196 // If we don't know how many files there will be due
197 // to usage of --files or --files0.
198 if (files_total
== 0)
199 fprintf(file
, "%s (%u)\n", filename
,
202 fprintf(file
, "%s (%u/%u)\n", filename
,
203 files_pos
, files_total
);
213 message_filename(const char *src_name
)
215 // Start numbering the files starting from one.
219 if (verbosity
>= V_VERBOSE
220 && (progress_automatic
|| opt_mode
== MODE_LIST
))
223 current_filename_printed
= false;
230 message_progress_start(lzma_stream
*strm
, bool is_passthru
, uint64_t in_size
)
232 // Store the pointer to the lzma_stream used to do the coding.
233 // It is needed to find out the position in the stream.
234 progress_strm
= strm
;
235 progress_is_from_passthru
= is_passthru
;
237 // Store the expected size of the file. If we aren't printing any
238 // statistics, then is will be unused. But since it is possible
239 // that the user sends us a signal to show statistics, we need
240 // to have it available anyway.
241 expected_in_size
= in_size
;
243 // Indicate that progress info may need to be printed before
244 // printing error messages.
245 progress_started
= true;
247 // If progress indicator is wanted, print the filename and possibly
248 // the file count now.
249 if (verbosity
>= V_VERBOSE
&& progress_automatic
) {
250 // Start the timer to display the first progress message
251 // after one second. An alternative would be to show the
252 // first message almost immediately, but delaying by one
253 // second looks better to me, since extremely early
254 // progress info is pretty much useless.
256 // First disable a possibly existing alarm.
258 progress_needs_updating
= false;
261 progress_needs_updating
= true;
262 progress_next_update
= 1000;
270 /// Make the string indicating completion percentage.
272 progress_percentage(uint64_t in_pos
)
274 // If the size of the input file is unknown or the size told us is
275 // clearly wrong since we have processed more data than the alleged
276 // size of the file, show a static string indicating that we have
277 // no idea of the completion percentage.
278 if (expected_in_size
== 0 || in_pos
> expected_in_size
)
281 // Never show 100.0 % before we actually are finished.
282 double percentage
= (double)(in_pos
) / (double)(expected_in_size
)
285 // Use big enough buffer to hold e.g. a multibyte decimal point.
287 snprintf(buf
, sizeof(buf
), "%.1f %%", percentage
);
293 /// Make the string containing the amount of input processed, amount of
294 /// output produced, and the compression ratio.
296 progress_sizes(uint64_t compressed_pos
, uint64_t uncompressed_pos
, bool final
)
298 // Use big enough buffer to hold e.g. a multibyte thousand separators.
299 static char buf
[128];
301 size_t left
= sizeof(buf
);
303 // Print the sizes. If this the final message, use more reasonable
304 // units than MiB if the file was small.
305 const enum nicestr_unit unit_min
= final
? NICESTR_B
: NICESTR_MIB
;
306 my_snprintf(&pos
, &left
, "%s / %s",
307 uint64_to_nicestr(compressed_pos
,
308 unit_min
, NICESTR_TIB
, false, 0),
309 uint64_to_nicestr(uncompressed_pos
,
310 unit_min
, NICESTR_TIB
, false, 1));
312 // Avoid division by zero. If we cannot calculate the ratio, set
313 // it to some nice number greater than 10.0 so that it gets caught
314 // in the next if-clause.
315 const double ratio
= uncompressed_pos
> 0
316 ? (double)(compressed_pos
) / (double)(uncompressed_pos
)
319 // If the ratio is very bad, just indicate that it is greater than
320 // 9.999. This way the length of the ratio field stays fixed.
322 snprintf(pos
, left
, " > %.3f", 9.999);
324 snprintf(pos
, left
, " = %.3f", ratio
);
330 /// Make the string containing the processing speed of uncompressed data.
332 progress_speed(uint64_t uncompressed_pos
, uint64_t elapsed
)
334 // Don't print the speed immediately, since the early values look
339 // The first character of KiB/s, MiB/s, or GiB/s:
340 static const char unit
[] = { 'K', 'M', 'G' };
342 size_t unit_index
= 0;
344 // Calculate the speed as KiB/s.
345 double speed
= (double)(uncompressed_pos
)
346 / ((double)(elapsed
) * (1024.0 / 1000.0));
348 // Adjust the unit of the speed if needed.
349 while (speed
> 999.0) {
351 if (++unit_index
== ARRAY_SIZE(unit
))
352 return ""; // Way too fast ;-)
355 // Use decimal point only if the number is small. Examples:
360 // Use big enough buffer to hold e.g. a multibyte decimal point.
362 snprintf(buf
, sizeof(buf
), "%.*f %ciB/s",
363 speed
> 9.9 ? 0 : 1, speed
, unit
[unit_index
]);
368 /// Make a string indicating elapsed time. The format is either
369 /// M:SS or H:MM:SS depending on if the time is an hour or more.
371 progress_time(uint64_t mseconds
)
373 // 9999 hours = 416 days
374 static char buf
[sizeof("9999:59:59")];
376 // 32-bit variable is enough for elapsed time (136 years).
377 uint32_t seconds
= (uint32_t)(mseconds
/ 1000);
379 // Don't show anything if the time is zero or ridiculously big.
380 if (seconds
== 0 || seconds
> ((9999 * 60) + 59) * 60 + 59)
383 uint32_t minutes
= seconds
/ 60;
387 const uint32_t hours
= minutes
/ 60;
389 snprintf(buf
, sizeof(buf
),
390 "%" PRIu32
":%02" PRIu32
":%02" PRIu32
,
391 hours
, minutes
, seconds
);
393 snprintf(buf
, sizeof(buf
), "%" PRIu32
":%02" PRIu32
,
401 /// Return a string containing estimated remaining time when
402 /// reasonably possible.
404 progress_remaining(uint64_t in_pos
, uint64_t elapsed
)
406 // Don't show the estimated remaining time when it wouldn't
408 // - Input size is unknown.
409 // - Input has grown bigger since we started (de)compressing.
410 // - We haven't processed much data yet, so estimate would be
412 // - Only a few seconds has passed since we started (de)compressing,
413 // so estimate would be too inaccurate.
414 if (expected_in_size
== 0 || in_pos
> expected_in_size
415 || in_pos
< (UINT64_C(1) << 19) || elapsed
< 8000)
418 // Calculate the estimate. Don't give an estimate of zero seconds,
419 // since it is possible that all the input has been already passed
420 // to the library, but there is still quite a bit of output pending.
421 uint32_t remaining
= (uint32_t)((double)(expected_in_size
- in_pos
)
422 * ((double)(elapsed
) / 1000.0) / (double)(in_pos
));
426 static char buf
[sizeof("9 h 55 min")];
428 // Select appropriate precision for the estimated remaining time.
429 if (remaining
<= 10) {
430 // A maximum of 10 seconds remaining.
431 // Show the number of seconds as is.
432 snprintf(buf
, sizeof(buf
), "%" PRIu32
" s", remaining
);
434 } else if (remaining
<= 50) {
435 // A maximum of 50 seconds remaining.
436 // Round up to the next multiple of five seconds.
437 remaining
= (remaining
+ 4) / 5 * 5;
438 snprintf(buf
, sizeof(buf
), "%" PRIu32
" s", remaining
);
440 } else if (remaining
<= 590) {
441 // A maximum of 9 minutes and 50 seconds remaining.
442 // Round up to the next multiple of ten seconds.
443 remaining
= (remaining
+ 9) / 10 * 10;
444 snprintf(buf
, sizeof(buf
), "%" PRIu32
" min %" PRIu32
" s",
445 remaining
/ 60, remaining
% 60);
447 } else if (remaining
<= 59 * 60) {
448 // A maximum of 59 minutes remaining.
449 // Round up to the next multiple of a minute.
450 remaining
= (remaining
+ 59) / 60;
451 snprintf(buf
, sizeof(buf
), "%" PRIu32
" min", remaining
);
453 } else if (remaining
<= 9 * 3600 + 50 * 60) {
454 // A maximum of 9 hours and 50 minutes left.
455 // Round up to the next multiple of ten minutes.
456 remaining
= (remaining
+ 599) / 600 * 10;
457 snprintf(buf
, sizeof(buf
), "%" PRIu32
" h %" PRIu32
" min",
458 remaining
/ 60, remaining
% 60);
460 } else if (remaining
<= 23 * 3600) {
461 // A maximum of 23 hours remaining.
462 // Round up to the next multiple of an hour.
463 remaining
= (remaining
+ 3599) / 3600;
464 snprintf(buf
, sizeof(buf
), "%" PRIu32
" h", remaining
);
466 } else if (remaining
<= 9 * 24 * 3600 + 23 * 3600) {
467 // A maximum of 9 days and 23 hours remaining.
468 // Round up to the next multiple of an hour.
469 remaining
= (remaining
+ 3599) / 3600;
470 snprintf(buf
, sizeof(buf
), "%" PRIu32
" d %" PRIu32
" h",
471 remaining
/ 24, remaining
% 24);
473 } else if (remaining
<= 999 * 24 * 3600) {
474 // A maximum of 999 days remaining. ;-)
475 // Round up to the next multiple of a day.
476 remaining
= (remaining
+ 24 * 3600 - 1) / (24 * 3600);
477 snprintf(buf
, sizeof(buf
), "%" PRIu32
" d", remaining
);
480 // The estimated remaining time is too big. Don't show it.
488 /// Get how much uncompressed and compressed data has been processed.
490 progress_pos(uint64_t *in_pos
,
491 uint64_t *compressed_pos
, uint64_t *uncompressed_pos
)
494 if (progress_is_from_passthru
) {
495 // In passthru mode the progress info is in total_in/out but
496 // the *progress_strm itself isn't initialized and thus we
497 // cannot use lzma_get_progress().
498 *in_pos
= progress_strm
->total_in
;
499 out_pos
= progress_strm
->total_out
;
501 lzma_get_progress(progress_strm
, in_pos
, &out_pos
);
504 // It cannot have processed more input than it has been given.
505 assert(*in_pos
<= progress_strm
->total_in
);
507 // It cannot have produced more output than it claims to have ready.
508 assert(out_pos
>= progress_strm
->total_out
);
510 if (opt_mode
== MODE_COMPRESS
) {
511 *compressed_pos
= out_pos
;
512 *uncompressed_pos
= *in_pos
;
514 *compressed_pos
= *in_pos
;
515 *uncompressed_pos
= out_pos
;
523 message_progress_update(void)
525 if (!progress_needs_updating
)
528 // Calculate how long we have been processing this file.
529 const uint64_t elapsed
= mytime_get_elapsed();
532 if (progress_next_update
> elapsed
)
535 progress_next_update
= elapsed
+ 1000;
538 // Get our current position in the stream.
540 uint64_t compressed_pos
;
541 uint64_t uncompressed_pos
;
542 progress_pos(&in_pos
, &compressed_pos
, &uncompressed_pos
);
544 // Block signals so that fprintf() doesn't get interrupted.
547 // Print the filename if it hasn't been printed yet.
548 if (!current_filename_printed
)
551 // Print the actual progress message. The idea is that there is at
552 // least three spaces between the fields in typical situations, but
553 // even in rare situations there is at least one space.
554 const char *cols
[5] = {
555 progress_percentage(in_pos
),
556 progress_sizes(compressed_pos
, uncompressed_pos
, false),
557 progress_speed(uncompressed_pos
, elapsed
),
558 progress_time(elapsed
),
559 progress_remaining(in_pos
, elapsed
),
561 fprintf(stderr
, "\r %*s %*s %*s %10s %10s\r",
562 tuklib_mbstr_fw(cols
[0], 6), cols
[0],
563 tuklib_mbstr_fw(cols
[1], 35), cols
[1],
564 tuklib_mbstr_fw(cols
[2], 9), cols
[2],
569 // Updating the progress info was finished. Reset
570 // progress_needs_updating to wait for the next SIGALRM.
572 // NOTE: This has to be done before alarm(1) or with (very) bad
573 // luck we could be setting this to false after the alarm has already
575 progress_needs_updating
= false;
577 if (verbosity
>= V_VERBOSE
&& progress_automatic
) {
578 // Mark that the progress indicator is active, so if an error
579 // occurs, the error message gets printed cleanly.
580 progress_active
= true;
582 // Restart the timer so that progress_needs_updating gets
583 // set to true after about one second.
586 // The progress message was printed because user had sent us
587 // SIGALRM. In this case, each progress message is printed
592 // When SIGALRM isn't supported and we get here, it's always due to
593 // automatic progress update. We set progress_active here too like
595 assert(verbosity
>= V_VERBOSE
);
596 assert(progress_automatic
);
597 progress_active
= true;
607 progress_flush(bool finished
)
609 if (!progress_started
|| verbosity
< V_VERBOSE
)
613 uint64_t compressed_pos
;
614 uint64_t uncompressed_pos
;
615 progress_pos(&in_pos
, &compressed_pos
, &uncompressed_pos
);
617 // Avoid printing intermediate progress info if some error occurs
618 // in the beginning of the stream. (If something goes wrong later in
619 // the stream, it is sometimes useful to tell the user where the
620 // error approximately occurred, especially if the error occurs
621 // after a time-consuming operation.)
622 if (!finished
&& !progress_active
623 && (compressed_pos
== 0 || uncompressed_pos
== 0))
626 progress_active
= false;
628 const uint64_t elapsed
= mytime_get_elapsed();
632 // When using the auto-updating progress indicator, the final
633 // statistics are printed in the same format as the progress
635 if (progress_automatic
) {
636 const char *cols
[5] = {
637 finished
? "100 %" : progress_percentage(in_pos
),
638 progress_sizes(compressed_pos
, uncompressed_pos
, true),
639 progress_speed(uncompressed_pos
, elapsed
),
640 progress_time(elapsed
),
641 finished
? "" : progress_remaining(in_pos
, elapsed
),
643 fprintf(stderr
, "\r %*s %*s %*s %10s %10s\n",
644 tuklib_mbstr_fw(cols
[0], 6), cols
[0],
645 tuklib_mbstr_fw(cols
[1], 35), cols
[1],
646 tuklib_mbstr_fw(cols
[2], 9), cols
[2],
650 // The filename is always printed.
651 fprintf(stderr
, _("%s: "), filename
);
653 // Percentage is printed only if we didn't finish yet.
655 // Don't print the percentage when it isn't known
656 // (starts with a dash).
657 const char *percentage
= progress_percentage(in_pos
);
658 if (percentage
[0] != '-')
659 fprintf(stderr
, "%s, ", percentage
);
662 // Size information is always printed.
663 fprintf(stderr
, "%s", progress_sizes(
664 compressed_pos
, uncompressed_pos
, true));
666 // The speed and elapsed time aren't always shown.
667 const char *speed
= progress_speed(uncompressed_pos
, elapsed
);
668 if (speed
[0] != '\0')
669 fprintf(stderr
, ", %s", speed
);
671 const char *elapsed_str
= progress_time(elapsed
);
672 if (elapsed_str
[0] != '\0')
673 fprintf(stderr
, ", %s", elapsed_str
);
685 message_progress_end(bool success
)
687 assert(progress_started
);
688 progress_flush(success
);
689 progress_started
= false;
695 vmessage(enum message_verbosity v
, const char *fmt
, va_list ap
)
697 if (v
<= verbosity
) {
700 progress_flush(false);
702 // TRANSLATORS: This is the program name in the beginning
703 // of the line in messages. Usually it becomes "xz: ".
704 // This is a translatable string because French needs
705 // a space before a colon.
706 fprintf(stderr
, _("%s: "), progname
);
709 # pragma GCC diagnostic push
710 # pragma GCC diagnostic ignored "-Wformat-nonliteral"
712 vfprintf(stderr
, fmt
, ap
);
714 # pragma GCC diagnostic pop
727 message(enum message_verbosity v
, const char *fmt
, ...)
731 vmessage(v
, fmt
, ap
);
738 message_warning(const char *fmt
, ...)
742 vmessage(V_WARNING
, fmt
, ap
);
745 set_exit_status(E_WARNING
);
751 message_error(const char *fmt
, ...)
755 vmessage(V_ERROR
, fmt
, ap
);
758 set_exit_status(E_ERROR
);
764 message_fatal(const char *fmt
, ...)
768 vmessage(V_ERROR
, fmt
, ap
);
771 tuklib_exit(E_ERROR
, E_ERROR
, false);
778 message_fatal(_("Internal error (bug)"));
783 message_signal_handler(void)
785 message_fatal(_("Cannot establish signal handlers"));
790 message_strm(lzma_ret code
)
794 return _("No integrity check; not verifying file integrity");
796 case LZMA_UNSUPPORTED_CHECK
:
797 return _("Unsupported type of integrity check; "
798 "not verifying file integrity");
801 return strerror(ENOMEM
);
803 case LZMA_MEMLIMIT_ERROR
:
804 return _("Memory usage limit reached");
806 case LZMA_FORMAT_ERROR
:
807 return _("File format not recognized");
809 case LZMA_OPTIONS_ERROR
:
810 return _("Unsupported options");
812 case LZMA_DATA_ERROR
:
813 return _("Compressed data is corrupt");
816 return _("Unexpected end of input");
819 case LZMA_STREAM_END
:
821 case LZMA_PROG_ERROR
:
822 case LZMA_SEEK_NEEDED
:
823 case LZMA_RET_INTERNAL1
:
824 case LZMA_RET_INTERNAL2
:
825 case LZMA_RET_INTERNAL3
:
826 case LZMA_RET_INTERNAL4
:
827 case LZMA_RET_INTERNAL5
:
828 case LZMA_RET_INTERNAL6
:
829 case LZMA_RET_INTERNAL7
:
830 case LZMA_RET_INTERNAL8
:
831 // Without "default", compiler will warn if new constants
832 // are added to lzma_ret, it is not too easy to forget to
833 // add the new constants to this function.
837 return _("Internal error (bug)");
842 message_mem_needed(enum message_verbosity v
, uint64_t memusage
)
847 // Convert memusage to MiB, rounding up to the next full MiB.
848 // This way the user can always use the displayed usage as
849 // the new memory usage limit. (If we rounded to the nearest,
850 // the user might need to +1 MiB to get high enough limit.)
851 memusage
= round_up_to_mib(memusage
);
853 uint64_t memlimit
= hardware_memlimit_get(opt_mode
);
855 // Handle the case when there is no memory usage limit.
856 // This way we don't print a weird message with a huge number.
857 if (memlimit
== UINT64_MAX
) {
858 message(v
, _("%s MiB of memory is required. "
859 "The limiter is disabled."),
860 uint64_to_str(memusage
, 0));
865 // 2^64 with thousand separators + " MiB" suffix + '\0' = 26 + 4 + 1
866 // But there may be multibyte chars so reserve enough space.
867 char memlimitstr
[128];
869 // Show the memory usage limit as MiB unless it is less than 1 MiB.
870 // This way it's easy to notice errors where one has typed
871 // --memory=123 instead of --memory=123MiB.
872 if (memlimit
< (UINT32_C(1) << 20)) {
873 snprintf(memlimitstr
, sizeof(memlimitstr
), "%s B",
874 uint64_to_str(memlimit
, 1));
876 // Round up just like with memusage. If this function is
877 // called for informational purposes (to just show the
878 // current usage and limit), we should never show that
879 // the usage is higher than the limit, which would give
880 // a false impression that the memory usage limit isn't
881 // properly enforced.
882 snprintf(memlimitstr
, sizeof(memlimitstr
), "%s MiB",
883 uint64_to_str(round_up_to_mib(memlimit
), 1));
886 message(v
, _("%s MiB of memory is required. The limit is %s."),
887 uint64_to_str(memusage
, 0), memlimitstr
);
894 message_filters_show(enum message_verbosity v
, const lzma_filter
*filters
)
900 const lzma_ret ret
= lzma_str_from_filters(&buf
, filters
,
901 LZMA_STR_ENCODER
| LZMA_STR_GETOPT_LONG
, NULL
);
903 message_fatal("%s", message_strm(ret
));
905 fprintf(stderr
, _("%s: Filter chain: %s\n"), progname
, buf
);
912 message_try_help(void)
914 // Print this with V_WARNING instead of V_ERROR to prevent it from
915 // showing up when --quiet has been specified.
916 message(V_WARNING
, _("Try '%s --help' for more information."),
923 message_version(void)
925 // It is possible that liblzma version is different than the command
926 // line tool version, so print both.
928 printf("XZ_VERSION=%" PRIu32
"\nLIBLZMA_VERSION=%" PRIu32
"\n",
929 LZMA_VERSION
, lzma_version_number());
931 printf("xz (" PACKAGE_NAME
") " LZMA_VERSION_STRING
"\n");
932 printf("liblzma %s\n", lzma_version_string());
935 tuklib_exit(E_SUCCESS
, E_ERROR
, verbosity
!= V_SILENT
);
940 message_help(bool long_help
)
942 printf(_("Usage: %s [OPTION]... [FILE]...\n"
943 "Compress or decompress FILEs in the .xz format.\n\n"),
946 // NOTE: The short help doesn't currently have options that
949 puts(_("Mandatory arguments to long options are mandatory "
950 "for short options too.\n"));
953 puts(_(" Operation mode:\n"));
956 " -z, --compress force compression\n"
957 " -d, --decompress force decompression\n"
958 " -t, --test test compressed file integrity\n"
959 " -l, --list list information about .xz files"));
962 puts(_("\n Operation modifiers:\n"));
965 " -k, --keep keep (don't delete) input files\n"
966 " -f, --force force overwrite of output file and (de)compress links\n"
967 " -c, --stdout write to standard output and don't delete input files"));
968 // NOTE: --to-stdout isn't included above because it's not
969 // the recommended spelling. It was copied from gzip but other
970 // compressors with gzip-like syntax don't support it.
974 " --single-stream decompress only the first stream, and silently\n"
975 " ignore possible remaining input data"));
977 " --no-sparse do not create sparse files when decompressing\n"
978 " -S, --suffix=.SUF use the suffix '.SUF' on compressed files\n"
979 " --files[=FILE] read filenames to process from FILE; if FILE is\n"
980 " omitted, filenames are read from the standard input;\n"
981 " filenames must be terminated with the newline character\n"
982 " --files0[=FILE] like --files but use the null character as terminator"));
986 puts(_("\n Basic file format and compression options:\n"));
988 " -F, --format=FMT file format to encode or decode; possible values are\n"
989 " 'auto' (default), 'xz', 'lzma', 'lzip', and 'raw'\n"
990 " -C, --check=CHECK integrity check type: 'none' (use with caution),\n"
991 " 'crc32', 'crc64' (default), or 'sha256'"));
993 " --ignore-check don't verify the integrity check when decompressing"));
997 " -0 ... -9 compression preset; default is 6; take compressor *and*\n"
998 " decompressor memory usage into account before using 7-9!"));
1001 " -e, --extreme try to improve compression ratio by using more CPU time;\n"
1002 " does not affect decompressor memory requirements"));
1005 " -T, --threads=NUM use at most NUM threads; the default is 0 which uses\n"
1006 " as many threads as there are processor cores"));
1010 " --block-size=SIZE\n"
1011 " start a new .xz block after every SIZE bytes of input;\n"
1012 " use this to set the block size for threaded compression"));
1014 " --block-list=BLOCKS\n"
1015 " start a new .xz block after the given comma-separated\n"
1016 " intervals of uncompressed data; optionally, specify a\n"
1017 " filter chain number (0-9) followed by a ':' before the\n"
1018 " uncompressed data size"));
1020 " --flush-timeout=TIMEOUT\n"
1021 " when compressing, if more than TIMEOUT milliseconds has\n"
1022 " passed since the previous flush and reading more input\n"
1023 " would block, all pending data is flushed out"
1025 puts(_( // xgettext:no-c-format
1026 " --memlimit-compress=LIMIT\n"
1027 " --memlimit-decompress=LIMIT\n"
1028 " --memlimit-mt-decompress=LIMIT\n"
1029 " -M, --memlimit=LIMIT\n"
1030 " set memory usage limit for compression, decompression,\n"
1031 " threaded decompression, or all of these; LIMIT is in\n"
1032 " bytes, % of RAM, or 0 for defaults"));
1035 " --no-adjust if compression settings exceed the memory usage limit,\n"
1036 " give an error instead of adjusting the settings downwards"));
1041 "\n Custom filter chain for compression (alternative for using presets):"));
1045 " --filters=FILTERS set the filter chain using the liblzma filter string\n"
1046 " syntax; use --filters-help for more information"
1050 " --filters1=FILTERS ... --filters9=FILTERS\n"
1051 " set additional filter chains using the liblzma filter\n"
1052 " string syntax to use with --block-list"
1056 " --filters-help display more information about the liblzma filter string\n"
1060 #if defined(HAVE_ENCODER_LZMA1) || defined(HAVE_DECODER_LZMA1) \
1061 || defined(HAVE_ENCODER_LZMA2) || defined(HAVE_DECODER_LZMA2)
1062 // TRANSLATORS: The word "literal" in "literal context bits"
1063 // means how many "context bits" to use when encoding
1064 // literals. A literal is a single 8-bit byte. It doesn't
1065 // mean "literally" here.
1068 " --lzma1[=OPTS] LZMA1 or LZMA2; OPTS is a comma-separated list of zero or\n"
1069 " --lzma2[=OPTS] more of the following options (valid values; default):\n"
1070 " preset=PRE reset options to a preset (0-9[e])\n"
1071 " dict=NUM dictionary size (4KiB - 1536MiB; 8MiB)\n"
1072 " lc=NUM number of literal context bits (0-4; 3)\n"
1073 " lp=NUM number of literal position bits (0-4; 0)\n"
1074 " pb=NUM number of position bits (0-4; 2)\n"
1075 " mode=MODE compression mode (fast, normal; normal)\n"
1076 " nice=NUM nice length of a match (2-273; 64)\n"
1077 " mf=NAME match finder (hc3, hc4, bt2, bt3, bt4; bt4)\n"
1078 " depth=NUM maximum search depth; 0=automatic (default)"));
1083 " --x86[=OPTS] x86 BCJ filter (32-bit and 64-bit)\n"
1084 " --arm[=OPTS] ARM BCJ filter\n"
1085 " --armthumb[=OPTS] ARM-Thumb BCJ filter\n"
1086 " --arm64[=OPTS] ARM64 BCJ filter\n"
1087 " --powerpc[=OPTS] PowerPC BCJ filter (big endian only)\n"
1088 " --ia64[=OPTS] IA-64 (Itanium) BCJ filter\n"
1089 " --sparc[=OPTS] SPARC BCJ filter\n"
1090 " --riscv[=OPTS] RISC-V BCJ filter\n"
1091 " Valid OPTS for all BCJ filters:\n"
1092 " start=NUM start offset for conversions (default=0)"));
1094 #if defined(HAVE_ENCODER_DELTA) || defined(HAVE_DECODER_DELTA)
1097 " --delta[=OPTS] Delta filter; valid OPTS (valid values; default):\n"
1098 " dist=NUM distance between bytes being subtracted\n"
1099 " from each other (1-256; 1)"));
1104 puts(_("\n Other options:\n"));
1107 " -q, --quiet suppress warnings; specify twice to suppress errors too\n"
1108 " -v, --verbose be verbose; specify twice for even more verbose"));
1112 " -Q, --no-warn make warnings not affect the exit status"));
1114 " --robot use machine-parsable messages (useful for scripts)"));
1117 " --info-memory display the total amount of RAM and the currently active\n"
1118 " memory usage limits, and exit"));
1120 " -h, --help display the short help (lists only the basic options)\n"
1121 " -H, --long-help display this long help and exit"));
1124 " -h, --help display this short help and exit\n"
1125 " -H, --long-help display the long help (lists also the advanced options)"));
1129 " -V, --version display the version number and exit"));
1131 puts(_("\nWith no FILE, or when FILE is -, read standard input.\n"));
1133 // TRANSLATORS: This message indicates the bug reporting address
1134 // for this package. Please add _another line_ saying
1135 // "Report translation bugs to <...>\n" with the email or WWW
1136 // address for translation bugs. Thanks.
1137 printf(_("Report bugs to <%s> (in English or Finnish).\n"),
1139 printf(_("%s home page: <%s>\n"), PACKAGE_NAME
, PACKAGE_URL
);
1141 #if LZMA_VERSION_STABILITY != LZMA_VERSION_STABILITY_STABLE
1143 "THIS IS A DEVELOPMENT VERSION NOT INTENDED FOR PRODUCTION USE."));
1146 tuklib_exit(E_SUCCESS
, E_ERROR
, verbosity
!= V_SILENT
);
1151 message_filters_help(void)
1153 char *encoder_options
;
1154 if (lzma_str_list_filters(&encoder_options
, LZMA_VLI_UNKNOWN
,
1155 LZMA_STR_ENCODER
, NULL
) != LZMA_OK
)
1160 "Filter chains are set using the --filters=FILTERS or\n"
1161 "--filters1=FILTERS ... --filters9=FILTERS options. Each filter in the chain\n"
1162 "can be separated by spaces or '--'. Alternatively a preset <0-9>[e] can be\n"
1163 "specified instead of a filter chain.\n"
1166 puts(_("The supported filters and their options are:"));
1169 puts(encoder_options
);
1171 tuklib_exit(E_SUCCESS
, E_ERROR
, verbosity
!= V_SILENT
);