Printing messages to stderr. More...
#include "private.h"
#include <stdarg.h>
Defines | |
#define | my_alarm alarm |
Functions | |
static void | progress_signal_handler (int sig lzma_attribute((unused))) |
Signal handler for SIGALRM. | |
static double | my_time (void) |
Get the current time as double. | |
static void | lzma_attribute ((format(printf, 3, 4))) |
Wrapper for snprintf() to help constructing a string in pieces. | |
void | message_init (const char *given_argv0) |
Initializes the message functions. | |
void | message_verbosity_increase (void) |
Increase verbosity level by one step unless it was at maximum. | |
void | message_verbosity_decrease (void) |
Decrease verbosity level by one step unless it was at minimum. | |
void | message_set_files (unsigned int files) |
static void | print_filename (void) |
void | message_progress_start (const char *src_name, uint64_t in_size) |
static const char * | progress_percentage (uint64_t in_pos) |
Make the string indicating completion percentage. | |
static void | progress_sizes_helper (char **pos, size_t *left, uint64_t value, bool final) |
static const char * | progress_sizes (uint64_t compressed_pos, uint64_t uncompressed_pos, bool final) |
static const char * | progress_speed (uint64_t uncompressed_pos, double elapsed) |
Make the string containing the processing speed of uncompressed data. | |
static const char * | progress_time (uint32_t seconds) |
static const char * | progress_remaining (uint64_t in_pos, double elapsed) |
void | message_progress_update (uint64_t in_pos, uint64_t out_pos) |
void | message_progress_end (uint64_t in_pos, uint64_t out_pos, bool success) |
Finishes the progress message if we were in verbose mode. | |
static void | vmessage (enum message_verbosity v, const char *fmt, va_list ap) |
void | message (enum message_verbosity v, const char *fmt,...) |
void | message_warning (const char *fmt,...) |
void | message_error (const char *fmt,...) |
void | message_fatal (const char *fmt,...) |
void | message_bug (void) |
void | message_signal_handler (void) |
const char * | message_strm (lzma_ret code) |
Convert lzma_ret to a string. | |
void | message_filters (enum message_verbosity v, const lzma_filter *filters) |
Print the filter chain. | |
void | message_try_help (void) |
Print a message that user should try --help. | |
void | message_version (void) |
Prints the version number to stdout and exits with exit status SUCCESS. | |
void | message_help (bool long_help) |
Print the help message. | |
Variables | |
static const char * | argv0 |
Name of the program which is prefixed to the error messages. | |
static unsigned int | files_pos = 0 |
Number of the current file. | |
static unsigned int | files_total |
Total number of input files; zero if unknown. | |
static enum message_verbosity | verbosity = V_WARNING |
Verbosity level. | |
static const char * | filename |
Filename which we will print with the verbose messages. | |
static bool | first_filename_printed = false |
static bool | current_filename_printed = false |
static bool | progress_automatic |
True if we should print progress indicator and update it automatically. | |
static bool | progress_active = false |
static uint64_t | expected_in_size |
static double | start_time |
Time when we started processing the file. | |
static volatile sig_atomic_t | progress_needs_updating = false |
Printing messages to stderr.
static void progress_signal_handler | ( | int sig | lzma_attribute(unused) | ) | [static] |
static double my_time | ( | void | ) | [static] |
Get the current time as double.
Referenced by message_progress_end().
static void lzma_attribute | ( | (format(printf, 3, 4)) | ) | [static] |
Wrapper for snprintf() to help constructing a string in pieces.
void message_init | ( | const char * | argv0 | ) |
Initializes the message functions.
argv0 | Name of the program i.e. argv[0] from main() | |
verbosity | Verbosity level |
If an error occurs, this function doesn't return.
References argv0, message_signal_handler(), progress_automatic, and progress_signal_handler().
void message_verbosity_increase | ( | void | ) |
void message_verbosity_decrease | ( | void | ) |
void message_set_files | ( | unsigned int | files | ) |
Set the total number of files to be processed (stdin is counted as a file here). The default is one.
References files_total.
static void print_filename | ( | void | ) | [static] |
Prints the name of the current file if it hasn't been printed already, except if we are processing exactly one stream from stdin to stdout. I think it looks nicer to not print "(stdin)" when --verbose is used in a pipe and no other files are processed.
References current_filename_printed, filename, files_pos, files_total, first_filename_printed, signals_block(), and signals_unblock().
static const char* progress_percentage | ( | uint64_t | in_pos | ) | [static] |
Make the string indicating completion percentage.
References expected_in_size.
static const char* progress_sizes | ( | uint64_t | compressed_pos, | |
uint64_t | uncompressed_pos, | |||
bool | final | |||
) | [static] |
Make the string containing the amount of input processed, amount of output produced, and the compression ratio.
Referenced by message_progress_end().
static const char* progress_speed | ( | uint64_t | uncompressed_pos, | |
double | elapsed | |||
) | [static] |
Make the string containing the processing speed of uncompressed data.
Referenced by message_progress_end().
static const char* progress_time | ( | uint32_t | seconds | ) | [static] |
Make a string indicating elapsed or remaining time. The format is either M:SS or H:MM:SS depending on if the time is an hour or more.
Referenced by message_progress_end(), and progress_remaining().
static const char* progress_remaining | ( | uint64_t | in_pos, | |
double | elapsed | |||
) | [static] |
Make the string to contain the estimated remaining time, or if the amount of input isn't known, how much time has elapsed.
References expected_in_size, and progress_time().
void message_progress_end | ( | uint64_t | in_pos, | |
uint64_t | out_pos, | |||
bool | success | |||
) |
Finishes the progress message if we were in verbose mode.
in_pos | Final input position i.e. how much input there was. | |
out_pos | Final output position | |
success | True if the operation was successful. We don't print the final progress message if the operation wasn't successful. |
References filename, my_time(), opt_mode, progress_active, progress_automatic, progress_sizes(), progress_speed(), progress_time(), signals_block(), signals_unblock(), start_time, user_abort, V_VERBOSE, and verbosity.
void message_bug | ( | void | ) |
Print an error message that an internal error occurred and exit with EXIT_ERROR.
References message_fatal().
void message_signal_handler | ( | void | ) |
Print a message that establishing signal handlers failed, and exit with exit status ERROR.
References message_fatal().
Referenced by message_init(), and signals_init().
const char* message_strm | ( | lzma_ret | code | ) |
Convert lzma_ret to a string.
References LZMA_BUF_ERROR, LZMA_DATA_ERROR, LZMA_FORMAT_ERROR, LZMA_GET_CHECK, LZMA_MEM_ERROR, LZMA_NO_CHECK, LZMA_OK, LZMA_OPTIONS_ERROR, LZMA_PROG_ERROR, LZMA_STREAM_END, and LZMA_UNSUPPORTED_CHECK.
void message_filters | ( | enum message_verbosity | v, | |
const lzma_filter * | filters | |||
) |
Print the filter chain.
References argv0, lzma_options_lzma::depth, lzma_options_lzma::dict_size, lzma_options_delta::dist, lzma_filter::id, lzma_options_lzma::lc, lzma_options_lzma::lp, LZMA_FILTER_ARM, LZMA_FILTER_ARMTHUMB, LZMA_FILTER_DELTA, LZMA_FILTER_IA64, LZMA_FILTER_LZMA1, LZMA_FILTER_LZMA2, LZMA_FILTER_POWERPC, LZMA_FILTER_SPARC, LZMA_FILTER_X86, LZMA_MF_BT2, LZMA_MF_BT3, LZMA_MF_BT4, LZMA_MF_HC3, LZMA_MF_HC4, LZMA_MODE_FAST, LZMA_MODE_NORMAL, LZMA_VLI_UNKNOWN, lzma_options_lzma::mf, lzma_options_lzma::mode, lzma_options_lzma::nice_len, lzma_filter::options, lzma_options_lzma::pb, and verbosity.
void message_try_help | ( | void | ) |
void message_version | ( | void | ) |
Prints the version number to stdout and exits with exit status SUCCESS.
References my_exit().
void message_help | ( | bool | long_help | ) |
Print the help message.
References argv0, hardware_memlimit_decoder(), hardware_memlimit_encoder(), my_exit(), and opt_threads.
const char* argv0 [static] |
Name of the program which is prefixed to the error messages.
Referenced by message_filters(), message_help(), message_init(), and message_try_help().
unsigned int files_pos = 0 [static] |
Number of the current file.
Referenced by print_filename().
unsigned int files_total [static] |
Total number of input files; zero if unknown.
Referenced by message_set_files(), and print_filename().
enum message_verbosity verbosity = V_WARNING [static] |
Verbosity level.
Referenced by message_filters(), message_progress_end(), message_verbosity_decrease(), and message_verbosity_increase().
const char* filename [static] |
Filename which we will print with the verbose messages.
Referenced by message_progress_end(), and print_filename().
bool first_filename_printed = false [static] |
True once the a filename has been printed to stderr as part of progress message. If automatic progress updating isn't enabled, this becomes true after the first progress message has been printed due to user sending SIGALRM. Once this variable is true, we will print an empty line before the next filename to make the output more readable.
Referenced by print_filename().
bool current_filename_printed = false [static] |
This is set to true when we have printed the current filename to stderr as part of a progress message. This variable is useful only if not updating progress automatically: if user sends many SIGALRM signals, we won't print the name of the same file multiple times.
Referenced by print_filename().
bool progress_automatic [static] |
True if we should print progress indicator and update it automatically.
Referenced by message_init(), and message_progress_end().
bool progress_active = false [static] |
This is true when a progress message was printed and the cursor is still on the same line with the progress message. In that case, a newline has to be printed before any error messages.
Referenced by message_progress_end().
uint64_t expected_in_size [static] |
Expected size of the input stream is needed to show completion percentage and estimate remaining time.
Referenced by progress_percentage(), and progress_remaining().
double start_time [static] |
Time when we started processing the file.
Referenced by message_progress_end().
volatile sig_atomic_t progress_needs_updating = false [static] |
The signal handler for SIGALRM sets this to true. It is set back to false once the progress message has been updated.
Referenced by progress_signal_handler().