Rizin
unix-like reverse engineering framework and cli tools
|
Printing messages. More...
Go to the source code of this file.
Functions | |
void | message_init (void) |
Initializes the message functions. More... | |
void | message_verbosity_increase (void) |
Increase verbosity level by one step unless it was at maximum. More... | |
void | message_verbosity_decrease (void) |
Decrease verbosity level by one step unless it was at minimum. More... | |
enum message_verbosity | message_verbosity_get (void) |
Get the current verbosity level. More... | |
void | message_set_files (unsigned int files) |
Set the total number of files to be processed. More... | |
static void | print_filename (void) |
void | message_filename (const char *src_name) |
Set the name of the current file and possibly print it too. More... | |
void | message_progress_start (lzma_stream *strm, bool is_passthru, uint64_t in_size) |
Start progress info handling. More... | |
static const char * | progress_percentage (uint64_t in_pos) |
Make the string indicating completion percentage. More... | |
static const char * | progress_sizes (uint64_t compressed_pos, uint64_t uncompressed_pos, bool final) |
static const char * | progress_speed (uint64_t uncompressed_pos, uint64_t elapsed) |
Make the string containing the processing speed of uncompressed data. More... | |
static const char * | progress_time (uint64_t mseconds) |
static const char * | progress_remaining (uint64_t in_pos, uint64_t elapsed) |
static void | progress_pos (uint64_t *in_pos, uint64_t *compressed_pos, uint64_t *uncompressed_pos) |
Get how much uncompressed and compressed data has been processed. More... | |
void | message_progress_update (void) |
static void | progress_flush (bool finished) |
void | message_progress_end (bool success) |
Finishes the progress message if we were in verbose mode. More... | |
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. More... | |
void | message_mem_needed (enum message_verbosity v, uint64_t memusage) |
Display how much memory was needed and how much the limit was. More... | |
static const char * | uint32_to_optstr (uint32_t num) |
Convert uint32_t to a nice string for –lzma[12]=dict=SIZE. More... | |
void | message_filters_to_str (char buf[FILTERS_STR_SIZE], const lzma_filter *filters, bool all_known) |
Get the filter chain as a string. More... | |
void | message_filters_show (enum message_verbosity v, const lzma_filter *filters) |
Print the filter chain. More... | |
void | message_try_help (void) |
Print a message that user should try –help. More... | |
void | message_version (void) |
Prints the version number to stdout and exits with exit status SUCCESS. More... | |
void | message_help (bool long_help) |
Print the help message. More... | |
Variables | |
static unsigned int | files_pos = 0 |
Number of the current file. More... | |
static unsigned int | files_total |
Total number of input files; zero if unknown. More... | |
static enum message_verbosity | verbosity = V_WARNING |
Verbosity level. More... | |
static const char * | filename |
Filename which we will print with the verbose messages. More... | |
static bool | first_filename_printed = false |
static bool | current_filename_printed = false |
static bool | progress_automatic |
static bool | progress_started = false |
static bool | progress_active = false |
static lzma_stream * | progress_strm |
Pointer to lzma_stream used to do the encoding or decoding. More... | |
static bool | progress_is_from_passthru |
static uint64_t | expected_in_size |
static bool | progress_needs_updating = false |
static uint64_t | progress_next_update |
Elapsed time when the next progress message update should be done. More... | |
Printing messages.
Definition in file message.c.
void message | ( | enum message_verbosity | v, |
const char * | fmt, | ||
... | |||
) |
Definition at line 740 of file message.c.
References v, and vmessage().
Referenced by message_mem_needed(), and message_try_help().
void message_bug | ( | void | ) |
Print an error message that an internal error occurred and exit with EXIT_ERROR.
Definition at line 789 of file message.c.
References _, and message_fatal().
Referenced by coder_init(), io_read(), options_lzma(), parse_block_header(), and parse_indexes().
void message_error | ( | const char * | fmt, |
... | |||
) |
Definition at line 764 of file message.c.
References E_ERROR, set_exit_status(), V_ERROR, and vmessage().
Referenced by coder_normal(), compressed_name(), io_close(), io_close_dest(), io_close_src(), io_open_dest_real(), io_open_src_real(), io_pread(), io_read(), io_unlink(), io_wait(), io_write(), io_write_buf(), is_empty_filename(), is_tty_stdin(), is_tty_stdout(), list_file(), main(), parse_block_header(), parse_indexes(), read_name(), and uncompressed_name().
void message_fatal | ( | const char * | fmt, |
... | |||
) |
Definition at line 777 of file message.c.
References E_ERROR, tuklib_exit, V_ERROR, and vmessage().
Referenced by args_parse(), coder_add_filter(), coder_init(), io_init(), list_file(), lzma_attribute(), main(), message_bug(), message_signal_handler(), options_lzma(), parse_block_list(), parse_environment(), parse_options(), parse_real(), str_to_uint64(), suffix_set(), and xrealloc().
void message_filename | ( | const char * | src_name | ) |
Set the name of the current file and possibly print it too.
The name is printed immediately if –list was used or if –verbose 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.
Definition at line 232 of file message.c.
References current_filename_printed, files_pos, MODE_LIST, opt_mode, print_filename(), progress_automatic, V_VERBOSE, and verbosity.
Referenced by coder_run(), and list_file().
void message_filters_show | ( | enum message_verbosity | v, |
const lzma_filter * | filters | ||
) |
Print the filter chain.
Definition at line 1050 of file message.c.
References _, filters, FILTERS_STR_SIZE, message_filters_to_str(), progname, v, and verbosity.
Referenced by coder_init().
void message_filters_to_str | ( | char | buf[FILTERS_STR_SIZE], |
const lzma_filter * | filters, | ||
bool | all_known | ||
) |
Get the filter chain as a string.
buf | Pointer to caller allocated buffer to hold the filter chain string |
filters | Pointer to the filter chain |
all_known | If true, all filter options are printed. If false, only the options that get stored into .xz headers are printed. |
Definition at line 917 of file message.c.
References assert(), lzma_options_lzma::depth, lzma_options_lzma::dict_size, lzma_options_delta::dist, filters, FILTERS_STR_SIZE, i, 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, my_snprintf(), lzma_options_lzma::nice_len, NULL, lzma_filter::options, lzma_options_lzma::pb, pos, PRIu32, lzma_options_bcj::start_offset, and uint32_to_optstr().
Referenced by message_filters_show(), and parse_block_header().
void message_help | ( | bool | long_help | ) |
Print the help message.
Definition at line 1091 of file message.c.
References _, E_ERROR, E_SUCCESS, PACKAGE_BUGREPORT, PACKAGE_NAME, PACKAGE_URL, printf(), progname, tuklib_exit, V_SILENT, and verbosity.
Referenced by parse_real().
void message_init | ( | void | ) |
Initializes the message functions.
If an error occurs, this function doesn't return.
Definition at line 114 of file message.c.
References i, message_progress_sigs, message_signal_handler(), NULL, progress_automatic, and STDERR_FILENO.
Referenced by main().
void message_mem_needed | ( | enum message_verbosity | v, |
uint64_t | memusage | ||
) |
Display how much memory was needed and how much the limit was.
Definition at line 846 of file message.c.
References _, hardware_memlimit_get(), memlimit, message(), opt_mode, round_up_to_mib(), snprintf, UINT32_C, UINT64_MAX, uint64_to_str(), v, and verbosity.
Referenced by coder_init(), coder_normal(), lzma_attribute(), and parse_indexes().
void message_progress_end | ( | bool | finished | ) |
Finishes the progress message if we were in verbose mode.
finished | True if the whole stream was successfully coded and output written to the output stream. |
Definition at line 707 of file message.c.
References assert(), progress_flush(), and progress_started.
Referenced by coder_run().
void message_progress_start | ( | lzma_stream * | strm, |
bool | is_passthru, | ||
uint64_t | in_size | ||
) |
Start progress info handling.
message_filename() must be called before this function to set the filename.
This must be paired with a call to message_progress_end() before the given *strm becomes invalid.
strm | Pointer to lzma_stream used for the coding. |
in_size | Size of the input file, or zero if unknown. |
Definition at line 249 of file message.c.
References alarm, expected_in_size, in_size, progress_automatic, progress_is_from_passthru, progress_needs_updating, progress_next_update, progress_started, progress_strm, strm, V_VERBOSE, and verbosity.
Referenced by coder_run().
void message_progress_update | ( | void | ) |
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.
Definition at line 545 of file message.c.
References alarm, assert(), current_filename_printed, in_pos, mytime_get_elapsed(), print_filename(), progress_active, progress_automatic, progress_needs_updating, progress_next_update, progress_percentage(), progress_pos(), progress_remaining(), progress_sizes(), progress_speed(), progress_time(), signals_block(), signals_unblock(), tuklib_mbstr_fw, V_VERBOSE, and verbosity.
Referenced by coder_normal(), and coder_passthru().
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().
Definition at line 188 of file message.c.
References files, and files_total.
Referenced by main().
void message_signal_handler | ( | void | ) |
Print a message that establishing signal handlers failed, and exit with exit status ERROR.
Definition at line 796 of file message.c.
References _, and message_fatal().
Referenced by message_init(), and signals_init().
Convert lzma_ret to a string.
Definition at line 803 of file message.c.
References _, ENOMEM, LZMA_BUF_ERROR, LZMA_DATA_ERROR, LZMA_FORMAT_ERROR, LZMA_GET_CHECK, LZMA_MEM_ERROR, LZMA_MEMLIMIT_ERROR, LZMA_NO_CHECK, LZMA_OK, LZMA_OPTIONS_ERROR, LZMA_PROG_ERROR, LZMA_STREAM_END, and LZMA_UNSUPPORTED_CHECK.
Referenced by coder_normal(), parse_block_header(), and parse_indexes().
void message_try_help | ( | void | ) |
void message_verbosity_decrease | ( | void | ) |
enum message_verbosity message_verbosity_get | ( | void | ) |
Get the current verbosity level.
Definition at line 171 of file message.c.
Referenced by hardware_memlimit_show(), list_file(), list_totals(), main(), print_info_adv(), print_info_robot(), print_totals_adv(), and print_totals_robot().
void message_verbosity_increase | ( | void | ) |
Increase verbosity level by one step unless it was at maximum.
Definition at line 161 of file message.c.
References V_DEBUG, and verbosity.
Referenced by parse_real().
void message_version | ( | void | ) |
Prints the version number to stdout and exits with exit status SUCCESS.
Definition at line 1074 of file message.c.
References E_ERROR, E_SUCCESS, LZMA_VERSION, LZMA_VERSION_STRING, opt_robot, PACKAGE_NAME, printf(), PRIu32, tuklib_exit, V_SILENT, and verbosity.
Referenced by parse_real().
void message_warning | ( | const char * | fmt, |
... | |||
) |
Definition at line 751 of file message.c.
References E_WARNING, set_exit_status(), V_WARNING, and vmessage().
Referenced by coder_normal(), io_copy_attrs(), io_open_src_real(), msg_suffix(), and uncompressed_name().
|
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.
Definition at line 200 of file message.c.
References current_filename_printed, benchmark::FILE, files_pos, files_total, first_filename_printed, MODE_LIST, opt_mode, opt_robot, signals_block(), signals_unblock(), and stdin_filename.
Referenced by message_filename(), and message_progress_update().
|
static |
Definition at line 629 of file message.c.
References in_pos, mytime_get_elapsed(), percentage, progress_active, progress_automatic, progress_percentage(), progress_pos(), progress_remaining(), progress_sizes(), progress_speed(), progress_started, progress_time(), signals_block(), signals_unblock(), tuklib_mbstr_fw, V_VERBOSE, and verbosity.
Referenced by message_progress_end(), and vmessage().
Make the string indicating completion percentage.
Definition at line 291 of file message.c.
References expected_in_size, in_pos, percentage, and snprintf.
Referenced by message_progress_update(), and progress_flush().
|
static |
Get how much uncompressed and compressed data has been processed.
Definition at line 512 of file message.c.
References assert(), in_pos, MODE_COMPRESS, opt_mode, out_pos, progress_is_from_passthru, progress_strm, lzma_stream::total_in, and lzma_stream::total_out.
Referenced by message_progress_update(), and progress_flush().
Return a string containing estimated remaining time when reasonably possible.
Definition at line 426 of file message.c.
References expected_in_size, in_pos, PRIu32, snprintf, and UINT64_C.
Referenced by message_progress_update(), and progress_flush().
|
static |
Make the string containing the amount of input processed, amount of output produced, and the compression ratio.
Definition at line 315 of file message.c.
References my_snprintf(), NICESTR_B, NICESTR_MIB, NICESTR_TIB, pos, snprintf, and uint64_to_nicestr().
Referenced by message_progress_update(), and progress_flush().
Make the string containing the processing speed of uncompressed data.
Definition at line 351 of file message.c.
References ARRAY_SIZE, and snprintf.
Referenced by message_progress_update(), and progress_flush().
Make a string indicating elapsed time. The format is either M:SS or H:MM:SS depending on if the time is an hour or more.
Definition at line 393 of file message.c.
References PRIu32, and snprintf.
Referenced by message_progress_update(), and progress_flush().
Convert uint32_t to a nice string for –lzma[12]=dict=SIZE.
The idea is to use KiB or MiB suffix when possible.
Definition at line 901 of file message.c.
References num, PRIu32, snprintf, and UINT32_C.
Referenced by message_filters_to_str().
|
static |
Definition at line 717 of file message.c.
References _, progname, progress_flush(), signals_block(), signals_unblock(), v, and verbosity.
Referenced by message(), message_error(), message_fatal(), and message_warning().
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 SIGINFO, SIGUSR1, or SIGALRM signals, we won't print the name of the same file multiple times.
Definition at line 41 of file message.c.
Referenced by message_filename(), message_progress_update(), and print_filename().
|
static |
Expected size of the input stream is needed to show completion percentage and estimate remaining time.
Definition at line 66 of file message.c.
Referenced by message_progress_start(), progress_percentage(), and progress_remaining().
Number of the current file.
Definition at line 19 of file message.c.
Referenced by message_filename(), and print_filename().
Total number of input files; zero if unknown.
Definition at line 22 of file message.c.
Referenced by message_set_files(), and print_filename().
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 SIGINFO, SIGUSR1, or SIGALRM. Once this variable is true, we will print an empty line before the next filename to make the output more readable.
Definition at line 35 of file message.c.
Referenced by print_filename().
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.
Definition at line 54 of file message.c.
Referenced by message_progress_update(), and progress_flush().
|
static |
True if we should print progress indicator and update it automatically if also verbose >= V_VERBOSE.
Definition at line 45 of file message.c.
Referenced by message_filename(), message_init(), message_progress_start(), message_progress_update(), and progress_flush().
|
static |
This is true if we are in passthru mode (not actually compressing or decompressing) and thus cannot use lzma_get_progress(progress_strm, ...). That is, we are using coder_passthru() in coder.c.
Definition at line 62 of file message.c.
Referenced by message_progress_start(), and progress_pos().
This is true when progress message printing is wanted. Using the same variable name as above to avoid some ifdefs.
Definition at line 105 of file message.c.
Referenced by message_progress_start(), and message_progress_update().
|
static |
Elapsed time when the next progress message update should be done.
Definition at line 108 of file message.c.
Referenced by message_progress_start(), and message_progress_update().
True if message_progress_start() has been called but message_progress_end() hasn't been called yet.
Definition at line 49 of file message.c.
Referenced by message_progress_end(), message_progress_start(), and progress_flush().
|
static |
Pointer to lzma_stream used to do the encoding or decoding.
Definition at line 57 of file message.c.
Referenced by message_progress_start(), and progress_pos().
|
static |
Verbosity level.
Definition at line 22 of file message.c.
Referenced by message_filename(), message_filters_show(), message_help(), message_mem_needed(), message_progress_start(), message_progress_update(), message_verbosity_decrease(), message_verbosity_increase(), message_version(), progress_flush(), and vmessage().