Applied a patch from Laurence Anderson to fix the wget statusbar and a patch

to usage.h to document the -q option.
This commit is contained in:
Mark Whitley 2001-04-17 18:13:16 +00:00
parent 3828dbed57
commit 30ac01cca7
5 changed files with 37 additions and 41 deletions

View File

@ -1719,7 +1719,7 @@
" 31 46 1365 /etc/passwd\n" " 31 46 1365 /etc/passwd\n"
#define wget_trivial_usage \ #define wget_trivial_usage \
"[-c] [-O file] url" "[-c] [-q] [-O file] url"
#define wget_full_usage \ #define wget_full_usage \
"wget retrieves files via HTTP or FTP\n\n" \ "wget retrieves files via HTTP or FTP\n\n" \
"Options:\n" \ "Options:\n" \

View File

@ -1719,7 +1719,7 @@
" 31 46 1365 /etc/passwd\n" " 31 46 1365 /etc/passwd\n"
#define wget_trivial_usage \ #define wget_trivial_usage \
"[-c] [-O file] url" "[-c] [-q] [-O file] url"
#define wget_full_usage \ #define wget_full_usage \
"wget retrieves files via HTTP or FTP\n\n" \ "wget retrieves files via HTTP or FTP\n\n" \
"Options:\n" \ "Options:\n" \

View File

@ -59,7 +59,7 @@ static int chunked = 0; /* chunked transfer encoding */
#ifdef BB_FEATURE_WGET_STATUSBAR #ifdef BB_FEATURE_WGET_STATUSBAR
static char *curfile; /* Name of current file being transferred. */ static char *curfile; /* Name of current file being transferred. */
static struct timeval start; /* Time a transfer started. */ static struct timeval start; /* Time a transfer started. */
static volatile unsigned long statbytes; /* Number of bytes transferred so far. */ static volatile unsigned long statbytes = 0; /* Number of bytes transferred so far. */
/* For progressmeter() -- number of seconds before xfer considered "stalled" */ /* For progressmeter() -- number of seconds before xfer considered "stalled" */
static const int STALLTIME = 5; static const int STALLTIME = 5;
#endif #endif
@ -390,18 +390,15 @@ read_response: if (fgets(buf, sizeof(buf), sfp) == NULL)
fgets(buf, sizeof(buf), dfp); fgets(buf, sizeof(buf), dfp);
filesize = strtol(buf, (char **) NULL, 16); filesize = strtol(buf, (char **) NULL, 16);
} }
do {
#ifdef BB_FEATURE_WGET_STATUSBAR #ifdef BB_FEATURE_WGET_STATUSBAR
statbytes=0;
if (quiet_flag==FALSE) if (quiet_flag==FALSE)
progressmeter(-1); progressmeter(-1);
#endif #endif
do {
while ((filesize > 0 || !got_clen) && (n = fread(buf, 1, chunked ? (filesize > sizeof(buf) ? sizeof(buf) : filesize) : sizeof(buf), dfp)) > 0) { while ((filesize > 0 || !got_clen) && (n = fread(buf, 1, chunked ? (filesize > sizeof(buf) ? sizeof(buf) : filesize) : sizeof(buf), dfp)) > 0) {
fwrite(buf, 1, n, output); fwrite(buf, 1, n, output);
#ifdef BB_FEATURE_WGET_STATUSBAR #ifdef BB_FEATURE_WGET_STATUSBAR
statbytes+=n; statbytes+=n;
if (quiet_flag==FALSE)
progressmeter(1);
#endif #endif
if (got_clen) if (got_clen)
filesize -= n; filesize -= n;
@ -417,17 +414,16 @@ read_response: if (fgets(buf, sizeof(buf), sfp) == NULL)
if (n == 0 && ferror(dfp)) if (n == 0 && ferror(dfp))
perror_msg_and_die("network read error"); perror_msg_and_die("network read error");
} while (chunked); } while (chunked);
#ifdef BB_FEATURE_WGET_STATUSBAR
if (quiet_flag==FALSE)
progressmeter(1);
#endif
if (!proxy && target.is_ftp) { if (!proxy && target.is_ftp) {
fclose(dfp); fclose(dfp);
if (ftpcmd(NULL, NULL, sfp, buf) != 226) if (ftpcmd(NULL, NULL, sfp, buf) != 226)
error_msg_and_die("ftp error: %s", buf+4); error_msg_and_die("ftp error: %s", buf+4);
ftpcmd("QUIT", NULL, sfp, buf); ftpcmd("QUIT", NULL, sfp, buf);
} }
#ifdef BB_FEATURE_WGET_STATUSBAR
if (quiet_flag==FALSE)
putc('\n', stderr);
#endif
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
@ -609,7 +605,7 @@ progressmeter(int flag)
{ {
static const char prefixes[] = " KMGTP"; static const char prefixes[] = " KMGTP";
static struct timeval lastupdate; static struct timeval lastupdate;
static off_t lastsize; static off_t lastsize, totalsize;
struct timeval now, td, wait; struct timeval now, td, wait;
off_t cursize, abbrevsize; off_t cursize, abbrevsize;
double elapsed; double elapsed;
@ -620,12 +616,13 @@ progressmeter(int flag)
(void) gettimeofday(&start, (struct timezone *) 0); (void) gettimeofday(&start, (struct timezone *) 0);
lastupdate = start; lastupdate = start;
lastsize = 0; lastsize = 0;
totalsize = filesize; /* as filesize changes.. */
} }
(void) gettimeofday(&now, (struct timezone *) 0); (void) gettimeofday(&now, (struct timezone *) 0);
cursize = statbytes; cursize = statbytes;
if (filesize != 0 && !chunked) { if (totalsize != 0 && !chunked) {
ratio = 100.0 * cursize / filesize; ratio = 100.0 * cursize / totalsize;
ratio = MAX(ratio, 0); ratio = MAX(ratio, 0);
ratio = MIN(ratio, 100); ratio = MIN(ratio, 100);
} else } else
@ -665,14 +662,14 @@ progressmeter(int flag)
timersub(&now, &start, &td); timersub(&now, &start, &td);
elapsed = td.tv_sec + (td.tv_usec / 1000000.0); elapsed = td.tv_sec + (td.tv_usec / 1000000.0);
if (statbytes <= 0 || elapsed <= 0.0 || cursize > filesize) { if (wait.tv_sec >= STALLTIME) {
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
" --:-- ETA");
} else if (wait.tv_sec >= STALLTIME) {
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
" - stalled -"); " - stalled -");
} else if (statbytes <= 0 || elapsed <= 0.0 || cursize > totalsize || chunked) {
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
" --:-- ETA");
} else { } else {
remaining = (int) (filesize / (statbytes / elapsed) - elapsed); remaining = (int) (totalsize / (statbytes / elapsed) - elapsed);
i = remaining / 3600; i = remaining / 3600;
if (i) if (i)
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
@ -696,6 +693,7 @@ progressmeter(int flag)
} else if (flag == 1) { } else if (flag == 1) {
alarmtimer(0); alarmtimer(0);
statbytes = 0; statbytes = 0;
putc('\n', stderr);
} }
} }
#endif #endif
@ -735,7 +733,7 @@ progressmeter(int flag)
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: wget.c,v 1.35 2001/04/11 20:11:51 kraai Exp $ * $Id: wget.c,v 1.36 2001/04/17 18:13:16 markw Exp $
*/ */

View File

@ -1719,7 +1719,7 @@
" 31 46 1365 /etc/passwd\n" " 31 46 1365 /etc/passwd\n"
#define wget_trivial_usage \ #define wget_trivial_usage \
"[-c] [-O file] url" "[-c] [-q] [-O file] url"
#define wget_full_usage \ #define wget_full_usage \
"wget retrieves files via HTTP or FTP\n\n" \ "wget retrieves files via HTTP or FTP\n\n" \
"Options:\n" \ "Options:\n" \

36
wget.c
View File

@ -59,7 +59,7 @@ static int chunked = 0; /* chunked transfer encoding */
#ifdef BB_FEATURE_WGET_STATUSBAR #ifdef BB_FEATURE_WGET_STATUSBAR
static char *curfile; /* Name of current file being transferred. */ static char *curfile; /* Name of current file being transferred. */
static struct timeval start; /* Time a transfer started. */ static struct timeval start; /* Time a transfer started. */
static volatile unsigned long statbytes; /* Number of bytes transferred so far. */ static volatile unsigned long statbytes = 0; /* Number of bytes transferred so far. */
/* For progressmeter() -- number of seconds before xfer considered "stalled" */ /* For progressmeter() -- number of seconds before xfer considered "stalled" */
static const int STALLTIME = 5; static const int STALLTIME = 5;
#endif #endif
@ -390,18 +390,15 @@ read_response: if (fgets(buf, sizeof(buf), sfp) == NULL)
fgets(buf, sizeof(buf), dfp); fgets(buf, sizeof(buf), dfp);
filesize = strtol(buf, (char **) NULL, 16); filesize = strtol(buf, (char **) NULL, 16);
} }
do {
#ifdef BB_FEATURE_WGET_STATUSBAR #ifdef BB_FEATURE_WGET_STATUSBAR
statbytes=0;
if (quiet_flag==FALSE) if (quiet_flag==FALSE)
progressmeter(-1); progressmeter(-1);
#endif #endif
do {
while ((filesize > 0 || !got_clen) && (n = fread(buf, 1, chunked ? (filesize > sizeof(buf) ? sizeof(buf) : filesize) : sizeof(buf), dfp)) > 0) { while ((filesize > 0 || !got_clen) && (n = fread(buf, 1, chunked ? (filesize > sizeof(buf) ? sizeof(buf) : filesize) : sizeof(buf), dfp)) > 0) {
fwrite(buf, 1, n, output); fwrite(buf, 1, n, output);
#ifdef BB_FEATURE_WGET_STATUSBAR #ifdef BB_FEATURE_WGET_STATUSBAR
statbytes+=n; statbytes+=n;
if (quiet_flag==FALSE)
progressmeter(1);
#endif #endif
if (got_clen) if (got_clen)
filesize -= n; filesize -= n;
@ -417,17 +414,16 @@ read_response: if (fgets(buf, sizeof(buf), sfp) == NULL)
if (n == 0 && ferror(dfp)) if (n == 0 && ferror(dfp))
perror_msg_and_die("network read error"); perror_msg_and_die("network read error");
} while (chunked); } while (chunked);
#ifdef BB_FEATURE_WGET_STATUSBAR
if (quiet_flag==FALSE)
progressmeter(1);
#endif
if (!proxy && target.is_ftp) { if (!proxy && target.is_ftp) {
fclose(dfp); fclose(dfp);
if (ftpcmd(NULL, NULL, sfp, buf) != 226) if (ftpcmd(NULL, NULL, sfp, buf) != 226)
error_msg_and_die("ftp error: %s", buf+4); error_msg_and_die("ftp error: %s", buf+4);
ftpcmd("QUIT", NULL, sfp, buf); ftpcmd("QUIT", NULL, sfp, buf);
} }
#ifdef BB_FEATURE_WGET_STATUSBAR
if (quiet_flag==FALSE)
putc('\n', stderr);
#endif
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
@ -609,7 +605,7 @@ progressmeter(int flag)
{ {
static const char prefixes[] = " KMGTP"; static const char prefixes[] = " KMGTP";
static struct timeval lastupdate; static struct timeval lastupdate;
static off_t lastsize; static off_t lastsize, totalsize;
struct timeval now, td, wait; struct timeval now, td, wait;
off_t cursize, abbrevsize; off_t cursize, abbrevsize;
double elapsed; double elapsed;
@ -620,12 +616,13 @@ progressmeter(int flag)
(void) gettimeofday(&start, (struct timezone *) 0); (void) gettimeofday(&start, (struct timezone *) 0);
lastupdate = start; lastupdate = start;
lastsize = 0; lastsize = 0;
totalsize = filesize; /* as filesize changes.. */
} }
(void) gettimeofday(&now, (struct timezone *) 0); (void) gettimeofday(&now, (struct timezone *) 0);
cursize = statbytes; cursize = statbytes;
if (filesize != 0 && !chunked) { if (totalsize != 0 && !chunked) {
ratio = 100.0 * cursize / filesize; ratio = 100.0 * cursize / totalsize;
ratio = MAX(ratio, 0); ratio = MAX(ratio, 0);
ratio = MIN(ratio, 100); ratio = MIN(ratio, 100);
} else } else
@ -665,14 +662,14 @@ progressmeter(int flag)
timersub(&now, &start, &td); timersub(&now, &start, &td);
elapsed = td.tv_sec + (td.tv_usec / 1000000.0); elapsed = td.tv_sec + (td.tv_usec / 1000000.0);
if (statbytes <= 0 || elapsed <= 0.0 || cursize > filesize) { if (wait.tv_sec >= STALLTIME) {
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
" --:-- ETA");
} else if (wait.tv_sec >= STALLTIME) {
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
" - stalled -"); " - stalled -");
} else if (statbytes <= 0 || elapsed <= 0.0 || cursize > totalsize || chunked) {
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
" --:-- ETA");
} else { } else {
remaining = (int) (filesize / (statbytes / elapsed) - elapsed); remaining = (int) (totalsize / (statbytes / elapsed) - elapsed);
i = remaining / 3600; i = remaining / 3600;
if (i) if (i)
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
@ -696,6 +693,7 @@ progressmeter(int flag)
} else if (flag == 1) { } else if (flag == 1) {
alarmtimer(0); alarmtimer(0);
statbytes = 0; statbytes = 0;
putc('\n', stderr);
} }
} }
#endif #endif
@ -735,7 +733,7 @@ progressmeter(int flag)
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: wget.c,v 1.35 2001/04/11 20:11:51 kraai Exp $ * $Id: wget.c,v 1.36 2001/04/17 18:13:16 markw Exp $
*/ */