"Fossies" - the Fresh Open Source Software Archive

Member "lzip-1.22-rc2/list.cc" (17 May 2020, 4086 Bytes) of package /linux/misc/lzip-1.22-rc2.tar.lz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "list.cc" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 1.21_vs_1.22-rc1.

    1 /* Lzip - LZMA lossless data compressor
    2    Copyright (C) 2008-2020 Antonio Diaz Diaz.
    3 
    4    This program is free software: you can redistribute it and/or modify
    5    it under the terms of the GNU General Public License as published by
    6    the Free Software Foundation, either version 2 of the License, or
    7    (at your option) any later version.
    8 
    9    This program is distributed in the hope that it will be useful,
   10    but WITHOUT ANY WARRANTY; without even the implied warranty of
   11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12    GNU General Public License for more details.
   13 
   14    You should have received a copy of the GNU General Public License
   15    along with this program.  If not, see <http://www.gnu.org/licenses/>.
   16 */
   17 
   18 #define _FILE_OFFSET_BITS 64
   19 
   20 #include <cstdio>
   21 #include <cstring>
   22 #include <string>
   23 #include <vector>
   24 #include <stdint.h>
   25 #include <unistd.h>
   26 #include <sys/stat.h>
   27 
   28 #include "lzip.h"
   29 #include "lzip_index.h"
   30 
   31 
   32 namespace {
   33 
   34 void list_line( const unsigned long long uncomp_size,
   35                 const unsigned long long comp_size,
   36                 const char * const input_filename )
   37   {
   38   if( uncomp_size > 0 )
   39     std::printf( "%14llu %14llu %6.2f%%  %s\n", uncomp_size, comp_size,
   40                   100.0 - ( ( 100.0 * comp_size ) / uncomp_size ),
   41                   input_filename );
   42   else
   43     std::printf( "%14llu %14llu   -INF%%  %s\n", uncomp_size, comp_size,
   44                   input_filename );
   45   }
   46 
   47 } // end namespace
   48 
   49 
   50 int list_files( const std::vector< std::string > & filenames,
   51                 const bool ignore_trailing, const bool loose_trailing )
   52   {
   53   unsigned long long total_comp = 0, total_uncomp = 0;
   54   int files = 0, retval = 0;
   55   bool first_post = true;
   56   bool stdin_used = false;
   57   for( unsigned i = 0; i < filenames.size(); ++i )
   58     {
   59     const bool from_stdin = ( filenames[i] == "-" );
   60     if( from_stdin ) { if( stdin_used ) continue; else stdin_used = true; }
   61     const char * const input_filename =
   62       from_stdin ? "(stdin)" : filenames[i].c_str();
   63     struct stat in_stats;               // not used
   64     const int infd = from_stdin ? STDIN_FILENO :
   65       open_instream( input_filename, &in_stats, false, true );
   66     if( infd < 0 ) { set_retval( retval, 1 ); continue; }
   67 
   68     const Lzip_index lzip_index( infd, ignore_trailing, loose_trailing );
   69     close( infd );
   70     if( lzip_index.retval() != 0 )
   71       {
   72       show_file_error( input_filename, lzip_index.error().c_str() );
   73       set_retval( retval, lzip_index.retval() );
   74       continue;
   75       }
   76     if( verbosity >= 0 )
   77       {
   78       const unsigned long long udata_size = lzip_index.udata_size();
   79       const unsigned long long cdata_size = lzip_index.cdata_size();
   80       total_comp += cdata_size; total_uncomp += udata_size; ++files;
   81       const long members = lzip_index.members();
   82       if( first_post )
   83         {
   84         first_post = false;
   85         if( verbosity >= 1 ) std::fputs( "   dict   memb  trail ", stdout );
   86         std::fputs( "  uncompressed     compressed   saved  name\n", stdout );
   87         }
   88       if( verbosity >= 1 )
   89         std::printf( "%s %5ld %6lld ",
   90                      format_ds( lzip_index.dictionary_size() ), members,
   91                      lzip_index.file_size() - cdata_size );
   92       list_line( udata_size, cdata_size, input_filename );
   93 
   94       if( verbosity >= 2 && members > 1 )
   95         {
   96         std::fputs( " member      data_pos      data_size     member_pos    member_size\n", stdout );
   97         for( long i = 0; i < members; ++i )
   98           {
   99           const Block & db = lzip_index.dblock( i );
  100           const Block & mb = lzip_index.mblock( i );
  101           std::printf( "%6ld %14llu %14llu %14llu %14llu\n",
  102                        i + 1, db.pos(), db.size(), mb.pos(), mb.size() );
  103           }
  104         first_post = true;  // reprint heading after list of members
  105         }
  106       std::fflush( stdout );
  107       }
  108     }
  109   if( verbosity >= 0 && files > 1 )
  110     {
  111     if( verbosity >= 1 ) std::fputs( "                      ", stdout );
  112     list_line( total_uncomp, total_comp, "(totals)" );
  113     std::fflush( stdout );
  114     }
  115   return retval;
  116   }