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

Single driver

This commit is contained in:
Dave Vasilevsky 2010-10-14 01:48:08 -04:00
parent e675206a8e
commit 4713b32cf1
5 changed files with 9 additions and 99 deletions

View File

@ -17,8 +17,8 @@ CC = gcc
COMPILE = $(CC) $(CFLAGS) -c -o COMPILE = $(CC) $(CFLAGS) -c -o
LD = $(CC) $(LDFLAGS) -o LD = $(CC) $(LDFLAGS) -o
PROGS = write read list PROGS = pixz
COMMON = common.o endian.o cpu.o COMMON = common.o endian.o cpu.o read.o write.o list.o
all: $(PROGS) all: $(PROGS)

32
list.c
View File

@ -2,40 +2,8 @@
#include <getopt.h> #include <getopt.h>
void pixz_list(bool tar);
#pragma mark FUNCTION DEFINITIONS #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) { void pixz_list(bool tar) {
decode_index(); decode_index();
lzma_index_iter iter; lzma_index_iter iter;

7
pixz.h
View File

@ -28,6 +28,13 @@
#endif #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 #pragma mark UTILS
FILE *gInFile, *gOutFile; FILE *gInFile, *gOutFile;

26
read.c
View File

@ -58,35 +58,9 @@ static size_t gBlockInSize = 0, gBlockOutSize = 0;
static void set_block_sizes(void); static void set_block_sizes(void);
void pixz_read(bool verify, size_t nspecs, char **specs);
#pragma mark MAIN #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) { void pixz_read(bool verify, size_t nspecs, char **specs) {
decode_index(); decode_index();
if (verify) if (verify)

39
write.c
View File

@ -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_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) {
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) { void pixz_write(bool tar, uint32_t level) {
gTar = tar; gTar = tar;