2008-11-19 13:46:52 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
/// \file message.h
|
|
|
|
/// \brief Printing messages to stderr
|
|
|
|
//
|
2009-04-13 04:27:40 -04:00
|
|
|
// Author: Lasse Collin
|
2008-11-19 13:46:52 -05:00
|
|
|
//
|
2009-04-13 04:27:40 -04:00
|
|
|
// This file has been put into the public domain.
|
|
|
|
// You can do whatever you want with this file.
|
2008-11-19 13:46:52 -05:00
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/// Verbosity levels
|
|
|
|
enum message_verbosity {
|
|
|
|
V_SILENT, ///< No messages
|
|
|
|
V_ERROR, ///< Only error messages
|
|
|
|
V_WARNING, ///< Errors and warnings
|
|
|
|
V_VERBOSE, ///< Errors, warnings, and verbose statistics
|
2010-10-19 04:44:37 -04:00
|
|
|
V_DEBUG, ///< Very verbose
|
2008-11-19 13:46:52 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-10-11 14:26:19 -04:00
|
|
|
/// \brief Signals used for progress message handling
|
|
|
|
extern const int message_progress_sigs[];
|
|
|
|
|
|
|
|
|
2008-11-19 13:46:52 -05:00
|
|
|
/// \brief Initializes the message functions
|
|
|
|
///
|
|
|
|
/// If an error occurs, this function doesn't return.
|
|
|
|
///
|
2009-09-19 02:47:30 -04:00
|
|
|
extern void message_init(void);
|
2008-11-19 13:46:52 -05:00
|
|
|
|
|
|
|
|
|
|
|
/// Increase verbosity level by one step unless it was at maximum.
|
|
|
|
extern void message_verbosity_increase(void);
|
|
|
|
|
|
|
|
/// Decrease verbosity level by one step unless it was at minimum.
|
|
|
|
extern void message_verbosity_decrease(void);
|
|
|
|
|
2009-09-19 02:47:30 -04:00
|
|
|
/// Get the current verbosity level.
|
|
|
|
extern enum message_verbosity message_verbosity_get(void);
|
|
|
|
|
2008-11-19 13:46:52 -05:00
|
|
|
|
|
|
|
/// \brief Print a message if verbosity level is at least "verbosity"
|
|
|
|
///
|
|
|
|
/// This doesn't touch the exit status.
|
|
|
|
extern void message(enum message_verbosity verbosity, const char *fmt, ...)
|
2011-05-17 04:54:38 -04:00
|
|
|
lzma_attribute((__format__(__printf__, 2, 3)));
|
2008-11-19 13:46:52 -05:00
|
|
|
|
|
|
|
|
|
|
|
/// \brief Prints a warning and possibly sets exit status
|
|
|
|
///
|
|
|
|
/// The message is printed only if verbosity level is at least V_WARNING.
|
|
|
|
/// The exit status is set to WARNING unless it was already at ERROR.
|
|
|
|
extern void message_warning(const char *fmt, ...)
|
2011-05-17 04:54:38 -04:00
|
|
|
lzma_attribute((__format__(__printf__, 1, 2)));
|
2008-11-19 13:46:52 -05:00
|
|
|
|
|
|
|
|
|
|
|
/// \brief Prints an error message and sets exit status
|
|
|
|
///
|
|
|
|
/// The message is printed only if verbosity level is at least V_ERROR.
|
|
|
|
/// The exit status is set to ERROR.
|
|
|
|
extern void message_error(const char *fmt, ...)
|
2011-05-17 04:54:38 -04:00
|
|
|
lzma_attribute((__format__(__printf__, 1, 2)));
|
2008-11-19 13:46:52 -05:00
|
|
|
|
|
|
|
|
|
|
|
/// \brief Prints an error message and exits with EXIT_ERROR
|
|
|
|
///
|
|
|
|
/// The message is printed only if verbosity level is at least V_ERROR.
|
|
|
|
extern void message_fatal(const char *fmt, ...)
|
2011-05-17 04:54:38 -04:00
|
|
|
lzma_attribute((__format__(__printf__, 1, 2)))
|
|
|
|
lzma_attribute((__noreturn__));
|
2008-11-19 13:46:52 -05:00
|
|
|
|
|
|
|
|
|
|
|
/// Print an error message that an internal error occurred and exit with
|
|
|
|
/// EXIT_ERROR.
|
2011-05-17 04:54:38 -04:00
|
|
|
extern void message_bug(void) lzma_attribute((__noreturn__));
|
2008-11-19 13:46:52 -05:00
|
|
|
|
|
|
|
|
|
|
|
/// Print a message that establishing signal handlers failed, and exit with
|
|
|
|
/// exit status ERROR.
|
2011-05-17 04:54:38 -04:00
|
|
|
extern void message_signal_handler(void) lzma_attribute((__noreturn__));
|
2008-11-19 13:46:52 -05:00
|
|
|
|
|
|
|
|
2008-12-17 13:11:23 -05:00
|
|
|
/// Convert lzma_ret to a string.
|
2008-11-19 13:46:52 -05:00
|
|
|
extern const char *message_strm(lzma_ret code);
|
|
|
|
|
|
|
|
|
2010-01-24 09:57:40 -05:00
|
|
|
/// Display how much memory was needed and how much the limit was.
|
|
|
|
extern void message_mem_needed(enum message_verbosity v, uint64_t memusage);
|
|
|
|
|
|
|
|
|
2010-09-10 03:30:33 -04:00
|
|
|
/// Buffer size for message_filters_to_str()
|
|
|
|
#define FILTERS_STR_SIZE 512
|
|
|
|
|
|
|
|
|
2010-05-16 11:42:22 -04:00
|
|
|
/// \brief Get the filter chain as a string
|
|
|
|
///
|
2010-09-10 03:30:33 -04:00
|
|
|
/// \param buf Pointer to caller allocated buffer to hold
|
|
|
|
/// the filter chain string
|
2010-05-16 11:42:22 -04:00
|
|
|
/// \param filters Pointer to the filter chain
|
|
|
|
/// \param all_known If true, all filter options are printed.
|
|
|
|
/// If false, only the options that get stored
|
|
|
|
/// into .xz headers are printed.
|
2010-09-10 03:30:33 -04:00
|
|
|
extern void message_filters_to_str(char buf[FILTERS_STR_SIZE],
|
2010-05-16 11:42:22 -04:00
|
|
|
const lzma_filter *filters, bool all_known);
|
|
|
|
|
|
|
|
|
2008-12-17 13:11:23 -05:00
|
|
|
/// Print the filter chain.
|
2010-05-16 11:42:22 -04:00
|
|
|
extern void message_filters_show(
|
2008-12-17 13:11:23 -05:00
|
|
|
enum message_verbosity v, const lzma_filter *filters);
|
|
|
|
|
|
|
|
|
2008-11-19 13:46:52 -05:00
|
|
|
/// Print a message that user should try --help.
|
|
|
|
extern void message_try_help(void);
|
|
|
|
|
|
|
|
|
|
|
|
/// Prints the version number to stdout and exits with exit status SUCCESS.
|
2011-05-17 04:54:38 -04:00
|
|
|
extern void message_version(void) lzma_attribute((__noreturn__));
|
2008-11-19 13:46:52 -05:00
|
|
|
|
|
|
|
|
|
|
|
/// Print the help message.
|
2011-05-17 04:54:38 -04:00
|
|
|
extern void message_help(bool long_help) lzma_attribute((__noreturn__));
|
2008-11-19 13:46:52 -05:00
|
|
|
|
|
|
|
|
2010-01-31 05:01:54 -05:00
|
|
|
/// \brief Set the total number of files to be processed
|
|
|
|
///
|
|
|
|
/// Standard input is counted as a file here. This is used when printing
|
|
|
|
/// the filename via message_filename().
|
|
|
|
extern void message_set_files(unsigned int files);
|
|
|
|
|
|
|
|
|
|
|
|
/// \brief Set the name of the current file and possibly print it too
|
|
|
|
///
|
2010-02-12 06:16:15 -05:00
|
|
|
/// The name is printed immediately if --list was used or if --verbose
|
2010-01-31 05:01:54 -05:00
|
|
|
/// was used and stderr is a terminal. Even when the filename isn't printed,
|
|
|
|
/// it is stored so that it can be printed later if needed for progress
|
|
|
|
/// messages.
|
|
|
|
extern void message_filename(const char *src_name);
|
|
|
|
|
|
|
|
|
2009-02-22 11:52:49 -05:00
|
|
|
/// \brief Start progress info handling
|
2008-11-19 13:46:52 -05:00
|
|
|
///
|
2010-01-31 05:01:54 -05:00
|
|
|
/// message_filename() must be called before this function to set
|
|
|
|
/// the filename.
|
|
|
|
///
|
2009-02-22 11:52:49 -05:00
|
|
|
/// This must be paired with a call to message_progress_end() before the
|
|
|
|
/// given *strm becomes invalid.
|
|
|
|
///
|
|
|
|
/// \param strm Pointer to lzma_stream used for the coding.
|
|
|
|
/// \param in_size Size of the input file, or zero if unknown.
|
|
|
|
///
|
2010-01-31 05:01:54 -05:00
|
|
|
extern void message_progress_start(lzma_stream *strm, uint64_t in_size);
|
2008-11-19 13:46:52 -05:00
|
|
|
|
|
|
|
|
2009-02-22 11:52:49 -05:00
|
|
|
/// Update the progress info if in verbose mode and enough time has passed
|
|
|
|
/// since the previous update. This can be called only when
|
|
|
|
/// message_progress_start() has already been used.
|
|
|
|
extern void message_progress_update(void);
|
2008-11-19 13:46:52 -05:00
|
|
|
|
|
|
|
|
|
|
|
/// \brief Finishes the progress message if we were in verbose mode
|
|
|
|
///
|
2009-02-22 11:52:49 -05:00
|
|
|
/// \param finished True if the whole stream was successfully coded
|
|
|
|
/// and output written to the output stream.
|
2008-11-19 13:46:52 -05:00
|
|
|
///
|
2009-02-22 11:52:49 -05:00
|
|
|
extern void message_progress_end(bool finished);
|