From 1bca5b995a8fdd85afa0aa817dbba3c2411fb21a Mon Sep 17 00:00:00 2001 From: Emmanuel Marty Date: Mon, 17 Oct 2022 09:42:39 +0200 Subject: [PATCH] Add documentation comments --- src/frame.c | 2 ++ src/frame.h | 2 ++ src/shrink_block_v1.c | 6 +++--- src/shrink_context.c | 5 +++-- src/shrink_context.h | 1 + src/stream.c | 2 ++ 6 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/frame.c b/src/frame.c index f1d6be2..8eadccc 100644 --- a/src/frame.c +++ b/src/frame.c @@ -60,6 +60,7 @@ int lzsa_get_frame_size(void) { * * @param pFrameData encoding buffer * @param nMaxFrameDataSize max encoding buffer size, in bytes + * @param nFormatVersion version of format to use (1-2) * * @return number of encoded bytes, or -1 for failure */ @@ -146,6 +147,7 @@ int lzsa_encode_footer_frame(unsigned char *pFrameData, const int nMaxFrameDataS * * @param pFrameData data bytes * @param nFrameDataSize number of bytes to decode + * @param nFormatVersion pointer to returned format version, if successful * * @return 0 for success, or -1 for failure */ diff --git a/src/frame.h b/src/frame.h index 7b5db99..fdc9e95 100644 --- a/src/frame.h +++ b/src/frame.h @@ -56,6 +56,7 @@ int lzsa_get_frame_size(void); * * @param pFrameData encoding buffer * @param nMaxFrameDataSize max encoding buffer size, in bytes + * @param nFormatVersion version of format to use (1-2) * * @return number of encoded bytes, or -1 for failure */ @@ -98,6 +99,7 @@ int lzsa_encode_footer_frame(unsigned char *pFrameData, const int nMaxFrameDataS * * @param pFrameData data bytes * @param nFrameDataSize number of bytes to decode + * @param nFormatVersion pointer to returned format version, if successful * * @return 0 for success, or -1 for failure */ diff --git a/src/shrink_block_v1.c b/src/shrink_block_v1.c index 37669dd..b4506c4 100644 --- a/src/shrink_block_v1.c +++ b/src/shrink_block_v1.c @@ -141,7 +141,7 @@ static inline int lzsa_write_match_varlen_v1(unsigned char *pOutData, int nOutOf /** * Get offset encoding cost in bits * - * @param nMatchOffset offset to get cost of + * @param __nMatchOffset offset to get cost of * * @return cost in bits */ @@ -625,11 +625,11 @@ static int lzsa_write_block_v1(lzsa_compressor *pCompressor, const lzsa_match *p * @return size of compressed data in output buffer, or -1 if the data is uncompressible */ static int lzsa_write_raw_uncompressed_block_v1(lzsa_compressor *pCompressor, const unsigned char *pInWindow, const int nStartOffset, const int nEndOffset, unsigned char *pOutData, const int nMaxOutDataSize) { - int nNumLiterals = nEndOffset - nStartOffset; + const int nNumLiterals = nEndOffset - nStartOffset; const int nTokenLiteralsLen = (nNumLiterals >= LITERALS_RUN_LEN_V1) ? LITERALS_RUN_LEN_V1 : nNumLiterals; int nOutOffset = 0; - int nCommandSize = 8 /* token */ + lzsa_get_literals_varlen_size_v1(nNumLiterals) + (nNumLiterals << 3) + 4; + const int nCommandSize = 8 /* token */ + lzsa_get_literals_varlen_size_v1(nNumLiterals) + (nNumLiterals << 3) + 4; if ((nOutOffset + (nCommandSize >> 3)) > nMaxOutDataSize) return -1; diff --git a/src/shrink_context.c b/src/shrink_context.c index 32bfb16..949368b 100644 --- a/src/shrink_context.c +++ b/src/shrink_context.c @@ -45,14 +45,15 @@ * @param pCompressor compression context to initialize * @param nMaxWindowSize maximum size of input data window (previously compressed bytes + bytes to compress) * @param nMinMatchSize minimum match size (cannot be less than MIN_MATCH_SIZE) + * @param nFormatVersion version of format to use (1-2) * @param nFlags compression flags * * @return 0 for success, non-zero for failure */ int lzsa_compressor_init(lzsa_compressor *pCompressor, const int nMaxWindowSize, const int nMinMatchSize, const int nFormatVersion, const int nFlags) { int nResult; - int nMinMatchSizeForFormat = (nFormatVersion == 1) ? MIN_MATCH_SIZE_V1 : MIN_MATCH_SIZE_V2; - int nMaxMinMatchForFormat = (nFormatVersion == 1) ? 5 : 3; + const int nMinMatchSizeForFormat = (nFormatVersion == 1) ? MIN_MATCH_SIZE_V1 : MIN_MATCH_SIZE_V2; + const int nMaxMinMatchForFormat = (nFormatVersion == 1) ? 5 : 3; nResult = divsufsort_init(&pCompressor->divsufsort_context); pCompressor->intervals = NULL; diff --git a/src/shrink_context.h b/src/shrink_context.h index 81478b4..a0ad140 100644 --- a/src/shrink_context.h +++ b/src/shrink_context.h @@ -145,6 +145,7 @@ typedef struct _lzsa_compressor { * @param pCompressor compression context to initialize * @param nMaxWindowSize maximum size of input data window (previously compressed bytes + bytes to compress) * @param nMinMatchSize minimum match size (cannot be less than MIN_MATCH_SIZE) + * @param nFormatVersion version of format to use (1-2) * @param nFlags compression flags * * @return 0 for success, non-zero for failure diff --git a/src/stream.c b/src/stream.c index 06e63e8..7094ab1 100644 --- a/src/stream.c +++ b/src/stream.c @@ -105,7 +105,9 @@ int lzsa_filestream_open(lzsa_stream_t *stream, const char *pszInFilename, const const char* stdInOutFile = "-"; const char* stdInMode = "rb"; const char* stdOutMode = "wb"; +#ifdef _WIN32 int result; +#endif if (!strncmp(pszInFilename, stdInOutFile, 1)) { if (!strncmp(pszMode, stdInMode, 2)) {