xref: /freebsd/contrib/xz/src/xz/message.h (revision 069ac184)
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,    ///< Very verbose
20 };
21 
22 
23 /// \brief      Signals used for progress message handling
24 extern const int message_progress_sigs[];
25 
26 
27 /// \brief      Initializes the message functions
28 ///
29 /// If an error occurs, this function doesn't return.
30 ///
31 extern void message_init(void);
32 
33 
34 /// Increase verbosity level by one step unless it was at maximum.
35 extern void message_verbosity_increase(void);
36 
37 /// Decrease verbosity level by one step unless it was at minimum.
38 extern void message_verbosity_decrease(void);
39 
40 /// Get the current verbosity level.
41 extern enum message_verbosity message_verbosity_get(void);
42 
43 
44 /// \brief      Print a message if verbosity level is at least "verbosity"
45 ///
46 /// This doesn't touch the exit status.
47 lzma_attribute((__format__(__printf__, 2, 3)))
48 extern void message(enum message_verbosity verbosity, const char *fmt, ...);
49 
50 
51 /// \brief      Prints a warning and possibly sets exit status
52 ///
53 /// The message is printed only if verbosity level is at least V_WARNING.
54 /// The exit status is set to WARNING unless it was already at ERROR.
55 lzma_attribute((__format__(__printf__, 1, 2)))
56 extern void message_warning(const char *fmt, ...);
57 
58 
59 /// \brief      Prints an error message and sets exit status
60 ///
61 /// The message is printed only if verbosity level is at least V_ERROR.
62 /// The exit status is set to ERROR.
63 lzma_attribute((__format__(__printf__, 1, 2)))
64 extern void message_error(const char *fmt, ...);
65 
66 
67 /// \brief      Prints an error message and exits with EXIT_ERROR
68 ///
69 /// The message is printed only if verbosity level is at least V_ERROR.
70 tuklib_attr_noreturn
71 lzma_attribute((__format__(__printf__, 1, 2)))
72 extern void message_fatal(const char *fmt, ...);
73 
74 
75 /// Print an error message that an internal error occurred and exit with
76 /// EXIT_ERROR.
77 tuklib_attr_noreturn
78 extern void message_bug(void);
79 
80 
81 /// Print a message that establishing signal handlers failed, and exit with
82 /// exit status ERROR.
83 tuklib_attr_noreturn
84 extern void message_signal_handler(void);
85 
86 
87 /// Convert lzma_ret to a string.
88 extern const char *message_strm(lzma_ret code);
89 
90 
91 /// Display how much memory was needed and how much the limit was.
92 extern void message_mem_needed(enum message_verbosity v, uint64_t memusage);
93 
94 
95 /// Print the filter chain.
96 extern void message_filters_show(
97 		enum message_verbosity v, const lzma_filter *filters);
98 
99 
100 /// Print a message that user should try --help.
101 extern void message_try_help(void);
102 
103 
104 /// Prints the version number to stdout and exits with exit status SUCCESS.
105 tuklib_attr_noreturn
106 extern void message_version(void);
107 
108 
109 /// Print the help message.
110 tuklib_attr_noreturn
111 extern void message_help(bool long_help);
112 
113 
114 /// \brief      Set the total number of files to be processed
115 ///
116 /// Standard input is counted as a file here. This is used when printing
117 /// the filename via message_filename().
118 extern void message_set_files(unsigned int files);
119 
120 
121 /// \brief      Set the name of the current file and possibly print it too
122 ///
123 /// The name is printed immediately if --list was used or if --verbose
124 /// was used and stderr is a terminal. Even when the filename isn't printed,
125 /// it is stored so that it can be printed later if needed for progress
126 /// messages.
127 extern void message_filename(const char *src_name);
128 
129 
130 /// \brief      Start progress info handling
131 ///
132 /// message_filename() must be called before this function to set
133 /// the filename.
134 ///
135 /// This must be paired with a call to message_progress_end() before the
136 /// given *strm becomes invalid.
137 ///
138 /// \param      strm      Pointer to lzma_stream used for the coding.
139 /// \param      in_size   Size of the input file, or zero if unknown.
140 ///
141 extern void message_progress_start(lzma_stream *strm,
142 		bool is_passthru, uint64_t in_size);
143 
144 
145 /// Update the progress info if in verbose mode and enough time has passed
146 /// since the previous update. This can be called only when
147 /// message_progress_start() has already been used.
148 extern void message_progress_update(void);
149 
150 
151 /// \brief      Finishes the progress message if we were in verbose mode
152 ///
153 /// \param      finished    True if the whole stream was successfully coded
154 ///                         and output written to the output stream.
155 ///
156 extern void message_progress_end(bool finished);
157