summaryrefslogtreecommitdiffstats
path: root/zcmp.cc
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--zcmp.cc28
1 files changed, 12 insertions, 16 deletions
diff --git a/zcmp.cc b/zcmp.cc
index 68e219e..1cbd384 100644
--- a/zcmp.cc
+++ b/zcmp.cc
@@ -1,5 +1,5 @@
/* Zcmp - decompress and compare two files byte by byte
- Copyright (C) 2010-2015 Antonio Diaz Diaz.
+ Copyright (C) 2010-2016 Antonio Diaz Diaz.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -50,11 +50,11 @@ namespace {
void show_help()
{
- std::printf( "Zcmp compares two files (\"-\" means standard input), and if they\n"
- "differ, tells the first byte and line number where they differ. Bytes\n"
- "and lines are numbered starting with 1. If any given file is compressed,\n"
- "its decompressed content is used. Compressed files are decompressed on\n"
- "the fly; no temporary files are created.\n"
+ std::printf( "Zcmp compares two files ('-' means standard input), and if they differ,\n"
+ "tells the first byte and line number where they differ. Bytes and lines\n"
+ "are numbered starting with 1. If any given file is compressed, its\n"
+ "decompressed content is used. Compressed files are decompressed on the\n"
+ "fly; no temporary files are created.\n"
"\nThe supported formats are bzip2, gzip, lzip and xz.\n"
"\nUsage: zcmp [options] file1 [file2]\n"
"\nCompares <file1> to <file2>. If <file2> is omitted zcmp tries the\n"
@@ -106,9 +106,8 @@ long long getnum( const char * const ptr, const char ** const tailp = 0,
if( !errno && tail[0] && std::isalpha( tail[0] ) )
{
- int factor = ( tail[1] == 'i' ) ? 1024 : 1000;
- int exponent = 0;
- bool bad_multiplier = false;
+ const int factor = ( tail[1] == 'i' ) ? 1024 : 1000;
+ int exponent = 0; // 0 = bad multiplier
switch( tail[0] )
{
case 'Y': exponent = 8; break;
@@ -118,13 +117,10 @@ long long getnum( const char * const ptr, const char ** const tailp = 0,
case 'T': exponent = 4; break;
case 'G': exponent = 3; break;
case 'M': exponent = 2; break;
- case 'K': if( factor == 1024 ) exponent = 1; else bad_multiplier = true;
- break;
- case 'k': if( factor == 1000 ) exponent = 1; else bad_multiplier = true;
- break;
- default : bad_multiplier = true;
+ case 'K': if( factor == 1024 ) exponent = 1; break;
+ case 'k': if( factor == 1000 ) exponent = 1; break;
}
- if( bad_multiplier )
+ if( exponent <= 0 )
{
show_error( "Bad multiplier in numerical argument.", 0, true );
std::exit( 2 );
@@ -298,7 +294,7 @@ int cmp( const long long max_size, const int infd[2],
if( verbosity >= 0 )
std::fprintf( stderr, "%s: EOF on %s\n",
program_name, filenames[rd[1]<rd[0]].c_str() );
- return 1;
+ return 1;
}
if( min_rd != buffer_size ) break;
}