From d972496aa806b2502c766636d8ee576abf38a43e Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sun, 25 Apr 2010 16:26:00 +1000 Subject: [PATCH] Make messages come via stdout instead of stderror courtesy of Alexander Saprykin --- main.c | 137 ++++++++++++++++++++++++++++-------------------------- runzip.c | 6 +-- rzip.c | 26 +++++------ rzip.h | 5 +- stream.c | 26 +++++------ util.c | 6 +-- zpipe.cpp | 28 +++++------ 7 files changed, 121 insertions(+), 113 deletions(-) diff --git a/main.c b/main.c index a63fde5..593f836 100644 --- a/main.c +++ b/main.c @@ -23,36 +23,36 @@ struct rzip_control control; static void usage(void) { - fprintf(stderr, "lrzip version %d.%d%d\n", LRZIP_MAJOR_VERSION, LRZIP_MINOR_VERSION, LRZIP_MINOR_SUBVERSION); - fprintf(stderr, "Copyright (C) Con Kolivas 2006-2010\n\n"); - fprintf(stderr, "Based on rzip "); - fprintf(stderr, "Copyright (C) Andrew Tridgell 1998-2003\n"); - fprintf(stderr, "usage: lrzip [options] \n"); - fprintf(stderr, " Options:\n"); - fprintf(stderr, " -w size compression window in hundreds of MB\n"); - fprintf(stderr, " default chosen by heuristic dependent on ram and chosen compression\n"); - fprintf(stderr, " -d decompress\n"); - fprintf(stderr, " -o filename specify the output file name and/or path\n"); - fprintf(stderr, " -O directory specify the output directory when -o is not used\n"); - fprintf(stderr, " -S suffix specify compressed suffix (default '.lrz')\n"); - fprintf(stderr, " -f force overwrite of any existing files\n"); - fprintf(stderr, " -D delete existing files\n"); - fprintf(stderr, " -P don't set permissions on output file - may leave it world-readable\n"); - fprintf(stderr, " -q don't show compression progress\n"); - fprintf(stderr, " -L level set lzma/bzip2/gzip compression level (1-9, default 7)\n"); - fprintf(stderr, " -n no backend compression - prepare for other compressor\n"); - fprintf(stderr, " -l lzo compression (ultra fast)\n"); - fprintf(stderr, " -b bzip2 compression\n"); - fprintf(stderr, " -g gzip compression using zlib\n"); - fprintf(stderr, " -z zpaq compression (best, extreme compression, extremely slow)\n"); - fprintf(stderr, " -M Maximum window and level - (all available ram and level 9)\n"); - fprintf(stderr, " -T value Compression threshold with LZO test. (0 (nil) - 10 (high), default 1)\n"); - fprintf(stderr, " -N value Set nice value to value (default 19)\n"); - fprintf(stderr, " -v[v] Increase verbosity\n"); - fprintf(stderr, " -V show version\n"); - fprintf(stderr, " -t test compressed file integrity\n"); - fprintf(stderr, " -i show compressed file information\n"); - fprintf(stderr, "\nIf no filenames or \"-\" is specified, stdin/out will be used.\n"); + fprintf(stdout, "lrzip version %d.%d%d\n", LRZIP_MAJOR_VERSION, LRZIP_MINOR_VERSION, LRZIP_MINOR_SUBVERSION); + fprintf(stdout, "Copyright (C) Con Kolivas 2006-2010\n\n"); + fprintf(stdout, "Based on rzip "); + fprintf(stdout, "Copyright (C) Andrew Tridgell 1998-2003\n"); + fprintf(stdout, "usage: lrzip [options] \n"); + fprintf(stdout, " Options:\n"); + fprintf(stdout, " -w size compression window in hundreds of MB\n"); + fprintf(stdout, " default chosen by heuristic dependent on ram and chosen compression\n"); + fprintf(stdout, " -d decompress\n"); + fprintf(stdout, " -o filename specify the output file name and/or path\n"); + fprintf(stdout, " -O directory specify the output directory when -o is not used\n"); + fprintf(stdout, " -S suffix specify compressed suffix (default '.lrz')\n"); + fprintf(stdout, " -f force overwrite of any existing files\n"); + fprintf(stdout, " -D delete existing files\n"); + fprintf(stdout, " -P don't set permissions on output file - may leave it world-readable\n"); + fprintf(stdout, " -q don't show compression progress\n"); + fprintf(stdout, " -L level set lzma/bzip2/gzip compression level (1-9, default 7)\n"); + fprintf(stdout, " -n no backend compression - prepare for other compressor\n"); + fprintf(stdout, " -l lzo compression (ultra fast)\n"); + fprintf(stdout, " -b bzip2 compression\n"); + fprintf(stdout, " -g gzip compression using zlib\n"); + fprintf(stdout, " -z zpaq compression (best, extreme compression, extremely slow)\n"); + fprintf(stdout, " -M Maximum window and level - (all available ram and level 9)\n"); + fprintf(stdout, " -T value Compression threshold with LZO test. (0 (nil) - 10 (high), default 1)\n"); + fprintf(stdout, " -N value Set nice value to value (default 19)\n"); + fprintf(stdout, " -v[v] Increase verbosity\n"); + fprintf(stdout, " -V show version\n"); + fprintf(stdout, " -t test compressed file integrity\n"); + fprintf(stdout, " -i show compressed file information\n"); + fprintf(stdout, "\nIf no filenames or \"-\" is specified, stdin/out will be used.\n"); } static void write_magic(int fd_in, int fd_out) @@ -117,13 +117,13 @@ static void read_magic(int fd_in, i64 *expected_size) control.lzma_properties[i] = magic[i + 16]; } if (control.flags & FLAG_VERBOSE) { - fprintf(stderr, "Detected lrzip version %d.%d file.\n", control.major_version, control.minor_version); - fflush(stderr); + fprintf(control.msgout, "Detected lrzip version %d.%d file.\n", control.major_version, control.minor_version); + fflush(control.msgout); } if (control.major_version > LRZIP_MAJOR_VERSION || (control.major_version == LRZIP_MAJOR_VERSION && control.minor_version > LRZIP_MINOR_VERSION)) { - fprintf(stderr, "Attempting to work with file produced by newer lrzip version %d.%d file.\n", control.major_version, control.minor_version); - fflush(stderr); + fprintf(control.msgout, "Attempting to work with file produced by newer lrzip version %d.%d file.\n", control.major_version, control.minor_version); + fflush(control.msgout); } } @@ -141,13 +141,13 @@ static void preserve_perms(int fd_in, int fd_out) fchown(fd_out, st.st_uid, st.st_gid); } -/* Open a temporary outputfile for testing decompression or stdout */ +/* Open a temporary outputfile for testing decompression or msgout */ static int open_tmpoutfile(void) { int fd_out; if ((control.flags & FLAG_STDOUT) && (control.flags & FLAG_VERBOSE)) - fprintf(stderr, "Outputting to stdout.\n"); + fprintf(control.msgout, "Outputting to stdout.\n"); control.outfile = realloc(NULL, 16); strcpy(control.outfile, "lrzipout.XXXXXX"); if (!control.outfile) @@ -166,7 +166,7 @@ static void dump_tmpoutfile(int fd_out) int tmpchar; if (control.flags & FLAG_SHOW_PROGRESS) - fprintf(stderr, "Dumping to stdout.\n"); + fprintf(control.msgout, "Dumping to stdout.\n"); /* flush anything not yet in the temporary file */ fflush(NULL); tmpoutfp = fdopen(fd_out, "r"); @@ -177,7 +177,7 @@ static void dump_tmpoutfile(int fd_out) while ((tmpchar = fgetc(tmpoutfp)) != EOF) putchar(tmpchar); - fflush(stdout); + fflush(control.msgout); } /* Open a temporary inputfile to perform stdin */ @@ -203,7 +203,7 @@ static void read_tmpinfile(int fd_in) int tmpchar; if (control.flags & FLAG_SHOW_PROGRESS) - fprintf(stderr, "Copying from stdin.\n"); + fprintf(control.msgout, "Copying from stdin.\n"); tmpinfp = fdopen(fd_in, "w+"); if (tmpinfp == NULL) fatal("Failed to fdopen in tmpfile: %s\n", strerror(errno)); @@ -272,8 +272,8 @@ static void decompress_file(void) } if ((control.flags & FLAG_SHOW_PROGRESS) && !(control.flags & FLAG_STDOUT)) { - fprintf(stderr, "Output filename is: %s...Decompressing...\n", control.outfile); - fflush(stderr); + fprintf(control.msgout, "Output filename is: %s...Decompressing...\n", control.outfile); + fflush(control.msgout); } } @@ -308,8 +308,8 @@ static void decompress_file(void) read_magic(fd_in, &expected_size); if (control.flags & FLAG_SHOW_PROGRESS) { - fprintf(stderr, "Decompressing..."); - fflush(stderr); + fprintf(control.msgout, "Decompressing..."); + fflush(control.msgout); } runzip_fd(fd_in, fd_out, fd_hist, expected_size); @@ -318,11 +318,11 @@ static void decompress_file(void) dump_tmpoutfile(fd_out); /* if we get here, no fatal errors during decompression */ - fprintf(stderr, "\r"); + fprintf(control.msgout, "\r"); if (!(control.flags & (FLAG_STDOUT | FLAG_TEST_ONLY))) - fprintf(stderr, "Output filename is: %s: ", control.outfile); - fprintf(stderr, "[OK] - %lld bytes \n", (long long)expected_size); - fflush(stderr); + fprintf(control.msgout, "Output filename is: %s: ", control.outfile); + fprintf(control.msgout, "[OK] - %lld bytes \n", (long long)expected_size); + fflush(control.msgout); if (close(fd_hist) != 0 || close(fd_out) != 0) fatal("Failed to close files\n"); @@ -400,23 +400,23 @@ static void get_fileinfo(void) cratio = (long double)expected_size / (long double)infile_size; - fprintf(stderr, "%s:\nlrzip version: %d.%d file\n", infilecopy, control.major_version, control.minor_version); - fprintf(stderr, "Compression: "); + fprintf(control.msgout, "%s:\nlrzip version: %d.%d file\n", infilecopy, control.major_version, control.minor_version); + fprintf(control.msgout, "Compression: "); if (ctype == CTYPE_NONE) - fprintf(stderr, "rzip alone\n"); + fprintf(control.msgout, "rzip alone\n"); else if (ctype == CTYPE_BZIP2) - fprintf(stderr, "rzip + bzip2\n"); + fprintf(control.msgout, "rzip + bzip2\n"); else if (ctype == CTYPE_LZO) - fprintf(stderr, "rzip + lzo\n"); + fprintf(control.msgout, "rzip + lzo\n"); else if (ctype == CTYPE_LZMA) - fprintf(stderr, "rzip + lzma\n"); + fprintf(control.msgout, "rzip + lzma\n"); else if (ctype == CTYPE_GZIP) - fprintf(stderr, "rzip + gzip\n"); + fprintf(control.msgout, "rzip + gzip\n"); else if (ctype == CTYPE_ZPAQ) - fprintf(stderr, "rzip + zpaq\n"); - fprintf(stderr, "Decompressed file size: %llu\n", expected_size); - fprintf(stderr, "Compressed file size: %llu\n", infile_size); - fprintf(stderr, "Compression ratio: %.3Lf\n", cratio); + fprintf(control.msgout, "rzip + zpaq\n"); + fprintf(control.msgout, "Decompressed file size: %llu\n", expected_size); + fprintf(control.msgout, "Compressed file size: %llu\n", infile_size); + fprintf(control.msgout, "Compression ratio: %.3Lf\n", cratio); if (control.flags & FLAG_STDIN) { if (unlink(control.infile) != 0) @@ -443,7 +443,7 @@ static void compress_file(void) if (!(control.flags & FLAG_STDIN)) { /* is extension at end of infile? */ if ((tmp = strrchr(control.infile, '.')) && !strcmp(tmp, control.suffix)) { - fprintf(stderr, "%s: already has %s suffix. Skipping...\n", control.infile, control.suffix); + fprintf(control.msgout, "%s: already has %s suffix. Skipping...\n", control.infile, control.suffix); return; } @@ -466,7 +466,7 @@ static void compress_file(void) fatal("Failed to allocate outfile name\n"); strcpy(control.outfile, control.outname); strcat(control.outfile, control.suffix); - fprintf(stderr, "Suffix added to %s.\nFull pathname is: %s\n", control.outname, control.outfile); + fprintf(control.msgout, "Suffix added to %s.\nFull pathname is: %s\n", control.outname, control.outfile); } else /* no, already has suffix */ control.outfile = strdup(control.outname); } else { @@ -490,7 +490,7 @@ static void compress_file(void) strcpy(control.outfile, tmpinfile); strcat(control.outfile, control.suffix); if ( control.flags & FLAG_SHOW_PROGRESS ) - fprintf(stderr, "Output filename is: %s\n", control.outfile); + fprintf(control.msgout, "Output filename is: %s\n", control.outfile); } if (control.flags & FLAG_FORCE_REPLACE) @@ -575,6 +575,7 @@ int main(int argc, char *argv[]) memset(&control, 0, sizeof(control)); + control.msgout = stderr; control.flags = FLAG_SHOW_PROGRESS | FLAG_KEEP_FILES; control.suffix = ".lrz"; control.outdir = NULL; @@ -657,7 +658,7 @@ int main(int argc, char *argv[]) control.flags &= ~FLAG_SHOW_PROGRESS; break; case 'V': - fprintf(stderr, "lrzip version %d.%d%d\n", + fprintf(stdout, "lrzip version %d.%d%d\n", LRZIP_MAJOR_VERSION, LRZIP_MINOR_VERSION, LRZIP_MINOR_SUBVERSION); exit(0); break; @@ -836,13 +837,19 @@ int main(int argc, char *argv[]) if (control.infile && (strcmp(control.infile, "-") == 0)) control.flags |= FLAG_STDIN; - if (control.outname && (strcmp(control.outname, "-") == 0)) + if (control.outname && (strcmp(control.outname, "-") == 0)) { control.flags |= FLAG_STDOUT; + control.msgout = stderr; + } /* If we're using stdin and no output filename, use stdout */ - if ((control.flags & FLAG_STDIN) && !control.outname) + if ((control.flags & FLAG_STDIN) && !control.outname) { control.flags |= FLAG_STDOUT; + control.msgout = stderr; + } + if (!(control.flags & FLAG_STDOUT)) + control.msgout = stdout; /* Implement signal handler only once flags are set */ handler.sa_handler = &sighandler; sigaction(SIGTERM, &handler, 0); @@ -865,7 +872,7 @@ int main(int argc, char *argv[]) minutes = (int)(total_time - hours * 3600) / 60; seconds = total_time - hours * 60 - minutes * 60; if ((control.flags & FLAG_SHOW_PROGRESS) && !(control.flags & FLAG_INFO)) - fprintf(stderr, "Total time: %02d:%02d:%06.3f\n", hours, minutes, seconds); + fprintf(control.msgout, "Total time: %02d:%02d:%06.3f\n", hours, minutes, seconds); } return 0; diff --git a/runzip.c b/runzip.c index e332d10..391ac44 100644 --- a/runzip.c +++ b/runzip.c @@ -234,9 +234,9 @@ static i64 runzip_chunk(int fd_in, int fd_out, int fd_hist, i64 expected_size, i if (control.flags & FLAG_SHOW_PROGRESS) { if ( p != l ) { prog_done = (double)(tally+total) / (double)divisor[divisor_index]; - fprintf(stderr, "%3d%% %9.2f / %9.2f %s\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b", + fprintf(control.msgout, "%3d%% %9.2f / %9.2f %s\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b", p, prog_done, prog_tsize, suffix[divisor_index] ); - fflush(stderr); + fflush(control.msgout); l = p; } } @@ -268,7 +268,7 @@ i64 runzip_fd(int fd_in, int fd_out, int fd_hist, i64 expected_size) gettimeofday(&end,NULL); if (control.flags & FLAG_SHOW_PROGRESS) - fprintf(stderr, "\nAverage DeCompression Speed: %6.3fMB/s\n", + fprintf(control.msgout, "\nAverage DeCompression Speed: %6.3fMB/s\n", (total / 1024 / 1024) / (double)((end.tv_sec-start.tv_sec)? : 1)); return total; } diff --git a/rzip.c b/rzip.c index cbb3571..9656462 100644 --- a/rzip.c +++ b/rzip.c @@ -241,7 +241,7 @@ again: better_than_min = increase_mask(st->minimum_tag_mask); if (control.flags & FLAG_VERBOSITY_MAX) { if (!st->tag_clean_ptr) - fprintf(stderr, "\nStarting sweep for mask %u\n", (unsigned int)st->minimum_tag_mask); + fprintf(control.msgout, "\nStarting sweep for mask %u\n", (unsigned int)st->minimum_tag_mask); } for (; st->tag_clean_ptr < (1U<hash_bits); st->tag_clean_ptr++) { @@ -370,9 +370,9 @@ static void show_distrib(struct rzip_state *st) } if (total != st->hash_count) - fprintf(stderr, "/tWARNING: hash_count says total %lld\n", st->hash_count); + fprintf(control.msgout, "/tWARNING: hash_count says total %lld\n", st->hash_count); - fprintf(stderr, "\t%lld total hashes -- %lld in primary bucket (%-2.3f%%)\n", total, primary, + fprintf(control.msgout, "\t%lld total hashes -- %lld in primary bucket (%-2.3f%%)\n", total, primary, primary*100.0/total); } @@ -399,7 +399,7 @@ static void hash_search(struct rzip_state *st, uchar *buf, for (st->hash_bits = 0; (1U << st->hash_bits) < hashsize; st->hash_bits++); if (control.flags & FLAG_VERBOSITY_MAX) - fprintf(stderr, "hashsize = %lld. bits = %lld. %luMB\n", + fprintf(control.msgout, "hashsize = %lld. bits = %lld. %luMB\n", hashsize, st->hash_bits, st->level->mb_used); /* 66% full at max. */ @@ -473,8 +473,8 @@ static void hash_search(struct rzip_state *st, uchar *buf, fstat(st->fd_in, &s1); fstat(st->fd_out, &s2); - fprintf(stderr, "%2lld%%\r", pct); - fflush(stderr); + fprintf(control.msgout, "%2lld%%\r", pct); + fflush(control.msgout); lastpct = pct; } } @@ -617,7 +617,7 @@ void rzip_fd(int fd_in, int fd_out) eta_minutes = (unsigned int)((finish_time - elapsed_time) - eta_hours * 3600) / 60; eta_seconds = (unsigned int)(finish_time - elapsed_time) - eta_hours * 60 - eta_minutes * 60; chunkmbs=(last_chunk / 1024 / 1024) / (double)(current.tv_sec-last.tv_sec); - fprintf(stderr, "\nPass %d / %d -- Elapsed Time: %02d:%02d:%02d. ETA: %02d:%02d:%02d. Compress Speed: %3.3fMB/s.\n", + fprintf(control.msgout, "\nPass %d / %d -- Elapsed Time: %02d:%02d:%02d. ETA: %02d:%02d:%02d. Compress Speed: %3.3fMB/s.\n", pass, passes, elapsed_hours, elapsed_minutes, elapsed_seconds, eta_hours, eta_minutes, eta_seconds, chunkmbs); } @@ -635,21 +635,21 @@ void rzip_fd(int fd_in, int fd_out) fstat(fd_out, &s2); if (control.flags & FLAG_VERBOSITY_MAX) { - fprintf(stderr, "matches=%u match_bytes=%u\n", + fprintf(control.msgout, "matches=%u match_bytes=%u\n", (unsigned int)st->stats.matches, (unsigned int)st->stats.match_bytes); - fprintf(stderr, "literals=%u literal_bytes=%u\n", + fprintf(control.msgout, "literals=%u literal_bytes=%u\n", (unsigned int)st->stats.literals, (unsigned int)st->stats.literal_bytes); - fprintf(stderr, "true_tag_positives=%u false_tag_positives=%u\n", + fprintf(control.msgout, "true_tag_positives=%u false_tag_positives=%u\n", (unsigned int)st->stats.tag_hits, (unsigned int)st->stats.tag_misses); - fprintf(stderr, "inserts=%u match %.3f\n", + fprintf(control.msgout, "inserts=%u match %.3f\n", (unsigned int)st->stats.inserts, (1.0 + st->stats.match_bytes) / st->stats.literal_bytes); } if (control.flags & FLAG_SHOW_PROGRESS) { if (!(control.flags & FLAG_STDIN)) - fprintf(stderr, "%s - ", control.infile); - fprintf(stderr, "Compression Ratio: %.3f. Average Compression Speed: %6.3fMB/s.\n", + fprintf(control.msgout, "%s - ", control.infile); + fprintf(control.msgout, "Compression Ratio: %.3f. Average Compression Speed: %6.3fMB/s.\n", 1.0 * s.st_size / s2.st_size, chunkmbs); } diff --git a/rzip.h b/rzip.h index b09dcc1..318db65 100644 --- a/rzip.h +++ b/rzip.h @@ -152,6 +152,7 @@ struct rzip_control { char *outname; char *outfile; char *outdir; + FILE *msgout; //stream for output messages const char *suffix; int compression_level; unsigned char lzma_properties[5]; // lzma properties, encoded @@ -181,5 +182,5 @@ int close_stream_in(void *ss); void read_config(struct rzip_control *s); ssize_t write_1g(int fd, void *buf, i64 len); ssize_t read_1g(int fd, void *buf, i64 len); -extern void zpipe_compress(FILE *in, FILE *out, long long int buf_len, int progress); -extern void zpipe_decompress(FILE *in, FILE *out, long long int buf_len, int progress); +extern void zpipe_compress(FILE *in, FILE *out, FILE *msgout, long long int buf_len, int progress); +extern void zpipe_decompress(FILE *in, FILE *out, FILE *msgout, long long int buf_len, int progress); diff --git a/stream.c b/stream.c index b7e5204..7fb257d 100644 --- a/stream.c +++ b/stream.c @@ -134,7 +134,7 @@ static void zpaq_compress_buf(struct stream *s, int *c_type, i64 *c_len) if (!out) fatal("Failed to open_memstream in zpaq_compress_buf\n"); - zpipe_compress(in, out, s->buflen, (int)(control.flags & FLAG_SHOW_PROGRESS)); + zpipe_compress(in, out, control.msgout, s->buflen, (int)(control.flags & FLAG_SHOW_PROGRESS)); if (memstream_update_buffer(out, &c_buf, &dlen) != 0) fatal("Failed to memstream_update_buffer in zpaq_compress_buf"); @@ -227,8 +227,8 @@ static void lzma_compress_buf(struct stream *s, int *c_type, i64 *c_len) return; if (control.flags & FLAG_SHOW_PROGRESS) { - fprintf(stderr, "\tProgress percentage pausing during lzma compression..."); - fflush(stderr); + fprintf(control.msgout, "\tProgress percentage pausing during lzma compression..."); + fflush(control.msgout); } /* with LZMA SDK 4.63, we pass compression level and threads only * and receive properties in control->lzma_properties */ @@ -271,10 +271,10 @@ static void lzma_compress_buf(struct stream *s, int *c_type, i64 *c_len) *c_type = CTYPE_LZMA; out: if (control.flags & FLAG_VERBOSITY_MAX) - fprintf(stderr, "\n"); + fprintf(control.msgout, "\n"); else if ((control.flags & FLAG_SHOW_PROGRESS || control.flags & FLAG_VERBOSITY )) - fprintf(stderr, "\r\t \r"); - fflush(stderr); + fprintf(control.msgout, "\r\t \r"); + fflush(control.msgout); } static void lzo_compress_buf(struct stream *s, int *c_type, i64 *c_len) @@ -335,7 +335,7 @@ static int zpaq_decompress_buf(struct stream *s) return -1; } - zpipe_decompress(in, out, s->buflen, (int)(control.flags & FLAG_SHOW_PROGRESS)); + zpipe_decompress(in, out, control.msgout, s->buflen, (int)(control.flags & FLAG_SHOW_PROGRESS)); if (memstream_update_buffer(out, &c_buf, &dlen) != 0) fatal("Failed to memstream_update_buffer in zpaq_decompress_buf"); @@ -1007,8 +1007,8 @@ static int lzo_compresses(struct stream *s) fatal("Unable to allocate c_buf in lzo_compresses\n"); if (control.flags & FLAG_SHOW_PROGRESS) { - fprintf(stderr, "\tlzo testing for incompressible data..."); - fflush(stderr); + fprintf(control.msgout, "\tlzo testing for incompressible data..."); + fflush(control.msgout); } /* Test progressively larger blocks at a time and as soon as anything @@ -1034,14 +1034,14 @@ static int lzo_compresses(struct stream *s) } } if (control.flags & FLAG_VERBOSITY_MAX) - fprintf(stderr, "%s for chunk %ld. Compressed size = %5.2F%% of chunk, %d Passes\n", + fprintf(control.msgout, "%s for chunk %ld. Compressed size = %5.2F%% of chunk, %d Passes\n", (ret == 0? "FAILED - below threshold" : "OK"), save_len, 100 * ((double) best_dlen / (double) in_len), workcounter); else if (control.flags & FLAG_VERBOSITY) - fprintf(stderr, "%s\r", (ret == 0? "FAILED - below threshold" : "OK")); + fprintf(control.msgout, "%s\r", (ret == 0? "FAILED - below threshold" : "OK")); else if (control.flags & FLAG_SHOW_PROGRESS) - fprintf(stderr, "\r\t \r"); - fflush(stderr); + fprintf(control.msgout, "\r\t \r"); + fflush(control.msgout); free(wrkmem); free(c_buf); diff --git a/util.c b/util.c index e1be7b5..40192d8 100644 --- a/util.c +++ b/util.c @@ -90,11 +90,11 @@ void read_config( struct rzip_control *control ) fp = fopen("lrzip.conf", "r"); if (fp) - fprintf(stderr, "Using configuration file ./lrzip.conf\n"); + fprintf(control->msgout, "Using configuration file ./lrzip.conf\n"); if (fp == NULL) { fp = fopen("/etc/lrzip/lrzip.conf", "r"); if (fp) - fprintf(stderr, "Using configuration file /etc/lrzip/lrzip.conf\n"); + fprintf(control->msgout, "Using configuration file /etc/lrzip/lrzip.conf\n"); } if (fp == NULL) { HOME=getenv("HOME"); @@ -103,7 +103,7 @@ void read_config( struct rzip_control *control ) strcat(homeconf,"/.lrzip/lrzip.conf"); fp = fopen(homeconf, "r"); if (fp) - fprintf(stderr, "Using configuration file %s\n", homeconf); + fprintf(control->msgout, "Using configuration file %s\n", homeconf); } } if (fp == NULL) diff --git a/zpipe.cpp b/zpipe.cpp index 1f3b3af..1663972 100644 --- a/zpipe.cpp +++ b/zpipe.cpp @@ -1568,7 +1568,7 @@ bool find_start(FILE *in) { } // Decompress to stdout -static void decompress(FILE *in, FILE *out, long long int buf_len, int progress) { +static void decompress(FILE *in, FILE *out, FILE *msgout, long long int buf_len, int progress) { long long int len = 0; static int last_pct = 0, chunk = 0; @@ -1601,8 +1601,8 @@ static void decompress(FILE *in, FILE *out, long long int buf_len, int progress) len++; pct = (len * 100 / buf_len); if (pct != last_pct) { - fprintf(stderr, "\r ZPAQ Chunk %d of 2 Decompress: %i%% \r", (chunk + 1), pct); - fflush(stderr); + fprintf(msgout, "\r ZPAQ Chunk %d of 2 Decompress: %i%% \r", (chunk + 1), pct); + fflush(msgout); last_pct = pct; } } @@ -1624,15 +1624,15 @@ static void decompress(FILE *in, FILE *out, long long int buf_len, int progress) if (c!=255) error("missing end of block marker"); } if (progress) { - fprintf(stderr, "\t \r"); - fflush(stderr); + fprintf(msgout, "\t \r"); + fflush(msgout); } chunk ^= 1; } -extern "C" void zpipe_decompress(FILE *in, FILE *out, long long int buf_len, int progress) +extern "C" void zpipe_decompress(FILE *in, FILE *out, FILE *msgout, long long int buf_len, int progress) { - decompress(in, out, buf_len, progress); + decompress(in, out, msgout, buf_len, progress); } //////////////////////////// Compressor //////////////////////////// @@ -1694,7 +1694,7 @@ void Encoder::compress(int c) { //////////////////////////// Compress //////////////////////////// // Compress to 1 segment in 1 block -static void compress(FILE *in, FILE *out, long long int buf_len, int progress) { +static void compress(FILE *in, FILE *out, FILE *msgout, long long int buf_len, int progress) { // Compiled initialization lists generated by "zpaq vtrmid.cfg" static U8 header[71]={ // COMP 34 bytes from mid.cfg @@ -1738,8 +1738,8 @@ static void compress(FILE *in, FILE *out, long long int buf_len, int progress) { len++; pct = (len * 100 / buf_len); if (pct != last_pct) { - fprintf(stderr, "\r\tZPAQ Chunk %i of 2 compress: %i%% \r", (chunk + 1), pct); - fflush(stderr); + fprintf(msgout, "\r\tZPAQ Chunk %i of 2 compress: %i%% \r", (chunk + 1), pct); + fflush(msgout); last_pct = pct; } } @@ -1747,8 +1747,8 @@ static void compress(FILE *in, FILE *out, long long int buf_len, int progress) { sha1.put(c); } if (progress) { - fprintf(stderr, "\t \r"); - fflush(stderr); + fprintf(msgout, "\t \r"); + fflush(msgout); } enc.compress(-1); // end of segment @@ -1765,7 +1765,7 @@ static void compress(FILE *in, FILE *out, long long int buf_len, int progress) { chunk ^= 1; } -extern "C" void zpipe_compress(FILE *in, FILE *out, long long int buf_len, int progress) +extern "C" void zpipe_compress(FILE *in, FILE *out, FILE *msgout, long long int buf_len, int progress) { - compress(in, out, buf_len, progress); + compress(in, out, msgout, buf_len, progress); }