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