X-Git-Url: http://sjero.net/git/?a=blobdiff_plain;f=src%2Fprogress.c;h=de108e76be44bb72e29bcdeef9a2a8e800472f54;hb=e72b57629bf49cdfd663002a8bb336a67b958979;hp=edb3053058fb96a6971152885ad73bd5e9565936;hpb=2f5e7187a2b0d970b93bf4d13f66dcb88fa1a0bb;p=wget diff --git a/src/progress.c b/src/progress.c index edb30530..de108e76 100644 --- a/src/progress.c +++ b/src/progress.c @@ -453,8 +453,8 @@ dot_set_params (const char *params) } else fprintf (stderr, - _("Invalid dot style specification `%s'; leaving unchanged.\n"), - params); + _("Invalid dot style specification %s; leaving unchanged.\n"), + quote (params)); } /* "Thermometer" (bar) progress. */ @@ -797,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; @@ -829,6 +828,9 @@ get_eta (void) bytes_cols_diff = nbytes - ncols; } + if (bcd != NULL) + *bcd = bytes_cols_diff; + return eta_trans; } @@ -874,12 +876,16 @@ create_image (struct bar_progress *bp, double dl_total_time, bool done) "[]" - progress bar decorations - 2 chars " nnn,nnn,nnn" - downloaded bytes - 12 chars or very rarely more " 12.5K/s" - download rate - 8 chars - " eta 36m 51s" - ETA - 13 chars + " eta 36m 51s" - ETA - 14 chars "=====>..." - progress bar - the rest */ int dlbytes_size = 1 + MAX (size_grouped_len, 11); - int progress_size = bp->width - (4 + 2 + dlbytes_size + 8 + 13); + 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; @@ -1023,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) @@ -1035,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 @@ -1047,8 +1059,6 @@ create_image (struct bar_progress *bp, double dl_total_time, bool done) move_to_end (p); } - assert (p - bp->buffer - bytes_cols_diff - size_grouped_diff <= bp->width); - while (p - bp->buffer - bytes_cols_diff - size_grouped_diff < bp->width) *p++ = ' '; *p = '\0';