]> icculus.org git repositories - icculus/xz.git/blob - src/xz/message.h
7ef9b165425c91aba3489ea76a4155fff692cc9e
[icculus/xz.git] / src / xz / message.h
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file       message.h
4 /// \brief      Printing messages to stderr
5 //
6 //  Copyright (C) 2007-2008 Lasse Collin
7 //
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.
12 //
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.
17 //
18 ///////////////////////////////////////////////////////////////////////////////
19
20 #ifndef MESSAGE_H
21 #define MESSAGE_H
22
23
24 /// Verbosity levels
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?
31 };
32
33
34 /// \brief      Initializes the message functions
35 ///
36 /// \param      argv0       Name of the program i.e. argv[0] from main()
37 /// \param      verbosity   Verbosity level
38 ///
39 /// If an error occurs, this function doesn't return.
40 ///
41 extern void message_init(const char *argv0);
42
43
44 /// Increase verbosity level by one step unless it was at maximum.
45 extern void message_verbosity_increase(void);
46
47 /// Decrease verbosity level by one step unless it was at minimum.
48 extern void message_verbosity_decrease(void);
49
50
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);
54
55
56 /// \brief      Print a message if verbosity level is at least "verbosity"
57 ///
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)));
61
62
63 /// \brief      Prints a warning and possibly sets exit status
64 ///
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)));
69
70
71 /// \brief      Prints an error message and sets exit status
72 ///
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)));
77
78
79 /// \brief      Prints an error message and exits with EXIT_ERROR
80 ///
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));
85
86
87 /// Print an error message that an internal error occurred and exit with
88 /// EXIT_ERROR.
89 extern void message_bug(void) lzma_attribute((noreturn));
90
91
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));
95
96
97 /// Converts lzma_ret to a string.
98 extern const char *message_strm(lzma_ret code);
99
100
101 /// Print a message that user should try --help.
102 extern void message_try_help(void);
103
104
105 /// Prints the version number to stdout and exits with exit status SUCCESS.
106 extern void message_version(void) lzma_attribute((noreturn));
107
108
109 /// Print the help message.
110 extern void message_help(bool long_help) lzma_attribute((noreturn));
111
112
113 ///
114 extern void message_progress_start(const char *filename, uint64_t in_size);
115
116
117 ///
118 extern void message_progress_update(uint64_t in_pos, uint64_t out_pos);
119
120
121 /// \brief      Finishes the progress message if we were in verbose mode
122 ///
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.
128 ///
129 extern void message_progress_end(
130                 uint64_t in_pos, uint64_t out_pos, bool success);
131
132 #endif