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 /// \param argv0 Name of the program i.e. argv[0] from main()
26 /// \param verbosity Verbosity level
28 /// If an error occurs, this function doesn't return.
30 extern void message_init(const char *argv0);
33 /// Increase verbosity level by one step unless it was at maximum.
34 extern void message_verbosity_increase(void);
36 /// Decrease verbosity level by one step unless it was at minimum.
37 extern void message_verbosity_decrease(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 /// Prints the version number to stdout and exits with exit status SUCCESS.
100 extern void message_version(void) lzma_attribute((noreturn));
103 /// Print the help message.
104 extern void message_help(bool long_help) lzma_attribute((noreturn));
107 /// \brief Start progress info handling
109 /// This must be paired with a call to message_progress_end() before the
110 /// given *strm becomes invalid.
112 /// \param strm Pointer to lzma_stream used for the coding.
113 /// \param filename Name of the input file. stdin_filename is
114 /// handled specially.
115 /// \param in_size Size of the input file, or zero if unknown.
117 extern void message_progress_start(
118 lzma_stream *strm, const char *filename, uint64_t in_size);
121 /// Update the progress info if in verbose mode and enough time has passed
122 /// since the previous update. This can be called only when
123 /// message_progress_start() has already been used.
124 extern void message_progress_update(void);
127 /// \brief Finishes the progress message if we were in verbose mode
129 /// \param finished True if the whole stream was successfully coded
130 /// and output written to the output stream.
132 extern void message_progress_end(bool finished);