From 4d364776fc785a234cebba08bc93cd06202103dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 20 May 2016 08:48:30 +0200 Subject: Merging upstream version 1.5. Signed-off-by: Daniel Baumann --- zcmp.cc | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) (limited to 'zcmp.cc') 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 to . If 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]