]> icculus.org git repositories - icculus/xz.git/blob - src/xz/message.h
xz: Multiple fixes.
[icculus/xz.git] / src / xz / message.h
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file       message.h
4 /// \brief      Printing messages to stderr
5 //
6 //  Author:     Lasse Collin
7 //
8 //  This file has been put into the public domain.
9 //  You can do whatever you want with this file.
10 //
11 ///////////////////////////////////////////////////////////////////////////////
12
13 /// Verbosity levels
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?
20 };
21
22
23 /// \brief      Initializes the message functions
24 ///
25 /// If an error occurs, this function doesn't return.
26 ///
27 extern void message_init(void);
28
29
30 /// Increase verbosity level by one step unless it was at maximum.
31 extern void message_verbosity_increase(void);
32
33 /// Decrease verbosity level by one step unless it was at minimum.
34 extern void message_verbosity_decrease(void);
35
36 /// Get the current verbosity level.
37 extern enum message_verbosity message_verbosity_get(void);
38
39
40 /// \brief      Print a message if verbosity level is at least "verbosity"
41 ///
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)));
45
46
47 /// \brief      Prints a warning and possibly sets exit status
48 ///
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)));
53
54
55 /// \brief      Prints an error message and sets exit status
56 ///
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)));
61
62
63 /// \brief      Prints an error message and exits with EXIT_ERROR
64 ///
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));
69
70
71 /// Print an error message that an internal error occurred and exit with
72 /// EXIT_ERROR.
73 extern void message_bug(void) lzma_attribute((noreturn));
74
75
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));
79
80
81 /// Convert lzma_ret to a string.
82 extern const char *message_strm(lzma_ret code);
83
84
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);
87
88
89 /// Buffer size for message_filters_to_str()
90 #define FILTERS_STR_SIZE 512
91
92
93 /// \brief      Get the filter chain as a string
94 ///
95 /// \param      buf         Pointer to caller allocated buffer to hold
96 ///                         the filter chain string
97 /// \param      filters     Pointer to the filter chain
98 /// \param      all_known   If true, all filter options are printed.
99 ///                         If false, only the options that get stored
100 ///                         into .xz headers are printed.
101 extern void message_filters_to_str(char buf[FILTERS_STR_SIZE],
102                 const lzma_filter *filters, bool all_known);
103
104
105 /// Print the filter chain.
106 extern void message_filters_show(
107                 enum message_verbosity v, const lzma_filter *filters);
108
109
110 /// Print a message that user should try --help.
111 extern void message_try_help(void);
112
113
114 /// Prints the version number to stdout and exits with exit status SUCCESS.
115 extern void message_version(void) lzma_attribute((noreturn));
116
117
118 /// Print the help message.
119 extern void message_help(bool long_help) lzma_attribute((noreturn));
120
121
122 /// \brief      Set the total number of files to be processed
123 ///
124 /// Standard input is counted as a file here. This is used when printing
125 /// the filename via message_filename().
126 extern void message_set_files(unsigned int files);
127
128
129 /// \brief      Set the name of the current file and possibly print it too
130 ///
131 /// The name is printed immediately if --list was used or if --verbose
132 /// was used and stderr is a terminal. Even when the filename isn't printed,
133 /// it is stored so that it can be printed later if needed for progress
134 /// messages.
135 extern void message_filename(const char *src_name);
136
137
138 /// \brief      Start progress info handling
139 ///
140 /// message_filename() must be called before this function to set
141 /// the filename.
142 ///
143 /// This must be paired with a call to message_progress_end() before the
144 /// given *strm becomes invalid.
145 ///
146 /// \param      strm      Pointer to lzma_stream used for the coding.
147 /// \param      in_size   Size of the input file, or zero if unknown.
148 ///
149 extern void message_progress_start(lzma_stream *strm, uint64_t in_size);
150
151
152 /// Update the progress info if in verbose mode and enough time has passed
153 /// since the previous update. This can be called only when
154 /// message_progress_start() has already been used.
155 extern void message_progress_update(void);
156
157
158 /// \brief      Finishes the progress message if we were in verbose mode
159 ///
160 /// \param      finished    True if the whole stream was successfully coded
161 ///                         and output written to the output stream.
162 ///
163 extern void message_progress_end(bool finished);