diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-10-07 08:14:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-10-07 08:14:58 +0000 |
commit | c0f0f7eb32c314973c36f3f6afd375f80544311f (patch) | |
tree | 77cba6ec8b0c87b257239db470e2b55ebe922a93 /main_common.cc | |
parent | Adding upstream version 1.24. (diff) | |
download | lziprecover-c0f0f7eb32c314973c36f3f6afd375f80544311f.tar.xz lziprecover-c0f0f7eb32c314973c36f3f6afd375f80544311f.zip |
Adding upstream version 1.25~pre1.upstream/1.25_pre1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'main_common.cc')
-rw-r--r-- | main_common.cc | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/main_common.cc b/main_common.cc index dfaccac..4a40acf 100644 --- a/main_common.cc +++ b/main_common.cc @@ -15,6 +15,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ +int cl_verbosity = 0; // used to silence internal_error if '-q' +int verbosity = 0; + namespace { const char * const program_year = "2024"; @@ -29,8 +32,8 @@ void show_version() } -// separate numbers of 5 or more digits in groups of 3 digits using '_' -const char * format_num3( long long num ) +// separate numbers of 6 or more digits in groups of 3 digits using '_' +const char * format_num3p( long long num, const bool raw = false ) { enum { buffers = 8, bufsize = 4 * sizeof num, n = 10 }; const char * const si_prefix = "kMGTPEZYRQ"; @@ -42,7 +45,7 @@ const char * format_num3( long long num ) char * p = buf + bufsize - 1; // fill the buffer backwards *p = 0; // terminator const bool negative = num < 0; - if( num > 1024 || num < -1024 ) + if( !raw && ( num > 9999 || num < -9999 ) ) { char prefix = 0; // try binary first, then si for( int i = 0; i < n && num != 0 && num % 1024 == 0; ++i ) @@ -53,7 +56,7 @@ const char * format_num3( long long num ) { num /= 1000; prefix = si_prefix[i]; } if( prefix ) *(--p) = prefix; } - const bool split = num >= 10000 || num <= -10000; + const bool split = num >= 100000 || num <= -100000; for( int i = 0; ; ) { @@ -136,8 +139,8 @@ long long getnum( const char * const arg, const char * const option_name, { if( verbosity >= 0 ) std::fprintf( stderr, "%s: '%s': Value out of limits [%s,%s] in " - "option '%s'.\n", program_name, arg, format_num3( llimit ), - format_num3( ulimit ), option_name ); + "option '%s'.\n", program_name, arg, format_num3p( llimit ), + format_num3p( ulimit ), option_name ); std::exit( 1 ); } if( tailp ) *tailp = tail; @@ -148,7 +151,6 @@ long long getnum( const char * const arg, const char * const option_name, // Recognized formats: <pos>,<value> <pos>,+<value> <pos>,f<value> -// void Bad_byte::parse_bb( const char * const arg, const char * const pn ) { argument = arg; @@ -166,6 +168,9 @@ void Bad_byte::parse_bb( const char * const arg, const char * const pn ) } +const char * format_num3( long long num ) { return format_num3p( num, true ); } + + void show_error( const char * const msg, const int errcode, const bool help ) { if( verbosity < 0 ) return; @@ -191,7 +196,7 @@ void show_file_error( const char * const filename, const char * const msg, void internal_error( const char * const msg ) { - if( verbosity >= 0 ) + if( cl_verbosity >= 0 ) std::fprintf( stderr, "%s: internal error: %s\n", program_name, msg ); std::exit( 3 ); } |