X-Git-Url: http://sjero.net/git/?p=wget;a=blobdiff_plain;f=src%2Fprogress.c;h=2f1c22259dd1800579a5e94edb704436ac570a6f;hp=62e8d87dad544453e2d9b3b37b6c7da600ced6a1;hb=123f5c39669abc055987d69a311785c861494c87;hpb=76780021d822779f839bbf85883292e15eb3f587 diff --git a/src/progress.c b/src/progress.c index 62e8d87d..2f1c2225 100644 --- a/src/progress.c +++ b/src/progress.c @@ -28,8 +28,6 @@ Corresponding Source for a non-source form of such a combination shall include the source code for the parts of OpenSSL used as well as that of the covered work. */ -#define USE_GNULIB_ALLOC - #include "wget.h" #include @@ -95,10 +93,10 @@ static int current_impl_locked; bool valid_progress_implementation_p (const char *name) { - int i; + size_t i; struct progress_implementation *pi = implementations; char *colon = strchr (name, ':'); - int namelen = colon ? colon - name : strlen (name); + size_t namelen = colon ? (size_t) (colon - name) : strlen (name); for (i = 0; i < countof (implementations); i++, pi++) if (!strncmp (pi->name, name, namelen)) @@ -111,7 +109,7 @@ valid_progress_implementation_p (const char *name) void set_progress_implementation (const char *name) { - int i, namelen; + size_t i, namelen; struct progress_implementation *pi = implementations; const char *colon; @@ -119,7 +117,7 @@ set_progress_implementation (const char *name) name = DEFAULT_PROGRESS_IMPLEMENTATION; colon = strchr (name, ':'); - namelen = colon ? colon - name : strlen (name); + namelen = colon ? (size_t) (colon - name) : strlen (name); for (i = 0; i < countof (implementations); i++, pi++) if (!strncmp (pi->name, name, namelen)) @@ -799,15 +797,14 @@ count_cols (const char *mbs) # define count_cols(mbs) ((int)(strlen(mbs))) #endif -/* Translation note: "ETA" is English-centric, but this must - be short, ideally 3 chars. Abbreviate if necessary. */ -static const char eta_str[] = N_(" eta %s"); -static const char *eta_trans; -static int bytes_cols_diff; - const char * -get_eta (void) +get_eta (int *bcd) { + /* Translation note: "ETA" is English-centric, but this must + be short, ideally 3 chars. Abbreviate if necessary. */ + static const char eta_str[] = N_(" eta %s"); + static const char *eta_trans; + static int bytes_cols_diff; if (eta_trans == NULL) { int nbytes; @@ -831,6 +828,9 @@ get_eta (void) bytes_cols_diff = nbytes - ncols; } + if (bcd != NULL) + *bcd = bytes_cols_diff; + return eta_trans; } @@ -883,6 +883,10 @@ create_image (struct bar_progress *bp, double dl_total_time, bool done) int dlbytes_size = 1 + MAX (size_grouped_len, 11); int progress_size = bp->width - (4 + 2 + dlbytes_size + 8 + 14); + /* The difference between the number of bytes used, + and the number of columns used. */ + int bytes_cols_diff = 0; + if (progress_size < 5) progress_size = 0; @@ -1025,7 +1029,8 @@ create_image (struct bar_progress *bp, double dl_total_time, bool done) bp->last_eta_time = dl_total_time; } - sprintf (p, get_eta(), eta_to_human_short (eta, false)); + sprintf (p, get_eta(&bytes_cols_diff), + eta_to_human_short (eta, false)); move_to_end (p); } else if (bp->total_length > 0) @@ -1037,11 +1042,16 @@ create_image (struct bar_progress *bp, double dl_total_time, bool done) else { /* When the download is done, print the elapsed time. */ + int nbytes; + int ncols; /* Note to translators: this should not take up more room than available here. Abbreviate if necessary. */ strcpy (p, _(" in ")); - move_to_end (p); /* not p+=6, think translations! */ + nbytes = strlen (p); + ncols = count_cols (p); + bytes_cols_diff = nbytes - ncols; + p += nbytes; if (dl_total_time >= 10) strcpy (p, eta_to_human_short ((int) (dl_total_time + 0.5), false)); else