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 /// Print the filter chain.
90 extern void message_filters(
91 enum message_verbosity v, const lzma_filter *filters);
94 /// Print a message that user should try --help.
95 extern void message_try_help(void);
98 /// Print the memory usage limit and exit.
99 extern void message_memlimit(void) lzma_attribute((noreturn));
102 /// Prints the version number to stdout and exits with exit status SUCCESS.
103 extern void message_version(void) lzma_attribute((noreturn));
106 /// Print the help message.
107 extern void message_help(bool long_help) lzma_attribute((noreturn));
110 /// \brief Set the total number of files to be processed
112 /// Standard input is counted as a file here. This is used when printing
113 /// the filename via message_filename().
114 extern void message_set_files(unsigned int files);
117 /// \brief Set the name of the current file and possibly print it too
119 /// The name is printed immediatelly if --list was used or if --verbose
120 /// was used and stderr is a terminal. Even when the filename isn't printed,
121 /// it is stored so that it can be printed later if needed for progress
123 extern void message_filename(const char *src_name);
126 /// \brief Start progress info handling
128 /// message_filename() must be called before this function to set
131 /// This must be paired with a call to message_progress_end() before the
132 /// given *strm becomes invalid.
134 /// \param strm Pointer to lzma_stream used for the coding.
135 /// \param in_size Size of the input file, or zero if unknown.
137 extern void message_progress_start(lzma_stream *strm, uint64_t in_size);
140 /// Update the progress info if in verbose mode and enough time has passed
141 /// since the previous update. This can be called only when
142 /// message_progress_start() has already been used.
143 extern void message_progress_update(void);
146 /// \brief Finishes the progress message if we were in verbose mode
148 /// \param finished True if the whole stream was successfully coded
149 /// and output written to the output stream.
151 extern void message_progress_end(bool finished);