- display a limited progress bar (containing bytes xferred and xfer rate)
when the file size is unknown - disable progress bar during remglob()
This commit is contained in:
parent
21928fdd78
commit
83a00b2109
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: util.c,v 1.103 2000/11/15 00:11:04 lukem Exp $ */
|
||||
/* $NetBSD: util.c,v 1.104 2001/02/19 20:02:42 lukem Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1997-2000 The NetBSD Foundation, Inc.
|
||||
|
@ -75,7 +75,7 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: util.c,v 1.103 2000/11/15 00:11:04 lukem Exp $");
|
||||
__RCSID("$NetBSD: util.c,v 1.104 2001/02/19 20:02:42 lukem Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
|
@ -522,7 +522,7 @@ remglob(char *argv[], int doswitch, char **errbuf)
|
|||
static char buf[MAXPATHLEN];
|
||||
static FILE *ftemp = NULL;
|
||||
static char **args;
|
||||
int oldverbose, oldhash, fd, len;
|
||||
int oldverbose, oldhash, oldprogress, fd, len;
|
||||
char *cp, *mode;
|
||||
|
||||
if (!mflag || !connected) {
|
||||
|
@ -556,7 +556,9 @@ remglob(char *argv[], int doswitch, char **errbuf)
|
|||
oldverbose = verbose;
|
||||
verbose = (errbuf != NULL) ? -1 : 0;
|
||||
oldhash = hash;
|
||||
oldprogress = progress;
|
||||
hash = 0;
|
||||
progress = 0;
|
||||
if (doswitch)
|
||||
pswitch(!proxy);
|
||||
for (mode = "w"; *++argv != NULL; mode = "a")
|
||||
|
@ -569,6 +571,7 @@ remglob(char *argv[], int doswitch, char **errbuf)
|
|||
pswitch(!proxy);
|
||||
verbose = oldverbose;
|
||||
hash = oldhash;
|
||||
progress = oldprogress;
|
||||
ftemp = fopen(temp, "r");
|
||||
(void)unlink(temp);
|
||||
if (ftemp == NULL) {
|
||||
|
@ -888,9 +891,9 @@ progressmeter(int flag)
|
|||
lastsize = restart_point;
|
||||
}
|
||||
#ifndef NO_PROGRESS
|
||||
len = 0;
|
||||
if (!progress || filesize <= 0)
|
||||
if (!progress)
|
||||
return;
|
||||
len = 0;
|
||||
|
||||
/*
|
||||
* print progress bar only if we are foreground process.
|
||||
|
@ -907,20 +910,23 @@ progressmeter(int flag)
|
|||
wait.tv_sec = 0;
|
||||
}
|
||||
|
||||
ratio = (int)((double)cursize * 100.0 / (double)filesize);
|
||||
ratio = MAX(ratio, 0);
|
||||
ratio = MIN(ratio, 100);
|
||||
len += snprintf(buf + len, BUFLEFT, "\r%3d%% ", ratio);
|
||||
len += snprintf(buf + len, BUFLEFT, "\r");
|
||||
if (filesize > 0) {
|
||||
ratio = (int)((double)cursize * 100.0 / (double)filesize);
|
||||
ratio = MAX(ratio, 0);
|
||||
ratio = MIN(ratio, 100);
|
||||
len += snprintf(buf + len, BUFLEFT, "%3d%% ", ratio);
|
||||
|
||||
/*
|
||||
* calculate the length of the `*' bar, ensuring that
|
||||
* the number of stars won't exceed the buffer size
|
||||
*/
|
||||
barlength = MIN(sizeof(buf) - 1, ttywidth) - BAROVERHEAD;
|
||||
if (barlength > 0) {
|
||||
i = barlength * ratio / 100;
|
||||
len += snprintf(buf + len, BUFLEFT,
|
||||
"|%.*s%*s|", i, stars, barlength - i, "");
|
||||
barlength = MIN(sizeof(buf) - 1, ttywidth) - BAROVERHEAD;
|
||||
if (barlength > 0) {
|
||||
i = barlength * ratio / 100;
|
||||
len += snprintf(buf + len, BUFLEFT,
|
||||
"|%.*s%*s|", i, stars, barlength - i, "");
|
||||
}
|
||||
}
|
||||
|
||||
abbrevsize = cursize;
|
||||
|
@ -948,24 +954,30 @@ progressmeter(int flag)
|
|||
(int)((bytespersec % 1024) * 100 / 1024),
|
||||
prefixes[i]);
|
||||
|
||||
if (bytes <= 0 || elapsed <= 0.0 || cursize > filesize) {
|
||||
len += snprintf(buf + len, BUFLEFT, " --:-- ETA");
|
||||
} else if (wait.tv_sec >= STALLTIME) {
|
||||
len += snprintf(buf + len, BUFLEFT, " - stalled -");
|
||||
} else {
|
||||
remaining = (int)
|
||||
((filesize - restart_point) / (bytes / elapsed) - elapsed);
|
||||
if (remaining >= 100 * SECSPERHOUR)
|
||||
if (filesize > 0) {
|
||||
if (bytes <= 0 || elapsed <= 0.0 || cursize > filesize) {
|
||||
len += snprintf(buf + len, BUFLEFT, " --:-- ETA");
|
||||
else {
|
||||
i = remaining / SECSPERHOUR;
|
||||
if (i)
|
||||
len += snprintf(buf + len, BUFLEFT, "%2d:", i);
|
||||
else
|
||||
len += snprintf(buf + len, BUFLEFT, " ");
|
||||
i = remaining % SECSPERHOUR;
|
||||
len += snprintf(buf + len, BUFLEFT,
|
||||
"%02d:%02d ETA", i / 60, i % 60);
|
||||
} else if (wait.tv_sec >= STALLTIME) {
|
||||
len += snprintf(buf + len, BUFLEFT, " - stalled -");
|
||||
} else {
|
||||
remaining = (int)
|
||||
((filesize - restart_point) / (bytes / elapsed) -
|
||||
elapsed);
|
||||
if (remaining >= 100 * SECSPERHOUR)
|
||||
len += snprintf(buf + len, BUFLEFT,
|
||||
" --:-- ETA");
|
||||
else {
|
||||
i = remaining / SECSPERHOUR;
|
||||
if (i)
|
||||
len += snprintf(buf + len, BUFLEFT,
|
||||
"%2d:", i);
|
||||
else
|
||||
len += snprintf(buf + len, BUFLEFT,
|
||||
" ");
|
||||
i = remaining % SECSPERHOUR;
|
||||
len += snprintf(buf + len, BUFLEFT,
|
||||
"%02d:%02d ETA", i / 60, i % 60);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (flag == 1)
|
||||
|
|
Loading…
Reference in New Issue