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 extern void message(enum message_verbosity verbosity, const char *fmt, ...) 48 lzma_attribute((__format__(__printf__, 2, 3))); 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 extern void message_warning(const char *fmt, ...) 56 lzma_attribute((__format__(__printf__, 1, 2))); 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 extern void message_error(const char *fmt, ...) 64 lzma_attribute((__format__(__printf__, 1, 2))); 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 extern void message_fatal(const char *fmt, ...) 71 lzma_attribute((__format__(__printf__, 1, 2))) 72 lzma_attribute((__noreturn__)); 73 74 75 /// Print an error message that an internal error occurred and exit with 76 /// EXIT_ERROR. 77 extern void message_bug(void) lzma_attribute((__noreturn__)); 78 79 80 /// Print a message that establishing signal handlers failed, and exit with 81 /// exit status ERROR. 82 extern void message_signal_handler(void) lzma_attribute((__noreturn__)); 83 84 85 /// Convert lzma_ret to a string. 86 extern const char *message_strm(lzma_ret code); 87 88 89 /// Display how much memory was needed and how much the limit was. 90 extern void message_mem_needed(enum message_verbosity v, uint64_t memusage); 91 92 93 /// Print the filter chain. 94 extern void message_filters_show( 95 enum message_verbosity v, const lzma_filter *filters); 96 97 98 /// Print a message that user should try --help. 99 extern void message_try_help(void); 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, 138 bool is_passthru, uint64_t in_size); 139 140 141 /// Update the progress info if in verbose mode and enough time has passed 142 /// since the previous update. This can be called only when 143 /// message_progress_start() has already been used. 144 extern void message_progress_update(void); 145 146 147 /// \brief Finishes the progress message if we were in verbose mode 148 /// 149 /// \param finished True if the whole stream was successfully coded 150 /// and output written to the output stream. 151 /// 152 extern void message_progress_end(bool finished); 153