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

Move operations to functions

This commit is contained in:
Dave Vasilevsky 2010-10-14 00:56:26 -04:00
parent cfa025697d
commit e675206a8e
4 changed files with 29 additions and 26 deletions

8
list.c
View File

@ -2,6 +2,7 @@
#include <getopt.h> #include <getopt.h>
void pixz_list(bool tar);
#pragma mark FUNCTION DEFINITIONS #pragma mark FUNCTION DEFINITIONS
@ -31,6 +32,11 @@ int main(int argc, char **argv) {
die("Usage: %s -f [FILE]", progname); die("Usage: %s -f [FILE]", progname);
} }
pixz_list(tar);
return 0;
}
void pixz_list(bool tar) {
decode_index(); decode_index();
lzma_index_iter iter; lzma_index_iter iter;
lzma_index_iter_init(&iter, gIndex); lzma_index_iter_init(&iter, gIndex);
@ -48,6 +54,4 @@ int main(int argc, char **argv) {
lzma_index_end(gIndex, NULL); lzma_index_end(gIndex, NULL);
lzma_end(&gStream); lzma_end(&gStream);
return 0;
} }

7
pixz.h
View File

@ -20,6 +20,13 @@
#define CHUNKSIZE 4096 #define CHUNKSIZE 4096
#define DEBUG 1
#if DEBUG
#define debug(str, ...) fprintf(stderr, str "\n", ##__VA_ARGS__)
#else
#define debug(...)
#endif
#pragma mark UTILS #pragma mark UTILS

14
read.c
View File

@ -5,13 +5,6 @@
#include <getopt.h> #include <getopt.h>
#define DEBUG 0
#if DEBUG
#define debug(str, ...) fprintf(stderr, str "\n", ##__VA_ARGS__)
#else
#define debug(...)
#endif
#pragma mark DECLARE WANTED #pragma mark DECLARE WANTED
@ -64,7 +57,8 @@ static lzma_vli gFileIndexOffset = 0;
static size_t gBlockInSize = 0, gBlockOutSize = 0; static size_t gBlockInSize = 0, gBlockOutSize = 0;
static void set_block_sizes(void); 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 #pragma mark MAIN
@ -93,7 +87,7 @@ int main(int argc, char **argv) {
return 0; 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(); decode_index();
if (verify) if (verify)
gFileIndexOffset = read_file_index(0); gFileIndexOffset = read_file_index(0);
@ -419,7 +413,7 @@ static ssize_t tar_read(struct archive *ar, void *ref, const void **bufp) {
off = 0; off = 0;
size = ib->outsize; size = ib->outsize;
} }
debug("tar off = %zu, size = %zu", off, size); debug("tar off = %llu, size = %zu", (unsigned long long)off, size);
gArLastOffset = off; gArLastOffset = off;
gArLastSize = size; gArLastSize = size;

26
write.c
View File

@ -17,10 +17,7 @@ struct io_block_t {
#pragma mark GLOBALS #pragma mark GLOBALS
#define DEBUG 0
static bool gTar = true; static bool gTar = true;
static uint32_t gPreset = LZMA_PRESET_DEFAULT;
static size_t gBlockInSize = 0, gBlockOutSize = 0; static size_t gBlockInSize = 0, gBlockOutSize = 0;
@ -40,12 +37,6 @@ static size_t gFileIndexBufPos = 0;
#pragma mark FUNCTION DECLARATIONS #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 read_thread();
static void encode_thread(size_t thnum); static void encode_thread(size_t thnum);
static void *block_create(); 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_bytes(size_t size, uint8_t *buf);
static void write_file_index_buf(lzma_action action); static void write_file_index_buf(lzma_action action);
void pixz_write(bool tar, uint32_t level);
#pragma mark FUNCTION DEFINITIONS #pragma mark FUNCTION DEFINITIONS
int main(int argc, char **argv) { int main(int argc, char **argv) {
char *progname = argv[0]; char *progname = argv[0];
uint32_t level = LZMA_PRESET_DEFAULT;
bool tar = true;
debug("launch"); debug("launch");
int ch; int ch;
while ((ch = getopt(argc, argv, "t0123456789")) != -1) { while ((ch = getopt(argc, argv, "t0123456789")) != -1) {
switch (ch) { switch (ch) {
case 't': case 't':
gTar = false; tar = false;
break; break;
default: default:
if (optopt >= '0' && optopt <= '9') { if (optopt >= '0' && optopt <= '9') {
gPreset = optopt - '0'; level = optopt - '0';
} else { } else {
die("Unknown option"); die("Unknown option");
} }
@ -90,7 +84,6 @@ int main(int argc, char **argv) {
argc -= optind - 1; argc -= optind - 1;
argv += optind - 1; argv += optind - 1;
if (argc == 1) { if (argc == 1) {
gInFile = stdin; gInFile = stdin;
gOutFile = stdout; gOutFile = stdout;
@ -103,9 +96,15 @@ int main(int argc, char **argv) {
die("Usage: %s [-t] [INPUT OUTPUT]", progname); die("Usage: %s [-t] [INPUT OUTPUT]", progname);
} }
pixz_write(tar, level);
}
void pixz_write(bool tar, uint32_t level) {
gTar = tar;
// xz options // xz options
lzma_options_lzma lzma_opts; lzma_options_lzma lzma_opts;
if (lzma_lzma_preset(&lzma_opts, gPreset)) if (lzma_lzma_preset(&lzma_opts, level))
die("Error setting lzma options"); die("Error setting lzma options");
gFilters[0] = (lzma_filter){ .id = LZMA_FILTER_LZMA2, gFilters[0] = (lzma_filter){ .id = LZMA_FILTER_LZMA2,
.options = &lzma_opts }; .options = &lzma_opts };
@ -149,7 +148,6 @@ int main(int argc, char **argv) {
pipeline_destroy(); pipeline_destroy();
debug("exit"); debug("exit");
return 0;
} }