diff --git a/src/expand_streaming.h b/src/expand_streaming.h index 30dd88d..c92d135 100644 --- a/src/expand_streaming.h +++ b/src/expand_streaming.h @@ -39,9 +39,6 @@ extern "C" { #endif -/* Forward declaration */ -typedef enum _lzsa_status_t lzsa_status_t; - /*-------------- File API -------------- */ /** diff --git a/src/lib.h b/src/lib.h index 2520b13..0983550 100755 --- a/src/lib.h +++ b/src/lib.h @@ -48,24 +48,6 @@ extern "C" { #endif -/** High level status for compression and decompression */ -typedef enum _lzsa_status_t { - LZSA_OK = 0, /**< Success */ - LZSA_ERROR_SRC, /**< Error reading input */ - LZSA_ERROR_DST, /**< Error reading output */ - LZSA_ERROR_DICTIONARY, /**< Error reading dictionary */ - LZSA_ERROR_MEMORY, /**< Out of memory */ - - /* Compression-specific status codes */ - LZSA_ERROR_COMPRESSION, /**< Internal compression error */ - LZSA_ERROR_RAW_TOOLARGE, /**< Input is too large to be compressed to a raw block */ - LZSA_ERROR_RAW_UNCOMPRESSED, /**< Input is incompressible and raw blocks don't support uncompressed data */ - - /* Decompression-specific status codes */ - LZSA_ERROR_FORMAT, /**< Invalid input format or magic number when decompressing */ - LZSA_ERROR_DECOMPRESSION /**< Internal decompression error */ -} lzsa_status_t; - /* Compression flags */ #define LZSA_FLAG_FAVOR_RATIO (1<<0) /**< 1 to compress with the best ratio, 0 to trade some compression ratio for extra decompression speed */ #define LZSA_FLAG_RAW_BLOCK (1<<1) /**< 1 to emit raw block */ diff --git a/src/matchfinder.c b/src/matchfinder.c index 18ed597..12815d5 100644 --- a/src/matchfinder.c +++ b/src/matchfinder.c @@ -33,7 +33,6 @@ #include #include "matchfinder.h" #include "format.h" -#include "lib.h" /** * Hash index into TAG_BITS diff --git a/src/matchfinder.h b/src/matchfinder.h index ca52296..024aaad 100644 --- a/src/matchfinder.h +++ b/src/matchfinder.h @@ -33,14 +33,12 @@ #ifndef _MATCHFINDER_H #define _MATCHFINDER_H +#include "shrink_context.h" + #ifdef __cplusplus extern "C" { #endif -/* Forward declarations */ -typedef struct _lzsa_match lzsa_match; -typedef struct _lzsa_compressor lzsa_compressor; - /** * Parse input data, build suffix array and overlaid data structures to speed up match finding * diff --git a/src/shrink_block_v1.h b/src/shrink_block_v1.h index cc89cde..8f667e5 100644 --- a/src/shrink_block_v1.h +++ b/src/shrink_block_v1.h @@ -33,8 +33,11 @@ #ifndef _SHRINK_BLOCK_V1_H #define _SHRINK_BLOCK_V1_H -/* Forward declarations */ -typedef struct _lzsa_compressor lzsa_compressor; +#include "shrink_context.h" + +#ifdef __cplusplus +extern "C" { +#endif /** * Select the most optimal matches, reduce the token count if possible, and then emit a block of compressed LZSA1 data @@ -50,4 +53,8 @@ typedef struct _lzsa_compressor lzsa_compressor; */ int lzsa_optimize_and_write_block_v1(lzsa_compressor *pCompressor, const unsigned char *pInWindow, const int nPreviousBlockSize, const int nInDataSize, unsigned char *pOutData, const int nMaxOutDataSize); +#ifdef __cplusplus +} +#endif + #endif /* _SHRINK_BLOCK_V1_H */ diff --git a/src/shrink_block_v2.h b/src/shrink_block_v2.h index 4a83608..edf6c23 100644 --- a/src/shrink_block_v2.h +++ b/src/shrink_block_v2.h @@ -33,8 +33,11 @@ #ifndef _SHRINK_BLOCK_V2_H #define _SHRINK_BLOCK_V2_H -/* Forward declarations */ -typedef struct _lzsa_compressor lzsa_compressor; +#include "shrink_context.h" + +#ifdef __cplusplus +extern "C" { +#endif /** * Select the most optimal matches, reduce the token count if possible, and then emit a block of compressed LZSA2 data @@ -50,4 +53,8 @@ typedef struct _lzsa_compressor lzsa_compressor; */ int lzsa_optimize_and_write_block_v2(lzsa_compressor *pCompressor, const unsigned char *pInWindow, const int nPreviousBlockSize, const int nInDataSize, unsigned char *pOutData, const int nMaxOutDataSize); +#ifdef __cplusplus +} +#endif + #endif /* _SHRINK_BLOCK_V2_H */ diff --git a/src/shrink_streaming.h b/src/shrink_streaming.h index 0920edf..387560f 100644 --- a/src/shrink_streaming.h +++ b/src/shrink_streaming.h @@ -33,16 +33,13 @@ #ifndef _SHRINK_STREAMING_H #define _SHRINK_STREAMING_H +#include "shrink_context.h" #include "stream.h" #ifdef __cplusplus extern "C" { #endif -/* Forward declaration */ -typedef enum _lzsa_status_t lzsa_status_t; -typedef struct _lzsa_stats lzsa_stats; - /*-------------- File API -------------- */ /** diff --git a/src/stream.c b/src/stream.c index 7094ab1..8e32036 100644 --- a/src/stream.c +++ b/src/stream.c @@ -44,7 +44,7 @@ * * @param stream stream */ -static void lzsa_filestream_close(lzsa_stream_t *stream) { +static void lzsa_filestream_close(struct _lzsa_stream_t *stream) { if (stream->obj) { fclose((FILE*)stream->obj); stream->obj = NULL; @@ -64,7 +64,7 @@ static void lzsa_filestream_close(lzsa_stream_t *stream) { * * @return number of bytes read */ -static size_t lzsa_filestream_read(lzsa_stream_t *stream, void *ptr, size_t size) { +static size_t lzsa_filestream_read(struct _lzsa_stream_t *stream, void *ptr, size_t size) { return fread(ptr, 1, size, (FILE*)stream->obj); } @@ -77,7 +77,7 @@ static size_t lzsa_filestream_read(lzsa_stream_t *stream, void *ptr, size_t size * * @return number of bytes written */ -static size_t lzsa_filestream_write(lzsa_stream_t *stream, void *ptr, size_t size) { +static size_t lzsa_filestream_write(struct _lzsa_stream_t *stream, void *ptr, size_t size) { return fwrite(ptr, 1, size, (FILE*)stream->obj); } @@ -88,7 +88,7 @@ static size_t lzsa_filestream_write(lzsa_stream_t *stream, void *ptr, size_t siz * * @return nonzero if the end of the data has been reached, 0 if there is more data */ -static int lzsa_filestream_eof(lzsa_stream_t *stream) { +static int lzsa_filestream_eof(struct _lzsa_stream_t *stream) { return feof((FILE*)stream->obj); } diff --git a/src/stream.h b/src/stream.h index a8b7922..e156a7b 100644 --- a/src/stream.h +++ b/src/stream.h @@ -37,8 +37,23 @@ extern "C" { #endif -/* Forward declaration */ -typedef struct _lzsa_stream_t lzsa_stream_t; +/** High level status for compression and decompression */ +typedef enum _lzsa_status_t { + LZSA_OK = 0, /**< Success */ + LZSA_ERROR_SRC, /**< Error reading input */ + LZSA_ERROR_DST, /**< Error reading output */ + LZSA_ERROR_DICTIONARY, /**< Error reading dictionary */ + LZSA_ERROR_MEMORY, /**< Out of memory */ + + /* Compression-specific status codes */ + LZSA_ERROR_COMPRESSION, /**< Internal compression error */ + LZSA_ERROR_RAW_TOOLARGE, /**< Input is too large to be compressed to a raw block */ + LZSA_ERROR_RAW_UNCOMPRESSED, /**< Input is incompressible and raw blocks don't support uncompressed data */ + + /* Decompression-specific status codes */ + LZSA_ERROR_FORMAT, /**< Invalid input format or magic number when decompressing */ + LZSA_ERROR_DECOMPRESSION /**< Internal decompression error */ +} lzsa_status_t; /* I/O stream */ typedef struct _lzsa_stream_t { @@ -54,7 +69,7 @@ typedef struct _lzsa_stream_t { * * @return number of bytes read */ - size_t(*read)(lzsa_stream_t *stream, void *ptr, size_t size); + size_t(*read)(struct _lzsa_stream_t *stream, void *ptr, size_t size); /** * Write to stream @@ -65,7 +80,7 @@ typedef struct _lzsa_stream_t { * * @return number of bytes written */ - size_t(*write)(lzsa_stream_t *stream, void *ptr, size_t size); + size_t(*write)(struct _lzsa_stream_t *stream, void *ptr, size_t size); /** @@ -75,14 +90,14 @@ typedef struct _lzsa_stream_t { * * @return nonzero if the end of the data has been reached, 0 if there is more data */ - int(*eof)(lzsa_stream_t *stream); + int(*eof)(struct _lzsa_stream_t *stream); /** * Close stream * * @param stream stream */ - void(*close)(lzsa_stream_t *stream); + void(*close)(struct _lzsa_stream_t *stream); } lzsa_stream_t; /**