1
0
Fork 0

Merging upstream version 1.11.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-24 06:00:56 +01:00
parent ddac2f7869
commit bd6a3e4e88
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
31 changed files with 734 additions and 377 deletions

View file

@ -1,5 +1,5 @@
/* Zdiff - decompress and compare two files line by line
Copyright (C) 2010-2021 Antonio Diaz Diaz.
Copyright (C) 2010-2022 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
@ -31,7 +31,7 @@
#include <stdint.h>
#include <unistd.h>
#include <sys/stat.h>
#if defined(__MSVCRT__) || defined(__OS2__)
#if defined __MSVCRT__ || defined __OS2__
#include <io.h>
#endif
@ -39,7 +39,6 @@
#include "rc.h"
#include "zutils.h"
// 'verbosity' is always 0 in zdiff; no --verbose or --quiet available.
namespace {
@ -54,7 +53,8 @@ void show_help()
"input. If any file given is compressed, its decompressed content is used.\n"
"zdiff is a front end to the program diff and has the limitation that messages\n"
"from diff refer to temporary file names instead of those specified.\n"
"\nThe formats supported are bzip2, gzip, lzip, and xz.\n"
"\n'zdiff -v -V' prints the version of the diff program used.\n"
"\nThe formats supported are bzip2, gzip, lzip, xz, and zstd.\n"
"\nUsage: zdiff [options] file1 [file2]\n"
"\nzdiff compares file1 to file2. The standard input is used only if file1 or\n"
"file2 refers to standard input. If file2 is omitted zdiff tries the\n"
@ -63,7 +63,7 @@ void show_help()
" the corresponding uncompressed file (the name of file1 with the\n"
" extension removed).\n"
"\n - If file1 is uncompressed, compares it with the decompressed\n"
" contents of file1.[lz|bz2|gz|xz] (the first one that is found).\n"
" contents of file1.[lz|bz2|gz|zst|xz] (the first one that is found).\n"
"\nExit status is 0 if inputs are identical, 1 if different, 2 if trouble.\n"
"Some options only work if the diff program used supports them.\n"
"\nOptions:\n"
@ -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)\n"
" -O, --force-format=[<f1>][,<f2>] force the formats given (bz2,gz,lz,xz,zst)\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"
@ -87,13 +87,15 @@ void show_help()
" -T, --initial-tab make tabs line up by prepending a tab\n"
" -u use the unified output format\n"
" -U, --unified=<n> same as -u but use <n> lines of context\n"
" -v, --verbose verbose mode (for --version)\n"
" -w, --ignore-all-space ignore all white space\n"
" -W, --width=<n> output at most <n> print columns\n"
" -y, --side-by-side output in two columns\n"
" --bz2=<command> set compressor and options for bzip2 format\n"
" --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" );
" --xz=<command> set compressor and options for xz format\n"
" --zst=<command> set compressor and options for zstd format\n" );
show_help_addr();
}
@ -264,7 +266,7 @@ void set_signals()
int main( const int argc, const char * const argv[] )
{
enum { bz2_opt = 256, gz_opt, lz_opt, xz_opt };
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 };
program_name = "zdiff";
@ -291,15 +293,17 @@ int main( const int argc, const char * const argv[] )
{ 'T', "initial-tab", Arg_parser::no },
{ 'u', 0, Arg_parser::no },
{ 'U', "unified", Arg_parser::yes },
{ 'v', "verbose", Arg_parser::no },
{ 'V', "version", Arg_parser::no },
{ 'w', "ignore-all-space", Arg_parser::no },
{ 'W', "width", Arg_parser::yes },
{ 'y', "side-by-side", Arg_parser::no },
{ bz2_opt, "bz2", Arg_parser::yes },
{ gz_opt, "gz", Arg_parser::yes },
{ lz_opt, "lz", Arg_parser::yes },
{ xz_opt, "xz", Arg_parser::yes },
{ 0 , 0, Arg_parser::no } };
{ bz2_opt, "bz2", Arg_parser::yes },
{ gz_opt, "gz", Arg_parser::yes },
{ lz_opt, "lz", Arg_parser::yes },
{ xz_opt, "xz", Arg_parser::yes },
{ zst_opt, "zst", Arg_parser::yes },
{ 0, 0, Arg_parser::no } };
const Arg_parser parser( argc, argv, options );
if( parser.error().size() ) // bad option
@ -312,6 +316,7 @@ int main( const int argc, const char * const argv[] )
{
const int code = parser.code( argind );
if( !code ) break; // no more options
const char * const pn = parser.parsed_name( argind ).c_str();
const std::string & arg = parser.argument( argind );
switch( code )
{
@ -325,9 +330,9 @@ int main( const int argc, const char * const argv[] )
case 'E': diff_args.push_back( "-E" ); break;
case 'h': show_help(); return 0;
case 'i': diff_args.push_back( "-i" ); break;
case 'M': parse_format_list( arg ); break;
case 'M': parse_format_list( arg, pn ); break;
case 'N': break;
case 'O': parse_format_types2( arg, format_types ); break;
case 'O': parse_format_types2( arg, pn, format_types ); break;
case 'p': diff_args.push_back( "-p" ); break;
case 'q': diff_args.push_back( "-q" ); break;
case 's': diff_args.push_back( "-s" ); break;
@ -336,7 +341,8 @@ int main( const int argc, const char * const argv[] )
case 'u': diff_args.push_back( "-u" ); break;
case 'U': diff_args.push_back( "-U" );
diff_args.push_back( arg.c_str() ); break;
case 'V': show_version(); return 0;
case 'v': verbosity = 1; 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.c_str() ); break;
@ -345,18 +351,19 @@ int main( const int argc, const char * const argv[] )
case gz_opt: parse_compressor( arg, fmt_gz ); break;
case lz_opt: parse_compressor( arg, fmt_lz ); break;
case xz_opt: parse_compressor( arg, fmt_xz ); break;
case zst_opt: parse_compressor( arg, fmt_zst ); break;
default : internal_error( "uncaught option." );
}
} // end process options
#if defined(__MSVCRT__) || defined(__OS2__)
#if defined __MSVCRT__ || defined __OS2__
setmode( STDIN_FILENO, O_BINARY );
setmode( STDOUT_FILENO, O_BINARY );
#endif
if( argind >= parser.arguments() )
{ show_error( "No files given.", 0, true ); return 2; }
if( argind + 2 < parser.arguments() )
if( parser.arguments() - argind > 2 )
{ show_error( "Too many files.", 0, true ); return 2; }
const int files = parser.arguments() - argind;
@ -427,7 +434,19 @@ int main( const int argc, const char * const argv[] )
int retval = wait_for_child( diff_pid, DIFF );
for( int i = 0; i < 2; ++i )
if( !good_status( children[i], retval == 0 ) ) retval = 2;
{
int infd; // fifo from decompressor
do infd = open( fifonames[i].c_str(), O_RDONLY | O_NONBLOCK | O_BINARY );
while( infd < 0 && errno == EINTR );
bool finished = false; // set to true if fifo is empty and at EOF
if( infd >= 0 )
{
uint8_t b;
if( readblock( infd, &b, 1 ) <= 0 && errno == 0 ) finished = true;
close( infd );
}
if( !good_status( children[i], finished ) ) retval = 2;
}
for( int i = 0; i < 2; ++i )
if( filenames[i] != "-" && close( infd[i] ) != 0 )