summaryrefslogtreecommitdiff
path: root/scp.c
diff options
context:
space:
mode:
authorBen Lindstrom <mouring@eviladmin.org>2002-12-23 02:53:08 +0000
committerBen Lindstrom <mouring@eviladmin.org>2002-12-23 02:53:08 +0000
commit40b950356303d5293f1f684d2748be18291541af (patch)
tree6504c4e365f0d8fb4955737e436ce022b9000f46 /scp.c
parent1d568f9fce07fd6ea1f6d9f84cd204a17264e28e (diff)
- markus@cvs.openbsd.org 2002/12/13 15:20:52
[scp.c] 1) include stalling time in total time 2) truncate filenames to 45 instead of 20 characters 3) print rate instead of progress bar, no more stars 4) scale output to tty width based on a patch from Niels; ok fries@ lebel@ fgs@ millert@
Diffstat (limited to 'scp.c')
-rw-r--r--scp.c65
1 files changed, 35 insertions, 30 deletions
diff --git a/scp.c b/scp.c
index eb5f23e4..71d2a0d9 100644
--- a/scp.c
+++ b/scp.c
@@ -75,7 +75,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: scp.c,v 1.95 2002/12/05 11:08:35 markus Exp $");
+RCSID("$OpenBSD: scp.c,v 1.96 2002/12/13 15:20:52 markus Exp $");
#include "xmalloc.h"
#include "atomicio.h"
@@ -1119,13 +1119,19 @@ foregroundproc(void)
void
progressmeter(int flag)
{
+ static const char spaces[] = " "
+ " "
+ " "
+ " "
+ " "
+ " ";
static const char prefixes[] = " KMGTP";
static struct timeval lastupdate;
static off_t lastsize;
struct timeval now, td, wait;
- off_t cursize, abbrevsize;
+ off_t cursize, abbrevsize, bytespersec;
double elapsed;
- int ratio, barlength, i, remaining;
+ int ratio, remaining, i, ai, bi, nspaces;
char buf[512];
if (flag == -1) {
@@ -1145,45 +1151,44 @@ progressmeter(int flag)
} else
ratio = 100;
- snprintf(buf, sizeof(buf), "\r%-20.20s %3d%% ", curfile, ratio);
-
- barlength = getttywidth() - 51;
- if (barlength > 0) {
- i = barlength * ratio / 100;
- snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
- "|%.*s%*s|", i,
- "*******************************************************"
- "*******************************************************"
- "*******************************************************"
- "*******************************************************"
- "*******************************************************"
- "*******************************************************"
- "*******************************************************",
- barlength - i, "");
- }
- i = 0;
abbrevsize = cursize;
- while (abbrevsize >= 100000 && i < sizeof(prefixes)) {
- i++;
+ for (ai = 0; abbrevsize >= 10000 && ai < sizeof(prefixes); ai++)
abbrevsize >>= 10;
- }
- snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " %5lu %c%c ",
- (unsigned long) abbrevsize, prefixes[i],
- prefixes[i] == ' ' ? ' ' : 'B');
timersub(&now, &lastupdate, &wait);
if (cursize > lastsize) {
lastupdate = now;
lastsize = cursize;
- if (wait.tv_sec >= STALLTIME) {
- start.tv_sec += wait.tv_sec;
- start.tv_usec += wait.tv_usec;
- }
wait.tv_sec = 0;
}
timersub(&now, &start, &td);
elapsed = td.tv_sec + (td.tv_usec / 1000000.0);
+ bytespersec = 0;
+ if (statbytes > 0) {
+ bytespersec = statbytes;
+ if (elapsed > 0.0)
+ bytespersec /= elapsed;
+ }
+ for (bi = 1; bytespersec >= 1024000 && bi < sizeof(prefixes); bi++)
+ bytespersec >>= 10;
+
+ nspaces = MIN(getttywidth() - 79, sizeof(spaces) - 1);
+
+ snprintf(buf, sizeof(buf),
+ "\r%-45.45s%.*s%3d%% %4lld%c%c %3lld.%01d%cB/s",
+ curfile,
+ nspaces,
+ spaces,
+ ratio,
+ (long long)abbrevsize,
+ prefixes[ai],
+ ai == 0 ? ' ' : 'B',
+ (long long)(bytespersec / 1024),
+ (int)((bytespersec % 1024) * 10 / 1024),
+ prefixes[bi]
+ );
+
if (flag != 1 &&
(statbytes <= 0 || elapsed <= 0.0 || cursize > totalbytes)) {
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),