From 114c5495cdf182d7eedb42b4eece229054614877 Mon Sep 17 00:00:00 2001
From: Darshit Shah
Date: Thu, 17 Apr 2014 11:12:15 +0200
Subject: [PATCH] Add new option, show-progress
---
src/http.c | 5 +----
src/init.c | 2 ++
src/log.c | 4 ++++
src/log.h | 2 +-
src/main.c | 8 ++++++--
src/options.h | 1 +
src/progress.c | 40 ++++++++++++++++++++--------------------
src/retr.c | 2 +-
8 files changed, 36 insertions(+), 28 deletions(-)
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..eaa3b04 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;
@@ -1218,6 +1219,9 @@ main (int argc, char **argv)
/* All user options have now been processed, so it's now safe to do
interoption dependency checks. */
+ if (opt.verbose == 1)
+ opt.show_progress = true;
+
if (opt.noclobber && opt.convert_links)
{
fprintf (stderr,
@@ -1502,7 +1506,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..9e744f6 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);
@@ -581,7 +581,7 @@ bar_create (wgint initial, wgint total)
* for multibyte characters. */
bp->buffer = xmalloc (bp->width + 100);
- logputs (LOG_VERBOSE, "\n");
+ logputs (LOG_PROGRESS, "\n");
create_image (bp, 0, false);
display_image (bp->buffer);
@@ -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..900c782 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
--
1.9.2