diff --git a/Makefile.am b/Makefile.am index 43b06d9..1407d72 100644 --- a/Makefile.am +++ b/Makefile.am @@ -107,12 +107,14 @@ install-exec-hook: $(LN_S) -f lrzip$(EXEEXT) $(DESTDIR)$(bindir)/lrunzip$(EXEEXT) $(LN_S) -f lrzip$(EXEEXT) $(DESTDIR)$(bindir)/lrzcat$(EXEEXT) $(LN_S) -f lrztar$(EXEEXT) $(DESTDIR)$(bindir)/lrzuntar$(EXEEXT) + $(LN_S) -f lrz$(EXEEXT) $(DESTDIR)$(bindir)/lrz$(EXEEXT) uninstall-local: rm -f $(bindir)/lrunzip rm -f $(bindir)/lrzcat rm -f $(bindir)/lrzuntar + rm -f $(bindir)/lrz .PHONY: doc diff --git a/main.c b/main.c index 40c943a..74589b7 100644 --- a/main.c +++ b/main.c @@ -50,6 +50,7 @@ #endif #include +#include #include "rzip.h" #include "lrzip_core.h" @@ -61,7 +62,7 @@ static rzip_control base_control, local_control, *control; -static void usage(void) +static void usage(bool compat) { print_output("lrzip version %s\n", PACKAGE_VERSION); print_output("Copyright (C) Con Kolivas 2006-2015\n"); @@ -69,20 +70,30 @@ static void usage(void) print_output("Copyright (C) Andrew Tridgell 1998-2003\n\n"); print_output("Usage: lrzip [options] \n"); print_output("General options:\n"); - print_output(" -c, --check check integrity of file written on decompression\n"); + if (compat) { + print_output(" -c, --stdout output to STDOUT\n"); + print_output(" -C, --check check integrity of file written on decompression\n"); + } else + print_output(" -c, -C, --check check integrity of file written on decompression\n"); print_output(" -d, --decompress decompress\n"); print_output(" -e, --encrypt password protected sha512/aes128 encryption on compression\n"); print_output(" -h, -?, --help show help\n"); print_output(" -H, --hash display md5 hash integrity information\n"); print_output(" -i, --info show compressed file information\n"); - print_output(" -q, --quiet don't show compression progress\n"); + if (compat) + print_output(" -P, --progress show compression progress\n"); + else + print_output(" -q, --quiet don't show compression progress\n"); print_output(" -t, --test test compressed file integrity\n"); print_output(" -v[v], --verbose Increase verbosity\n"); print_output(" -V, --version show version\n"); print_output("Options affecting output:\n"); - print_output(" -D, --delete delete existing files\n"); + if (!compat) + print_output(" -D, --delete delete existing files\n"); print_output(" -f, --force force overwrite of any existing files\n"); - print_output(" -k, --keep-broken keep broken or damaged output files\n"); + if (compat) + print_output(" -k, --keep don't delete source files on de/compression\n"); + print_output(" -%s, --keep-broken keep broken or damaged output files\n", compat ? "K" : "k, -K"); print_output(" -o, --outfile filename specify the output file name and/or path\n"); print_output(" -O, --outdir directory specify the output directory when -o is not used\n"); print_output(" -S, --suffix suffix specify compressed suffix (default '.lrz')\n"); @@ -94,7 +105,7 @@ static void usage(void) print_output(" -z, --zpaq zpaq compression (best, extreme compression, extremely slow)\n"); print_output("Low level options:\n"); print_output(" -L, --level level set lzma/bzip2/gzip compression level (1-9, default 7)\n"); - print_output(" -N, --nice-level value Set nice value to value (default 19)\n"); + print_output(" -N, --nice-level value Set nice value to value (default %d)\n", compat ? 0 : 19); print_output(" -p, --threads value Set processor count to override number of threads\n"); print_output(" -m, --maxram size Set maximim available ram in hundreds of MB\n"); print_output(" overrides detected ammount of available ram\n"); @@ -191,6 +202,7 @@ static void show_summary(void) static struct option long_options[] = { {"bzip2", no_argument, 0, 'b'}, {"check", no_argument, 0, 'c'}, + {"check", no_argument, 0, 'C'}, {"decompress", no_argument, 0, 'd'}, {"delete", no_argument, 0, 'D'}, {"encrypt", no_argument, 0, 'e'}, @@ -200,6 +212,7 @@ static struct option long_options[] = { {"hash", no_argument, 0, 'H'}, {"info", no_argument, 0, 'i'}, {"keep-broken", no_argument, 0, 'k'}, + {"keep-broken", no_argument, 0, 'K'}, {"lzo", no_argument, 0, 'l'}, {"level", no_argument, 0, 'L'}, {"maxram", required_argument, 0, 'm'}, @@ -208,6 +221,7 @@ static struct option long_options[] = { {"outfile", required_argument, 0, 'o'}, {"outdir", required_argument, 0, 'O'}, {"threads", required_argument, 0, 'p'}, + {"progress", no_argument, 0, 'P'}, {"quiet", no_argument, 0, 'q'}, {"suffix", required_argument, 0, 'S'}, {"test", no_argument, 0, 't'}, @@ -217,29 +231,40 @@ static struct option long_options[] = { {"version", no_argument, 0, 'V'}, {"window", required_argument, 0, 'w'}, {"zpaq", no_argument, 0, 'z'}, + {"fast", no_argument, 0, '1'}, + {"best", no_argument, 0, '9'}, {0, 0, 0, 0}, }; int main(int argc, char *argv[]) { + bool lrzcat = false, compat = false; struct timeval start_time, end_time; struct sigaction handler; double seconds,total_time; // for timers - bool lrzcat = false; int c, i; int hours,minutes; extern int optind; - char *eptr; /* for environment */ + char *eptr, *av; /* for environment */ control = &base_control; initialise_control(control); - if (strstr(argv[0], "lrunzip")) + av = basename(argv[0]); + if (!strcmp(av, "lrunzip")) control->flags |= FLAG_DECOMPRESS; - else if (strstr(argv[0], "lrzcat")) { + else if (!strcmp(av, "lrzcat")) { control->flags |= FLAG_DECOMPRESS | FLAG_STDOUT; lrzcat = true; + } else if (!strcmp(av, "lrz")) { + /* Called in gzip compatible command line mode */ + control->flags &= ~FLAG_SHOW_PROGRESS; + control->nice_val = 0; + control->flags &= ~FLAG_KEEP_FILES; + compat = true; + long_options[1].name = "stdout"; + long_options[11].name = "keep"; } /* generate crc table */ @@ -255,7 +280,7 @@ int main(int argc, char *argv[]) else if (!strstr(eptr,"NOCONFIG")) read_config(control); - while ((c = getopt_long(argc, argv, "bcdDefghHiklL:nN:o:O:p:qS:tTUm:vVw:z?", long_options, &i)) != -1) { + while ((c = getopt_long(argc, argv, "bcCdDefghHikKlL:nN:o:O:pP:qS:tTUm:vVw:z?123456789", long_options, &i)) != -1) { switch (c) { case 'b': if (control->flags & FLAG_NOT_LZMA) @@ -263,6 +288,11 @@ int main(int argc, char *argv[]) control->flags |= FLAG_BZIP2_COMPRESS; break; case 'c': + if (compat) { + control->flags |= FLAG_STDOUT; + break; + } + case 'C': control->flags |= FLAG_CHECK; control->flags |= FLAG_HASH; break; @@ -285,7 +315,7 @@ int main(int argc, char *argv[]) break; case 'h': case '?': - usage(); + usage(compat); return -1; case 'H': control->flags |= FLAG_HASH; @@ -294,6 +324,11 @@ int main(int argc, char *argv[]) control->flags |= FLAG_INFO; break; case 'k': + if (compat) { + control->flags |= FLAG_KEEP_FILES; + break; + } + case 'K': control->flags |= FLAG_KEEP_BROKEN; break; case 'l': @@ -388,6 +423,17 @@ int main(int argc, char *argv[]) failure("Can only use one of -l, -b, -g, -z or -n\n"); control->flags |= FLAG_ZPAQ_COMPRESS; break; + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + control->compression_level = c - '0'; + break; } } @@ -482,12 +528,12 @@ int main(int argc, char *argv[]) if (!FORCE_REPLACE) { if (STDIN && isatty(fileno((FILE *)stdin))) { print_err("Will not read stdin from a terminal. Use -f to override.\n"); - usage(); + usage(compat); exit (1); } if (!TEST_ONLY && STDOUT && isatty(fileno((FILE *)stdout))) { print_err("Will not write stdout to a terminal. Use -f to override.\n"); - usage(); + usage(compat); exit (1); } }