1 #ifndef LIBRARIES_LZMA_H
    2 #define LIBRARIES_LZMA_H
    3 
    4 /*
    5 
    6 	MorphOS Shared LZMALib
    7 
    8 	lzma.library include
    9 
   10 	Copyright © 2017-2025 The MorphOS Development Team, All Rights Reserved.
   11 
   12 */
   13 
   14 /*
   15 
   16 	This is a merged and cleaned-up version of lzma API includes
   17 
   18 	For the documentation that was contained here, please see the
   19 	original liblzma distribution, or the documentation with the
   20 	MorphOS SDK (when it's done)
   21 
   22 */
   23 
   24 #ifndef LZMA_MANUAL_HEADERS
   25 #include <stddef.h>
   26 #include <stdint.h>
   27 #endif /* LZMA_MANUAL_HEADERS */
   28 
   29 #pragma pack(8)
   30 
   31 #ifndef LZMA_API_IMPORT
   32 #	define LZMA_API_IMPORT
   33 #endif
   34 #ifndef LZMA_API_CALL
   35 #	define LZMA_API_CALL
   36 #endif
   37 #ifndef LZMA_API
   38 #	define LZMA_API(type) type
   39 #endif
   40 #ifndef lzma_nothrow
   41 #	if defined(__cplusplus)
   42 #		define lzma_nothrow throw()
   43 #	elif __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
   44 #		define lzma_nothrow __attribute__((__nothrow__))
   45 #	else
   46 #		define lzma_nothrow
   47 #	endif
   48 #endif
   49 #if __GNUC__ >= 3
   50 #	ifndef lzma_attribute
   51 #		define lzma_attribute(attr) __attribute__(attr)
   52 #	endif
   53 #	ifndef lzma_attr_warn_unused_result
   54 #		if __GNUC__ == 3 && __GNUC_MINOR__ < 4
   55 #			define lzma_attr_warn_unused_result
   56 #		endif
   57 #	endif
   58 #else
   59 #	ifndef lzma_attribute
   60 #		define lzma_attribute(attr)
   61 #	endif
   62 #endif
   63 #ifndef lzma_attr_pure
   64 #	define lzma_attr_pure lzma_attribute((__pure__))
   65 #endif
   66 #ifndef lzma_attr_const
   67 #	define lzma_attr_const lzma_attribute((__const__))
   68 #endif
   69 #ifndef lzma_attr_warn_unused_result
   70 #	define lzma_attr_warn_unused_result \
   71 		lzma_attribute((__warn_unused_result__))
   72 #endif
   73 
   74 #ifdef __cplusplus
   75 extern "C" {
   76 #endif
   77 
   78 /* version.h */
   79 #ifdef LZMA_HAVE_VERSION_INFO
   80 /*
   81 	This information should not be used and is only provided for
   82 	source level compatibility reasons. New code should call
   83 	lzma_version_number() and lzma_version_string().
   84 */
   85 #define LZMA_VERSION_MAJOR 5
   86 #define LZMA_VERSION_MINOR 2
   87 #define LZMA_VERSION_PATCH 13
   88 #define LZMA_VERSION_STABILITY LZMA_VERSION_STABILITY_STABLE
   89 #ifndef LZMA_VERSION_COMMIT
   90 #	define LZMA_VERSION_COMMIT ""
   91 #endif
   92 #define LZMA_VERSION_STABILITY_ALPHA 0
   93 #define LZMA_VERSION_STABILITY_BETA 1
   94 #define LZMA_VERSION_STABILITY_STABLE 2
   95 #define LZMA_VERSION (LZMA_VERSION_MAJOR * UINT32_C(10000000) \
   96 		+ LZMA_VERSION_MINOR * UINT32_C(10000) \
   97 		+ LZMA_VERSION_PATCH * UINT32_C(10) \
   98 		+ LZMA_VERSION_STABILITY)
   99 #if LZMA_VERSION_STABILITY == LZMA_VERSION_STABILITY_ALPHA
  100 #	define LZMA_VERSION_STABILITY_STRING "alpha"
  101 #elif LZMA_VERSION_STABILITY == LZMA_VERSION_STABILITY_BETA
  102 #	define LZMA_VERSION_STABILITY_STRING "beta"
  103 #elif LZMA_VERSION_STABILITY == LZMA_VERSION_STABILITY_STABLE
  104 #	define LZMA_VERSION_STABILITY_STRING ""
  105 #else
  106 #	error Incorrect LZMA_VERSION_STABILITY
  107 #endif
  108 #define LZMA_VERSION_STRING_C_(major, minor, patch, stability, commit) \
  109 		#major "." #minor "." #patch stability commit
  110 #define LZMA_VERSION_STRING_C(major, minor, patch, stability, commit) \
  111 		LZMA_VERSION_STRING_C_(major, minor, patch, stability, commit)
  112 #define LZMA_VERSION_STRING LZMA_VERSION_STRING_C( \
  113 		LZMA_VERSION_MAJOR, LZMA_VERSION_MINOR, \
  114 		LZMA_VERSION_PATCH, LZMA_VERSION_STABILITY_STRING, \
  115 		LZMA_VERSION_COMMIT)
  116 #endif
  117 
  118 /* base.h */
  119 typedef unsigned char lzma_bool;
  120 typedef enum {
  121 	LZMA_RESERVED_ENUM      = 0
  122 } lzma_reserved_enum;
  123 typedef enum {
  124 	LZMA_OK                 = 0,
  125 	LZMA_STREAM_END         = 1,
  126 	LZMA_NO_CHECK           = 2,
  127 	LZMA_UNSUPPORTED_CHECK  = 3,
  128 	LZMA_GET_CHECK          = 4,
  129 	LZMA_MEM_ERROR          = 5,
  130 	LZMA_MEMLIMIT_ERROR     = 6,
  131 	LZMA_FORMAT_ERROR       = 7,
  132 	LZMA_OPTIONS_ERROR      = 8,
  133 	LZMA_DATA_ERROR         = 9,
  134 	LZMA_BUF_ERROR          = 10,
  135 	LZMA_PROG_ERROR         = 11,
  136 } lzma_ret;
  137 typedef enum {
  138 	LZMA_RUN = 0,
  139 	LZMA_SYNC_FLUSH = 1,
  140 	LZMA_FULL_FLUSH = 2,
  141 	LZMA_FULL_BARRIER = 4,
  142 	LZMA_FINISH = 3
  143 } lzma_action;
  144 typedef struct {
  145 	void *(LZMA_API_CALL *alloc)(void *opaque, size_t nmemb, size_t size);
  146 	void (LZMA_API_CALL *free)(void *opaque, void *ptr);
  147 	void *opaque;
  148 } lzma_allocator;
  149 typedef struct lzma_internal_s lzma_internal;
  150 typedef struct {
  151 	const uint8_t *next_in;
  152 	size_t avail_in;
  153 	uint64_t total_in;
  154 	uint8_t *next_out;
  155 	size_t avail_out;
  156 	uint64_t total_out;
  157 	const lzma_allocator *allocator;
  158 	lzma_internal *internal;
  159 	void *reserved_ptr1;
  160 	void *reserved_ptr2;
  161 	uint64_t reserved_int1;
  162 	uint64_t reserved_int2;
  163 	lzma_reserved_enum reserved_enum1;
  164 	lzma_reserved_enum reserved_enum2;
  165 } lzma_stream;
  166 #define LZMA_STREAM_INIT \
  167 	{ NULL, 0, 0, NULL, 0, 0, NULL, NULL, \
  168 	NULL, NULL, 0, 0, LZMA_RESERVED_ENUM, LZMA_RESERVED_ENUM }
  169 
  170 /* vli.h */
  171 #define LZMA_VLI_MAX (UINT64_MAX / 2)
  172 #define LZMA_VLI_UNKNOWN UINT64_MAX
  173 #define LZMA_VLI_BYTES_MAX 9
  174 #define LZMA_VLI_C(n) UINT64_C(n)
  175 typedef uint64_t lzma_vli;
  176 #define lzma_vli_is_valid(vli) \
  177 	((vli) <= LZMA_VLI_MAX || (vli) == LZMA_VLI_UNKNOWN)
  178 
  179 /* check.h */
  180 typedef enum {
  181 	LZMA_CHECK_NONE     = 0,
  182 	LZMA_CHECK_CRC32    = 1,
  183 	LZMA_CHECK_CRC64    = 4,
  184 	LZMA_CHECK_SHA256   = 10
  185 } lzma_check;
  186 #define LZMA_CHECK_ID_MAX 15
  187 #define LZMA_CHECK_SIZE_MAX 64
  188 
  189 /* filter.h */
  190 #define LZMA_FILTERS_MAX 4
  191 typedef struct {
  192 	lzma_vli id;
  193 	void *options;
  194 } lzma_filter;
  195 
  196 /* bcj.h */
  197 #define LZMA_FILTER_X86         LZMA_VLI_C(0x04)
  198 #define LZMA_FILTER_POWERPC     LZMA_VLI_C(0x05)
  199 #define LZMA_FILTER_IA64        LZMA_VLI_C(0x06)
  200 #define LZMA_FILTER_ARM         LZMA_VLI_C(0x07)
  201 #define LZMA_FILTER_ARMTHUMB    LZMA_VLI_C(0x08)
  202 #define LZMA_FILTER_SPARC       LZMA_VLI_C(0x09)
  203 typedef struct {
  204 	uint32_t start_offset;
  205 } lzma_options_bcj;
  206 
  207 /* delta.h */
  208 #define LZMA_FILTER_DELTA       LZMA_VLI_C(0x03)
  209 typedef enum {
  210 	LZMA_DELTA_TYPE_BYTE
  211 } lzma_delta_type;
  212 typedef struct {
  213 	lzma_delta_type type;
  214 	uint32_t dist;
  215 #	define LZMA_DELTA_DIST_MIN 1
  216 #	define LZMA_DELTA_DIST_MAX 256
  217 	uint32_t reserved_int1;
  218 	uint32_t reserved_int2;
  219 	uint32_t reserved_int3;
  220 	uint32_t reserved_int4;
  221 	void *reserved_ptr1;
  222 	void *reserved_ptr2;
  223 } lzma_options_delta;
  224 
  225 /* lzma.h */
  226 #define LZMA_FILTER_LZMA1       LZMA_VLI_C(0x4000000000000001)
  227 #define LZMA_FILTER_LZMA2       LZMA_VLI_C(0x21)
  228 typedef enum {
  229 	LZMA_MF_HC3     = 0x03,
  230 	LZMA_MF_HC4     = 0x04,
  231 	LZMA_MF_BT2     = 0x12,
  232 	LZMA_MF_BT3     = 0x13,
  233 	LZMA_MF_BT4     = 0x14
  234 } lzma_match_finder;
  235 typedef enum {
  236 	LZMA_MODE_FAST = 1,
  237 	LZMA_MODE_NORMAL = 2
  238 } lzma_mode;
  239 typedef struct {
  240 	uint32_t dict_size;
  241 #	define LZMA_DICT_SIZE_MIN       UINT32_C(4096)
  242 #	define LZMA_DICT_SIZE_DEFAULT   (UINT32_C(1) << 23)
  243 	const uint8_t *preset_dict;
  244 	uint32_t preset_dict_size;
  245 	uint32_t lc;
  246 #	define LZMA_LCLP_MIN    0
  247 #	define LZMA_LCLP_MAX    4
  248 #	define LZMA_LC_DEFAULT  3
  249 	uint32_t lp;
  250 #	define LZMA_LP_DEFAULT  0
  251 	uint32_t pb;
  252 #	define LZMA_PB_MIN      0
  253 #	define LZMA_PB_MAX      4
  254 #	define LZMA_PB_DEFAULT  2
  255 	lzma_mode mode;
  256 	uint32_t nice_len;
  257 	lzma_match_finder mf;
  258 	uint32_t depth;
  259 	void *reserved_ptr1;
  260 	void *reserved_ptr2;
  261 	uint32_t reserved_int1;
  262 	uint32_t reserved_int2;
  263 	uint32_t reserved_int3;
  264 	uint32_t reserved_int4;
  265 	uint32_t reserved_int5;
  266 	uint32_t reserved_int6;
  267 	uint32_t reserved_int7;
  268 	uint32_t reserved_int8;
  269 	lzma_reserved_enum reserved_enum1;
  270 	lzma_reserved_enum reserved_enum2;
  271 	lzma_reserved_enum reserved_enum3;
  272 	lzma_reserved_enum reserved_enum4;
  273 } lzma_options_lzma;
  274 
  275 /* container.h */
  276 #define LZMA_PRESET_DEFAULT     UINT32_C(6)
  277 #define LZMA_PRESET_LEVEL_MASK  UINT32_C(0x1F)
  278 #define LZMA_PRESET_EXTREME       (UINT32_C(1) << 31)
  279 typedef struct {
  280 	uint32_t flags;
  281 	uint32_t threads;
  282 	uint64_t block_size;
  283 	uint32_t timeout;
  284 	uint32_t preset;
  285 	const lzma_filter *filters;
  286 	lzma_check check;
  287 	lzma_reserved_enum reserved_enum1;
  288 	lzma_reserved_enum reserved_enum2;
  289 	lzma_reserved_enum reserved_enum3;
  290 	uint32_t reserved_int1;
  291 	uint32_t reserved_int2;
  292 	uint32_t reserved_int3;
  293 	uint32_t reserved_int4;
  294 	uint64_t reserved_int5;
  295 	uint64_t reserved_int6;
  296 	uint64_t reserved_int7;
  297 	uint64_t reserved_int8;
  298 	void *reserved_ptr1;
  299 	void *reserved_ptr2;
  300 	void *reserved_ptr3;
  301 	void *reserved_ptr4;
  302 } lzma_mt;
  303 #define LZMA_TELL_NO_CHECK              UINT32_C(0x01)
  304 #define LZMA_TELL_UNSUPPORTED_CHECK     UINT32_C(0x02)
  305 #define LZMA_TELL_ANY_CHECK             UINT32_C(0x04)
  306 #define LZMA_IGNORE_CHECK               UINT32_C(0x10)
  307 #define LZMA_CONCATENATED               UINT32_C(0x08)
  308 
  309 /* stream_flags.h */
  310 #define LZMA_STREAM_HEADER_SIZE 12
  311 typedef struct {
  312 	uint32_t version;
  313 	lzma_vli backward_size;
  314 #	define LZMA_BACKWARD_SIZE_MIN 4
  315 #	define LZMA_BACKWARD_SIZE_MAX (LZMA_VLI_C(1) << 34)
  316 	lzma_check check;
  317 	lzma_reserved_enum reserved_enum1;
  318 	lzma_reserved_enum reserved_enum2;
  319 	lzma_reserved_enum reserved_enum3;
  320 	lzma_reserved_enum reserved_enum4;
  321 	lzma_reserved_enum reserved_enum5;
  322 	lzma_reserved_enum reserved_enum6;
  323 	lzma_bool reserved_bool1;
  324 	lzma_bool reserved_bool2;
  325 	lzma_bool reserved_bool3;
  326 	lzma_bool reserved_bool4;
  327 	lzma_bool reserved_bool5;
  328 	lzma_bool reserved_bool6;
  329 	lzma_bool reserved_bool7;
  330 	lzma_bool reserved_bool8;
  331 	uint32_t reserved_int1;
  332 	uint32_t reserved_int2;
  333 	uint32_t reserved_int3;
  334 	uint32_t reserved_int4;
  335 } lzma_stream_flags;
  336 
  337 /* block.h */
  338 typedef struct {
  339 	uint32_t version;
  340 	uint32_t header_size;
  341 #	define LZMA_BLOCK_HEADER_SIZE_MIN 8
  342 #	define LZMA_BLOCK_HEADER_SIZE_MAX 1024
  343 	lzma_check check;
  344 	lzma_vli compressed_size;
  345 	lzma_vli uncompressed_size;
  346 	lzma_filter *filters;
  347 	uint8_t raw_check[LZMA_CHECK_SIZE_MAX];
  348 	void *reserved_ptr1;
  349 	void *reserved_ptr2;
  350 	void *reserved_ptr3;
  351 	uint32_t reserved_int1;
  352 	uint32_t reserved_int2;
  353 	lzma_vli reserved_int3;
  354 	lzma_vli reserved_int4;
  355 	lzma_vli reserved_int5;
  356 	lzma_vli reserved_int6;
  357 	lzma_vli reserved_int7;
  358 	lzma_vli reserved_int8;
  359 	lzma_reserved_enum reserved_enum1;
  360 	lzma_reserved_enum reserved_enum2;
  361 	lzma_reserved_enum reserved_enum3;
  362 	lzma_reserved_enum reserved_enum4;
  363 	lzma_bool reserved_bool1;
  364 	lzma_bool reserved_bool2;
  365 	lzma_bool reserved_bool3;
  366 	lzma_bool reserved_bool4;
  367 	lzma_bool reserved_bool5;
  368 	lzma_bool reserved_bool6;
  369 	lzma_bool reserved_bool7;
  370 	lzma_bool reserved_bool8;
  371 } lzma_block;
  372 #define lzma_block_header_size_decode(b) (((uint32_t)(b) + 1) * 4)
  373 
  374 /* index.h */
  375 typedef struct lzma_index_s lzma_index;
  376 typedef struct {
  377 	struct {
  378 		const lzma_stream_flags *flags;
  379 		const void *reserved_ptr1;
  380 		const void *reserved_ptr2;
  381 		const void *reserved_ptr3;
  382 		lzma_vli number;
  383 		lzma_vli block_count;
  384 		lzma_vli compressed_offset;
  385 		lzma_vli uncompressed_offset;
  386 		lzma_vli compressed_size;
  387 		lzma_vli uncompressed_size;
  388 		lzma_vli padding;
  389 		lzma_vli reserved_vli1;
  390 		lzma_vli reserved_vli2;
  391 		lzma_vli reserved_vli3;
  392 		lzma_vli reserved_vli4;
  393 	} stream;
  394 	struct {
  395 		lzma_vli number_in_file;
  396 		lzma_vli compressed_file_offset;
  397 		lzma_vli uncompressed_file_offset;
  398 		lzma_vli number_in_stream;
  399 		lzma_vli compressed_stream_offset;
  400 		lzma_vli uncompressed_stream_offset;
  401 		lzma_vli uncompressed_size;
  402 		lzma_vli unpadded_size;
  403 		lzma_vli total_size;
  404 		lzma_vli reserved_vli1;
  405 		lzma_vli reserved_vli2;
  406 		lzma_vli reserved_vli3;
  407 		lzma_vli reserved_vli4;
  408 		const void *reserved_ptr1;
  409 		const void *reserved_ptr2;
  410 		const void *reserved_ptr3;
  411 		const void *reserved_ptr4;
  412 	} block;
  413 	union {
  414 		const void *p;
  415 		size_t s;
  416 		lzma_vli v;
  417 	} internal[6];
  418 } lzma_index_iter;
  419 typedef enum {
  420 	LZMA_INDEX_ITER_ANY             = 0,
  421 	LZMA_INDEX_ITER_STREAM          = 1,
  422 	LZMA_INDEX_ITER_BLOCK           = 2,
  423 	LZMA_INDEX_ITER_NONEMPTY_BLOCK  = 3
  424 } lzma_index_iter_mode;
  425 
  426 /* index_hash.h */
  427 typedef struct lzma_index_hash_s lzma_index_hash;
  428 
  429 #ifdef __cplusplus
  430 }
  431 #endif
  432 
  433 #pragma pack()
  434 
  435 #endif /* LIBRARIES_LZMA_H */