From e89956051ffb6ae2bd2e1426bac9140d3c1f42b1 Mon Sep 17 00:00:00 2001 From: Darshit Shah Date: Sat, 19 Apr 2014 13:19:57 +0200 Subject: [PATCH] Implement new option, --show-progress --- src/ChangeLog | 19 +++++++++++++++++++ src/http.c | 5 +---- src/init.c | 2 ++ src/log.c | 4 ++++ src/log.h | 2 +- src/main.c | 7 +++++-- src/options.h | 1 + src/progress.c | 38 +++++++++++++++++++------------------- src/retr.c | 4 ++-- 9 files changed, 54 insertions(+), 28 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 4f88172..be08b26 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,22 @@ +2014-04-19 Darshit Shah + + * log.h (log_options): Add new logging options, LOG_PROGRESS. All progress + bar related output should use LOG_PROGRESS. + * log.c (CHECK_VERBOSE): Implement LOG_PROGRESS output + * progress.c (dot_create, print_row_stats, dot_update, dot_finish, + bar_finish, display_image): Output progress information through LOG_PROGRESS + * http.c (gethttp): Print progress information through LOG_PROGRESS + * main.c (option_data): Add new switch, --show-progress + (main): If in verbose output, show progress bar by default + (main): Set progress implemetation when displaying progress bar + (no_prefix): Increase buffer size to 2048 to prevent overflows + * init.c (commands): Add new command, showprogress + (defaults): By default initialize show_progress to false + * options.h (options): Add new option, show_progress + * retr.c (fd_read_body): Create and update progress bar when + opt.show_progress is set + (fd_read_body): Display progress information in Windows console titlebars + 2014-03-26 Darshit Shah * ftp.c (getftp): Rearrange parameters to fix compiler warning diff --git a/src/http.c b/src/http.c index 8bba70d..cbf68a0 100644 --- a/src/http.c +++ b/src/http.c @@ -2945,11 +2945,8 @@ read_header: fp = output_stream; /* Print fetch message, if opt.verbose. */ - if (opt.verbose) - { - logprintf (LOG_NOTQUIET, _("Saving to: %s\n"), + logprintf (LOG_PROGRESS, _("Saving to: %s\n"), HYPHENP (hs->local_file) ? quote ("STDOUT") : quote (hs->local_file)); - } err = read_response_body (hs, sock, fp, contlen, contrange, diff --git a/src/init.c b/src/init.c index 9ed72b2..7d024f8 100644 --- a/src/init.c +++ b/src/init.c @@ -268,6 +268,7 @@ static const struct { #endif { "serverresponse", &opt.server_response, cmd_boolean }, { "showalldnsentries", &opt.show_all_dns_entries, cmd_boolean }, + { "showprogress", &opt.show_progress, cmd_boolean }, { "spanhosts", &opt.spanhost, cmd_boolean }, { "spider", &opt.spider, cmd_boolean }, { "startpos", &opt.start_pos, cmd_bytes }, @@ -410,6 +411,7 @@ defaults (void) /* Use a negative value to mark the absence of --start-pos option */ opt.start_pos = -1; + opt.show_progress = false; } /* Return the user's home directory (strdup-ed), or NULL if none is diff --git a/src/log.c b/src/log.c index 4f93a21..3bd5833 100644 --- a/src/log.c +++ b/src/log.c @@ -278,6 +278,10 @@ saved_append (const char *s) #define CHECK_VERBOSE(x) \ switch (x) \ { \ + case LOG_PROGRESS: \ + if (!opt.show_progress) \ + return; \ + break; \ case LOG_ALWAYS: \ break; \ case LOG_NOTQUIET: \ diff --git a/src/log.h b/src/log.h index d74ca53..144be24 100644 --- a/src/log.h +++ b/src/log.h @@ -36,7 +36,7 @@ as that of the covered work. */ #include -enum log_options { LOG_VERBOSE, LOG_NOTQUIET, LOG_NONVERBOSE, LOG_ALWAYS }; +enum log_options { LOG_VERBOSE, LOG_NOTQUIET, LOG_NONVERBOSE, LOG_ALWAYS, LOG_PROGRESS }; void log_set_warc_log_fp (FILE *); diff --git a/src/main.c b/src/main.c index 39fcff4..67ee139 100644 --- a/src/main.c +++ b/src/main.c @@ -247,6 +247,7 @@ static struct cmdline_option option_data[] = { IF_SSL ("private-key"), 0, OPT_VALUE, "privatekey", -1 }, { IF_SSL ("private-key-type"), 0, OPT_VALUE, "privatekeytype", -1 }, { "progress", 0, OPT_VALUE, "progress", -1 }, + { "show-progress", 0, OPT_BOOLEAN, "showprogress", -1 }, { "protocol-directories", 0, OPT_BOOLEAN, "protocoldirectories", -1 }, { "proxy", 0, OPT_BOOLEAN, "useproxy", -1 }, { "proxy__compat", 'Y', OPT_VALUE, "useproxy", -1 }, /* back-compatible */ @@ -316,7 +317,7 @@ static struct cmdline_option option_data[] = static char * no_prefix (const char *s) { - static char buffer[1024]; + static char buffer[2048]; static char *p = buffer; char *cp = p; @@ -1245,6 +1246,8 @@ main (int argc, char **argv) if (opt.verbose == -1) opt.verbose = !opt.quiet; + if (opt.verbose == 1) + opt.show_progress = true; /* Sanity checks. */ if (opt.verbose && opt.quiet) @@ -1502,7 +1505,7 @@ for details.\n\n")); /* Initialize progress. Have to do this after the options are processed so we know where the log file is. */ - if (opt.verbose) + if (opt.show_progress) set_progress_implementation (opt.progress_type); /* Fill in the arguments. */ diff --git a/src/options.h b/src/options.h index b527829..563207f 100644 --- a/src/options.h +++ b/src/options.h @@ -134,6 +134,7 @@ struct options char **no_proxy; char *base_href; char *progress_type; /* progress indicator type. */ + bool show_progress; /* Show only the progress bar */ char *proxy_user; /*oli*/ char *proxy_passwd; diff --git a/src/progress.c b/src/progress.c index 2e888a9..21efb6f 100644 --- a/src/progress.c +++ b/src/progress.c @@ -237,18 +237,18 @@ dot_create (wgint initial, wgint total) /* Align the [ skipping ... ] line with the dots. To do that, insert the number of spaces equal to the number of digits in the skipped amount in K. */ - logprintf (LOG_VERBOSE, _("\n%*s[ skipping %sK ]"), + logprintf (LOG_PROGRESS, _("\n%*s[ skipping %sK ]"), 2 + skipped_k_len, "", number_to_static_string (skipped_k)); } - logprintf (LOG_VERBOSE, "\n%6sK", + logprintf (LOG_PROGRESS, "\n%6sK", number_to_static_string (skipped / 1024)); for (; remainder >= dot_bytes; remainder -= dot_bytes) { if (dp->dots % opt.dot_spacing == 0) - logputs (LOG_VERBOSE, " "); - logputs (LOG_VERBOSE, ","); + logputs (LOG_PROGRESS, " "); + logputs (LOG_PROGRESS, ","); ++dp->dots; } assert (dp->dots < opt.dots_in_line); @@ -289,7 +289,7 @@ print_row_stats (struct dot_progress *dp, double dltime, bool last) been retrieved. 12.8% will round to 12% because the 13% mark has not yet been reached. 100% is only shown when done. */ int percentage = 100.0 * bytes_displayed / dp->total_length; - logprintf (LOG_VERBOSE, "%3d%%", percentage); + logprintf (LOG_PROGRESS, "%3d%%", percentage); } { @@ -306,7 +306,7 @@ print_row_stats (struct dot_progress *dp, double dltime, bool last) if (dp->rows == dp->initial_length / ROW_BYTES) bytes_this_row -= dp->initial_length % ROW_BYTES; rate = calc_rate (bytes_this_row, dltime - dp->last_timer_value, &units); - logprintf (LOG_VERBOSE, " %4.*f%c", + logprintf (LOG_PROGRESS, " %4.*f%c", rate >= 99.95 ? 0 : rate >= 9.995 ? 1 : 2, rate, names[units]); dp->last_timer_value = dltime; @@ -323,7 +323,7 @@ print_row_stats (struct dot_progress *dp, double dltime, bool last) wgint bytes_sofar = bytes_displayed - dp->initial_length; double eta = dltime * bytes_remaining / bytes_sofar; if (eta < INT_MAX - 1) - logprintf (LOG_VERBOSE, " %s", + logprintf (LOG_PROGRESS, " %s", eta_to_human_short ((int) (eta + 0.5), true)); } } @@ -331,10 +331,10 @@ print_row_stats (struct dot_progress *dp, double dltime, bool last) { /* When done, print the total download time */ if (dltime >= 10) - logprintf (LOG_VERBOSE, "=%s", + logprintf (LOG_PROGRESS, "=%s", eta_to_human_short ((int) (dltime + 0.5), true)); else - logprintf (LOG_VERBOSE, "=%ss", print_decimal (dltime)); + logprintf (LOG_PROGRESS, "=%ss", print_decimal (dltime)); } } @@ -353,12 +353,12 @@ dot_update (void *progress, wgint howmuch, double dltime) for (; dp->accumulated >= dot_bytes; dp->accumulated -= dot_bytes) { if (dp->dots == 0) - logprintf (LOG_VERBOSE, "\n%6sK", + logprintf (LOG_PROGRESS, "\n%6sK", number_to_static_string (dp->rows * ROW_BYTES / 1024)); if (dp->dots % opt.dot_spacing == 0) - logputs (LOG_VERBOSE, " "); - logputs (LOG_VERBOSE, "."); + logputs (LOG_PROGRESS, " "); + logputs (LOG_PROGRESS, "."); ++dp->dots; if (dp->dots >= opt.dots_in_line) @@ -385,17 +385,17 @@ dot_finish (void *progress, double dltime) log_set_flush (false); if (dp->dots == 0) - logprintf (LOG_VERBOSE, "\n%6sK", + logprintf (LOG_PROGRESS, "\n%6sK", number_to_static_string (dp->rows * ROW_BYTES / 1024)); for (i = dp->dots; i < opt.dots_in_line; i++) { if (i % opt.dot_spacing == 0) - logputs (LOG_VERBOSE, " "); - logputs (LOG_VERBOSE, " "); + logputs (LOG_PROGRESS, " "); + logputs (LOG_PROGRESS, " "); } print_row_stats (dp, dltime, true); - logputs (LOG_VERBOSE, "\n\n"); + logputs (LOG_PROGRESS, "\n\n"); log_set_flush (false); xfree (dp); @@ -650,7 +650,7 @@ bar_finish (void *progress, double dltime) create_image (bp, dltime, true); display_image (bp->buffer); - logputs (LOG_VERBOSE, "\n\n"); + logputs (LOG_PROGRESS, "\n\n"); xfree (bp->buffer); xfree (bp); @@ -1070,8 +1070,8 @@ static void display_image (char *buf) { bool old = log_set_save_context (false); - logputs (LOG_VERBOSE, "\r"); - logputs (LOG_VERBOSE, buf); + logputs (LOG_PROGRESS, "\r"); + logputs (LOG_PROGRESS, buf); log_set_save_context (old); } diff --git a/src/retr.c b/src/retr.c index 683c811..eafb19b 100644 --- a/src/retr.c +++ b/src/retr.c @@ -262,7 +262,7 @@ fd_read_body (int fd, FILE *out, wgint toread, wgint startpos, if (flags & rb_skip_startpos) skip = startpos; - if (opt.verbose) + if (opt.show_progress) { /* If we're skipping STARTPOS bytes, pass 0 as the INITIAL argument to progress_create because the indicator doesn't @@ -411,7 +411,7 @@ fd_read_body (int fd, FILE *out, wgint toread, wgint startpos, if (progress) progress_update (progress, ret, ptimer_read (timer)); #ifdef WINDOWS - if (toread > 0 && !opt.quiet) + if (toread > 0 && opt.show_progress) ws_percenttitle (100.0 * (startpos + sum_read) / (startpos + toread)); #endif -- 1.9.2