From 41e8014d2c5f483e23aae3fa0aa799b0ff3d0c4b Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sun, 27 Feb 2022 20:07:31 +1100 Subject: [PATCH] Add a -Q/--very-quiet option to suppress normal output to console. --- lrzip_private.h | 3 +++ main.c | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lrzip_private.h b/lrzip_private.h index 0e853f7..8571522 100644 --- a/lrzip_private.h +++ b/lrzip_private.h @@ -229,6 +229,7 @@ typedef sem_t cksem_t; #define FLAG_TMP_OUTBUF (1 << 21) #define FLAG_TMP_INBUF (1 << 22) #define FLAG_ENCRYPT (1 << 23) +#define FLAG_OUTPUT (1 << 24) #define NO_MD5 (!(HASH_CHECK) && !(HAS_MD5)) @@ -308,6 +309,7 @@ typedef sem_t cksem_t; #define TMP_OUTBUF (control->flags & FLAG_TMP_OUTBUF) #define TMP_INBUF (control->flags & FLAG_TMP_INBUF) #define ENCRYPT (control->flags & FLAG_ENCRYPT) +#define SHOW_OUTPUT (control->flags & FLAG_OUTPUT) #define IS_FROM_FILE ( !!(control->inFILE) && !STDIN ) @@ -547,6 +549,7 @@ static inline void print_err(const rzip_control *control, unsigned int line, con } while (0) #define print_output(...) do {\ + if (SHOW_OUTPUT) \ print_stuff(1, __VA_ARGS__); \ } while (0) diff --git a/main.c b/main.c index 33c85af..ce6daed 100644 --- a/main.c +++ b/main.c @@ -87,8 +87,10 @@ static void usage(bool compat) if (compat) { print_output(" -L, --license display software version and license\n"); print_output(" -P, --progress show compression progress\n"); - } else + } else { print_output(" -q, --quiet don't show compression progress\n"); + print_output(" -Q, --very-quiet don't show any output\n"); + } print_output(" -r, --recursive operate recursively on directories\n"); print_output(" -t, --test test compressed file integrity\n"); print_output(" -v[v%s], --verbose Increase verbosity\n", compat ? "v" : ""); @@ -246,6 +248,7 @@ static struct option long_options[] = { {"threads", required_argument, 0, 'p'}, {"progress", no_argument, 0, 'P'}, {"quiet", no_argument, 0, 'q'}, + {"very-quiet", no_argument, 0, 'Q'}, {"recursive", no_argument, 0, 'r'}, {"suffix", required_argument, 0, 'S'}, {"test", no_argument, 0, 't'}, /* 25 */ @@ -300,7 +303,7 @@ static void recurse_dirlist(char *indir, char **dirlist, int *entries) closedir(dirp); } -static const char *loptions = "bcCdDefghHiKlL:nN:o:O:p:PqrS:tTUm:vVw:z?"; +static const char *loptions = "bcCdDefghHiKlL:nN:o:O:p:PqQrS:tTUm:vVw:z?"; static const char *coptions = "bcCdefghHikKlLnN:o:O:p:PrS:tTUm:vVw:z?123456789"; int main(int argc, char *argv[]) @@ -324,6 +327,7 @@ int main(int argc, char *argv[]) initialise_control(control); av = basename(argv[0]); + control->flags |= FLAG_OUTPUT; if (!strcmp(av, "lrunzip")) control->flags |= FLAG_DECOMPRESS; else if (!strcmp(av, "lrzcat")) { @@ -488,6 +492,10 @@ int main(int argc, char *argv[]) case 'q': control->flags &= ~FLAG_SHOW_PROGRESS; break; + case 'Q': + control->flags &= ~FLAG_SHOW_PROGRESS; + control->flags &= ~FLAG_OUTPUT; + break; case 'r': recurse = true; break; @@ -553,6 +561,9 @@ int main(int argc, char *argv[]) } } + if (compat) + control->flags &= ~FLAG_OUTPUT; + argc -= optind; argv += optind;