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 /// Set the total number of files to be processed (stdin is counted as a file
41 /// here). The default is one.
42 extern void message_set_files(unsigned int files);
45 /// \brief Print a message if verbosity level is at least "verbosity"
47 /// This doesn't touch the exit status.
48 extern void message(enum message_verbosity verbosity, const char *fmt, ...)
49 lzma_attribute((format(printf, 2, 3)));
52 /// \brief Prints a warning and possibly sets exit status
54 /// The message is printed only if verbosity level is at least V_WARNING.
55 /// The exit status is set to WARNING unless it was already at ERROR.
56 extern void message_warning(const char *fmt, ...)
57 lzma_attribute((format(printf, 1, 2)));
60 /// \brief Prints an error message and sets exit status
62 /// The message is printed only if verbosity level is at least V_ERROR.
63 /// The exit status is set to ERROR.
64 extern void message_error(const char *fmt, ...)
65 lzma_attribute((format(printf, 1, 2)));
68 /// \brief Prints an error message and exits with EXIT_ERROR
70 /// The message is printed only if verbosity level is at least V_ERROR.
71 extern void message_fatal(const char *fmt, ...)
72 lzma_attribute((format(printf, 1, 2)))
73 lzma_attribute((noreturn));
76 /// Print an error message that an internal error occurred and exit with
78 extern void message_bug(void) lzma_attribute((noreturn));
81 /// Print a message that establishing signal handlers failed, and exit with
82 /// exit status ERROR.
83 extern void message_signal_handler(void) lzma_attribute((noreturn));
86 /// Convert lzma_ret to a string.
87 extern const char *message_strm(lzma_ret code);
90 /// Print the filter chain.
91 extern void message_filters(
92 enum message_verbosity v, const lzma_filter *filters);
95 /// Print a message that user should try --help.
96 extern void message_try_help(void);
99 /// Print the memory usage limit and exit.
100 extern void message_memlimit(void) lzma_attribute((noreturn));
103 /// Prints the version number to stdout and exits with exit status SUCCESS.
104 extern void message_version(void) lzma_attribute((noreturn));
107 /// Print the help message.
108 extern void message_help(bool long_help) lzma_attribute((noreturn));
111 /// \brief Start progress info handling
113 /// This must be paired with a call to message_progress_end() before the
114 /// given *strm becomes invalid.
116 /// \param strm Pointer to lzma_stream used for the coding.
117 /// \param filename Name of the input file. stdin_filename is
118 /// handled specially.
119 /// \param in_size Size of the input file, or zero if unknown.
121 extern void message_progress_start(
122 lzma_stream *strm, const char *filename, uint64_t in_size);
125 /// Update the progress info if in verbose mode and enough time has passed
126 /// since the previous update. This can be called only when
127 /// message_progress_start() has already been used.
128 extern void message_progress_update(void);
131 /// \brief Finishes the progress message if we were in verbose mode
133 /// \param finished True if the whole stream was successfully coded
134 /// and output written to the output stream.
136 extern void message_progress_end(bool finished);