1 ///////////////////////////////////////////////////////////////////////////////
4 /// \brief Printing messages to stderr
6 // Copyright (C) 2007-2008 Lasse Collin
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
18 ///////////////////////////////////////////////////////////////////////////////
25 enum message_verbosity {
26 V_SILENT, ///< No messages
27 V_ERROR, ///< Only error messages
28 V_WARNING, ///< Errors and warnings
29 V_VERBOSE, ///< Errors, warnings, and verbose statistics
30 V_DEBUG, ///< Debugging, FIXME remove?
34 /// \brief Initializes the message functions
36 /// \param argv0 Name of the program i.e. argv[0] from main()
37 /// \param verbosity Verbosity level
39 /// If an error occurs, this function doesn't return.
41 extern void message_init(const char *argv0);
44 /// Increase verbosity level by one step unless it was at maximum.
45 extern void message_verbosity_increase(void);
47 /// Decrease verbosity level by one step unless it was at minimum.
48 extern void message_verbosity_decrease(void);
51 /// Set the total number of files to be processed (stdin is counted as a file
52 /// here). The default is one.
53 extern void message_set_files(unsigned int files);
56 /// \brief Print a message if verbosity level is at least "verbosity"
58 /// This doesn't touch the exit status.
59 extern void message(enum message_verbosity verbosity, const char *fmt, ...)
60 lzma_attribute((format(printf, 2, 3)));
63 /// \brief Prints a warning and possibly sets exit status
65 /// The message is printed only if verbosity level is at least V_WARNING.
66 /// The exit status is set to WARNING unless it was already at ERROR.
67 extern void message_warning(const char *fmt, ...)
68 lzma_attribute((format(printf, 1, 2)));
71 /// \brief Prints an error message and sets exit status
73 /// The message is printed only if verbosity level is at least V_ERROR.
74 /// The exit status is set to ERROR.
75 extern void message_error(const char *fmt, ...)
76 lzma_attribute((format(printf, 1, 2)));
79 /// \brief Prints an error message and exits with EXIT_ERROR
81 /// The message is printed only if verbosity level is at least V_ERROR.
82 extern void message_fatal(const char *fmt, ...)
83 lzma_attribute((format(printf, 1, 2)))
84 lzma_attribute((noreturn));
87 /// Print an error message that an internal error occurred and exit with
89 extern void message_bug(void) lzma_attribute((noreturn));
92 /// Print a message that establishing signal handlers failed, and exit with
93 /// exit status ERROR.
94 extern void message_signal_handler(void) lzma_attribute((noreturn));
97 /// Converts lzma_ret to a string.
98 extern const char *message_strm(lzma_ret code);
101 /// Print a message that user should try --help.
102 extern void message_try_help(void);
105 /// Prints the version number to stdout and exits with exit status SUCCESS.
106 extern void message_version(void) lzma_attribute((noreturn));
109 /// Print the help message.
110 extern void message_help(bool long_help) lzma_attribute((noreturn));
114 extern void message_progress_start(const char *filename, uint64_t in_size);
118 extern void message_progress_update(uint64_t in_pos, uint64_t out_pos);
121 /// \brief Finishes the progress message if we were in verbose mode
123 /// \param in_pos Final input position i.e. how much input there was.
124 /// \param out_pos Final output position
125 /// \param success True if the operation was successful. We don't
126 /// print the final progress message if the operation
127 /// wasn't successful.
129 extern void message_progress_end(
130 uint64_t in_pos, uint64_t out_pos, bool success);