12940b44dSPeter Avalos /////////////////////////////////////////////////////////////////////////////// 22940b44dSPeter Avalos // 32940b44dSPeter Avalos /// \file message.h 42940b44dSPeter Avalos /// \brief Printing messages to stderr 52940b44dSPeter Avalos // 62940b44dSPeter Avalos // Author: Lasse Collin 72940b44dSPeter Avalos // 82940b44dSPeter Avalos // This file has been put into the public domain. 92940b44dSPeter Avalos // You can do whatever you want with this file. 102940b44dSPeter Avalos // 112940b44dSPeter Avalos /////////////////////////////////////////////////////////////////////////////// 122940b44dSPeter Avalos 132940b44dSPeter Avalos /// Verbosity levels 142940b44dSPeter Avalos enum message_verbosity { 152940b44dSPeter Avalos V_SILENT, ///< No messages 162940b44dSPeter Avalos V_ERROR, ///< Only error messages 172940b44dSPeter Avalos V_WARNING, ///< Errors and warnings 182940b44dSPeter Avalos V_VERBOSE, ///< Errors, warnings, and verbose statistics 192940b44dSPeter Avalos V_DEBUG, ///< Very verbose 202940b44dSPeter Avalos }; 212940b44dSPeter Avalos 222940b44dSPeter Avalos 232940b44dSPeter Avalos /// \brief Signals used for progress message handling 242940b44dSPeter Avalos extern const int message_progress_sigs[]; 252940b44dSPeter Avalos 262940b44dSPeter Avalos 272940b44dSPeter Avalos /// \brief Initializes the message functions 282940b44dSPeter Avalos /// 292940b44dSPeter Avalos /// If an error occurs, this function doesn't return. 302940b44dSPeter Avalos /// 312940b44dSPeter Avalos extern void message_init(void); 322940b44dSPeter Avalos 332940b44dSPeter Avalos 342940b44dSPeter Avalos /// Increase verbosity level by one step unless it was at maximum. 352940b44dSPeter Avalos extern void message_verbosity_increase(void); 362940b44dSPeter Avalos 372940b44dSPeter Avalos /// Decrease verbosity level by one step unless it was at minimum. 382940b44dSPeter Avalos extern void message_verbosity_decrease(void); 392940b44dSPeter Avalos 402940b44dSPeter Avalos /// Get the current verbosity level. 412940b44dSPeter Avalos extern enum message_verbosity message_verbosity_get(void); 422940b44dSPeter Avalos 432940b44dSPeter Avalos 442940b44dSPeter Avalos /// \brief Print a message if verbosity level is at least "verbosity" 452940b44dSPeter Avalos /// 462940b44dSPeter Avalos /// This doesn't touch the exit status. 472940b44dSPeter Avalos extern void message(enum message_verbosity verbosity, const char *fmt, ...) 48114db65bSPeter Avalos lzma_attribute((__format__(__printf__, 2, 3))); 492940b44dSPeter Avalos 502940b44dSPeter Avalos 512940b44dSPeter Avalos /// \brief Prints a warning and possibly sets exit status 522940b44dSPeter Avalos /// 532940b44dSPeter Avalos /// The message is printed only if verbosity level is at least V_WARNING. 542940b44dSPeter Avalos /// The exit status is set to WARNING unless it was already at ERROR. 552940b44dSPeter Avalos extern void message_warning(const char *fmt, ...) 56114db65bSPeter Avalos lzma_attribute((__format__(__printf__, 1, 2))); 572940b44dSPeter Avalos 582940b44dSPeter Avalos 592940b44dSPeter Avalos /// \brief Prints an error message and sets exit status 602940b44dSPeter Avalos /// 612940b44dSPeter Avalos /// The message is printed only if verbosity level is at least V_ERROR. 622940b44dSPeter Avalos /// The exit status is set to ERROR. 632940b44dSPeter Avalos extern void message_error(const char *fmt, ...) 64114db65bSPeter Avalos lzma_attribute((__format__(__printf__, 1, 2))); 652940b44dSPeter Avalos 662940b44dSPeter Avalos 672940b44dSPeter Avalos /// \brief Prints an error message and exits with EXIT_ERROR 682940b44dSPeter Avalos /// 692940b44dSPeter Avalos /// The message is printed only if verbosity level is at least V_ERROR. 702940b44dSPeter Avalos extern void message_fatal(const char *fmt, ...) 71114db65bSPeter Avalos lzma_attribute((__format__(__printf__, 1, 2))) 72114db65bSPeter Avalos lzma_attribute((__noreturn__)); 732940b44dSPeter Avalos 742940b44dSPeter Avalos 752940b44dSPeter Avalos /// Print an error message that an internal error occurred and exit with 762940b44dSPeter Avalos /// EXIT_ERROR. 77114db65bSPeter Avalos extern void message_bug(void) lzma_attribute((__noreturn__)); 782940b44dSPeter Avalos 792940b44dSPeter Avalos 802940b44dSPeter Avalos /// Print a message that establishing signal handlers failed, and exit with 812940b44dSPeter Avalos /// exit status ERROR. 82114db65bSPeter Avalos extern void message_signal_handler(void) lzma_attribute((__noreturn__)); 832940b44dSPeter Avalos 842940b44dSPeter Avalos 852940b44dSPeter Avalos /// Convert lzma_ret to a string. 862940b44dSPeter Avalos extern const char *message_strm(lzma_ret code); 872940b44dSPeter Avalos 882940b44dSPeter Avalos 892940b44dSPeter Avalos /// Display how much memory was needed and how much the limit was. 902940b44dSPeter Avalos extern void message_mem_needed(enum message_verbosity v, uint64_t memusage); 912940b44dSPeter Avalos 922940b44dSPeter Avalos 932940b44dSPeter Avalos /// Buffer size for message_filters_to_str() 942940b44dSPeter Avalos #define FILTERS_STR_SIZE 512 952940b44dSPeter Avalos 962940b44dSPeter Avalos 972940b44dSPeter Avalos /// \brief Get the filter chain as a string 982940b44dSPeter Avalos /// 992940b44dSPeter Avalos /// \param buf Pointer to caller allocated buffer to hold 1002940b44dSPeter Avalos /// the filter chain string 1012940b44dSPeter Avalos /// \param filters Pointer to the filter chain 1022940b44dSPeter Avalos /// \param all_known If true, all filter options are printed. 1032940b44dSPeter Avalos /// If false, only the options that get stored 1042940b44dSPeter Avalos /// into .xz headers are printed. 1052940b44dSPeter Avalos extern void message_filters_to_str(char buf[FILTERS_STR_SIZE], 1062940b44dSPeter Avalos const lzma_filter *filters, bool all_known); 1072940b44dSPeter Avalos 1082940b44dSPeter Avalos 1092940b44dSPeter Avalos /// Print the filter chain. 1102940b44dSPeter Avalos extern void message_filters_show( 1112940b44dSPeter Avalos enum message_verbosity v, const lzma_filter *filters); 1122940b44dSPeter Avalos 1132940b44dSPeter Avalos 1142940b44dSPeter Avalos /// Print a message that user should try --help. 1152940b44dSPeter Avalos extern void message_try_help(void); 1162940b44dSPeter Avalos 1172940b44dSPeter Avalos 1182940b44dSPeter Avalos /// Prints the version number to stdout and exits with exit status SUCCESS. 119114db65bSPeter Avalos extern void message_version(void) lzma_attribute((__noreturn__)); 1202940b44dSPeter Avalos 1212940b44dSPeter Avalos 1222940b44dSPeter Avalos /// Print the help message. 123114db65bSPeter Avalos extern void message_help(bool long_help) lzma_attribute((__noreturn__)); 1242940b44dSPeter Avalos 1252940b44dSPeter Avalos 1262940b44dSPeter Avalos /// \brief Set the total number of files to be processed 1272940b44dSPeter Avalos /// 1282940b44dSPeter Avalos /// Standard input is counted as a file here. This is used when printing 1292940b44dSPeter Avalos /// the filename via message_filename(). 1302940b44dSPeter Avalos extern void message_set_files(unsigned int files); 1312940b44dSPeter Avalos 1322940b44dSPeter Avalos 1332940b44dSPeter Avalos /// \brief Set the name of the current file and possibly print it too 1342940b44dSPeter Avalos /// 1352940b44dSPeter Avalos /// The name is printed immediately if --list was used or if --verbose 1362940b44dSPeter Avalos /// was used and stderr is a terminal. Even when the filename isn't printed, 1372940b44dSPeter Avalos /// it is stored so that it can be printed later if needed for progress 1382940b44dSPeter Avalos /// messages. 1392940b44dSPeter Avalos extern void message_filename(const char *src_name); 1402940b44dSPeter Avalos 1412940b44dSPeter Avalos 1422940b44dSPeter Avalos /// \brief Start progress info handling 1432940b44dSPeter Avalos /// 1442940b44dSPeter Avalos /// message_filename() must be called before this function to set 1452940b44dSPeter Avalos /// the filename. 1462940b44dSPeter Avalos /// 1472940b44dSPeter Avalos /// This must be paired with a call to message_progress_end() before the 1482940b44dSPeter Avalos /// given *strm becomes invalid. 1492940b44dSPeter Avalos /// 1502940b44dSPeter Avalos /// \param strm Pointer to lzma_stream used for the coding. 1512940b44dSPeter Avalos /// \param in_size Size of the input file, or zero if unknown. 1522940b44dSPeter Avalos /// 153*e151908bSDaniel Fojt extern void message_progress_start(lzma_stream *strm, 154*e151908bSDaniel Fojt bool is_passthru, uint64_t in_size); 1552940b44dSPeter Avalos 1562940b44dSPeter Avalos 1572940b44dSPeter Avalos /// Update the progress info if in verbose mode and enough time has passed 1582940b44dSPeter Avalos /// since the previous update. This can be called only when 1592940b44dSPeter Avalos /// message_progress_start() has already been used. 1602940b44dSPeter Avalos extern void message_progress_update(void); 1612940b44dSPeter Avalos 1622940b44dSPeter Avalos 1632940b44dSPeter Avalos /// \brief Finishes the progress message if we were in verbose mode 1642940b44dSPeter Avalos /// 1652940b44dSPeter Avalos /// \param finished True if the whole stream was successfully coded 1662940b44dSPeter Avalos /// and output written to the output stream. 1672940b44dSPeter Avalos /// 1682940b44dSPeter Avalos extern void message_progress_end(bool finished); 169