1 ///////////////////////////////////////////////////////////////////////////////
4 /// \brief Printing messages to stderr
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 ///////////////////////////////////////////////////////////////////////////////
14 enum message_verbosity {
15 V_SILENT, ///< No messages
16 V_ERROR, ///< Only error messages
17 V_WARNING, ///< Errors and warnings
18 V_VERBOSE, ///< Errors, warnings, and verbose statistics
19 V_DEBUG, ///< Debugging, FIXME remove?
23 /// \brief Initializes the message functions
25 /// If an error occurs, this function doesn't return.
27 extern void message_init(void);
30 /// Increase verbosity level by one step unless it was at maximum.
31 extern void message_verbosity_increase(void);
33 /// Decrease verbosity level by one step unless it was at minimum.
34 extern void message_verbosity_decrease(void);
36 /// Get the current verbosity level.
37 extern enum message_verbosity message_verbosity_get(void);
40 /// \brief Print a message if verbosity level is at least "verbosity"
42 /// This doesn't touch the exit status.
43 extern void message(enum message_verbosity verbosity, const char *fmt, ...)
44 lzma_attribute((format(printf, 2, 3)));
47 /// \brief Prints a warning and possibly sets exit status
49 /// The message is printed only if verbosity level is at least V_WARNING.
50 /// The exit status is set to WARNING unless it was already at ERROR.
51 extern void message_warning(const char *fmt, ...)
52 lzma_attribute((format(printf, 1, 2)));
55 /// \brief Prints an error message and sets exit status
57 /// The message is printed only if verbosity level is at least V_ERROR.
58 /// The exit status is set to ERROR.
59 extern void message_error(const char *fmt, ...)
60 lzma_attribute((format(printf, 1, 2)));
63 /// \brief Prints an error message and exits with EXIT_ERROR
65 /// The message is printed only if verbosity level is at least V_ERROR.
66 extern void message_fatal(const char *fmt, ...)
67 lzma_attribute((format(printf, 1, 2)))
68 lzma_attribute((noreturn));
71 /// Print an error message that an internal error occurred and exit with
73 extern void message_bug(void) lzma_attribute((noreturn));
76 /// Print a message that establishing signal handlers failed, and exit with
77 /// exit status ERROR.
78 extern void message_signal_handler(void) lzma_attribute((noreturn));
81 /// Convert lzma_ret to a string.
82 extern const char *message_strm(lzma_ret code);
85 /// Display how much memory was needed and how much the limit was.
86 extern void message_mem_needed(enum message_verbosity v, uint64_t memusage);
89 /// \brief Get the filter chain as a string
91 /// \param filters Pointer to the filter chain
92 /// \param all_known If true, all filter options are printed.
93 /// If false, only the options that get stored
94 /// into .xz headers are printed.
96 /// \return Pointer to a statically allocated buffer.
97 extern const char *message_filters_to_str(
98 const lzma_filter *filters, bool all_known);
101 /// Print the filter chain.
102 extern void message_filters_show(
103 enum message_verbosity v, const lzma_filter *filters);
106 /// Print a message that user should try --help.
107 extern void message_try_help(void);
110 /// Prints the version number to stdout and exits with exit status SUCCESS.
111 extern void message_version(void) lzma_attribute((noreturn));
114 /// Print the help message.
115 extern void message_help(bool long_help) lzma_attribute((noreturn));
118 /// \brief Set the total number of files to be processed
120 /// Standard input is counted as a file here. This is used when printing
121 /// the filename via message_filename().
122 extern void message_set_files(unsigned int files);
125 /// \brief Set the name of the current file and possibly print it too
127 /// The name is printed immediately if --list was used or if --verbose
128 /// was used and stderr is a terminal. Even when the filename isn't printed,
129 /// it is stored so that it can be printed later if needed for progress
131 extern void message_filename(const char *src_name);
134 /// \brief Start progress info handling
136 /// message_filename() must be called before this function to set
139 /// This must be paired with a call to message_progress_end() before the
140 /// given *strm becomes invalid.
142 /// \param strm Pointer to lzma_stream used for the coding.
143 /// \param in_size Size of the input file, or zero if unknown.
145 extern void message_progress_start(lzma_stream *strm, uint64_t in_size);
148 /// Update the progress info if in verbose mode and enough time has passed
149 /// since the previous update. This can be called only when
150 /// message_progress_start() has already been used.
151 extern void message_progress_update(void);
154 /// \brief Finishes the progress message if we were in verbose mode
156 /// \param finished True if the whole stream was successfully coded
157 /// and output written to the output stream.
159 extern void message_progress_end(bool finished);