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 ///////////////////////////////////////////////////////////////////////////////
15 #ifdef HAVE_SYS_TIME_H
16 # include <sys/time.h>
22 /// Number of the current file
23 static unsigned int files_pos = 0;
25 /// Total number of input files; zero if unknown.
26 static unsigned int files_total;
29 static enum message_verbosity verbosity = V_WARNING;
31 /// Filename which we will print with the verbose messages
32 static const char *filename;
34 /// True once the a filename has been printed to stderr as part of progress
35 /// message. If automatic progress updating isn't enabled, this becomes true
36 /// after the first progress message has been printed due to user sending
37 /// SIGINFO, SIGUSR1, or SIGALRM. Once this variable is true, we will print
38 /// an empty line before the next filename to make the output more readable.
39 static bool first_filename_printed = false;
41 /// This is set to true when we have printed the current filename to stderr
42 /// as part of a progress message. This variable is useful only if not
43 /// updating progress automatically: if user sends many SIGINFO, SIGUSR1, or
44 /// SIGALRM signals, we won't print the name of the same file multiple times.
45 static bool current_filename_printed = false;
47 /// True if we should print progress indicator and update it automatically
48 /// if also verbose >= V_VERBOSE.
49 static bool progress_automatic;
51 /// True if message_progress_start() has been called but
52 /// message_progress_end() hasn't been called yet.
53 static bool progress_started = false;
55 /// This is true when a progress message was printed and the cursor is still
56 /// on the same line with the progress message. In that case, a newline has
57 /// to be printed before any error messages.
58 static bool progress_active = false;
60 /// Pointer to lzma_stream used to do the encoding or decoding.
61 static lzma_stream *progress_strm;
63 /// Expected size of the input stream is needed to show completion percentage
64 /// and estimate remaining time.
65 static uint64_t expected_in_size;
67 /// Time when we started processing the file
68 static uint64_t start_time;
71 // Use alarm() and SIGALRM when they are supported. This has two minor
72 // advantages over the alternative of polling gettimeofday():
73 // - It is possible for the user to send SIGINFO, SIGUSR1, or SIGALRM to
74 // get intermediate progress information even when --verbose wasn't used
75 // or stderr is not a terminal.
76 // - alarm() + SIGALRM seems to have slightly less overhead than polling
80 /// The signal handler for SIGALRM sets this to true. It is set back to false
81 /// once the progress message has been updated.
82 static volatile sig_atomic_t progress_needs_updating = false;
84 /// Signal handler for SIGALRM
86 progress_signal_handler(int sig lzma_attribute((unused)))
88 progress_needs_updating = true;
94 /// This is true when progress message printing is wanted. Using the same
95 /// variable name as above to avoid some ifdefs.
96 static bool progress_needs_updating = false;
98 /// Elapsed time when the next progress message update should be done.
99 static uint64_t progress_next_update;
104 /// Get the current time as microseconds since epoch
109 gettimeofday(&tv, NULL);
110 return (uint64_t)(tv.tv_sec) * UINT64_C(1000000) + tv.tv_usec;
117 // If --verbose is used, we use a progress indicator if and only
118 // if stderr is a terminal. If stderr is not a terminal, we print
119 // verbose information only after finishing the file. As a special
120 // exception, even if --verbose was not used, user can send SIGALRM
121 // to make us print progress information once without automatic
123 progress_automatic = isatty(STDERR_FILENO);
125 // Commented out because COLUMNS is rarely exported to environment.
126 // Most users have at least 80 columns anyway, let's think something
127 // fancy here if enough people complain.
129 if (progress_automatic) {
130 // stderr is a terminal. Check the COLUMNS environment
131 // variable to see if the terminal is wide enough. If COLUMNS
132 // doesn't exist or it has some unparsable value, we assume
133 // that the terminal is wide enough.
134 const char *columns_str = getenv("COLUMNS");
135 if (columns_str != NULL) {
137 const long columns = strtol(columns_str, &endptr, 10);
138 if (*endptr != '\0' || columns < 80)
139 progress_automatic = false;
145 // DJGPP lacks SA_RESTART, but it shouldn't give EINTR
146 // in most places either.
147 # if defined(__DJGPP__) && !defined(SA_RESTART)
148 # define SA_RESTART 0
151 // Establish the signal handlers which set a flag to tell us that
152 // progress info should be updated. Since these signals don't
153 // require any quick action, we set SA_RESTART. That way we don't
154 // need to block them either in signals_block() to keep stdio
155 // functions from getting EINTR.
156 static const int sigs[] = {
167 sigemptyset(&sa.sa_mask);
168 sa.sa_flags = SA_RESTART;
169 sa.sa_handler = &progress_signal_handler;
171 for (size_t i = 0; i < ARRAY_SIZE(sigs); ++i)
172 if (sigaction(sigs[i], &sa, NULL))
173 message_signal_handler();
181 message_verbosity_increase(void)
183 if (verbosity < V_DEBUG)
191 message_verbosity_decrease(void)
193 if (verbosity > V_SILENT)
200 extern enum message_verbosity
201 message_verbosity_get(void)
208 message_set_files(unsigned int files)
215 /// Prints the name of the current file if it hasn't been printed already,
216 /// except if we are processing exactly one stream from stdin to stdout.
217 /// I think it looks nicer to not print "(stdin)" when --verbose is used
218 /// in a pipe and no other files are processed.
222 if (files_total != 1 || filename != stdin_filename) {
225 FILE *file = opt_mode == MODE_LIST ? stdout : stderr;
227 // If a file was already processed, put an empty line
228 // before the next filename to improve readability.
229 if (first_filename_printed)
232 first_filename_printed = true;
233 current_filename_printed = true;
235 // If we don't know how many files there will be due
236 // to usage of --files or --files0.
237 if (files_total == 0)
238 fprintf(file, "%s (%u)\n", filename,
241 fprintf(file, "%s (%u/%u)\n", filename,
242 files_pos, files_total);
252 message_filename(const char *src_name)
254 // Start numbering the files starting from one.
258 if (verbosity >= V_VERBOSE
259 && (progress_automatic || opt_mode == MODE_LIST))
262 current_filename_printed = false;
269 message_progress_start(lzma_stream *strm, uint64_t in_size)
271 // Store the pointer to the lzma_stream used to do the coding.
272 // It is needed to find out the position in the stream.
273 progress_strm = strm;
275 // Store the processing start time of the file and its expected size.
276 // If we aren't printing any statistics, then these are unused. But
277 // since it is possible that the user sends us a signal to show
278 // statistics, we need to have these available anyway.
279 start_time = my_time();
280 expected_in_size = in_size;
282 // Indicate that progress info may need to be printed before
283 // printing error messages.
284 progress_started = true;
286 // If progress indicator is wanted, print the filename and possibly
287 // the file count now.
288 if (verbosity >= V_VERBOSE && progress_automatic) {
289 // Start the timer to display the first progress message
290 // after one second. An alternative would be to show the
291 // first message almost immediately, but delaying by one
292 // second looks better to me, since extremely early
293 // progress info is pretty much useless.
295 // First disable a possibly existing alarm.
297 progress_needs_updating = false;
300 progress_needs_updating = true;
301 progress_next_update = 1000000;
309 /// Make the string indicating completion percentage.
311 progress_percentage(uint64_t in_pos)
313 // If the size of the input file is unknown or the size told us is
314 // clearly wrong since we have processed more data than the alleged
315 // size of the file, show a static string indicating that we have
316 // no idea of the completion percentage.
317 if (expected_in_size == 0 || in_pos > expected_in_size)
320 // Never show 100.0 % before we actually are finished.
321 double percentage = (double)(in_pos) / (double)(expected_in_size)
324 // Use big enough buffer to hold e.g. a multibyte decimal point.
326 snprintf(buf, sizeof(buf), "%.1f %%", percentage);
332 /// Make the string containing the amount of input processed, amount of
333 /// output produced, and the compression ratio.
335 progress_sizes(uint64_t compressed_pos, uint64_t uncompressed_pos, bool final)
337 // Use big enough buffer to hold e.g. a multibyte thousand separators.
338 static char buf[128];
340 size_t left = sizeof(buf);
342 // Print the sizes. If this the final message, use more reasonable
343 // units than MiB if the file was small.
344 const enum nicestr_unit unit_min = final ? NICESTR_B : NICESTR_MIB;
345 my_snprintf(&pos, &left, "%s / %s",
346 uint64_to_nicestr(compressed_pos,
347 unit_min, NICESTR_TIB, false, 0),
348 uint64_to_nicestr(uncompressed_pos,
349 unit_min, NICESTR_TIB, false, 1));
351 // Avoid division by zero. If we cannot calculate the ratio, set
352 // it to some nice number greater than 10.0 so that it gets caught
353 // in the next if-clause.
354 const double ratio = uncompressed_pos > 0
355 ? (double)(compressed_pos) / (double)(uncompressed_pos)
358 // If the ratio is very bad, just indicate that it is greater than
359 // 9.999. This way the length of the ratio field stays fixed.
361 snprintf(pos, left, " > %.3f", 9.999);
363 snprintf(pos, left, " = %.3f", ratio);
369 /// Make the string containing the processing speed of uncompressed data.
371 progress_speed(uint64_t uncompressed_pos, uint64_t elapsed)
373 // Don't print the speed immediately, since the early values look
375 if (elapsed < 3000000)
378 static const char unit[][8] = {
384 size_t unit_index = 0;
386 // Calculate the speed as KiB/s.
387 double speed = (double)(uncompressed_pos)
388 / ((double)(elapsed) * (1024.0 / 1e6));
390 // Adjust the unit of the speed if needed.
391 while (speed > 999.0) {
393 if (++unit_index == ARRAY_SIZE(unit))
394 return ""; // Way too fast ;-)
397 // Use decimal point only if the number is small. Examples:
402 // Use big enough buffer to hold e.g. a multibyte decimal point.
404 snprintf(buf, sizeof(buf), "%.*f %s",
405 speed > 9.9 ? 0 : 1, speed, unit[unit_index]);
410 /// Make a string indicating elapsed or remaining time. The format is either
411 /// M:SS or H:MM:SS depending on if the time is an hour or more.
413 progress_time(uint64_t useconds)
415 // 9999 hours = 416 days
416 static char buf[sizeof("9999:59:59")];
418 uint32_t seconds = useconds / 1000000;
420 // Don't show anything if the time is zero or ridiculously big.
421 if (seconds == 0 || seconds > ((9999 * 60) + 59) * 60 + 59)
424 uint32_t minutes = seconds / 60;
428 const uint32_t hours = minutes / 60;
430 snprintf(buf, sizeof(buf),
431 "%" PRIu32 ":%02" PRIu32 ":%02" PRIu32,
432 hours, minutes, seconds);
434 snprintf(buf, sizeof(buf), "%" PRIu32 ":%02" PRIu32,
442 /// Return a string containing estimated remaining time when
443 /// reasonably possible.
445 progress_remaining(uint64_t in_pos, uint64_t elapsed)
447 // Don't show the estimated remaining time when it wouldn't
449 // - Input size is unknown.
450 // - Input has grown bigger since we started (de)compressing.
451 // - We haven't processed much data yet, so estimate would be
453 // - Only a few seconds has passed since we started (de)compressing,
454 // so estimate would be too inaccurate.
455 if (expected_in_size == 0 || in_pos > expected_in_size
456 || in_pos < (UINT64_C(1) << 19) || elapsed < 8000000)
459 // Calculate the estimate. Don't give an estimate of zero seconds,
460 // since it is possible that all the input has been already passed
461 // to the library, but there is still quite a bit of output pending.
462 uint32_t remaining = (double)(expected_in_size - in_pos)
463 * ((double)(elapsed) / 1e6) / (double)(in_pos);
467 static char buf[sizeof("9 h 55 min")];
469 // Select appropriate precision for the estimated remaining time.
470 if (remaining <= 10) {
471 // A maximum of 10 seconds remaining.
472 // Show the number of seconds as is.
473 snprintf(buf, sizeof(buf), "%" PRIu32 " s", remaining);
475 } else if (remaining <= 50) {
476 // A maximum of 50 seconds remaining.
477 // Round up to the next multiple of five seconds.
478 remaining = (remaining + 4) / 5 * 5;
479 snprintf(buf, sizeof(buf), "%" PRIu32 " s", remaining);
481 } else if (remaining <= 590) {
482 // A maximum of 9 minutes and 50 seconds remaining.
483 // Round up to the next multiple of ten seconds.
484 remaining = (remaining + 9) / 10 * 10;
485 snprintf(buf, sizeof(buf), "%" PRIu32 " min %" PRIu32 " s",
486 remaining / 60, remaining % 60);
488 } else if (remaining <= 59 * 60) {
489 // A maximum of 59 minutes remaining.
490 // Round up to the next multiple of a minute.
491 remaining = (remaining + 59) / 60;
492 snprintf(buf, sizeof(buf), "%" PRIu32 " min", remaining);
494 } else if (remaining <= 9 * 3600 + 50 * 60) {
495 // A maximum of 9 hours and 50 minutes left.
496 // Round up to the next multiple of ten minutes.
497 remaining = (remaining + 599) / 600 * 10;
498 snprintf(buf, sizeof(buf), "%" PRIu32 " h %" PRIu32 " min",
499 remaining / 60, remaining % 60);
501 } else if (remaining <= 23 * 3600) {
502 // A maximum of 23 hours remaining.
503 // Round up to the next multiple of an hour.
504 remaining = (remaining + 3599) / 3600;
505 snprintf(buf, sizeof(buf), "%" PRIu32 " h", remaining);
507 } else if (remaining <= 9 * 24 * 3600 + 23 * 3600) {
508 // A maximum of 9 days and 23 hours remaining.
509 // Round up to the next multiple of an hour.
510 remaining = (remaining + 3599) / 3600;
511 snprintf(buf, sizeof(buf), "%" PRIu32 " d %" PRIu32 " h",
512 remaining / 24, remaining % 24);
514 } else if (remaining <= 999 * 24 * 3600) {
515 // A maximum of 999 days remaining. ;-)
516 // Round up to the next multiple of a day.
517 remaining = (remaining + 24 * 3600 - 1) / (24 * 3600);
518 snprintf(buf, sizeof(buf), "%" PRIu32 " d", remaining);
521 // The estimated remaining time is too big. Don't show it.
529 /// Calculate the elapsed time as microseconds.
531 progress_elapsed(void)
533 return my_time() - start_time;
537 /// Get information about position in the stream. This is currently simple,
538 /// but it will become more complicated once we have multithreading support.
540 progress_pos(uint64_t *in_pos,
541 uint64_t *compressed_pos, uint64_t *uncompressed_pos)
543 *in_pos = progress_strm->total_in;
545 if (opt_mode == MODE_COMPRESS) {
546 *compressed_pos = progress_strm->total_out;
547 *uncompressed_pos = progress_strm->total_in;
549 *compressed_pos = progress_strm->total_in;
550 *uncompressed_pos = progress_strm->total_out;
558 message_progress_update(void)
560 if (!progress_needs_updating)
563 // Calculate how long we have been processing this file.
564 const uint64_t elapsed = progress_elapsed();
567 if (progress_next_update > elapsed)
570 progress_next_update = elapsed + 1000000;
573 // Get our current position in the stream.
575 uint64_t compressed_pos;
576 uint64_t uncompressed_pos;
577 progress_pos(&in_pos, &compressed_pos, &uncompressed_pos);
579 // Block signals so that fprintf() doesn't get interrupted.
582 // Print the filename if it hasn't been printed yet.
583 if (!current_filename_printed)
586 // Print the actual progress message. The idea is that there is at
587 // least three spaces between the fields in typical situations, but
588 // even in rare situations there is at least one space.
589 const char *cols[5] = {
590 progress_percentage(in_pos),
591 progress_sizes(compressed_pos, uncompressed_pos, false),
592 progress_speed(uncompressed_pos, elapsed),
593 progress_time(elapsed),
594 progress_remaining(in_pos, elapsed),
596 fprintf(stderr, "\r %*s %*s %*s %10s %10s\r",
597 tuklib_mbstr_fw(cols[0], 6), cols[0],
598 tuklib_mbstr_fw(cols[1], 35), cols[1],
599 tuklib_mbstr_fw(cols[2], 9), cols[2],
604 // Updating the progress info was finished. Reset
605 // progress_needs_updating to wait for the next SIGALRM.
607 // NOTE: This has to be done before alarm(1) or with (very) bad
608 // luck we could be setting this to false after the alarm has already
610 progress_needs_updating = false;
612 if (verbosity >= V_VERBOSE && progress_automatic) {
613 // Mark that the progress indicator is active, so if an error
614 // occurs, the error message gets printed cleanly.
615 progress_active = true;
617 // Restart the timer so that progress_needs_updating gets
618 // set to true after about one second.
621 // The progress message was printed because user had sent us
622 // SIGALRM. In this case, each progress message is printed
627 // When SIGALRM isn't supported and we get here, it's always due to
628 // automatic progress update. We set progress_active here too like
630 assert(verbosity >= V_VERBOSE);
631 assert(progress_automatic);
632 progress_active = true;
642 progress_flush(bool finished)
644 if (!progress_started || verbosity < V_VERBOSE)
648 uint64_t compressed_pos;
649 uint64_t uncompressed_pos;
650 progress_pos(&in_pos, &compressed_pos, &uncompressed_pos);
652 // Avoid printing intermediate progress info if some error occurs
653 // in the beginning of the stream. (If something goes wrong later in
654 // the stream, it is sometimes useful to tell the user where the
655 // error approximately occurred, especially if the error occurs
656 // after a time-consuming operation.)
657 if (!finished && !progress_active
658 && (compressed_pos == 0 || uncompressed_pos == 0))
661 progress_active = false;
663 const uint64_t elapsed = progress_elapsed();
667 // When using the auto-updating progress indicator, the final
668 // statistics are printed in the same format as the progress
670 if (progress_automatic) {
671 const char *cols[5] = {
672 finished ? "100 %" : progress_percentage(in_pos),
673 progress_sizes(compressed_pos, uncompressed_pos, true),
674 progress_speed(uncompressed_pos, elapsed),
675 progress_time(elapsed),
676 finished ? "" : progress_remaining(in_pos, elapsed),
678 fprintf(stderr, "\r %*s %*s %*s %10s %10s\n",
679 tuklib_mbstr_fw(cols[0], 6), cols[0],
680 tuklib_mbstr_fw(cols[1], 35), cols[1],
681 tuklib_mbstr_fw(cols[2], 9), cols[2],
685 // The filename is always printed.
686 fprintf(stderr, "%s: ", filename);
688 // Percentage is printed only if we didn't finish yet.
690 // Don't print the percentage when it isn't known
691 // (starts with a dash).
692 const char *percentage = progress_percentage(in_pos);
693 if (percentage[0] != '-')
694 fprintf(stderr, "%s, ", percentage);
697 // Size information is always printed.
698 fprintf(stderr, "%s", progress_sizes(
699 compressed_pos, uncompressed_pos, true));
701 // The speed and elapsed time aren't always shown.
702 const char *speed = progress_speed(uncompressed_pos, elapsed);
703 if (speed[0] != '\0')
704 fprintf(stderr, ", %s", speed);
706 const char *elapsed_str = progress_time(elapsed);
707 if (elapsed_str[0] != '\0')
708 fprintf(stderr, ", %s", elapsed_str);
720 message_progress_end(bool success)
722 assert(progress_started);
723 progress_flush(success);
724 progress_started = false;
730 vmessage(enum message_verbosity v, const char *fmt, va_list ap)
732 if (v <= verbosity) {
735 progress_flush(false);
737 fprintf(stderr, "%s: ", progname);
738 vfprintf(stderr, fmt, ap);
749 message(enum message_verbosity v, const char *fmt, ...)
753 vmessage(v, fmt, ap);
760 message_warning(const char *fmt, ...)
764 vmessage(V_WARNING, fmt, ap);
767 set_exit_status(E_WARNING);
773 message_error(const char *fmt, ...)
777 vmessage(V_ERROR, fmt, ap);
780 set_exit_status(E_ERROR);
786 message_fatal(const char *fmt, ...)
790 vmessage(V_ERROR, fmt, ap);
793 tuklib_exit(E_ERROR, E_ERROR, false);
800 message_fatal(_("Internal error (bug)"));
805 message_signal_handler(void)
807 message_fatal(_("Cannot establish signal handlers"));
812 message_strm(lzma_ret code)
816 return _("No integrity check; not verifying file integrity");
818 case LZMA_UNSUPPORTED_CHECK:
819 return _("Unsupported type of integrity check; "
820 "not verifying file integrity");
823 return strerror(ENOMEM);
825 case LZMA_MEMLIMIT_ERROR:
826 return _("Memory usage limit reached");
828 case LZMA_FORMAT_ERROR:
829 return _("File format not recognized");
831 case LZMA_OPTIONS_ERROR:
832 return _("Unsupported options");
834 case LZMA_DATA_ERROR:
835 return _("Compressed data is corrupt");
838 return _("Unexpected end of input");
841 case LZMA_STREAM_END:
843 case LZMA_PROG_ERROR:
844 return _("Internal error (bug)");
852 message_mem_needed(enum message_verbosity v, uint64_t memusage)
857 // Convert memusage to MiB, rounding up to the next full MiB.
858 // This way the user can always use the displayed usage as
859 // the new memory usage limit. (If we rounded to the nearest,
860 // the user might need to +1 MiB to get high enough limit.)
861 memusage = round_up_to_mib(memusage);
864 // 2^64 with thousand separators + " MiB" suffix + '\0' = 26 + 4 + 1
865 // But there may be multibyte chars so reserve enough space.
866 char memlimitstr[128];
868 // Show the memory usage limit as MiB unless it is less than 1 MiB.
869 // This way it's easy to notice errors where one has typed
870 // --memory=123 instead of --memory=123MiB.
871 uint64_t memlimit = hardware_memlimit_get(opt_mode);
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);
893 /// \brief Convert uint32_t to a nice string for --lzma[12]=dict=SIZE
895 /// The idea is to use KiB or MiB suffix when possible.
897 uint32_to_optstr(uint32_t num)
901 if ((num & ((UINT32_C(1) << 20) - 1)) == 0)
902 snprintf(buf, sizeof(buf), "%" PRIu32 "MiB", num >> 20);
903 else if ((num & ((UINT32_C(1) << 10) - 1)) == 0)
904 snprintf(buf, sizeof(buf), "%" PRIu32 "KiB", num >> 10);
906 snprintf(buf, sizeof(buf), "%" PRIu32, num);
913 message_filters_to_str(char buf[FILTERS_STR_SIZE],
914 const lzma_filter *filters, bool all_known)
917 size_t left = FILTERS_STR_SIZE;
919 for (size_t i = 0; filters[i].id != LZMA_VLI_UNKNOWN; ++i) {
920 // Add the dashes for the filter option. A space is
921 // needed after the first and later filters.
922 my_snprintf(&pos, &left, "%s", i == 0 ? "--" : " --");
924 switch (filters[i].id) {
925 case LZMA_FILTER_LZMA1:
926 case LZMA_FILTER_LZMA2: {
927 const lzma_options_lzma *opt = filters[i].options;
928 const char *mode = NULL;
929 const char *mf = NULL;
937 case LZMA_MODE_NORMAL:
973 // Add the filter name and dictionary size, which
975 my_snprintf(&pos, &left, "lzma%c=dict=%s",
976 filters[i].id == LZMA_FILTER_LZMA2
978 uint32_to_optstr(opt->dict_size));
980 // With LZMA1 also lc/lp/pb are known when
981 // decompressing, but this function is never
982 // used to print information about .lzma headers.
983 assert(filters[i].id == LZMA_FILTER_LZMA2
986 // Print the rest of the options, which are known
987 // only when compressing.
989 my_snprintf(&pos, &left,
990 ",lc=%" PRIu32 ",lp=%" PRIu32
992 ",mode=%s,nice=%" PRIu32 ",mf=%s"
994 opt->lc, opt->lp, opt->pb,
995 mode, opt->nice_len, mf, opt->depth);
999 case LZMA_FILTER_X86:
1000 case LZMA_FILTER_POWERPC:
1001 case LZMA_FILTER_IA64:
1002 case LZMA_FILTER_ARM:
1003 case LZMA_FILTER_ARMTHUMB:
1004 case LZMA_FILTER_SPARC: {
1005 static const char bcj_names[][9] = {
1014 const lzma_options_bcj *opt = filters[i].options;
1015 my_snprintf(&pos, &left, "%s", bcj_names[filters[i].id
1016 - LZMA_FILTER_X86]);
1018 // Show the start offset only when really needed.
1019 if (opt != NULL && opt->start_offset != 0)
1020 my_snprintf(&pos, &left, "=start=%" PRIu32,
1026 case LZMA_FILTER_DELTA: {
1027 const lzma_options_delta *opt = filters[i].options;
1028 my_snprintf(&pos, &left, "delta=dist=%" PRIu32,
1034 // This should be possible only if liblzma is
1035 // newer than the xz tool.
1036 my_snprintf(&pos, &left, "UNKNOWN");
1046 message_filters_show(enum message_verbosity v, const lzma_filter *filters)
1051 char buf[FILTERS_STR_SIZE];
1052 message_filters_to_str(buf, filters, true);
1053 fprintf(stderr, _("%s: Filter chain: %s\n"), progname, buf);
1059 message_try_help(void)
1061 // Print this with V_WARNING instead of V_ERROR to prevent it from
1062 // showing up when --quiet has been specified.
1063 message(V_WARNING, _("Try `%s --help' for more information."),
1070 message_version(void)
1072 // It is possible that liblzma version is different than the command
1073 // line tool version, so print both.
1075 printf("XZ_VERSION=%" PRIu32 "\nLIBLZMA_VERSION=%" PRIu32 "\n",
1076 LZMA_VERSION, lzma_version_number());
1078 printf("xz (" PACKAGE_NAME ") " LZMA_VERSION_STRING "\n");
1079 printf("liblzma %s\n", lzma_version_string());
1082 tuklib_exit(E_SUCCESS, E_ERROR, verbosity != V_SILENT);
1087 message_help(bool long_help)
1089 printf(_("Usage: %s [OPTION]... [FILE]...\n"
1090 "Compress or decompress FILEs in the .xz format.\n\n"),
1093 // NOTE: The short help doesn't currently have options that
1096 puts(_("Mandatory arguments to long options are mandatory "
1097 "for short options too.\n"));
1100 puts(_(" Operation mode:\n"));
1103 " -z, --compress force compression\n"
1104 " -d, --decompress force decompression\n"
1105 " -t, --test test compressed file integrity\n"
1106 " -l, --list list information about .xz files"));
1109 puts(_("\n Operation modifiers:\n"));
1112 " -k, --keep keep (don't delete) input files\n"
1113 " -f, --force force overwrite of output file and (de)compress links\n"
1114 " -c, --stdout write to standard output and don't delete input files"));
1118 " --no-sparse do not create sparse files when decompressing\n"
1119 " -S, --suffix=.SUF use the suffix `.SUF' on compressed files\n"
1120 " --files[=FILE] read filenames to process from FILE; if FILE is\n"
1121 " omitted, filenames are read from the standard input;\n"
1122 " filenames must be terminated with the newline character\n"
1123 " --files0[=FILE] like --files but use the null character as terminator"));
1126 puts(_("\n Basic file format and compression options:\n"));
1128 " -F, --format=FMT file format to encode or decode; possible values are\n"
1129 " `auto' (default), `xz', `lzma', and `raw'\n"
1130 " -C, --check=CHECK integrity check type: `none' (use with caution),\n"
1131 " `crc32', `crc64' (default), or `sha256'"));
1135 " -0 ... -9 compression preset; default is 6; take compressor *and*\n"
1136 " decompressor memory usage into account before using 7-9!"));
1139 " -e, --extreme try to improve compression ratio by using more CPU time;\n"
1140 " does not affect decompressor memory requirements"));
1143 puts(_( // xgettext:no-c-format
1144 " --memlimit-compress=LIMIT\n"
1145 " --memlimit-decompress=LIMIT\n"
1146 " -M, --memlimit=LIMIT\n"
1147 " set memory usage limit for compression, decompression,\n"
1148 " or both; LIMIT is in bytes, % of RAM, or 0 for defaults"));
1151 " --no-adjust if compression settings exceed the memory usage limit,\n"
1152 " give an error instead of adjusting the settings downwards"));
1157 "\n Custom filter chain for compression (alternative for using presets):"));
1159 #if defined(HAVE_ENCODER_LZMA1) || defined(HAVE_DECODER_LZMA1) \
1160 || defined(HAVE_ENCODER_LZMA2) || defined(HAVE_DECODER_LZMA2)
1161 // TRANSLATORS: The word "literal" in "literal context bits"
1162 // means how many "context bits" to use when encoding
1163 // literals. A literal is a single 8-bit byte. It doesn't
1164 // mean "literally" here.
1167 " --lzma1[=OPTS] LZMA1 or LZMA2; OPTS is a comma-separated list of zero or\n"
1168 " --lzma2[=OPTS] more of the following options (valid values; default):\n"
1169 " preset=PRE reset options to a preset (0-9[e])\n"
1170 " dict=NUM dictionary size (4KiB - 1536MiB; 8MiB)\n"
1171 " lc=NUM number of literal context bits (0-4; 3)\n"
1172 " lp=NUM number of literal position bits (0-4; 0)\n"
1173 " pb=NUM number of position bits (0-4; 2)\n"
1174 " mode=MODE compression mode (fast, normal; normal)\n"
1175 " nice=NUM nice length of a match (2-273; 64)\n"
1176 " mf=NAME match finder (hc3, hc4, bt2, bt3, bt4; bt4)\n"
1177 " depth=NUM maximum search depth; 0=automatic (default)"));
1182 " --x86[=OPTS] x86 BCJ filter (32-bit and 64-bit)\n"
1183 " --powerpc[=OPTS] PowerPC BCJ filter (big endian only)\n"
1184 " --ia64[=OPTS] IA-64 (Itanium) BCJ filter\n"
1185 " --arm[=OPTS] ARM BCJ filter (little endian only)\n"
1186 " --armthumb[=OPTS] ARM-Thumb BCJ filter (little endian only)\n"
1187 " --sparc[=OPTS] SPARC BCJ filter\n"
1188 " Valid OPTS for all BCJ filters:\n"
1189 " start=NUM start offset for conversions (default=0)"));
1191 #if defined(HAVE_ENCODER_DELTA) || defined(HAVE_DECODER_DELTA)
1194 " --delta[=OPTS] Delta filter; valid OPTS (valid values; default):\n"
1195 " dist=NUM distance between bytes being subtracted\n"
1196 " from each other (1-256; 1)"));
1201 puts(_("\n Other options:\n"));
1204 " -q, --quiet suppress warnings; specify twice to suppress errors too\n"
1205 " -v, --verbose be verbose; specify twice for even more verbose"));
1209 " -Q, --no-warn make warnings not affect the exit status"));
1211 " --robot use machine-parsable messages (useful for scripts)"));
1214 " --info-memory display the total amount of RAM and the currently active\n"
1215 " memory usage limits, and exit"));
1217 " -h, --help display the short help (lists only the basic options)\n"
1218 " -H, --long-help display this long help and exit"));
1221 " -h, --help display this short help and exit\n"
1222 " -H, --long-help display the long help (lists also the advanced options)"));
1226 " -V, --version display the version number and exit"));
1228 puts(_("\nWith no FILE, or when FILE is -, read standard input.\n"));
1230 // TRANSLATORS: This message indicates the bug reporting address
1231 // for this package. Please add _another line_ saying
1232 // "Report translation bugs to <...>\n" with the email or WWW
1233 // address for translation bugs. Thanks.
1234 printf(_("Report bugs to <%s> (in English or Finnish).\n"),
1236 printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
1238 tuklib_exit(E_SUCCESS, E_ERROR, verbosity != V_SILENT);