Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/ftp - display a limited progress bar (containing byt...



details:   https://anonhg.NetBSD.org/src/rev/ddcc1dad1bb8
branches:  trunk
changeset: 503997:ddcc1dad1bb8
user:      lukem <lukem%NetBSD.org@localhost>
date:      Mon Feb 19 20:02:42 2001 +0000

description:
- display a limited progress bar (containing bytes xferred and xfer rate)
  when the file size is unknown
- disable progress bar during remglob()

diffstat:

 usr.bin/ftp/util.c |  74 +++++++++++++++++++++++++++++++----------------------
 1 files changed, 43 insertions(+), 31 deletions(-)

diffs (138 lines):

diff -r addde6760425 -r ddcc1dad1bb8 usr.bin/ftp/util.c
--- a/usr.bin/ftp/util.c        Mon Feb 19 19:52:27 2001 +0000
+++ b/usr.bin/ftp/util.c        Mon Feb 19 20:02:42 2001 +0000
@@ -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 @@
         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 @@
                 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 @@
                         pswitch(!proxy);
                 verbose = oldverbose;
                hash = oldhash;
+               progress = oldprogress;
                 ftemp = fopen(temp, "r");
                 (void)unlink(temp);
                 if (ftemp == NULL) {
@@ -888,9 +891,9 @@
                lastsize = restart_point;
        }
 #ifndef NO_PROGRESS
+       if (!progress)
+               return;
        len = 0;
-       if (!progress || filesize <= 0)
-               return;
 
        /*
         * print progress bar only if we are foreground process.
@@ -907,20 +910,23 @@
                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 @@
            (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)



Home | Main Index | Thread Index | Old Index