diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-12-08 15:52:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-12-08 15:52:09 +0000 |
commit | 4568b11461f80bbc5fa0fb2c522205683ea14ec7 (patch) | |
tree | 58834b3aa970b99bc0a1b0fcb9ae5510ca149cb1 /zdiff.cc | |
parent | Adding upstream version 1.12~pre2. (diff) | |
download | zutils-4568b11461f80bbc5fa0fb2c522205683ea14ec7.tar.xz zutils-4568b11461f80bbc5fa0fb2c522205683ea14ec7.zip |
Adding upstream version 1.12~rc1.upstream/1.12_rc1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'zdiff.cc')
-rw-r--r-- | zdiff.cc | 55 |
1 files changed, 22 insertions, 33 deletions
@@ -79,7 +79,7 @@ void show_help() " -i, --ignore-case ignore case differences in file contents\n" " -M, --format=<list> process only the formats in <list>\n" " -N, --no-rcfile don't read runtime configuration file\n" - " -O, --force-format=[<f1>][,<f2>] force the formats given (bz2,gz,lz,xz,zst)\n" + " -O, --force-format=[<f1>][,<f2>] force one or both input formats\n" " -p, --show-c-function show which C function each change is in\n" " -q, --brief output only whether files differ\n" " -s, --report-identical-files report when two files are identical\n" @@ -95,7 +95,9 @@ void show_help() " --gz=<command> set compressor and options for gzip format\n" " --lz=<command> set compressor and options for lzip format\n" " --xz=<command> set compressor and options for xz format\n" - " --zst=<command> set compressor and options for zstd format\n" ); + " --zst=<command> set compressor and options for zstd format\n" + "\nValid formats for options '-M' and '-O' are 'bz2', 'gz', 'lz', 'xz', 'zst',\n" + "and 'un' for uncompressed.\n" ); show_help_addr(); } @@ -128,7 +130,7 @@ bool set_fifonames( const std::string filenames[2] ) if( p ) { fifonames[0] = p; fifonames[0] += '/'; } else fifonames[0] = "/tmp/"; - int n = getpid(); + unsigned n = getpid(); do fifonames[0] += codes[n % num_codes]; while( n /= num_codes ); const unsigned pos = fifonames[0].size(); fifonames[0] += '_'; @@ -186,12 +188,8 @@ bool set_data_feeder( const std::string & filename, { const int outfd = open( fifoname.c_str(), O_WRONLY | O_BINARY ); if( outfd < 0 ) - { - if( verbosity >= 0 ) - std::fprintf( stderr, "%s: Can't open FIFO '%s' for writing: %s\n", - program_name, fifoname.c_str(), std::strerror( errno ) ); - _exit( 2 ); - } + { show_file_error( fifoname.c_str(), "Can't open FIFO for writing", + errno ); _exit( 2 ); } if( dup2( fda[0], STDIN_FILENO ) >= 0 && dup2( outfd, STDOUT_FILENO ) >= 0 && close( fda[0] ) == 0 && close( fda[1] ) == 0 && @@ -225,12 +223,8 @@ bool set_data_feeder( const std::string & filename, { const int outfd = open( fifoname.c_str(), O_WRONLY | O_BINARY ); if( outfd < 0 ) - { - if( verbosity >= 0 ) - std::fprintf( stderr, "%s: Can't open FIFO '%s' for writing: %s\n", - program_name, fifoname.c_str(), std::strerror( errno ) ); - _exit( 2 ); - } + { show_file_error( fifoname.c_str(), "Can't open FIFO for writing", + errno ); _exit( 2 ); } if( !feed_data( filename, infd, outfd, magic_data, magic_size ) ) _exit( 2 ); if( close( outfd ) != 0 ) @@ -268,7 +262,7 @@ int main( const int argc, const char * const argv[] ) { enum { bz2_opt = 256, gz_opt, lz_opt, xz_opt, zst_opt }; std::vector< const char * > diff_args; // args to diff, maybe empty - int format_types[2] = { -1, -1 }; + int format_types[2] = { -1, -1 }; // < 0 means undefined program_name = "zdiff"; invocation_name = ( argc > 0 ) ? argv[0] : program_name; @@ -325,8 +319,7 @@ int main( const int argc, const char * const argv[] ) case 'b': diff_args.push_back( "-b" ); break; case 'B': diff_args.push_back( "-B" ); break; case 'c': diff_args.push_back( "-c" ); break; - case 'C': diff_args.push_back( "-C" ); - diff_args.push_back( arg ); break; + case 'C': diff_args.push_back( "-C" ); diff_args.push_back( arg ); break; case 'd': diff_args.push_back( "-d" ); break; case 'E': diff_args.push_back( "-E" ); break; case 'h': show_help(); return 0; @@ -340,19 +333,17 @@ int main( const int argc, const char * const argv[] ) case 't': diff_args.push_back( "-t" ); break; case 'T': diff_args.push_back( "-T" ); break; case 'u': diff_args.push_back( "-u" ); break; - case 'U': diff_args.push_back( "-U" ); - diff_args.push_back( arg ); break; - case 'v': verbosity = 1; break; + case 'U': diff_args.push_back( "-U" ); diff_args.push_back( arg ); break; + case 'v': if( verbosity < 4 ) ++verbosity; break; case 'V': show_version( DIFF " --version" ); return 0; case 'w': diff_args.push_back( "-w" ); break; - case 'W': diff_args.push_back( "-W" ); - diff_args.push_back( arg ); break; + case 'W': diff_args.push_back( "-W" ); diff_args.push_back( arg ); break; case 'y': diff_args.push_back( "-y" ); break; - case bz2_opt: parse_compressor( sarg, fmt_bz2 ); break; - case gz_opt: parse_compressor( sarg, fmt_gz ); break; - case lz_opt: parse_compressor( sarg, fmt_lz ); break; - case xz_opt: parse_compressor( sarg, fmt_xz ); break; - case zst_opt: parse_compressor( sarg, fmt_zst ); break; + case bz2_opt: parse_compressor( sarg, pn, fmt_bz2 ); break; + case gz_opt: parse_compressor( sarg, pn, fmt_gz ); break; + case lz_opt: parse_compressor( sarg, pn, fmt_lz ); break; + case xz_opt: parse_compressor( sarg, pn, fmt_xz ); break; + case zst_opt: parse_compressor( sarg, pn, fmt_zst ); break; default : internal_error( "uncaught option." ); } } // end process options @@ -362,12 +353,10 @@ int main( const int argc, const char * const argv[] ) setmode( STDOUT_FILENO, O_BINARY ); #endif - if( argind >= parser.arguments() ) - { show_error( "No files given.", 0, true ); return 2; } - if( parser.arguments() - argind > 2 ) - { show_error( "Too many files.", 0, true ); return 2; } - const int files = parser.arguments() - argind; + if( files < 1 ) { show_error( "No files given.", 0, true ); return 2; } + if( files > 2 ) { show_error( "Too many files.", 0, true ); return 2; } + std::string filenames[2]; // file names of the two input files filenames[0] = parser.argument( argind ); if( files == 2 ) filenames[1] = parser.argument( argind + 1 ); |