diff options
Diffstat (limited to '')
-rw-r--r-- | main.c | 60 |
1 files changed, 14 insertions, 46 deletions
@@ -128,6 +128,7 @@ static void show_help() printf( " -c, --stdout send output to standard output\n" ); printf( " -d, --decompress decompress\n" ); printf( " -f, --force overwrite existing output files\n" ); + printf( " -F, --recompress force recompression of compressed files\n" ); printf( " -k, --keep keep (don't delete) input files\n" ); printf( " -m, --match-length=<n> set match length limit in bytes [36]\n" ); printf( " -o, --output=<file> if reading stdin, place the output into <file>\n" ); @@ -244,10 +245,10 @@ static int get_dict_size( const char * const arg ) static int open_instream( const char * const name, struct stat * const in_statsp, const enum Mode program_mode, const int eindex, - const bool force, const bool to_stdout ) + const bool recompress, const bool to_stdout ) { int infd = -1; - if( program_mode == m_compress && !force && eindex >= 0 ) + if( program_mode == m_compress && !recompress && eindex >= 0 ) { if( verbosity >= 0 ) fprintf( stderr, "%s: Input file `%s' already has `%s' suffix.\n", @@ -327,7 +328,7 @@ static void set_d_outname( const char * const name, const int i ) output_filename = resize_buffer( output_filename, strlen( name ) + 4 + 1 ); strcpy( output_filename, name ); strcat( output_filename, ".out" ); - if( verbosity >= 0 ) + if( verbosity >= 1 ) fprintf( stderr, "%s: Can't guess original name for `%s' -- using `%s'.\n", program_name, name, output_filename ); } @@ -378,7 +379,7 @@ void cleanup_and_fail( const int retval ) fprintf( stderr, "%s: Deleting output file `%s', if it exists.\n", program_name, output_filename ); if( outfd >= 0 ) { close( outfd ); outfd = -1; } - if( remove( output_filename ) != 0 ) + if( remove( output_filename ) != 0 && errno != ENOENT ) show_error( "WARNING: deletion of output file (apparently) failed.", 0, false ); } exit( retval ); @@ -538,7 +539,7 @@ static int decompress( const int infd, struct Pretty_print * const pp, { Pp_show_msg( pp, "Invalid dictionary size in member header" ); retval = 2; break; } - if( verbosity >= 1 ) + if( verbosity >= 2 || ( verbosity == 1 && first_member ) ) { Pp_show_msg( pp, 0 ); if( verbosity >= 2 ) @@ -564,11 +565,14 @@ static int decompress( const int infd, struct Pretty_print * const pp, } retval = 2; break; } - if( verbosity >= 1 ) + if( verbosity >= 2 ) { if( testing ) fprintf( stderr, "ok\n" ); else fprintf( stderr, "done\n" ); } } Rd_free( &rdec ); + if( verbosity == 1 && retval == 0 ) + { if( testing ) fprintf( stderr, "ok\n" ); + else fprintf( stderr, "done\n" ); } return retval; } @@ -654,45 +658,6 @@ void internal_error( const char * const msg ) } -/* Returns the number of bytes really read. - If (returned value < size) and (errno == 0), means EOF was reached. -*/ -int readblock( const int fd, uint8_t * const buf, const int size ) - { - int rest = size; - while( true ) - { - int n; - errno = 0; - if( rest <= 0 ) break; - n = read( fd, buf + size - rest, rest ); - if( n > 0 ) rest -= n; - else if( n == 0 ) break; - else if( errno != EINTR && errno != EAGAIN ) break; - } - return ( rest > 0 ) ? size - rest : size; - } - - -/* Returns the number of bytes really written. - If (returned value < size), it is always an error. -*/ -int writeblock( const int fd, const uint8_t * const buf, const int size ) - { - int rest = size; - while( true ) - { - int n; - errno = 0; - if( rest <= 0 ) break; - n = write( fd, buf + size - rest, rest ); - if( n > 0 ) rest -= n; - else if( errno && errno != EINTR && errno != EAGAIN ) break; - } - return ( rest > 0 ) ? size - rest : size; - } - - int main( const int argc, const char * const argv[] ) { /* Mapping from gzip/bzip2 style 1..9 compression modes @@ -724,6 +689,7 @@ int main( const int argc, const char * const argv[] ) bool filenames_given = false; bool force = false; bool keep_input_files = false; + bool recompress = false; bool to_stdout = false; struct Pretty_print pp; @@ -744,6 +710,7 @@ int main( const int argc, const char * const argv[] ) { 'd', "decompress", ap_no }, { 'e', "extreme", ap_no }, { 'f', "force", ap_no }, + { 'F', "recompress", ap_no }, { 'h', "help", ap_no }, { 'k', "keep", ap_no }, { 'm', "match-length", ap_yes }, @@ -781,6 +748,7 @@ int main( const int argc, const char * const argv[] ) case 'd': program_mode = m_decompress; break; case 'e': break; /* ignored by now */ case 'f': force = true; break; + case 'F': recompress = true; break; case 'h': show_help(); return 0; case 'k': keep_input_files = true; break; case 'm': encoder_options.match_len_limit = @@ -871,7 +839,7 @@ int main( const int argc, const char * const argv[] ) const int eindex = extension_index( filenames[i] ); input_filename = filenames[i]; infd = open_instream( input_filename, &in_stats, program_mode, - eindex, force, to_stdout ); + eindex, recompress, to_stdout ); if( infd < 0 ) { if( retval < 1 ) retval = 1; continue; } if( program_mode != m_test ) { |