]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - contrib/xz/src/xz/message.h
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / contrib / xz / 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 /// Print the filter chain.
90 extern void message_filters(
91                 enum message_verbosity v, const lzma_filter *filters);
92
93
94 /// Print a message that user should try --help.
95 extern void message_try_help(void);
96
97
98 /// Print the memory usage limit and exit.
99 extern void message_memlimit(void) lzma_attribute((noreturn));
100
101
102 /// Prints the version number to stdout and exits with exit status SUCCESS.
103 extern void message_version(void) lzma_attribute((noreturn));
104
105
106 /// Print the help message.
107 extern void message_help(bool long_help) lzma_attribute((noreturn));
108
109
110 /// \brief      Set the total number of files to be processed
111 ///
112 /// Standard input is counted as a file here. This is used when printing
113 /// the filename via message_filename().
114 extern void message_set_files(unsigned int files);
115
116
117 /// \brief      Set the name of the current file and possibly print it too
118 ///
119 /// The name is printed immediately if --list was used or if --verbose
120 /// was used and stderr is a terminal. Even when the filename isn't printed,
121 /// it is stored so that it can be printed later if needed for progress
122 /// messages.
123 extern void message_filename(const char *src_name);
124
125
126 /// \brief      Start progress info handling
127 ///
128 /// message_filename() must be called before this function to set
129 /// the filename.
130 ///
131 /// This must be paired with a call to message_progress_end() before the
132 /// given *strm becomes invalid.
133 ///
134 /// \param      strm      Pointer to lzma_stream used for the coding.
135 /// \param      in_size   Size of the input file, or zero if unknown.
136 ///
137 extern void message_progress_start(lzma_stream *strm, uint64_t in_size);
138
139
140 /// Update the progress info if in verbose mode and enough time has passed
141 /// since the previous update. This can be called only when
142 /// message_progress_start() has already been used.
143 extern void message_progress_update(void);
144
145
146 /// \brief      Finishes the progress message if we were in verbose mode
147 ///
148 /// \param      finished    True if the whole stream was successfully coded
149 ///                         and output written to the output stream.
150 ///
151 extern void message_progress_end(bool finished);