src/xz/message.c File Reference

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


Detailed Description

Printing messages to stderr.


Function Documentation

static void progress_signal_handler ( int sig   lzma_attribute(unused)  )  [static]

Signal handler for SIGALRM.

References progress_needs_updating.

Referenced by message_init().

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.

Parameters:
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   ) 

Increase verbosity level by one step unless it was at maximum.

References V_DEBUG, and verbosity.

void message_verbosity_decrease ( void   ) 

Decrease verbosity level by one step unless it was at minimum.

References V_SILENT, and verbosity.

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.

Parameters:
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.

void message_signal_handler ( void   ) 

Print a message that establishing signal handlers failed, and exit with exit status ERROR.

Referenced by message_init(), and signals_init().

const char* message_strm ( lzma_ret  code  ) 

void message_filters ( enum message_verbosity  v,
const lzma_filter filters 
)

void message_try_help ( void   ) 

Print a message that user should try --help.

References argv0, and V_WARNING.

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  ) 


Variable Documentation

const char* argv0 [static]

Name of the program which is prefixed to the error messages.

Referenced by message_filters(), message_help(), message_init(), message_try_help(), and str_to_uint64().

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]

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().


Generated on Wed May 25 10:35:47 2011 for XZ Utils by  doxygen 1.5.5