2
0
mirror of https://github.com/vasi/pixz synced 2024-11-18 15:26:46 +00:00
pixz/pixz.h

141 lines
2.8 KiB
C
Raw Normal View History

2009-12-28 03:16:41 +00:00
#include <lzma.h>
2010-01-17 02:23:23 +00:00
#define __USE_LARGEFILE 1
2010-01-13 03:16:25 +00:00
#include <stdbool.h>
2009-12-28 03:16:41 +00:00
#include <stdio.h>
#include <stdlib.h>
2010-01-13 03:16:25 +00:00
#include <string.h>
2010-01-17 02:23:23 +00:00
#include <sys/types.h>
2009-12-28 03:16:41 +00:00
#include <pthread.h>
2009-12-28 03:16:41 +00:00
2010-01-13 03:16:25 +00:00
#pragma mark DEFINES
2009-12-28 03:16:41 +00:00
2010-10-11 03:48:34 +00:00
#define PIXZ_INDEX_MAGIC 0xDBAE14D62E324CA6LL
2010-01-13 03:16:25 +00:00
#define CHECK LZMA_CHECK_CRC32
2012-09-18 05:57:41 +00:00
#define MEMLIMIT (64ULL * 1024 * 1024 * 1024) // crazy high
2009-12-28 03:16:41 +00:00
2010-01-13 03:16:25 +00:00
#define CHUNKSIZE 4096
2009-12-28 03:16:41 +00:00
2010-10-14 06:16:06 +00:00
#define DEBUG 0
2010-10-14 04:56:26 +00:00
#if DEBUG
#define debug(str, ...) fprintf(stderr, str "\n", ##__VA_ARGS__)
#else
#define debug(...)
#endif
2009-12-28 03:16:41 +00:00
2010-10-14 05:48:08 +00:00
#pragma mark OPERATIONS
void pixz_list(bool tar);
void pixz_write(bool tar, uint32_t level);
void pixz_read(bool verify, size_t nspecs, char **specs);
2010-10-13 02:03:45 +00:00
#pragma mark UTILS
FILE *gInFile, *gOutFile;
2010-10-13 02:03:45 +00:00
lzma_stream gStream;
extern lzma_index *gIndex;
void die(const char *fmt, ...);
char *xstrdup(const char *s);
uint64_t xle64dec(const uint8_t *d);
void xle64enc(uint8_t *d, uint64_t n);
size_t num_threads(void);
void *decode_block_start(off_t block_seek);
#pragma mark INDEX
2009-12-28 03:16:41 +00:00
typedef struct file_index_t file_index_t;
2010-01-13 03:16:25 +00:00
struct file_index_t {
char *name;
off_t offset;
file_index_t *next;
2010-01-13 03:16:25 +00:00
};
2010-10-13 02:03:45 +00:00
extern file_index_t *gFileIndex, *gLastFile;
2010-10-13 03:40:27 +00:00
// As discovered from footer
extern lzma_check gCheck;
bool is_multi_header(const char *name);
2012-10-14 11:39:10 +00:00
bool decode_index(void); // true on success
2010-10-13 02:03:45 +00:00
2010-10-13 02:42:32 +00:00
lzma_vli find_file_index(void **bdatap);
lzma_vli read_file_index(void);
2010-10-14 06:11:46 +00:00
void dump_file_index(FILE *out, bool verbose);
2010-10-13 02:03:45 +00:00
void free_file_index(void);
#pragma mark QUEUE
typedef struct queue_item_t queue_item_t;
struct queue_item_t {
int type;
void *data;
queue_item_t *next;
};
typedef void (*queue_free_t)(int type, void *p);
typedef struct {
queue_item_t *first;
queue_item_t *last;
pthread_mutex_t mutex;
pthread_cond_t pop_cond;
queue_free_t freer;
} queue_t;
2010-01-09 23:10:42 +00:00
2010-10-13 02:03:45 +00:00
queue_t *queue_new(queue_free_t freer);
void queue_free(queue_t *q);
void queue_push(queue_t *q, int type, void *data);
int queue_pop(queue_t *q, void **datap);
2010-01-09 23:10:42 +00:00
2010-10-13 02:03:45 +00:00
#pragma mark PIPELINE
2010-01-09 23:10:42 +00:00
2012-10-14 05:59:35 +00:00
extern size_t gPipelineProcessMax;
2010-10-13 02:03:45 +00:00
extern queue_t *gPipelineStartQ, *gPipelineSplitQ, *gPipelineMergeQ;
2010-01-17 02:23:23 +00:00
2010-10-13 02:03:45 +00:00
typedef enum {
PIPELINE_ITEM,
PIPELINE_STOP
} pipeline_tag_t;
2010-01-10 02:56:01 +00:00
2010-10-13 02:03:45 +00:00
typedef struct pipeline_item_t pipeline_item_t;
struct pipeline_item_t {
size_t seq;
pipeline_item_t *next;
void *data;
};
2010-10-13 02:03:45 +00:00
typedef void* (*pipeline_data_create_t)(void);
typedef void (*pipeline_data_free_t)(void*);
typedef void (*pipeline_split_t)(void);
typedef void (*pipeline_process_t)(size_t);
void pipeline_create(
pipeline_data_create_t create,
pipeline_data_free_t destroy,
pipeline_split_t split,
pipeline_process_t process);
void pipeline_stop(void);
void pipeline_destroy(void);
2012-10-21 01:54:17 +00:00
void pipeline_dispatch(pipeline_item_t *item, queue_t *q);
2010-10-13 02:03:45 +00:00
void pipeline_split(pipeline_item_t *item);
pipeline_item_t *pipeline_merged();