summaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c39
1 files changed, 23 insertions, 16 deletions
diff --git a/main.c b/main.c
index 2674285..d82fd91 100644
--- a/main.c
+++ b/main.c
@@ -28,6 +28,10 @@
#include "LzmaDec.h"
#include "LzmaEnc.h"
+#if CHAR_BIT != 8
+#error "Environments where CHAR_BIT != 8 are not supported."
+#endif
+
static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }
static void SzFree(void *p, void *address) { p = p; MyFree(address); }
@@ -203,10 +207,10 @@ static int Decode2( CLzmaDec *state, ISeqOutStream *outStream,
ISeqInStream *inStream, Byte inBuf[], size_t * const inPos,
size_t * const inSize, const int version, const bool testing )
{
- long long total_in = sizeof (File_header), total_out = 0;
+ long long total_in = Fh_size, total_out = 0;
Byte outBuf[OUT_BUF_SIZE];
size_t outPos = 0;
- uint32_t crc = 0xFFFFFFFF;
+ uint32_t crc = 0xFFFFFFFFU;
LzmaDec_Init(state);
for (;;)
{
@@ -242,7 +246,7 @@ static int Decode2( CLzmaDec *state, ISeqOutStream *outStream,
{ show_error( "data error", 0, false ); return 1; }
bool error = false;
File_trailer trailer;
- const size_t trailer_size = Ft_size( version );
+ const size_t trailer_size = Ft_versioned_size( version );
if( *inSize - *inPos < trailer_size &&
!read_inbuf( inStream, inBuf, inPos, inSize ) ) return 1;
if( *inSize - *inPos < trailer_size )
@@ -258,13 +262,13 @@ static int Decode2( CLzmaDec *state, ISeqOutStream *outStream,
trailer[i] = inBuf[(*inPos)++];
total_in += trailer_size;
if( version == 0 ) Ft_set_member_size( trailer, total_in );
- if( Ft_get_data_crc( trailer ) != ( crc ^ 0xFFFFFFFF ) )
+ if( Ft_get_data_crc( trailer ) != ( crc ^ 0xFFFFFFFFU ) )
{
error = true;
if( verbosity >= 0 )
fprintf( stderr, "crc mismatch; trailer says %08X, data crc is %08X.\n",
(unsigned int)Ft_get_data_crc( trailer ),
- (unsigned int)( crc ^ 0xFFFFFFFF ) );
+ (unsigned int)( crc ^ 0xFFFFFFFFU ) );
}
if( Ft_get_data_size( trailer ) != total_out )
{
@@ -305,14 +309,14 @@ static int Decode( ISeqOutStream *outStream, ISeqInStream *inStream,
for( bool first_member = true; ; first_member = false )
{
- if( inSize < sizeof (File_header) &&
+ if( inSize < Fh_size &&
!read_inbuf( inStream, inBuf, &inPos, &inSize ) ) return 1;
- if( inSize < sizeof (File_header) ) // End Of File
+ if( inSize < Fh_size ) // End Of File
{
if( !first_member ) break;
show_error( "error reading member header", 0, false ); return 1;
}
- for( unsigned int i = 0; i < sizeof (File_header); ++i )
+ for( int i = 0; i < Fh_size; ++i )
header[i] = inBuf[inPos++];
if( !Fh_verify_magic( header ) )
{
@@ -332,7 +336,7 @@ static int Decode( ISeqOutStream *outStream, ISeqInStream *inStream,
Fh_get_dictionary_size( header ) > max_dictionary_size )
{
if( verbosity >= 0 )
- fprintf( stderr, "invalid dictionary size in member header" );
+ fprintf( stderr, "invalid dictionary size in member header.\n" );
return 2;
}
@@ -345,7 +349,7 @@ static int Decode( ISeqOutStream *outStream, ISeqInStream *inStream,
/* 5 bytes of LZMA properties */
unsigned char props[LZMA_PROPS_SIZE];
- props[0] = 93; // 45 * 2 + 3
+ props[0] = 93; // (45 * 2) + (9 * 0) + 3
int ds = Fh_get_dictionary_size( header );
for( int i = 1; i <= 4; ++i ) { props[i] = ds & 0xFF; ds >>= 8; }
@@ -388,7 +392,7 @@ static int Encode( ISeqOutStream *outStream, ISeqInStream *inStream,
encoder_options->match_len_limit > max_match_len )
internal_error( "invalid argument to encoder" );
- if( outStream->Write( outStream, header, sizeof (File_header) ) != sizeof (File_header) )
+ if( outStream->Write( outStream, header, Fh_size ) != Fh_size )
{ show_error( "can not write output file", errno, false ); retval = 1; }
else
if( LzmaEnc_Encode(enc, outStream, inStream, NULL, &g_Alloc, &g_Alloc) != 0 )
@@ -484,6 +488,7 @@ int main( const int argc, const char * const argv[] )
// to the corresponding LZMA compression modes.
const struct Lzma_options option_mapping[] =
{
+ { 1 << 16, 5 }, // -0
{ 1 << 20, 10 }, // -1
{ 3 << 19, 12 }, // -2
{ 1 << 21, 17 }, // -3
@@ -493,7 +498,7 @@ int main( const int argc, const char * const argv[] )
{ 1 << 24, 108 }, // -7
{ 3 << 23, 163 }, // -8
{ 1 << 25, 273 } }; // -9
- struct Lzma_options encoder_options = option_mapping[5]; // default = "-6"
+ struct Lzma_options encoder_options = option_mapping[6]; // default = "-6"
enum Mode program_mode = m_compress;
bool force = false;
bool keep_input_files = false;
@@ -505,6 +510,7 @@ int main( const int argc, const char * const argv[] )
const struct ap_Option options[] =
{
+ { '0', 0, ap_no },
{ '1', "fast", ap_no },
{ '2', 0, ap_no },
{ '3', 0, ap_no },
@@ -517,6 +523,7 @@ int main( const int argc, const char * const argv[] )
{ 'b', "member-size", ap_yes },
{ 'c', "stdout", ap_no },
{ 'd', "decompress", ap_no },
+ { 'e', "extreme", ap_no },
{ 'f', "force", ap_no },
{ 'h', "help", ap_no },
{ 'k', "keep", ap_no },
@@ -544,13 +551,13 @@ int main( const int argc, const char * const argv[] )
if( !code ) break; // no more options
switch( code )
{
- case '1': case '2': case '3':
- case '4': case '5': case '6':
- case '7': case '8': case '9':
- encoder_options = option_mapping[code-'1']; break;
+ case '0': case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
+ encoder_options = option_mapping[code-'0']; break;
case 'b': break;
case 'c': to_stdout = true; break;
case 'd': program_mode = m_decompress; break;
+ case 'e': break;
case 'f': force = true; break;
case 'h': show_help(); return 0;
case 'k': keep_input_files = true; break;