From 4713b32cf1b7508cc1a716203c3079b4c8b13268 Mon Sep 17 00:00:00 2001 From: Dave Vasilevsky Date: Thu, 14 Oct 2010 01:48:08 -0400 Subject: [PATCH] Single driver --- Makefile | 4 ++-- list.c | 32 -------------------------------- pixz.h | 7 +++++++ read.c | 26 -------------------------- write.c | 39 --------------------------------------- 5 files changed, 9 insertions(+), 99 deletions(-) diff --git a/Makefile b/Makefile index f29405d..5cf9d57 100644 --- a/Makefile +++ b/Makefile @@ -17,8 +17,8 @@ CC = gcc COMPILE = $(CC) $(CFLAGS) -c -o LD = $(CC) $(LDFLAGS) -o -PROGS = write read list -COMMON = common.o endian.o cpu.o +PROGS = pixz +COMMON = common.o endian.o cpu.o read.o write.o list.o all: $(PROGS) diff --git a/list.c b/list.c index 8a10575..d284ea7 100644 --- a/list.c +++ b/list.c @@ -2,40 +2,8 @@ #include -void pixz_list(bool tar); - #pragma mark FUNCTION DEFINITIONS -int main(int argc, char **argv) { - char *progname = argv[0]; - - bool tar = true; - int ch; - while ((ch = getopt(argc, argv, "t")) != -1) { - switch (ch) { - case 't': - tar = false; - break; - default: - die("Unknown option"); - } - } - argc -= optind - 1; - argv += optind - 1; - - if (argc == 1) { - gInFile = stdin; - } else if (argc == 2) { - if (!(gInFile = fopen(argv[1], "r"))) - die("Can't open input file"); - } else { - die("Usage: %s -f [FILE]", progname); - } - - pixz_list(tar); - return 0; -} - void pixz_list(bool tar) { decode_index(); lzma_index_iter iter; diff --git a/pixz.h b/pixz.h index 7aa445d..8e2474e 100644 --- a/pixz.h +++ b/pixz.h @@ -28,6 +28,13 @@ #endif +#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); + + #pragma mark UTILS FILE *gInFile, *gOutFile; diff --git a/read.c b/read.c index d447a21..e243144 100644 --- a/read.c +++ b/read.c @@ -58,35 +58,9 @@ static size_t gBlockInSize = 0, gBlockOutSize = 0; static void set_block_sizes(void); -void pixz_read(bool verify, size_t nspecs, char **specs); - #pragma mark MAIN -int main(int argc, char **argv) { - gInFile = stdin; - gOutFile = stdout; - bool verify = true; - int ch; - while ((ch = getopt(argc, argv, "i:o:v")) != -1) { - switch (ch) { - case 'i': - if (!(gInFile = fopen(optarg, "r"))) - die ("Can't open input file"); - break; - case 'o': - if (!(gOutFile = fopen(optarg, "w"))) - die ("Can't open output file"); - break; - case 'v': verify = false; break; - default: - die("Unknown option"); - } - } - pixz_read(verify, argc - optind, argv + optind); - return 0; -} - void pixz_read(bool verify, size_t nspecs, char **specs) { decode_index(); if (verify) diff --git a/write.c b/write.c index 055ec35..e65181f 100644 --- a/write.c +++ b/write.c @@ -57,48 +57,9 @@ 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': - tar = false; - break; - default: - if (optopt >= '0' && optopt <= '9') { - level = optopt - '0'; - } else { - die("Unknown option"); - } - } - } - argc -= optind - 1; - argv += optind - 1; - - if (argc == 1) { - gInFile = stdin; - gOutFile = stdout; - } else if (argc == 3) { - if (!(gInFile = fopen(argv[1], "r"))) - die("Can't open input file"); - if (!(gOutFile = fopen(argv[2], "w"))) - die("Can't open output file"); - } else { - die("Usage: %s [-t] [INPUT OUTPUT]", progname); - } - - pixz_write(tar, level); -} - void pixz_write(bool tar, uint32_t level) { gTar = tar;