Sorry guys In my previous mail I attached .patch extension file instead of
.txt extension.
Now correctly attached
Thanks
Sasi
---------- Forwarded message ----------
From: Sasikanth <[email protected]>
Date: Wed, Jan 11, 2012 at 3:18 PM
Subject: [PATCH] [wget-bug #33210], Add an option to output bandwidth in
bits
To: [email protected]
Hi all,
I added a new option --bits as requested in
https://savannah.gnu.org/bugs/?33210.
This patch will display all data length in bits format for --bits option.
I had verified it with http and ftp. Please let me know If I missed out
anything.
Attachments: patch and change log entry file
Thanks
Sasi
diff -ru orig/wget-1.13.4/src/ftp.c wget-1.13.4/src/ftp.c
--- orig/wget-1.13.4/src/ftp.c 2012-01-09 14:06:31.273731044 +0530
+++ wget-1.13.4/src/ftp.c 2012-01-11 14:05:33.793990983 +0530
@@ -217,18 +217,18 @@
static void
print_length (wgint size, wgint start, bool authoritative)
{
- logprintf (LOG_VERBOSE, _("Length: %s"), number_to_static_string (size));
+ logprintf (LOG_VERBOSE, _("Length: %s"), number_to_static_string
(convert_to_bits(size)));
if (size >= 1024)
- logprintf (LOG_VERBOSE, " (%s)", human_readable (size));
+ logprintf (LOG_VERBOSE, " (%s)", human_readable (convert_to_bits(size)));
if (start > 0)
{
if (size - start >= 1024)
logprintf (LOG_VERBOSE, _(", %s (%s) remaining"),
- number_to_static_string (size - start),
- human_readable (size - start));
+ number_to_static_string (convert_to_bits(size - start)),
+ human_readable (convert_to_bits(size - start)));
else
logprintf (LOG_VERBOSE, _(", %s remaining"),
- number_to_static_string (size - start));
+ number_to_static_string (convert_to_bits(size - start)));
}
logputs (LOG_VERBOSE, !authoritative ? _(" (unauthoritative)\n") : "\n");
}
@@ -1564,7 +1564,7 @@
: _("%s (%s) - %s saved [%s]\n\n"),
tms, tmrate,
write_to_stdout ? "" : quote (locf),
- number_to_static_string (qtyread));
+ number_to_static_string (convert_to_bits(qtyread)));
}
if (!opt.verbose && !opt.quiet)
{
@@ -1573,7 +1573,7 @@
time. */
char *hurl = url_string (u, URL_AUTH_HIDE_PASSWD);
logprintf (LOG_NONVERBOSE, "%s URL: %s [%s] -> \"%s\" [%d]\n",
- tms, hurl, number_to_static_string (qtyread), locf,
count);
+ tms, hurl, number_to_static_string
(convert_to_bits(qtyread)), locf, count);
xfree (hurl);
}
@@ -1792,7 +1792,7 @@
/* Sizes do not match */
logprintf (LOG_VERBOSE, _("\
The sizes do not match (local %s) -- retrieving.\n\n"),
- number_to_static_string (local_size));
+ number_to_static_string
(convert_to_bits(local_size)));
}
}
} /* opt.timestamping && f->type == FT_PLAINFILE */
@@ -2206,7 +2206,7 @@
sz = -1;
logprintf (LOG_NOTQUIET,
_("Wrote HTML-ized index to %s [%s].\n"),
- quote (filename), number_to_static_string
(sz));
+ quote (filename), number_to_static_string
(convert_to_bits(sz)));
}
else
logprintf (LOG_NOTQUIET,
diff -ru orig/wget-1.13.4/src/http.c wget-1.13.4/src/http.c
--- orig/wget-1.13.4/src/http.c 2012-01-09 14:06:31.274730346 +0530
+++ wget-1.13.4/src/http.c 2012-01-11 14:24:02.721099726 +0530
@@ -2423,19 +2423,19 @@
logputs (LOG_VERBOSE, _("Length: "));
if (contlen != -1)
{
- logputs (LOG_VERBOSE, number_to_static_string (contlen +
contrange));
+ logputs (LOG_VERBOSE, number_to_static_string (convert_to_bits
(contlen) + contrange));
if (contlen + contrange >= 1024)
logprintf (LOG_VERBOSE, " (%s)",
- human_readable (contlen + contrange));
+ human_readable (convert_to_bits(contlen) +
contrange));
if (contrange)
{
if (contlen >= 1024)
logprintf (LOG_VERBOSE, _(", %s (%s) remaining"),
- number_to_static_string (contlen),
- human_readable (contlen));
+ number_to_static_string
(convert_to_bits(contlen)),
+ human_readable (convert_to_bits(contlen)));
else
logprintf (LOG_VERBOSE, _(", %s remaining"),
- number_to_static_string (contlen));
+ number_to_static_string
(convert_to_bits(contlen)));
}
}
else
@@ -2625,6 +2625,7 @@
bool send_head_first = true;
char *file_name;
bool force_full_retrieve = false;
+ char *out_data_fmt = opt.bits_fmt? "bits": "bytes";
/* Assert that no value for *LOCAL_FILE was passed. */
assert (local_file == NULL || *local_file == NULL);
@@ -3038,13 +3039,13 @@
: _("%s (%s) - %s saved [%s/%s]\n\n"),
tms, tmrate,
write_to_stdout ? "" : quote (hstat.local_file),
- number_to_static_string (hstat.len),
- number_to_static_string (hstat.contlen));
+ number_to_static_string (convert_to_bits(hstat.len)),
+ number_to_static_string
(convert_to_bits(hstat.contlen)));
logprintf (LOG_NONVERBOSE,
"%s URL:%s [%s/%s] -> \"%s\" [%d]\n",
tms, u->url,
- number_to_static_string (hstat.len),
- number_to_static_string (hstat.contlen),
+ number_to_static_string (convert_to_bits(hstat.len)),
+ number_to_static_string
(convert_to_bits(hstat.contlen)),
hstat.local_file, count);
}
++numurls;
@@ -3074,10 +3075,10 @@
: _("%s (%s) - %s saved [%s]\n\n"),
tms, tmrate,
write_to_stdout ? "" : quote (hstat.local_file),
- number_to_static_string (hstat.len));
+ number_to_static_string
(convert_to_bits(hstat.len)));
logprintf (LOG_NONVERBOSE,
"%s URL:%s [%s] -> \"%s\" [%d]\n",
- tms, u->url, number_to_static_string (hstat.len),
+ tms, u->url, number_to_static_string
(convert_to_bits(hstat.len)),
hstat.local_file, count);
}
++numurls;
@@ -3096,8 +3097,9 @@
connection too soon */
{
logprintf (LOG_VERBOSE,
- _("%s (%s) - Connection closed at byte %s. "),
- tms, tmrate, number_to_static_string (hstat.len));
+ _("%s (%s) - Connection closed at %s %s. "),
+ tms, tmrate, out_data_fmt,
+ number_to_static_string (convert_to_bits(hstat.len)));
printwhat (count, opt.ntry);
continue;
}
@@ -3119,8 +3121,8 @@
if (hstat.contlen == -1)
{
logprintf (LOG_VERBOSE,
- _("%s (%s) - Read error at byte %s (%s)."),
- tms, tmrate, number_to_static_string (hstat.len),
+ _("%s (%s) - Read error at %s %s (%s)."),
+ tms, tmrate, out_data_fmt, number_to_static_string
(convert_to_bits(hstat.len)),
hstat.rderrmsg);
printwhat (count, opt.ntry);
continue;
@@ -3129,9 +3131,9 @@
{
logprintf (LOG_VERBOSE,
_("%s (%s) - Read error at byte %s/%s (%s). "),
- tms, tmrate,
- number_to_static_string (hstat.len),
- number_to_static_string (hstat.contlen),
+ tms, tmrate, out_data_fmt,
+ number_to_static_string (convert_to_bits(hstat.len)),
+ number_to_static_string
(convert_to_bits(hstat.contlen)),
hstat.rderrmsg);
printwhat (count, opt.ntry);
continue;
diff -ru orig/wget-1.13.4/src/init.c wget-1.13.4/src/init.c
--- orig/wget-1.13.4/src/init.c 2012-01-09 14:06:31.273731044 +0530
+++ wget-1.13.4/src/init.c 2012-01-11 14:39:07.075984135 +0530
@@ -126,6 +126,7 @@
{ "backups", &opt.backups, cmd_number },
{ "base", &opt.base_href, cmd_string },
{ "bindaddress", &opt.bind_address, cmd_string },
+ { "bits", &opt.bits_fmt, cmd_boolean},
#ifdef HAVE_SSL
{ "cacertificate", &opt.ca_cert, cmd_file },
#endif
diff -ru orig/wget-1.13.4/src/main.c wget-1.13.4/src/main.c
--- orig/wget-1.13.4/src/main.c 2012-01-09 14:06:31.272730625 +0530
+++ wget-1.13.4/src/main.c 2012-01-11 14:29:15.766987978 +0530
@@ -166,6 +166,7 @@
{ "backups", 0, OPT_BOOLEAN, "backups", -1 },
{ "base", 'B', OPT_VALUE, "base", -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-directory"), 0, OPT_VALUE, "cadirectory", -1 },
{ "cache", 0, OPT_BOOLEAN, "cache", -1 },
@@ -703,7 +704,11 @@
N_("\
-np, --no-parent don't ascend to the parent directory.\n"),
"\n",
-
+ N_("\
+Output format:\n"),
+ N_("\
+ --bits Output all data length in bits.\n"),
+ "\n",
N_("Mail bug reports and suggestions to <[email protected]>.\n")
};
diff -ru orig/wget-1.13.4/src/options.h wget-1.13.4/src/options.h
--- orig/wget-1.13.4/src/options.h 2012-01-09 14:06:31.272730625 +0530
+++ wget-1.13.4/src/options.h 2012-01-11 14:28:41.687373786 +0530
@@ -255,6 +255,7 @@
bool show_all_dns_entries; /* Show all the DNS entries when resolving a
name. */
+ bool bits_fmt; /*Output in bits format*/
};
extern struct options opt;
diff -ru orig/wget-1.13.4/src/retr.c wget-1.13.4/src/retr.c
--- orig/wget-1.13.4/src/retr.c 2012-01-09 14:06:31.274730346 +0530
+++ wget-1.13.4/src/retr.c 2012-01-11 13:36:26.138988119 +0530
@@ -578,6 +578,7 @@
{
static char res[20];
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;
double dlrate = calc_rate (bytes, secs, &units);
@@ -585,7 +586,7 @@
e.g. "1022", "247", "12.5", "2.38". */
sprintf (res, "%.*f %s",
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;
}
@@ -602,6 +603,10 @@
calc_rate (wgint bytes, double secs, int *units)
{
double dlrate;
+ double in_bits = 8.0;
+
+ if (!opt.bits_fmt)
+ in_bits = 1.0;
assert (secs >= 0);
assert (bytes >= 0);
@@ -613,16 +618,16 @@
0 and the timer's resolution, assume half the resolution. */
secs = ptimer_resolution () / 2.0;
- dlrate = bytes / secs;
- if (dlrate < 1024.0)
+ dlrate = convert_to_bits(bytes) / secs;
+ if (dlrate < (1024.0 * in_bits))
*units = 0;
- else if (dlrate < 1024.0 * 1024.0)
- *units = 1, dlrate /= 1024.0;
- else if (dlrate < 1024.0 * 1024.0 * 1024.0)
- *units = 2, dlrate /= (1024.0 * 1024.0);
+ else if (dlrate < (1024.0 * 1024.0 * in_bits))
+ *units = 1, dlrate /= (1024.0 * in_bits);
+ else if (dlrate < (1024.0 * 1024.0 * 1024.0 * in_bits))
+ *units = 2, dlrate /= (1024.0 * 1024.0 * in_bits);
else
/* Maybe someone will need this, one day. */
- *units = 3, dlrate /= (1024.0 * 1024.0 * 1024.0);
+ *units = 3, dlrate /= (1024.0 * 1024.0 * 1024.0 * in_bits);
return dlrate;
}
diff -ru orig/wget-1.13.4/src/utils.c wget-1.13.4/src/utils.c
--- orig/wget-1.13.4/src/utils.c 2012-01-09 14:06:31.271732441 +0530
+++ wget-1.13.4/src/utils.c 2012-01-11 14:21:16.206991121 +0530
@@ -1608,8 +1608,8 @@
double val = n / 1024.0;
/* Print values smaller than 10 with one decimal digits, and
others without any decimals. */
- snprintf (buf, sizeof (buf), "%.*f%c",
- val < 10 ? 1 : 0, val, powers[i]);
+ snprintf (buf, sizeof (buf), "%.*f%c%c",
+ val < 10 ? 1 : 0, val, powers[i], opt.bits_fmt?'b':'B');
return buf;
}
n /= 1024;
@@ -1826,6 +1826,15 @@
ringpos = (ringpos + 1) % RING_SIZE;
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
not possible, return 0. */
2012-01-11 Sasikantha babu <[email protected]>
* utils.c (human_readable): modified snprintf to print b(indicates
bits) if --bits option enabled otherwise B (Bytes)
(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 per bits per sec for --bits otherwise
bytes.
(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
* http.c (gethttp & http_loop): Handled --bits option while priting
data length
* ftp.c (print_length, ftp_retrieve_list & ftp_loop_internal):
Handled --bits option while priting data length