diff options
author | Mark Whitley <markw@lineo.com> | 2001-04-17 18:13:16 +0000 |
---|---|---|
committer | Mark Whitley <markw@lineo.com> | 2001-04-17 18:13:16 +0000 |
commit | 30ac01cca753a3e17e4abddf9ff81e4616390b86 (patch) | |
tree | 78d9ebc8cf5bd1aa6f7be52ab86fd6aa571b4b15 /networking/wget.c | |
parent | 3828dbed57fc9f6b620faf29445c43aefcf541c7 (diff) | |
download | busybox-w32-30ac01cca753a3e17e4abddf9ff81e4616390b86.tar.gz busybox-w32-30ac01cca753a3e17e4abddf9ff81e4616390b86.tar.bz2 busybox-w32-30ac01cca753a3e17e4abddf9ff81e4616390b86.zip |
Applied a patch from Laurence Anderson to fix the wget statusbar and a patch
to usage.h to document the -q option.
Diffstat (limited to 'networking/wget.c')
-rw-r--r-- | networking/wget.c | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/networking/wget.c b/networking/wget.c index 1c7c3b545..8261d9cb6 100644 --- a/networking/wget.c +++ b/networking/wget.c | |||
@@ -59,7 +59,7 @@ static int chunked = 0; /* chunked transfer encoding */ | |||
59 | #ifdef BB_FEATURE_WGET_STATUSBAR | 59 | #ifdef BB_FEATURE_WGET_STATUSBAR |
60 | static char *curfile; /* Name of current file being transferred. */ | 60 | static char *curfile; /* Name of current file being transferred. */ |
61 | static struct timeval start; /* Time a transfer started. */ | 61 | static struct timeval start; /* Time a transfer started. */ |
62 | static volatile unsigned long statbytes; /* Number of bytes transferred so far. */ | 62 | static volatile unsigned long statbytes = 0; /* Number of bytes transferred so far. */ |
63 | /* For progressmeter() -- number of seconds before xfer considered "stalled" */ | 63 | /* For progressmeter() -- number of seconds before xfer considered "stalled" */ |
64 | static const int STALLTIME = 5; | 64 | static const int STALLTIME = 5; |
65 | #endif | 65 | #endif |
@@ -390,18 +390,15 @@ read_response: if (fgets(buf, sizeof(buf), sfp) == NULL) | |||
390 | fgets(buf, sizeof(buf), dfp); | 390 | fgets(buf, sizeof(buf), dfp); |
391 | filesize = strtol(buf, (char **) NULL, 16); | 391 | filesize = strtol(buf, (char **) NULL, 16); |
392 | } | 392 | } |
393 | do { | ||
394 | #ifdef BB_FEATURE_WGET_STATUSBAR | 393 | #ifdef BB_FEATURE_WGET_STATUSBAR |
395 | statbytes=0; | ||
396 | if (quiet_flag==FALSE) | 394 | if (quiet_flag==FALSE) |
397 | progressmeter(-1); | 395 | progressmeter(-1); |
398 | #endif | 396 | #endif |
397 | do { | ||
399 | while ((filesize > 0 || !got_clen) && (n = fread(buf, 1, chunked ? (filesize > sizeof(buf) ? sizeof(buf) : filesize) : sizeof(buf), dfp)) > 0) { | 398 | while ((filesize > 0 || !got_clen) && (n = fread(buf, 1, chunked ? (filesize > sizeof(buf) ? sizeof(buf) : filesize) : sizeof(buf), dfp)) > 0) { |
400 | fwrite(buf, 1, n, output); | 399 | fwrite(buf, 1, n, output); |
401 | #ifdef BB_FEATURE_WGET_STATUSBAR | 400 | #ifdef BB_FEATURE_WGET_STATUSBAR |
402 | statbytes+=n; | 401 | statbytes+=n; |
403 | if (quiet_flag==FALSE) | ||
404 | progressmeter(1); | ||
405 | #endif | 402 | #endif |
406 | if (got_clen) | 403 | if (got_clen) |
407 | filesize -= n; | 404 | filesize -= n; |
@@ -417,17 +414,16 @@ read_response: if (fgets(buf, sizeof(buf), sfp) == NULL) | |||
417 | if (n == 0 && ferror(dfp)) | 414 | if (n == 0 && ferror(dfp)) |
418 | perror_msg_and_die("network read error"); | 415 | perror_msg_and_die("network read error"); |
419 | } while (chunked); | 416 | } while (chunked); |
420 | 417 | #ifdef BB_FEATURE_WGET_STATUSBAR | |
418 | if (quiet_flag==FALSE) | ||
419 | progressmeter(1); | ||
420 | #endif | ||
421 | if (!proxy && target.is_ftp) { | 421 | if (!proxy && target.is_ftp) { |
422 | fclose(dfp); | 422 | fclose(dfp); |
423 | if (ftpcmd(NULL, NULL, sfp, buf) != 226) | 423 | if (ftpcmd(NULL, NULL, sfp, buf) != 226) |
424 | error_msg_and_die("ftp error: %s", buf+4); | 424 | error_msg_and_die("ftp error: %s", buf+4); |
425 | ftpcmd("QUIT", NULL, sfp, buf); | 425 | ftpcmd("QUIT", NULL, sfp, buf); |
426 | } | 426 | } |
427 | #ifdef BB_FEATURE_WGET_STATUSBAR | ||
428 | if (quiet_flag==FALSE) | ||
429 | putc('\n', stderr); | ||
430 | #endif | ||
431 | exit(EXIT_SUCCESS); | 427 | exit(EXIT_SUCCESS); |
432 | } | 428 | } |
433 | 429 | ||
@@ -609,7 +605,7 @@ progressmeter(int flag) | |||
609 | { | 605 | { |
610 | static const char prefixes[] = " KMGTP"; | 606 | static const char prefixes[] = " KMGTP"; |
611 | static struct timeval lastupdate; | 607 | static struct timeval lastupdate; |
612 | static off_t lastsize; | 608 | static off_t lastsize, totalsize; |
613 | struct timeval now, td, wait; | 609 | struct timeval now, td, wait; |
614 | off_t cursize, abbrevsize; | 610 | off_t cursize, abbrevsize; |
615 | double elapsed; | 611 | double elapsed; |
@@ -620,12 +616,13 @@ progressmeter(int flag) | |||
620 | (void) gettimeofday(&start, (struct timezone *) 0); | 616 | (void) gettimeofday(&start, (struct timezone *) 0); |
621 | lastupdate = start; | 617 | lastupdate = start; |
622 | lastsize = 0; | 618 | lastsize = 0; |
619 | totalsize = filesize; /* as filesize changes.. */ | ||
623 | } | 620 | } |
624 | 621 | ||
625 | (void) gettimeofday(&now, (struct timezone *) 0); | 622 | (void) gettimeofday(&now, (struct timezone *) 0); |
626 | cursize = statbytes; | 623 | cursize = statbytes; |
627 | if (filesize != 0 && !chunked) { | 624 | if (totalsize != 0 && !chunked) { |
628 | ratio = 100.0 * cursize / filesize; | 625 | ratio = 100.0 * cursize / totalsize; |
629 | ratio = MAX(ratio, 0); | 626 | ratio = MAX(ratio, 0); |
630 | ratio = MIN(ratio, 100); | 627 | ratio = MIN(ratio, 100); |
631 | } else | 628 | } else |
@@ -665,14 +662,14 @@ progressmeter(int flag) | |||
665 | timersub(&now, &start, &td); | 662 | timersub(&now, &start, &td); |
666 | elapsed = td.tv_sec + (td.tv_usec / 1000000.0); | 663 | elapsed = td.tv_sec + (td.tv_usec / 1000000.0); |
667 | 664 | ||
668 | if (statbytes <= 0 || elapsed <= 0.0 || cursize > filesize) { | 665 | if (wait.tv_sec >= STALLTIME) { |
669 | snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), | ||
670 | " --:-- ETA"); | ||
671 | } else if (wait.tv_sec >= STALLTIME) { | ||
672 | snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), | 666 | snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), |
673 | " - stalled -"); | 667 | " - stalled -"); |
668 | } else if (statbytes <= 0 || elapsed <= 0.0 || cursize > totalsize || chunked) { | ||
669 | snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), | ||
670 | " --:-- ETA"); | ||
674 | } else { | 671 | } else { |
675 | remaining = (int) (filesize / (statbytes / elapsed) - elapsed); | 672 | remaining = (int) (totalsize / (statbytes / elapsed) - elapsed); |
676 | i = remaining / 3600; | 673 | i = remaining / 3600; |
677 | if (i) | 674 | if (i) |
678 | snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), | 675 | snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), |
@@ -696,6 +693,7 @@ progressmeter(int flag) | |||
696 | } else if (flag == 1) { | 693 | } else if (flag == 1) { |
697 | alarmtimer(0); | 694 | alarmtimer(0); |
698 | statbytes = 0; | 695 | statbytes = 0; |
696 | putc('\n', stderr); | ||
699 | } | 697 | } |
700 | } | 698 | } |
701 | #endif | 699 | #endif |
@@ -735,7 +733,7 @@ progressmeter(int flag) | |||
735 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 733 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
736 | * SUCH DAMAGE. | 734 | * SUCH DAMAGE. |
737 | * | 735 | * |
738 | * $Id: wget.c,v 1.35 2001/04/11 20:11:51 kraai Exp $ | 736 | * $Id: wget.c,v 1.36 2001/04/17 18:13:16 markw Exp $ |
739 | */ | 737 | */ |
740 | 738 | ||
741 | 739 | ||