summaryrefslogtreecommitdiffstats
path: root/lzd.cc
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lzd.cc21
1 files changed, 11 insertions, 10 deletions
diff --git a/lzd.cc b/lzd.cc
index f7572b2..9e1c3b8 100644
--- a/lzd.cc
+++ b/lzd.cc
@@ -1,5 +1,5 @@
/* Lzd - Educational decompressor for the lzip format
- Copyright (C) 2013-2021 Antonio Diaz Diaz.
+ Copyright (C) 2013-2022 Antonio Diaz Diaz.
This program is free software. Redistribution and use in source and
binary forms, with or without modification, are permitted provided
@@ -18,8 +18,8 @@
*/
/*
Exit status: 0 for a normal exit, 1 for environmental problems
- (file not found, invalid flags, I/O errors, etc), 2 to indicate a
- corrupt or invalid input file.
+ (file not found, invalid command line options, I/O errors, etc), 2 to
+ indicate a corrupt or invalid input file.
*/
#include <algorithm>
@@ -29,7 +29,7 @@
#include <cstring>
#include <stdint.h>
#include <unistd.h>
-#if defined(__MSVCRT__) || defined(__OS2__) || defined(__DJGPP__)
+#if defined __MSVCRT__ || defined __OS2__ || defined __DJGPP__
#include <fcntl.h>
#include <io.h>
#endif
@@ -147,7 +147,8 @@ class Range_decoder
public:
Range_decoder() : member_pos( 6 ), code( 0 ), range( 0xFFFFFFFFU )
{
- for( int i = 0; i < 5; ++i ) code = ( code << 8 ) | get_byte();
+ get_byte(); // discard first byte of the LZMA stream
+ for( int i = 0; i < 4; ++i ) code = ( code << 8 ) | get_byte();
}
uint8_t get_byte() { ++member_pos; return std::getc( stdin ); }
@@ -180,8 +181,8 @@ public:
}
else
{
- range -= bound;
code -= bound;
+ range -= bound;
bm.probability -= bm.probability >> bit_model_move_bits;
symbol = 1;
}
@@ -308,7 +309,7 @@ void LZ_decoder::flush_data()
}
-bool LZ_decoder::decode_member() // Returns false if error
+bool LZ_decoder::decode_member() // Return false if error
{
Bit_model bm_literal[1<<literal_context_bits][0x300];
Bit_model bm_match[State::states][pos_states];
@@ -415,11 +416,11 @@ int main( const int argc, const char * const argv[] )
{
std::printf(
"Lzd %s - Educational decompressor for the lzip format.\n"
- "Study the source to learn how a lzip decompressor works.\n"
+ "Study the source code to learn how a lzip decompressor works.\n"
"See the lzip manual for an explanation of the code.\n"
"\nUsage: %s [-d] < file.lz > file\n"
"Lzd decompresses from standard input to standard output.\n"
- "\nCopyright (C) 2021 Antonio Diaz Diaz.\n"
+ "\nCopyright (C) 2022 Antonio Diaz Diaz.\n"
"License 2-clause BSD.\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"
@@ -429,7 +430,7 @@ int main( const int argc, const char * const argv[] )
return 0;
}
-#if defined(__MSVCRT__) || defined(__OS2__) || defined(__DJGPP__)
+#if defined __MSVCRT__ || defined __OS2__ || defined __DJGPP__
setmode( STDIN_FILENO, O_BINARY );
setmode( STDOUT_FILENO, O_BINARY );
#endif