Merging upstream version 1.4~pre2.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
454cd28d9e
commit
06e5e699b7
30 changed files with 802 additions and 552 deletions
91
zdiff.cc
91
zdiff.cc
|
@ -1,5 +1,5 @@
|
|||
/* Zdiff - decompress and compare two files line by line
|
||||
Copyright (C) 2010-2014 Antonio Diaz Diaz.
|
||||
Copyright (C) 2010-2015 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
|
||||
|
@ -66,30 +66,31 @@ void show_help()
|
|||
" standard input.\n"
|
||||
"\nExit status is 0 if inputs are identical, 1 if different, 2 if trouble.\n"
|
||||
"\nOptions:\n"
|
||||
" -h, --help display this help and exit\n"
|
||||
" -V, --version output version information and exit\n"
|
||||
" -a, --text treat all files as text\n"
|
||||
" -b, --ignore-space-change ignore changes in the amount of white space\n"
|
||||
" -B, --ignore-blank-lines ignore changes whose lines are all blank\n"
|
||||
" -c use the context output format\n"
|
||||
" -C, --context=<n> same as -c but use <n> lines of context\n"
|
||||
" -d, --minimal try hard to find a smaller set of changes\n"
|
||||
" -E, --ignore-tab-expansion ignore changes due to tab expansion\n"
|
||||
" --format=[<fmt1>][,<fmt2>] force given formats (bz2, gz, lz, xz)\n"
|
||||
" -i, --ignore-case ignore case differences in file contents\n"
|
||||
" -N, --no-rcfile don't read runtime configuration file\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"
|
||||
" -t, --expand-tabs expand tabs to spaces in output\n"
|
||||
" -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"
|
||||
" -w, --ignore-all-space ignore all white space\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"
|
||||
" -h, --help display this help and exit\n"
|
||||
" -V, --version output version information and exit\n"
|
||||
" -a, --text treat all files as text\n"
|
||||
" -b, --ignore-space-change ignore changes in the amount of white space\n"
|
||||
" -B, --ignore-blank-lines ignore changes whose lines are all blank\n"
|
||||
" -c use the context output format\n"
|
||||
" -C, --context=<n> same as -c but use <n> lines of context\n"
|
||||
" -d, --minimal try hard to find a smaller set of changes\n"
|
||||
" -E, --ignore-tab-expansion ignore changes due to tab expansion\n"
|
||||
" -i, --ignore-case ignore case differences in file contents\n"
|
||||
" -M, --format=<list> exclude formats not in <list>\n"
|
||||
" -N, --no-rcfile don't read runtime configuration file\n"
|
||||
" -O, --force-format=[<f1>][,<f2>] force given formats (bz2, gz, lz, xz)\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"
|
||||
" -t, --expand-tabs expand tabs to spaces in output\n"
|
||||
" -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"
|
||||
" -w, --ignore-all-space ignore all white space\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"
|
||||
"Numbers may be followed by a multiplier: k = kB = 10^3 = 1000,\n"
|
||||
"Ki = KiB = 2^10 = 1024, M = 10^6, Mi = 2^20, G = 10^9, Gi = 2^30, etc...\n" );
|
||||
show_help_addr();
|
||||
|
@ -113,27 +114,23 @@ extern "C" void remove_fifos()
|
|||
}
|
||||
|
||||
|
||||
// Set fifonames[i] to "${TMPDIR}/<coded_pid><i>_<basename(filenames[i])>"
|
||||
// Set fifonames[i] to "${TMPDIR}/<coded_pid>[_-]<basename(filenames[i])>"
|
||||
// and create FIFOs.
|
||||
bool set_fifonames( const std::string filenames[2] )
|
||||
{
|
||||
enum { num_codes = 36 };
|
||||
const char * const codes = "0123456789abcdefghijklmnopqrstuvwxyz";
|
||||
const char * p = std::getenv( "TMPDIR" );
|
||||
const int pid = getpid();
|
||||
|
||||
for( int i = 0; i < 2; ++i )
|
||||
{
|
||||
if( p ) fifonames[i] = p; else fifonames[i] = "/tmp";
|
||||
fifonames[i] += '/';
|
||||
int n = ( 2 * pid ) + i;
|
||||
const unsigned pos = fifonames[i].size();
|
||||
do { fifonames[i].insert( pos, 1, codes[n % num_codes] );
|
||||
n /= num_codes; }
|
||||
while( n );
|
||||
fifonames[i] += '_';
|
||||
fifonames[i] += my_basename( filenames[i].c_str() );
|
||||
}
|
||||
if( p ) { fifonames[0] = p; fifonames[0] += '/'; }
|
||||
else fifonames[0] = "/tmp/";
|
||||
int n = getpid();
|
||||
const unsigned pos = fifonames[0].size();
|
||||
do fifonames[0].insert( pos, 1, codes[n % num_codes] );
|
||||
while( n /= num_codes );
|
||||
fifonames[1] = fifonames[0];
|
||||
fifonames[0] += '_'; fifonames[0] += my_basename( filenames[0].c_str() );
|
||||
fifonames[1] += '-'; fifonames[1] += my_basename( filenames[1].c_str() );
|
||||
|
||||
for( int i = 0; i < 2; ++i )
|
||||
if( mkfifo( fifonames[i].c_str(), S_IRUSR | S_IWUSR ) != 0 )
|
||||
|
@ -263,7 +260,7 @@ void set_signals()
|
|||
|
||||
int main( const int argc, const char * const argv[] )
|
||||
{
|
||||
enum { format_opt = 256, bz2_opt, gz_opt, lz_opt, xz_opt };
|
||||
enum { bz2_opt = 256, gz_opt, lz_opt, xz_opt };
|
||||
std::vector< const char * > diff_args; // args to diff, maybe empty
|
||||
int format_types[2] = { -1, -1 };
|
||||
invocation_name = argv[0];
|
||||
|
@ -280,7 +277,9 @@ int main( const int argc, const char * const argv[] )
|
|||
{ 'E', "ignore-tab-expansion", Arg_parser::no },
|
||||
{ 'h', "help", Arg_parser::no },
|
||||
{ 'i', "ignore-case", Arg_parser::no },
|
||||
{ 'M', "format", Arg_parser::yes },
|
||||
{ 'N', "no-rcfile", Arg_parser::no },
|
||||
{ 'O', "force-format", Arg_parser::yes },
|
||||
{ 'p', "show-c-function", Arg_parser::no },
|
||||
{ 'q', "brief", Arg_parser::no },
|
||||
{ 's', "report-identical-files", Arg_parser::no },
|
||||
|
@ -290,7 +289,6 @@ int main( const int argc, const char * const argv[] )
|
|||
{ 'U', "unified", Arg_parser::yes },
|
||||
{ 'V', "version", Arg_parser::no },
|
||||
{ 'w', "ignore-all-space", Arg_parser::no },
|
||||
{ format_opt, "format", Arg_parser::yes },
|
||||
{ bz2_opt, "bz2", Arg_parser::yes },
|
||||
{ gz_opt, "gz", Arg_parser::yes },
|
||||
{ lz_opt, "lz", Arg_parser::yes },
|
||||
|
@ -308,29 +306,32 @@ int main( const int argc, const char * const argv[] )
|
|||
{
|
||||
const int code = parser.code( argind );
|
||||
if( !code ) break; // no more options
|
||||
const char * const arg = parser.argument( argind ).c_str();
|
||||
const std::string & arg = parser.argument( argind );
|
||||
switch( code )
|
||||
{
|
||||
case 'a': diff_args.push_back( "-a" ); break;
|
||||
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.c_str() ); break;
|
||||
case 'd': diff_args.push_back( "-d" ); break;
|
||||
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 'N': break;
|
||||
case 'O': parse_format_types2( arg, 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;
|
||||
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 'U': diff_args.push_back( "-U" );
|
||||
diff_args.push_back( arg.c_str() ); break;
|
||||
case 'V': show_version(); return 0;
|
||||
case 'w': diff_args.push_back( "-w" ); break;
|
||||
case format_opt: parse_format_types( arg, format_types ); break;
|
||||
case bz2_opt: parse_compressor( arg, fmt_bz2 ); break;
|
||||
case gz_opt: parse_compressor( arg, fmt_gz ); break;
|
||||
case lz_opt: parse_compressor( arg, fmt_lz ); break;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue