mirror of
https://github.com/mirror/wget.git
synced 2024-12-29 14:30:48 +08:00
Accept --bit option
This commit is contained in:
parent
04f29f2f08
commit
b9b510ca5f
2
NEWS
2
NEWS
@ -20,6 +20,8 @@ Please send GNU Wget bug reports to <bug-wget@gnu.org>.
|
|||||||
** Print some diagnostic messages to stderr not to stdout.
|
** Print some diagnostic messages to stderr not to stdout.
|
||||||
|
|
||||||
** Report stdout close errors.
|
** Report stdout close errors.
|
||||||
|
|
||||||
|
** Accept the --bit option.
|
||||||
|
|
||||||
* Changes in Wget 1.13.4
|
* Changes in Wget 1.13.4
|
||||||
|
|
||||||
|
@ -1,3 +1,16 @@
|
|||||||
|
2012-03-06 Sasikantha Babu <sasikanth.v19@gmail.com>
|
||||||
|
|
||||||
|
* utils.c (convert_to_bits): Added new function convert_to_bits to
|
||||||
|
convert bytes to bits.
|
||||||
|
* retr.c (calc_rate): Modified the function to handle --bits
|
||||||
|
option and download rate calculated as bits per sec (SI-prefix)
|
||||||
|
for --bits otherwise bytes (IEC-prefix).
|
||||||
|
(retr_rate): Rates will display in bits per sec for --bits.
|
||||||
|
* options.h (struct opt): Added --bit option bool variable bits_fmt.
|
||||||
|
* main.c (print_help) : Added help for --bit.
|
||||||
|
* init.c: Defined command for --bit option.
|
||||||
|
* retr.h: Added function prototype.
|
||||||
|
|
||||||
2012-02-26 Giuseppe Scrivano <gscrivano@gnu.org>
|
2012-02-26 Giuseppe Scrivano <gscrivano@gnu.org>
|
||||||
|
|
||||||
* main.c: Include "closeout.h"
|
* main.c: Include "closeout.h"
|
||||||
|
@ -127,6 +127,7 @@ static const struct {
|
|||||||
{ "backups", &opt.backups, cmd_number },
|
{ "backups", &opt.backups, cmd_number },
|
||||||
{ "base", &opt.base_href, cmd_string },
|
{ "base", &opt.base_href, cmd_string },
|
||||||
{ "bindaddress", &opt.bind_address, cmd_string },
|
{ "bindaddress", &opt.bind_address, cmd_string },
|
||||||
|
{ "bits", &opt.bits_fmt, cmd_boolean},
|
||||||
#ifdef HAVE_SSL
|
#ifdef HAVE_SSL
|
||||||
{ "cacertificate", &opt.ca_cert, cmd_file },
|
{ "cacertificate", &opt.ca_cert, cmd_file },
|
||||||
#endif
|
#endif
|
||||||
|
@ -167,6 +167,7 @@ static struct cmdline_option option_data[] =
|
|||||||
{ "backups", 0, OPT_BOOLEAN, "backups", -1 },
|
{ "backups", 0, OPT_BOOLEAN, "backups", -1 },
|
||||||
{ "base", 'B', OPT_VALUE, "base", -1 },
|
{ "base", 'B', OPT_VALUE, "base", -1 },
|
||||||
{ "bind-address", 0, OPT_VALUE, "bindaddress", -1 },
|
{ "bind-address", 0, OPT_VALUE, "bindaddress", -1 },
|
||||||
|
{ "bits", 0, OPT_BOOLEAN, "bits", -1 },
|
||||||
{ IF_SSL ("ca-certificate"), 0, OPT_VALUE, "cacertificate", -1 },
|
{ IF_SSL ("ca-certificate"), 0, OPT_VALUE, "cacertificate", -1 },
|
||||||
{ IF_SSL ("ca-directory"), 0, OPT_VALUE, "cadirectory", -1 },
|
{ IF_SSL ("ca-directory"), 0, OPT_VALUE, "cadirectory", -1 },
|
||||||
{ "cache", 0, OPT_BOOLEAN, "cache", -1 },
|
{ "cache", 0, OPT_BOOLEAN, "cache", -1 },
|
||||||
@ -746,6 +747,11 @@ Recursive accept/reject:\n"),
|
|||||||
-np, --no-parent don't ascend to the parent directory.\n"),
|
-np, --no-parent don't ascend to the parent directory.\n"),
|
||||||
"\n",
|
"\n",
|
||||||
|
|
||||||
|
N_("\
|
||||||
|
Output format:\n"),
|
||||||
|
N_("\
|
||||||
|
--bits Output bandwidth in bits.\n"),
|
||||||
|
"\n",
|
||||||
N_("Mail bug reports and suggestions to <bug-wget@gnu.org>.\n")
|
N_("Mail bug reports and suggestions to <bug-wget@gnu.org>.\n")
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -266,6 +266,7 @@ struct options
|
|||||||
|
|
||||||
bool show_all_dns_entries; /* Show all the DNS entries when resolving a
|
bool show_all_dns_entries; /* Show all the DNS entries when resolving a
|
||||||
name. */
|
name. */
|
||||||
|
bool bits_fmt; /*Output bandwidth in bits format*/
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct options opt;
|
extern struct options opt;
|
||||||
|
@ -861,7 +861,7 @@ create_image (struct bar_progress *bp, double dl_total_time, bool done)
|
|||||||
struct bar_progress_hist *hist = &bp->hist;
|
struct bar_progress_hist *hist = &bp->hist;
|
||||||
|
|
||||||
/* The progress bar should look like this:
|
/* The progress bar should look like this:
|
||||||
xx% [=======> ] nn,nnn 12.34K/s eta 36m 51s
|
xx% [=======> ] nn,nnn 12.34KB/s eta 36m 51s
|
||||||
|
|
||||||
Calculate the geometry. The idea is to assign as much room as
|
Calculate the geometry. The idea is to assign as much room as
|
||||||
possible to the progress bar. The other idea is to never let
|
possible to the progress bar. The other idea is to never let
|
||||||
@ -873,7 +873,7 @@ create_image (struct bar_progress *bp, double dl_total_time, bool done)
|
|||||||
"xx% " or "100%" - percentage - 4 chars
|
"xx% " or "100%" - percentage - 4 chars
|
||||||
"[]" - progress bar decorations - 2 chars
|
"[]" - progress bar decorations - 2 chars
|
||||||
" nnn,nnn,nnn" - downloaded bytes - 12 chars or very rarely more
|
" nnn,nnn,nnn" - downloaded bytes - 12 chars or very rarely more
|
||||||
" 12.5K/s" - download rate - 8 chars
|
" 12.5KB/s" - download rate - 9 chars
|
||||||
" eta 36m 51s" - ETA - 14 chars
|
" eta 36m 51s" - ETA - 14 chars
|
||||||
|
|
||||||
"=====>..." - progress bar - the rest
|
"=====>..." - progress bar - the rest
|
||||||
@ -977,10 +977,11 @@ create_image (struct bar_progress *bp, double dl_total_time, bool done)
|
|||||||
*p++ = ' ';
|
*p++ = ' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
/* " 12.52K/s" */
|
/* " 12.52Kb/s or 12.52KB/s" */
|
||||||
if (hist->total_time > 0 && hist->total_bytes)
|
if (hist->total_time > 0 && hist->total_bytes)
|
||||||
{
|
{
|
||||||
static const char *short_units[] = { "B/s", "K/s", "M/s", "G/s" };
|
static const char *short_units[] = { "B/s", "KB/s", "MB/s", "GB/s" };
|
||||||
|
static const char *short_units_bits[] = { "b/s", "Kb/s", "Mb/s", "Gb/s" };
|
||||||
int units = 0;
|
int units = 0;
|
||||||
/* Calculate the download speed using the history ring and
|
/* Calculate the download speed using the history ring and
|
||||||
recent data that hasn't made it to the ring yet. */
|
recent data that hasn't made it to the ring yet. */
|
||||||
@ -988,7 +989,7 @@ create_image (struct bar_progress *bp, double dl_total_time, bool done)
|
|||||||
double dltime = hist->total_time + (dl_total_time - bp->recent_start);
|
double dltime = hist->total_time + (dl_total_time - bp->recent_start);
|
||||||
double dlspeed = calc_rate (dlquant, dltime, &units);
|
double dlspeed = calc_rate (dlquant, dltime, &units);
|
||||||
sprintf (p, " %4.*f%s", dlspeed >= 99.95 ? 0 : dlspeed >= 9.995 ? 1 : 2,
|
sprintf (p, " %4.*f%s", dlspeed >= 99.95 ? 0 : dlspeed >= 9.995 ? 1 : 2,
|
||||||
dlspeed, short_units[units]);
|
dlspeed, !opt.bits_fmt?short_units[units]:short_units_bits[units]);
|
||||||
move_to_end (p);
|
move_to_end (p);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
23
src/retr.c
23
src/retr.c
@ -620,6 +620,7 @@ retr_rate (wgint bytes, double secs)
|
|||||||
{
|
{
|
||||||
static char res[20];
|
static char res[20];
|
||||||
static const char *rate_names[] = {"B/s", "KB/s", "MB/s", "GB/s" };
|
static const char *rate_names[] = {"B/s", "KB/s", "MB/s", "GB/s" };
|
||||||
|
static const char *rate_names_bits[] = {"b/s", "Kb/s", "Mb/s", "Gb/s" };
|
||||||
int units;
|
int units;
|
||||||
|
|
||||||
double dlrate = calc_rate (bytes, secs, &units);
|
double dlrate = calc_rate (bytes, secs, &units);
|
||||||
@ -627,7 +628,7 @@ retr_rate (wgint bytes, double secs)
|
|||||||
e.g. "1022", "247", "12.5", "2.38". */
|
e.g. "1022", "247", "12.5", "2.38". */
|
||||||
sprintf (res, "%.*f %s",
|
sprintf (res, "%.*f %s",
|
||||||
dlrate >= 99.95 ? 0 : dlrate >= 9.995 ? 1 : 2,
|
dlrate >= 99.95 ? 0 : dlrate >= 9.995 ? 1 : 2,
|
||||||
dlrate, rate_names[units]);
|
dlrate, !opt.bits_fmt? rate_names[units]: rate_names_bits[units]);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@ -644,6 +645,11 @@ double
|
|||||||
calc_rate (wgint bytes, double secs, int *units)
|
calc_rate (wgint bytes, double secs, int *units)
|
||||||
{
|
{
|
||||||
double dlrate;
|
double dlrate;
|
||||||
|
double bibyte = 1000.0;
|
||||||
|
|
||||||
|
if (!opt.bits_fmt)
|
||||||
|
bibyte = 1024.0;
|
||||||
|
|
||||||
|
|
||||||
assert (secs >= 0);
|
assert (secs >= 0);
|
||||||
assert (bytes >= 0);
|
assert (bytes >= 0);
|
||||||
@ -655,16 +661,17 @@ calc_rate (wgint bytes, double secs, int *units)
|
|||||||
0 and the timer's resolution, assume half the resolution. */
|
0 and the timer's resolution, assume half the resolution. */
|
||||||
secs = ptimer_resolution () / 2.0;
|
secs = ptimer_resolution () / 2.0;
|
||||||
|
|
||||||
dlrate = bytes / secs;
|
dlrate = convert_to_bits (bytes) / secs;
|
||||||
if (dlrate < 1024.0)
|
if (dlrate < bibyte)
|
||||||
*units = 0;
|
*units = 0;
|
||||||
else if (dlrate < 1024.0 * 1024.0)
|
else if (dlrate < (bibyte * bibyte))
|
||||||
*units = 1, dlrate /= 1024.0;
|
*units = 1, dlrate /= bibyte;
|
||||||
else if (dlrate < 1024.0 * 1024.0 * 1024.0)
|
else if (dlrate < (bibyte * bibyte * bibyte))
|
||||||
*units = 2, dlrate /= (1024.0 * 1024.0);
|
*units = 2, dlrate /= (bibyte * bibyte);
|
||||||
|
|
||||||
else
|
else
|
||||||
/* Maybe someone will need this, one day. */
|
/* Maybe someone will need this, one day. */
|
||||||
*units = 3, dlrate /= (1024.0 * 1024.0 * 1024.0);
|
*units = 3, dlrate /= (bibyte * bibyte * bibyte);
|
||||||
|
|
||||||
return dlrate;
|
return dlrate;
|
||||||
}
|
}
|
||||||
|
@ -75,4 +75,6 @@ void set_local_file (const char **, const char *);
|
|||||||
|
|
||||||
bool input_file_url (const char *);
|
bool input_file_url (const char *);
|
||||||
|
|
||||||
|
wgint convert_to_bits (wgint num);
|
||||||
|
|
||||||
#endif /* RETR_H */
|
#endif /* RETR_H */
|
||||||
|
11
src/utils.c
11
src/utils.c
@ -1825,6 +1825,17 @@ number_to_static_string (wgint number)
|
|||||||
ringpos = (ringpos + 1) % RING_SIZE;
|
ringpos = (ringpos + 1) % RING_SIZE;
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Converts the byte to bits format if --bits option is enabled
|
||||||
|
*/
|
||||||
|
wgint
|
||||||
|
convert_to_bits (wgint num)
|
||||||
|
{
|
||||||
|
if (opt.bits_fmt)
|
||||||
|
return num * 8;
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Determine the width of the terminal we're running on. If that's
|
/* Determine the width of the terminal we're running on. If that's
|
||||||
not possible, return 0. */
|
not possible, return 0. */
|
||||||
|
Loading…
Reference in New Issue
Block a user