diff --git a/list.c b/list.c index fbe832b..8a10575 100644 --- a/list.c +++ b/list.c @@ -2,6 +2,7 @@ #include +void pixz_list(bool tar); #pragma mark FUNCTION DEFINITIONS @@ -31,6 +32,11 @@ int main(int argc, char **argv) { die("Usage: %s -f [FILE]", progname); } + pixz_list(tar); + return 0; +} + +void pixz_list(bool tar) { decode_index(); lzma_index_iter iter; lzma_index_iter_init(&iter, gIndex); @@ -48,6 +54,4 @@ int main(int argc, char **argv) { lzma_index_end(gIndex, NULL); lzma_end(&gStream); - - return 0; } diff --git a/pixz.h b/pixz.h index 630cbfd..7aa445d 100644 --- a/pixz.h +++ b/pixz.h @@ -20,6 +20,13 @@ #define CHUNKSIZE 4096 +#define DEBUG 1 +#if DEBUG + #define debug(str, ...) fprintf(stderr, str "\n", ##__VA_ARGS__) +#else + #define debug(...) +#endif + #pragma mark UTILS diff --git a/read.c b/read.c index 7331d3e..d447a21 100644 --- a/read.c +++ b/read.c @@ -5,13 +5,6 @@ #include -#define DEBUG 0 -#if DEBUG - #define debug(str, ...) fprintf(stderr, str "\n", ##__VA_ARGS__) -#else - #define debug(...) -#endif - #pragma mark DECLARE WANTED @@ -64,7 +57,8 @@ static lzma_vli gFileIndexOffset = 0; static size_t gBlockInSize = 0, gBlockOutSize = 0; static void set_block_sizes(void); -static void pixz_read(bool verify, size_t nspecs, char **specs); + +void pixz_read(bool verify, size_t nspecs, char **specs); #pragma mark MAIN @@ -93,7 +87,7 @@ int main(int argc, char **argv) { return 0; } -static void pixz_read(bool verify, size_t nspecs, char **specs) { +void pixz_read(bool verify, size_t nspecs, char **specs) { decode_index(); if (verify) gFileIndexOffset = read_file_index(0); @@ -419,7 +413,7 @@ static ssize_t tar_read(struct archive *ar, void *ref, const void **bufp) { off = 0; size = ib->outsize; } - debug("tar off = %zu, size = %zu", off, size); + debug("tar off = %llu, size = %zu", (unsigned long long)off, size); gArLastOffset = off; gArLastSize = size; diff --git a/write.c b/write.c index 7e3ce77..055ec35 100644 --- a/write.c +++ b/write.c @@ -17,10 +17,7 @@ struct io_block_t { #pragma mark GLOBALS -#define DEBUG 0 - static bool gTar = true; -static uint32_t gPreset = LZMA_PRESET_DEFAULT; static size_t gBlockInSize = 0, gBlockOutSize = 0; @@ -40,12 +37,6 @@ static size_t gFileIndexBufPos = 0; #pragma mark FUNCTION DECLARATIONS -#if DEBUG - #define debug(str, ...) fprintf(stderr, str "\n", ##__VA_ARGS__) -#else - #define debug(...) -#endif - static void read_thread(); static void encode_thread(size_t thnum); static void *block_create(); @@ -66,22 +57,25 @@ static void write_file_index(void); static void write_file_index_bytes(size_t size, uint8_t *buf); static void write_file_index_buf(lzma_action action); +void pixz_write(bool tar, uint32_t level); #pragma mark FUNCTION DEFINITIONS int main(int argc, char **argv) { char *progname = argv[0]; + uint32_t level = LZMA_PRESET_DEFAULT; + bool tar = true; debug("launch"); int ch; while ((ch = getopt(argc, argv, "t0123456789")) != -1) { switch (ch) { case 't': - gTar = false; + tar = false; break; default: if (optopt >= '0' && optopt <= '9') { - gPreset = optopt - '0'; + level = optopt - '0'; } else { die("Unknown option"); } @@ -89,7 +83,6 @@ int main(int argc, char **argv) { } argc -= optind - 1; argv += optind - 1; - if (argc == 1) { gInFile = stdin; @@ -103,9 +96,15 @@ int main(int argc, char **argv) { die("Usage: %s [-t] [INPUT OUTPUT]", progname); } + pixz_write(tar, level); +} + +void pixz_write(bool tar, uint32_t level) { + gTar = tar; + // xz options lzma_options_lzma lzma_opts; - if (lzma_lzma_preset(&lzma_opts, gPreset)) + if (lzma_lzma_preset(&lzma_opts, level)) die("Error setting lzma options"); gFilters[0] = (lzma_filter){ .id = LZMA_FILTER_LZMA2, .options = &lzma_opts }; @@ -149,7 +148,6 @@ int main(int argc, char **argv) { pipeline_destroy(); debug("exit"); - return 0; }