1 ///////////////////////////////////////////////////////////////////////////////
4 /// \brief Printing messages
6 // Author: Lasse Collin
8 // This file has been put into the public domain.
9 // You can do whatever you want with this file.
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;
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 /// Expected size of the input stream is needed to show completion percentage
60 /// and estimate remaining time.
61 static uint64_t expected_in_size;
64 // Use alarm() and SIGALRM when they are supported. This has two minor
65 // advantages over the alternative of polling gettimeofday():
66 // - It is possible for the user to send SIGINFO, SIGUSR1, or SIGALRM to
67 // get intermediate progress information even when --verbose wasn't used
68 // or stderr is not a terminal.
69 // - alarm() + SIGALRM seems to have slightly less overhead than polling
73 const int message_progress_sigs[] = {
84 /// The signal handler for SIGALRM sets this to true. It is set back to false
85 /// once the progress message has been updated.
86 static volatile sig_atomic_t progress_needs_updating = false;
88 /// Signal handler for SIGALRM
90 progress_signal_handler(int sig lzma_attribute((__unused__)))
92 progress_needs_updating = true;
98 /// This is true when progress message printing is wanted. Using the same
99 /// variable name as above to avoid some ifdefs.
100 static bool progress_needs_updating = false;
102 /// Elapsed time when the next progress message update should be done.
103 static uint64_t progress_next_update;
111 // If --verbose is used, we use a progress indicator if and only
112 // if stderr is a terminal. If stderr is not a terminal, we print
113 // verbose information only after finishing the file. As a special
114 // exception, even if --verbose was not used, user can send SIGALRM
115 // to make us print progress information once without automatic
117 progress_automatic = isatty(STDERR_FILENO);
119 // Commented out because COLUMNS is rarely exported to environment.
120 // Most users have at least 80 columns anyway, let's think something
121 // fancy here if enough people complain.
123 if (progress_automatic) {
124 // stderr is a terminal. Check the COLUMNS environment
125 // variable to see if the terminal is wide enough. If COLUMNS
126 // doesn't exist or it has some unparsable value, we assume
127 // that the terminal is wide enough.
128 const char *columns_str = getenv("COLUMNS");
129 if (columns_str != NULL) {
131 const long columns = strtol(columns_str, &endptr, 10);
132 if (*endptr != '\0' || columns < 80)
133 progress_automatic = false;
139 // Establish the signal handlers which set a flag to tell us that
140 // progress info should be updated.
142 sigemptyset(&sa.sa_mask);
144 sa.sa_handler = &progress_signal_handler;
146 for (size_t i = 0; message_progress_sigs[i] != 0; ++i)
147 if (sigaction(message_progress_sigs[i], &sa, NULL))
148 message_signal_handler();
156 message_verbosity_increase(void)
158 if (verbosity < V_DEBUG)
166 message_verbosity_decrease(void)
168 if (verbosity > V_SILENT)
175 extern enum message_verbosity
176 message_verbosity_get(void)
183 message_set_files(unsigned int files)
190 /// Prints the name of the current file if it hasn't been printed already,
191 /// except if we are processing exactly one stream from stdin to stdout.
192 /// I think it looks nicer to not print "(stdin)" when --verbose is used
193 /// in a pipe and no other files are processed.
197 if (!opt_robot && (files_total != 1 || filename != stdin_filename)) {
200 FILE *file = opt_mode == MODE_LIST ? stdout : stderr;
202 // If a file was already processed, put an empty line
203 // before the next filename to improve readability.
204 if (first_filename_printed)
207 first_filename_printed = true;
208 current_filename_printed = true;
210 // If we don't know how many files there will be due
211 // to usage of --files or --files0.
212 if (files_total == 0)
213 fprintf(file, "%s (%u)\n", filename,
216 fprintf(file, "%s (%u/%u)\n", filename,
217 files_pos, files_total);
227 message_filename(const char *src_name)
229 // Start numbering the files starting from one.
233 if (verbosity >= V_VERBOSE
234 && (progress_automatic || opt_mode == MODE_LIST))
237 current_filename_printed = false;
244 message_progress_start(lzma_stream *strm, uint64_t in_size)
246 // Store the pointer to the lzma_stream used to do the coding.
247 // It is needed to find out the position in the stream.
248 progress_strm = strm;
250 // Store the expected size of the file. If we aren't printing any
251 // statistics, then is will be unused. But since it is possible
252 // that the user sends us a signal to show statistics, we need
253 // to have it available anyway.
254 expected_in_size = in_size;
256 // Indicate that progress info may need to be printed before
257 // printing error messages.
258 progress_started = true;
260 // If progress indicator is wanted, print the filename and possibly
261 // the file count now.
262 if (verbosity >= V_VERBOSE && progress_automatic) {
263 // Start the timer to display the first progress message
264 // after one second. An alternative would be to show the
265 // first message almost immediately, but delaying by one
266 // second looks better to me, since extremely early
267 // progress info is pretty much useless.
269 // First disable a possibly existing alarm.
271 progress_needs_updating = false;
274 progress_needs_updating = true;
275 progress_next_update = 1000;
283 /// Make the string indicating completion percentage.
285 progress_percentage(uint64_t in_pos)
287 // If the size of the input file is unknown or the size told us is
288 // clearly wrong since we have processed more data than the alleged
289 // size of the file, show a static string indicating that we have
290 // no idea of the completion percentage.
291 if (expected_in_size == 0 || in_pos > expected_in_size)
294 // Never show 100.0 % before we actually are finished.
295 double percentage = (double)(in_pos) / (double)(expected_in_size)
298 // Use big enough buffer to hold e.g. a multibyte decimal point.
300 snprintf(buf, sizeof(buf), "%.1f %%", percentage);
306 /// Make the string containing the amount of input processed, amount of
307 /// output produced, and the compression ratio.
309 progress_sizes(uint64_t compressed_pos, uint64_t uncompressed_pos, bool final)
311 // Use big enough buffer to hold e.g. a multibyte thousand separators.
312 static char buf[128];
314 size_t left = sizeof(buf);
316 // Print the sizes. If this the final message, use more reasonable
317 // units than MiB if the file was small.
318 const enum nicestr_unit unit_min = final ? NICESTR_B : NICESTR_MIB;
319 my_snprintf(&pos, &left, "%s / %s",
320 uint64_to_nicestr(compressed_pos,
321 unit_min, NICESTR_TIB, false, 0),
322 uint64_to_nicestr(uncompressed_pos,
323 unit_min, NICESTR_TIB, false, 1));
325 // Avoid division by zero. If we cannot calculate the ratio, set
326 // it to some nice number greater than 10.0 so that it gets caught
327 // in the next if-clause.
328 const double ratio = uncompressed_pos > 0
329 ? (double)(compressed_pos) / (double)(uncompressed_pos)
332 // If the ratio is very bad, just indicate that it is greater than
333 // 9.999. This way the length of the ratio field stays fixed.
335 snprintf(pos, left, " > %.3f", 9.999);
337 snprintf(pos, left, " = %.3f", ratio);
343 /// Make the string containing the processing speed of uncompressed data.
345 progress_speed(uint64_t uncompressed_pos, uint64_t elapsed)
347 // Don't print the speed immediately, since the early values look
352 static const char unit[][8] = {
358 size_t unit_index = 0;
360 // Calculate the speed as KiB/s.
361 double speed = (double)(uncompressed_pos)
362 / ((double)(elapsed) * (1024.0 / 1000.0));
364 // Adjust the unit of the speed if needed.
365 while (speed > 999.0) {
367 if (++unit_index == ARRAY_SIZE(unit))
368 return ""; // Way too fast ;-)
371 // Use decimal point only if the number is small. Examples:
376 // Use big enough buffer to hold e.g. a multibyte decimal point.
378 snprintf(buf, sizeof(buf), "%.*f %s",
379 speed > 9.9 ? 0 : 1, speed, unit[unit_index]);
384 /// Make a string indicating elapsed time. The format is either
385 /// M:SS or H:MM:SS depending on if the time is an hour or more.
387 progress_time(uint64_t mseconds)
389 // 9999 hours = 416 days
390 static char buf[sizeof("9999:59:59")];
392 // 32-bit variable is enough for elapsed time (136 years).
393 uint32_t seconds = (uint32_t)(mseconds / 1000);
395 // Don't show anything if the time is zero or ridiculously big.
396 if (seconds == 0 || seconds > ((9999 * 60) + 59) * 60 + 59)
399 uint32_t minutes = seconds / 60;
403 const uint32_t hours = minutes / 60;
405 snprintf(buf, sizeof(buf),
406 "%" PRIu32 ":%02" PRIu32 ":%02" PRIu32,
407 hours, minutes, seconds);
409 snprintf(buf, sizeof(buf), "%" PRIu32 ":%02" PRIu32,
417 /// Return a string containing estimated remaining time when
418 /// reasonably possible.
420 progress_remaining(uint64_t in_pos, uint64_t elapsed)
422 // Don't show the estimated remaining time when it wouldn't
424 // - Input size is unknown.
425 // - Input has grown bigger since we started (de)compressing.
426 // - We haven't processed much data yet, so estimate would be
428 // - Only a few seconds has passed since we started (de)compressing,
429 // so estimate would be too inaccurate.
430 if (expected_in_size == 0 || in_pos > expected_in_size
431 || in_pos < (UINT64_C(1) << 19) || elapsed < 8000)
434 // Calculate the estimate. Don't give an estimate of zero seconds,
435 // since it is possible that all the input has been already passed
436 // to the library, but there is still quite a bit of output pending.
437 uint32_t remaining = (double)(expected_in_size - in_pos)
438 * ((double)(elapsed) / 1000.0) / (double)(in_pos);
442 static char buf[sizeof("9 h 55 min")];
444 // Select appropriate precision for the estimated remaining time.
445 if (remaining <= 10) {
446 // A maximum of 10 seconds remaining.
447 // Show the number of seconds as is.
448 snprintf(buf, sizeof(buf), "%" PRIu32 " s", remaining);
450 } else if (remaining <= 50) {
451 // A maximum of 50 seconds remaining.
452 // Round up to the next multiple of five seconds.
453 remaining = (remaining + 4) / 5 * 5;
454 snprintf(buf, sizeof(buf), "%" PRIu32 " s", remaining);
456 } else if (remaining <= 590) {
457 // A maximum of 9 minutes and 50 seconds remaining.
458 // Round up to the next multiple of ten seconds.
459 remaining = (remaining + 9) / 10 * 10;
460 snprintf(buf, sizeof(buf), "%" PRIu32 " min %" PRIu32 " s",
461 remaining / 60, remaining % 60);
463 } else if (remaining <= 59 * 60) {
464 // A maximum of 59 minutes remaining.
465 // Round up to the next multiple of a minute.
466 remaining = (remaining + 59) / 60;
467 snprintf(buf, sizeof(buf), "%" PRIu32 " min", remaining);
469 } else if (remaining <= 9 * 3600 + 50 * 60) {
470 // A maximum of 9 hours and 50 minutes left.
471 // Round up to the next multiple of ten minutes.
472 remaining = (remaining + 599) / 600 * 10;
473 snprintf(buf, sizeof(buf), "%" PRIu32 " h %" PRIu32 " min",
474 remaining / 60, remaining % 60);
476 } else if (remaining <= 23 * 3600) {
477 // A maximum of 23 hours remaining.
478 // Round up to the next multiple of an hour.
479 remaining = (remaining + 3599) / 3600;
480 snprintf(buf, sizeof(buf), "%" PRIu32 " h", remaining);
482 } else if (remaining <= 9 * 24 * 3600 + 23 * 3600) {
483 // A maximum of 9 days and 23 hours remaining.
484 // Round up to the next multiple of an hour.
485 remaining = (remaining + 3599) / 3600;
486 snprintf(buf, sizeof(buf), "%" PRIu32 " d %" PRIu32 " h",
487 remaining / 24, remaining % 24);
489 } else if (remaining <= 999 * 24 * 3600) {
490 // A maximum of 999 days remaining. ;-)
491 // Round up to the next multiple of a day.
492 remaining = (remaining + 24 * 3600 - 1) / (24 * 3600);
493 snprintf(buf, sizeof(buf), "%" PRIu32 " d", remaining);
496 // The estimated remaining time is too big. Don't show it.
504 /// Get how much uncompressed and compressed data has been processed.
506 progress_pos(uint64_t *in_pos,
507 uint64_t *compressed_pos, uint64_t *uncompressed_pos)
510 lzma_get_progress(progress_strm, in_pos, &out_pos);
512 // It cannot have processed more input than it has been given.
513 assert(*in_pos <= progress_strm->total_in);
515 // It cannot have produced more output than it claims to have ready.
516 assert(out_pos >= progress_strm->total_out);
518 if (opt_mode == MODE_COMPRESS) {
519 *compressed_pos = out_pos;
520 *uncompressed_pos = *in_pos;
522 *compressed_pos = *in_pos;
523 *uncompressed_pos = out_pos;
531 message_progress_update(void)
533 if (!progress_needs_updating)
536 // Calculate how long we have been processing this file.
537 const uint64_t elapsed = mytime_get_elapsed();
540 if (progress_next_update > elapsed)
543 progress_next_update = elapsed + 1000;
546 // Get our current position in the stream.
548 uint64_t compressed_pos;
549 uint64_t uncompressed_pos;
550 progress_pos(&in_pos, &compressed_pos, &uncompressed_pos);
552 // Block signals so that fprintf() doesn't get interrupted.
555 // Print the filename if it hasn't been printed yet.
556 if (!current_filename_printed)
559 // Print the actual progress message. The idea is that there is at
560 // least three spaces between the fields in typical situations, but
561 // even in rare situations there is at least one space.
562 const char *cols[5] = {
563 progress_percentage(in_pos),
564 progress_sizes(compressed_pos, uncompressed_pos, false),
565 progress_speed(uncompressed_pos, elapsed),
566 progress_time(elapsed),
567 progress_remaining(in_pos, elapsed),
569 fprintf(stderr, "\r %*s %*s %*s %10s %10s\r",
570 tuklib_mbstr_fw(cols[0], 6), cols[0],
571 tuklib_mbstr_fw(cols[1], 35), cols[1],
572 tuklib_mbstr_fw(cols[2], 9), cols[2],
577 // Updating the progress info was finished. Reset
578 // progress_needs_updating to wait for the next SIGALRM.
580 // NOTE: This has to be done before alarm(1) or with (very) bad
581 // luck we could be setting this to false after the alarm has already
583 progress_needs_updating = false;
585 if (verbosity >= V_VERBOSE && progress_automatic) {
586 // Mark that the progress indicator is active, so if an error
587 // occurs, the error message gets printed cleanly.
588 progress_active = true;
590 // Restart the timer so that progress_needs_updating gets
591 // set to true after about one second.
594 // The progress message was printed because user had sent us
595 // SIGALRM. In this case, each progress message is printed
600 // When SIGALRM isn't supported and we get here, it's always due to
601 // automatic progress update. We set progress_active here too like
603 assert(verbosity >= V_VERBOSE);
604 assert(progress_automatic);
605 progress_active = true;
615 progress_flush(bool finished)
617 if (!progress_started || verbosity < V_VERBOSE)
621 uint64_t compressed_pos;
622 uint64_t uncompressed_pos;
623 progress_pos(&in_pos, &compressed_pos, &uncompressed_pos);
625 // Avoid printing intermediate progress info if some error occurs
626 // in the beginning of the stream. (If something goes wrong later in
627 // the stream, it is sometimes useful to tell the user where the
628 // error approximately occurred, especially if the error occurs
629 // after a time-consuming operation.)
630 if (!finished && !progress_active
631 && (compressed_pos == 0 || uncompressed_pos == 0))
634 progress_active = false;
636 const uint64_t elapsed = mytime_get_elapsed();
640 // When using the auto-updating progress indicator, the final
641 // statistics are printed in the same format as the progress
643 if (progress_automatic) {
644 const char *cols[5] = {
645 finished ? "100 %" : progress_percentage(in_pos),
646 progress_sizes(compressed_pos, uncompressed_pos, true),
647 progress_speed(uncompressed_pos, elapsed),
648 progress_time(elapsed),
649 finished ? "" : progress_remaining(in_pos, elapsed),
651 fprintf(stderr, "\r %*s %*s %*s %10s %10s\n",
652 tuklib_mbstr_fw(cols[0], 6), cols[0],
653 tuklib_mbstr_fw(cols[1], 35), cols[1],
654 tuklib_mbstr_fw(cols[2], 9), cols[2],
658 // The filename is always printed.
659 fprintf(stderr, "%s: ", filename);
661 // Percentage is printed only if we didn't finish yet.
663 // Don't print the percentage when it isn't known
664 // (starts with a dash).
665 const char *percentage = progress_percentage(in_pos);
666 if (percentage[0] != '-')
667 fprintf(stderr, "%s, ", percentage);
670 // Size information is always printed.
671 fprintf(stderr, "%s", progress_sizes(
672 compressed_pos, uncompressed_pos, true));
674 // The speed and elapsed time aren't always shown.
675 const char *speed = progress_speed(uncompressed_pos, elapsed);
676 if (speed[0] != '\0')
677 fprintf(stderr, ", %s", speed);
679 const char *elapsed_str = progress_time(elapsed);
680 if (elapsed_str[0] != '\0')
681 fprintf(stderr, ", %s", elapsed_str);
693 message_progress_end(bool success)
695 assert(progress_started);
696 progress_flush(success);
697 progress_started = false;
703 vmessage(enum message_verbosity v, const char *fmt, va_list ap)
705 if (v <= verbosity) {
708 progress_flush(false);
710 // TRANSLATORS: This is the program name in the beginning
711 // of the line in messages. Usually it becomes "xz: ".
712 // This is a translatable string because French needs
713 // a space before a colon.
714 fprintf(stderr, _("%s: "), progname);
715 vfprintf(stderr, fmt, ap);
726 message(enum message_verbosity v, const char *fmt, ...)
730 vmessage(v, fmt, ap);
737 message_warning(const char *fmt, ...)
741 vmessage(V_WARNING, fmt, ap);
744 set_exit_status(E_WARNING);
750 message_error(const char *fmt, ...)
754 vmessage(V_ERROR, fmt, ap);
757 set_exit_status(E_ERROR);
763 message_fatal(const char *fmt, ...)
767 vmessage(V_ERROR, fmt, ap);
770 tuklib_exit(E_ERROR, E_ERROR, false);
777 message_fatal(_("Internal error (bug)"));
782 message_signal_handler(void)
784 message_fatal(_("Cannot establish signal handlers"));
789 message_strm(lzma_ret code)
793 return _("No integrity check; not verifying file integrity");
795 case LZMA_UNSUPPORTED_CHECK:
796 return _("Unsupported type of integrity check; "
797 "not verifying file integrity");
800 return strerror(ENOMEM);
802 case LZMA_MEMLIMIT_ERROR:
803 return _("Memory usage limit reached");
805 case LZMA_FORMAT_ERROR:
806 return _("File format not recognized");
808 case LZMA_OPTIONS_ERROR:
809 return _("Unsupported options");
811 case LZMA_DATA_ERROR:
812 return _("Compressed data is corrupt");
815 return _("Unexpected end of input");
818 case LZMA_STREAM_END:
820 case LZMA_PROG_ERROR:
821 // Without "default", compiler will warn if new constants
822 // are added to lzma_ret, it is not too easy to forget to
823 // add the new constants to this function.
827 return _("Internal error (bug)");
832 message_mem_needed(enum message_verbosity v, uint64_t memusage)
837 // Convert memusage to MiB, rounding up to the next full MiB.
838 // This way the user can always use the displayed usage as
839 // the new memory usage limit. (If we rounded to the nearest,
840 // the user might need to +1 MiB to get high enough limit.)
841 memusage = round_up_to_mib(memusage);
843 uint64_t memlimit = hardware_memlimit_get(opt_mode);
845 // Handle the case when there is no memory usage limit.
846 // This way we don't print a weird message with a huge number.
847 if (memlimit == UINT64_MAX) {
848 message(v, _("%s MiB of memory is required. "
849 "The limiter is disabled."),
850 uint64_to_str(memusage, 0));
855 // 2^64 with thousand separators + " MiB" suffix + '\0' = 26 + 4 + 1
856 // But there may be multibyte chars so reserve enough space.
857 char memlimitstr[128];
859 // Show the memory usage limit as MiB unless it is less than 1 MiB.
860 // This way it's easy to notice errors where one has typed
861 // --memory=123 instead of --memory=123MiB.
862 if (memlimit < (UINT32_C(1) << 20)) {
863 snprintf(memlimitstr, sizeof(memlimitstr), "%s B",
864 uint64_to_str(memlimit, 1));
866 // Round up just like with memusage. If this function is
867 // called for informational purposes (to just show the
868 // current usage and limit), we should never show that
869 // the usage is higher than the limit, which would give
870 // a false impression that the memory usage limit isn't
871 // properly enforced.
872 snprintf(memlimitstr, sizeof(memlimitstr), "%s MiB",
873 uint64_to_str(round_up_to_mib(memlimit), 1));
876 message(v, _("%s MiB of memory is required. The limit is %s."),
877 uint64_to_str(memusage, 0), memlimitstr);
883 /// \brief Convert uint32_t to a nice string for --lzma[12]=dict=SIZE
885 /// The idea is to use KiB or MiB suffix when possible.
887 uint32_to_optstr(uint32_t num)
891 if ((num & ((UINT32_C(1) << 20) - 1)) == 0)
892 snprintf(buf, sizeof(buf), "%" PRIu32 "MiB", num >> 20);
893 else if ((num & ((UINT32_C(1) << 10) - 1)) == 0)
894 snprintf(buf, sizeof(buf), "%" PRIu32 "KiB", num >> 10);
896 snprintf(buf, sizeof(buf), "%" PRIu32, num);
903 message_filters_to_str(char buf[FILTERS_STR_SIZE],
904 const lzma_filter *filters, bool all_known)
907 size_t left = FILTERS_STR_SIZE;
909 for (size_t i = 0; filters[i].id != LZMA_VLI_UNKNOWN; ++i) {
910 // Add the dashes for the filter option. A space is
911 // needed after the first and later filters.
912 my_snprintf(&pos, &left, "%s", i == 0 ? "--" : " --");
914 switch (filters[i].id) {
915 case LZMA_FILTER_LZMA1:
916 case LZMA_FILTER_LZMA2: {
917 const lzma_options_lzma *opt = filters[i].options;
918 const char *mode = NULL;
919 const char *mf = NULL;
927 case LZMA_MODE_NORMAL:
963 // Add the filter name and dictionary size, which
965 my_snprintf(&pos, &left, "lzma%c=dict=%s",
966 filters[i].id == LZMA_FILTER_LZMA2
968 uint32_to_optstr(opt->dict_size));
970 // With LZMA1 also lc/lp/pb are known when
971 // decompressing, but this function is never
972 // used to print information about .lzma headers.
973 assert(filters[i].id == LZMA_FILTER_LZMA2
976 // Print the rest of the options, which are known
977 // only when compressing.
979 my_snprintf(&pos, &left,
980 ",lc=%" PRIu32 ",lp=%" PRIu32
982 ",mode=%s,nice=%" PRIu32 ",mf=%s"
984 opt->lc, opt->lp, opt->pb,
985 mode, opt->nice_len, mf, opt->depth);
989 case LZMA_FILTER_X86:
990 case LZMA_FILTER_POWERPC:
991 case LZMA_FILTER_IA64:
992 case LZMA_FILTER_ARM:
993 case LZMA_FILTER_ARMTHUMB:
994 case LZMA_FILTER_SPARC: {
995 static const char bcj_names[][9] = {
1004 const lzma_options_bcj *opt = filters[i].options;
1005 my_snprintf(&pos, &left, "%s", bcj_names[filters[i].id
1006 - LZMA_FILTER_X86]);
1008 // Show the start offset only when really needed.
1009 if (opt != NULL && opt->start_offset != 0)
1010 my_snprintf(&pos, &left, "=start=%" PRIu32,
1016 case LZMA_FILTER_DELTA: {
1017 const lzma_options_delta *opt = filters[i].options;
1018 my_snprintf(&pos, &left, "delta=dist=%" PRIu32,
1024 // This should be possible only if liblzma is
1025 // newer than the xz tool.
1026 my_snprintf(&pos, &left, "UNKNOWN");
1036 message_filters_show(enum message_verbosity v, const lzma_filter *filters)
1041 char buf[FILTERS_STR_SIZE];
1042 message_filters_to_str(buf, filters, true);
1043 fprintf(stderr, _("%s: Filter chain: %s\n"), progname, buf);
1049 message_try_help(void)
1051 // Print this with V_WARNING instead of V_ERROR to prevent it from
1052 // showing up when --quiet has been specified.
1053 message(V_WARNING, _("Try `%s --help' for more information."),
1060 message_version(void)
1062 // It is possible that liblzma version is different than the command
1063 // line tool version, so print both.
1065 printf("XZ_VERSION=%" PRIu32 "\nLIBLZMA_VERSION=%" PRIu32 "\n",
1066 LZMA_VERSION, lzma_version_number());
1068 printf("xz (" PACKAGE_NAME ") " LZMA_VERSION_STRING "\n");
1069 printf("liblzma %s\n", lzma_version_string());
1072 tuklib_exit(E_SUCCESS, E_ERROR, verbosity != V_SILENT);
1077 message_help(bool long_help)
1079 printf(_("Usage: %s [OPTION]... [FILE]...\n"
1080 "Compress or decompress FILEs in the .xz format.\n\n"),
1083 // NOTE: The short help doesn't currently have options that
1086 puts(_("Mandatory arguments to long options are mandatory "
1087 "for short options too.\n"));
1090 puts(_(" Operation mode:\n"));
1093 " -z, --compress force compression\n"
1094 " -d, --decompress force decompression\n"
1095 " -t, --test test compressed file integrity\n"
1096 " -l, --list list information about .xz files"));
1099 puts(_("\n Operation modifiers:\n"));
1102 " -k, --keep keep (don't delete) input files\n"
1103 " -f, --force force overwrite of output file and (de)compress links\n"
1104 " -c, --stdout write to standard output and don't delete input files"));
1108 " --single-stream decompress only the first stream, and silently\n"
1109 " ignore possible remaining input data"));
1111 " --no-sparse do not create sparse files when decompressing\n"
1112 " -S, --suffix=.SUF use the suffix `.SUF' on compressed files\n"
1113 " --files[=FILE] read filenames to process from FILE; if FILE is\n"
1114 " omitted, filenames are read from the standard input;\n"
1115 " filenames must be terminated with the newline character\n"
1116 " --files0[=FILE] like --files but use the null character as terminator"));
1120 puts(_("\n Basic file format and compression options:\n"));
1122 " -F, --format=FMT file format to encode or decode; possible values are\n"
1123 " `auto' (default), `xz', `lzma', and `raw'\n"
1124 " -C, --check=CHECK integrity check type: `none' (use with caution),\n"
1125 " `crc32', `crc64' (default), or `sha256'"));
1127 " --ignore-check don't verify the integrity check when decompressing"));
1131 " -0 ... -9 compression preset; default is 6; take compressor *and*\n"
1132 " decompressor memory usage into account before using 7-9!"));
1135 " -e, --extreme try to improve compression ratio by using more CPU time;\n"
1136 " does not affect decompressor memory requirements"));
1139 " -T, --threads=NUM use at most NUM threads; the default is 1; set to 0\n"
1140 " to use as many threads as there are processor cores"));
1144 " --block-size=SIZE\n"
1145 " start a new .xz block after every SIZE bytes of input;\n"
1146 " use this to set the block size for threaded compression"));
1148 " --block-list=SIZES\n"
1149 " start a new .xz block after the given comma-separated\n"
1150 " intervals of uncompressed data"));
1152 " --flush-timeout=TIMEOUT\n"
1153 " when compressing, if more than TIMEOUT milliseconds has\n"
1154 " passed since the previous flush and reading more input\n"
1155 " would block, all pending data is flushed out"
1157 puts(_( // xgettext:no-c-format
1158 " --memlimit-compress=LIMIT\n"
1159 " --memlimit-decompress=LIMIT\n"
1160 " -M, --memlimit=LIMIT\n"
1161 " set memory usage limit for compression, decompression,\n"
1162 " or both; LIMIT is in bytes, % of RAM, or 0 for defaults"));
1165 " --no-adjust if compression settings exceed the memory usage limit,\n"
1166 " give an error instead of adjusting the settings downwards"));
1171 "\n Custom filter chain for compression (alternative for using presets):"));
1173 #if defined(HAVE_ENCODER_LZMA1) || defined(HAVE_DECODER_LZMA1) \
1174 || defined(HAVE_ENCODER_LZMA2) || defined(HAVE_DECODER_LZMA2)
1175 // TRANSLATORS: The word "literal" in "literal context bits"
1176 // means how many "context bits" to use when encoding
1177 // literals. A literal is a single 8-bit byte. It doesn't
1178 // mean "literally" here.
1181 " --lzma1[=OPTS] LZMA1 or LZMA2; OPTS is a comma-separated list of zero or\n"
1182 " --lzma2[=OPTS] more of the following options (valid values; default):\n"
1183 " preset=PRE reset options to a preset (0-9[e])\n"
1184 " dict=NUM dictionary size (4KiB - 1536MiB; 8MiB)\n"
1185 " lc=NUM number of literal context bits (0-4; 3)\n"
1186 " lp=NUM number of literal position bits (0-4; 0)\n"
1187 " pb=NUM number of position bits (0-4; 2)\n"
1188 " mode=MODE compression mode (fast, normal; normal)\n"
1189 " nice=NUM nice length of a match (2-273; 64)\n"
1190 " mf=NAME match finder (hc3, hc4, bt2, bt3, bt4; bt4)\n"
1191 " depth=NUM maximum search depth; 0=automatic (default)"));
1196 " --x86[=OPTS] x86 BCJ filter (32-bit and 64-bit)\n"
1197 " --powerpc[=OPTS] PowerPC BCJ filter (big endian only)\n"
1198 " --ia64[=OPTS] IA-64 (Itanium) BCJ filter\n"
1199 " --arm[=OPTS] ARM BCJ filter (little endian only)\n"
1200 " --armthumb[=OPTS] ARM-Thumb BCJ filter (little endian only)\n"
1201 " --sparc[=OPTS] SPARC BCJ filter\n"
1202 " Valid OPTS for all BCJ filters:\n"
1203 " start=NUM start offset for conversions (default=0)"));
1205 #if defined(HAVE_ENCODER_DELTA) || defined(HAVE_DECODER_DELTA)
1208 " --delta[=OPTS] Delta filter; valid OPTS (valid values; default):\n"
1209 " dist=NUM distance between bytes being subtracted\n"
1210 " from each other (1-256; 1)"));
1215 puts(_("\n Other options:\n"));
1218 " -q, --quiet suppress warnings; specify twice to suppress errors too\n"
1219 " -v, --verbose be verbose; specify twice for even more verbose"));
1223 " -Q, --no-warn make warnings not affect the exit status"));
1225 " --robot use machine-parsable messages (useful for scripts)"));
1228 " --info-memory display the total amount of RAM and the currently active\n"
1229 " memory usage limits, and exit"));
1231 " -h, --help display the short help (lists only the basic options)\n"
1232 " -H, --long-help display this long help and exit"));
1235 " -h, --help display this short help and exit\n"
1236 " -H, --long-help display the long help (lists also the advanced options)"));
1240 " -V, --version display the version number and exit"));
1242 puts(_("\nWith no FILE, or when FILE is -, read standard input.\n"));
1244 // TRANSLATORS: This message indicates the bug reporting address
1245 // for this package. Please add _another line_ saying
1246 // "Report translation bugs to <...>\n" with the email or WWW
1247 // address for translation bugs. Thanks.
1248 printf(_("Report bugs to <%s> (in English or Finnish).\n"),
1250 printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
1252 #if LZMA_VERSION_STABILITY != LZMA_VERSION_STABILITY_STABLE
1254 "THIS IS A DEVELOPMENT VERSION NOT INTENDED FOR PRODUCTION USE."));
1257 tuklib_exit(E_SUCCESS, E_ERROR, verbosity != V_SILENT);