Adding upstream version 0.6.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
2902fcb6e5
commit
64ab85d0eb
10 changed files with 678 additions and 650 deletions
31
lzd.cc
31
lzd.cc
|
@ -1,5 +1,5 @@
|
|||
/* Lzd - Educational decompressor for lzip files
|
||||
Copyright (C) 2013 Antonio Diaz Diaz.
|
||||
Copyright (C) 2013, 2014 Antonio Diaz Diaz.
|
||||
|
||||
This program is free software: you have unlimited permission
|
||||
to copy, distribute and modify it.
|
||||
|
@ -21,7 +21,7 @@
|
|||
#include <cstring>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#if defined(__MSVCRT__) || defined(__OS2__)
|
||||
#if defined(__MSVCRT__) || defined(__OS2__) || defined(_MSC_VER)
|
||||
#include <fcntl.h>
|
||||
#include <io.h>
|
||||
#endif
|
||||
|
@ -213,7 +213,7 @@ public:
|
|||
break;
|
||||
}
|
||||
}
|
||||
return symbol - 0x100;
|
||||
return symbol & 0xFF;
|
||||
}
|
||||
|
||||
int decode_len( Len_model & lm, const int pos_state )
|
||||
|
@ -263,7 +263,7 @@ public:
|
|||
pos( 0 ),
|
||||
stream_pos( 0 ),
|
||||
crc_( 0xFFFFFFFFU )
|
||||
{ buffer[dictionary_size-1] = 0; } // prev_byte of first_byte
|
||||
{ buffer[dictionary_size-1] = 0; } // prev_byte of first byte
|
||||
|
||||
~LZ_decoder() { delete[] buffer; }
|
||||
|
||||
|
@ -282,7 +282,7 @@ void LZ_decoder::flush_data()
|
|||
crc32.update_buf( crc_, buffer + stream_pos, size );
|
||||
errno = 0;
|
||||
if( std::fwrite( buffer + stream_pos, 1, size, stdout ) != size )
|
||||
{ std::fprintf( stderr, "Write error: %s\n", std::strerror( errno ) );
|
||||
{ std::fprintf( stderr, "Write error: %s.\n", std::strerror( errno ) );
|
||||
std::exit( 1 ); }
|
||||
if( pos >= dictionary_size ) { partial_data_pos += pos; pos = 0; }
|
||||
stream_pos = pos;
|
||||
|
@ -380,13 +380,13 @@ bool LZ_decoder::decode_member() // Returns false if error
|
|||
}
|
||||
}
|
||||
state.set_match();
|
||||
if( rep0 >= dictionary_size || ( rep0 >= pos && !partial_data_pos ) )
|
||||
return false;
|
||||
if( rep0 >= dictionary_size || rep0 >= data_position() )
|
||||
{ flush_data(); return false; }
|
||||
}
|
||||
for( int i = 0; i < len; ++i )
|
||||
put_byte( get_byte( rep0 ) );
|
||||
for( int i = 0; i < len; ++i ) put_byte( get_byte( rep0 ) );
|
||||
}
|
||||
}
|
||||
flush_data();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -402,7 +402,7 @@ int main( const int argc, const char * const argv[] )
|
|||
"It is not safe to use lzd for any real work.\n"
|
||||
"\nUsage: %s < file.lz > file\n", argv[0] );
|
||||
std::printf( "Lzd decompresses from standard input to standard output.\n"
|
||||
"\nCopyright (C) 2013 Antonio Diaz Diaz.\n"
|
||||
"\nCopyright (C) 2014 Antonio Diaz Diaz.\n"
|
||||
"This is free software: you are free to change and redistribute it.\n"
|
||||
"There is NO WARRANTY, to the extent permitted by law.\n"
|
||||
"Report bugs to lzip-bug@nongnu.org\n"
|
||||
|
@ -410,16 +410,15 @@ int main( const int argc, const char * const argv[] )
|
|||
return 0;
|
||||
}
|
||||
|
||||
#if defined(__MSVCRT__) || defined(__OS2__)
|
||||
setmode( STDIN_FILENO, O_BINARY );
|
||||
setmode( STDOUT_FILENO, O_BINARY );
|
||||
#if defined(__MSVCRT__) || defined(__OS2__) || defined(_MSC_VER)
|
||||
setmode( fileno( stdin ), O_BINARY );
|
||||
setmode( fileno( stdout ), O_BINARY );
|
||||
#endif
|
||||
|
||||
for( bool first_member = true; ; first_member = false )
|
||||
{
|
||||
File_header header;
|
||||
for( int i = 0; i < 6; ++i )
|
||||
header[i] = std::getc( stdin );
|
||||
for( int i = 0; i < 6; ++i ) header[i] = std::getc( stdin );
|
||||
if( std::feof( stdin ) || std::memcmp( header, "LZIP", 4 ) != 0 )
|
||||
{
|
||||
if( first_member )
|
||||
|
@ -454,7 +453,7 @@ int main( const int argc, const char * const argv[] )
|
|||
}
|
||||
|
||||
if( std::fclose( stdout ) != 0 )
|
||||
{ std::fprintf( stderr, "Can't close stdout: %s\n", std::strerror( errno ) );
|
||||
{ std::fprintf( stderr, "Can't close stdout: %s.\n", std::strerror( errno ) );
|
||||
return 1; }
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue