2025-02-17 20:44:01 +01:00
|
|
|
/* Clzip - LZMA lossless data compressor
|
2025-02-17 20:46:36 +01:00
|
|
|
Copyright (C) 2010-2019 Antonio Diaz Diaz.
|
2025-02-17 20:44:01 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define _FILE_OFFSET_BITS 64
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#include "lzip.h"
|
2025-02-17 20:46:36 +01:00
|
|
|
#include "lzip_index.h"
|
2025-02-17 20:44:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
static void list_line( const unsigned long long uncomp_size,
|
|
|
|
const unsigned long long comp_size,
|
|
|
|
const char * const input_filename )
|
|
|
|
{
|
|
|
|
if( uncomp_size > 0 )
|
|
|
|
printf( "%15llu %15llu %6.2f%% %s\n", uncomp_size, comp_size,
|
2025-02-17 20:45:25 +01:00
|
|
|
100.0 - ( ( 100.0 * comp_size ) / uncomp_size ),
|
2025-02-17 20:44:01 +01:00
|
|
|
input_filename );
|
|
|
|
else
|
|
|
|
printf( "%15llu %15llu -INF%% %s\n", uncomp_size, comp_size,
|
|
|
|
input_filename );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int list_files( const char * const filenames[], const int num_filenames,
|
2025-02-17 20:45:25 +01:00
|
|
|
const bool ignore_trailing, const bool loose_trailing )
|
2025-02-17 20:44:01 +01:00
|
|
|
{
|
|
|
|
unsigned long long total_comp = 0, total_uncomp = 0;
|
|
|
|
int files = 0, retval = 0;
|
|
|
|
int i;
|
|
|
|
bool first_post = true;
|
|
|
|
bool stdin_used = false;
|
|
|
|
for( i = 0; i < num_filenames; ++i )
|
|
|
|
{
|
|
|
|
const char * input_filename;
|
2025-02-17 20:46:36 +01:00
|
|
|
struct Lzip_index lzip_index;
|
2025-02-17 20:44:01 +01:00
|
|
|
struct stat in_stats; /* not used */
|
|
|
|
int infd;
|
|
|
|
const bool from_stdin = ( strcmp( filenames[i], "-" ) == 0 );
|
|
|
|
if( from_stdin ) { if( stdin_used ) continue; else stdin_used = true; }
|
|
|
|
input_filename = from_stdin ? "(stdin)" : filenames[i];
|
|
|
|
infd = from_stdin ? STDIN_FILENO :
|
|
|
|
open_instream( input_filename, &in_stats, true, true );
|
|
|
|
if( infd < 0 ) { if( retval < 1 ) retval = 1; continue; }
|
|
|
|
|
2025-02-17 20:46:36 +01:00
|
|
|
Li_init( &lzip_index, infd, ignore_trailing, loose_trailing );
|
2025-02-17 20:44:01 +01:00
|
|
|
close( infd );
|
2025-02-17 20:46:36 +01:00
|
|
|
if( lzip_index.retval != 0 )
|
2025-02-17 20:44:01 +01:00
|
|
|
{
|
2025-02-17 20:46:36 +01:00
|
|
|
show_file_error( input_filename, lzip_index.error, 0 );
|
|
|
|
if( retval < lzip_index.retval ) retval = lzip_index.retval;
|
|
|
|
Li_free( &lzip_index ); continue;
|
2025-02-17 20:44:01 +01:00
|
|
|
}
|
|
|
|
if( verbosity >= 0 )
|
|
|
|
{
|
2025-02-17 20:46:36 +01:00
|
|
|
const unsigned long long udata_size = Li_udata_size( &lzip_index );
|
|
|
|
const unsigned long long cdata_size = Li_cdata_size( &lzip_index );
|
2025-02-17 20:44:01 +01:00
|
|
|
total_comp += cdata_size; total_uncomp += udata_size; ++files;
|
|
|
|
if( first_post )
|
|
|
|
{
|
|
|
|
first_post = false;
|
|
|
|
if( verbosity >= 1 ) fputs( " dict memb trail ", stdout );
|
|
|
|
fputs( " uncompressed compressed saved name\n", stdout );
|
|
|
|
}
|
|
|
|
if( verbosity >= 1 )
|
|
|
|
{
|
|
|
|
long long trailing_size;
|
|
|
|
unsigned dictionary_size = 0;
|
|
|
|
long i;
|
2025-02-17 20:46:36 +01:00
|
|
|
for( i = 0; i < lzip_index.members; ++i )
|
2025-02-17 20:44:01 +01:00
|
|
|
dictionary_size =
|
2025-02-17 20:46:36 +01:00
|
|
|
max( dictionary_size, Li_dictionary_size( &lzip_index, i ) );
|
|
|
|
trailing_size = Li_file_size( &lzip_index ) - cdata_size;
|
2025-02-17 20:44:01 +01:00
|
|
|
printf( "%s %5ld %6lld ", format_ds( dictionary_size ),
|
2025-02-17 20:46:36 +01:00
|
|
|
lzip_index.members, trailing_size );
|
2025-02-17 20:44:01 +01:00
|
|
|
}
|
|
|
|
list_line( udata_size, cdata_size, input_filename );
|
|
|
|
|
2025-02-17 20:46:36 +01:00
|
|
|
if( verbosity >= 2 && lzip_index.members > 1 )
|
2025-02-17 20:44:01 +01:00
|
|
|
{
|
|
|
|
long i;
|
|
|
|
fputs( " member data_pos data_size member_pos member_size\n", stdout );
|
2025-02-17 20:46:36 +01:00
|
|
|
for( i = 0; i < lzip_index.members; ++i )
|
2025-02-17 20:44:01 +01:00
|
|
|
{
|
2025-02-17 20:46:36 +01:00
|
|
|
const struct Block * db = Li_dblock( &lzip_index, i );
|
|
|
|
const struct Block * mb = Li_mblock( &lzip_index, i );
|
2025-02-17 20:44:01 +01:00
|
|
|
printf( "%5ld %15llu %15llu %15llu %15llu\n",
|
|
|
|
i + 1, db->pos, db->size, mb->pos, mb->size );
|
|
|
|
}
|
|
|
|
first_post = true; /* reprint heading after list of members */
|
|
|
|
}
|
|
|
|
fflush( stdout );
|
|
|
|
}
|
2025-02-17 20:46:36 +01:00
|
|
|
Li_free( &lzip_index );
|
2025-02-17 20:44:01 +01:00
|
|
|
}
|
|
|
|
if( verbosity >= 0 && files > 1 )
|
|
|
|
{
|
|
|
|
if( verbosity >= 1 ) fputs( " ", stdout );
|
|
|
|
list_line( total_uncomp, total_comp, "(totals)" );
|
|
|
|
fflush( stdout );
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|