From 849866f9c1c00c7fb8369f00bf9818d7dd13da15 Mon Sep 17 00:00:00 2001 From: hubertf Date: Tue, 9 Mar 2004 17:04:24 +0000 Subject: [PATCH] Allow custom text printed before (left of) the progress bar from progress(1): miyu# cat openoffice-linux-1.1.0.tgz | progress -z -p 'Bytes written: ' dd of=/dev/null bs=1m Bytes written: 193 MB 13.83 MB/s 0+195211 records in and: miyu# progress -f openoffice-linux-1.1.0.tgz -z -p 'Bytes written: ' dd of=/dev/null bs=1m Bytes written: 28% |****** | 57919 KB 14.12 MB/s 00:09 ETA OK'd by lukem. --- doc/CHANGES | 4 +++- usr.bin/ftp/progressbar.c | 9 +++++++-- usr.bin/ftp/progressbar.h | 3 ++- usr.bin/progress/progress.1 | 9 +++++++-- usr.bin/progress/progress.c | 12 ++++++++---- 5 files changed, 27 insertions(+), 10 deletions(-) diff --git a/doc/CHANGES b/doc/CHANGES index dcb973be99e1..1d0cf227cf6d 100644 --- a/doc/CHANGES +++ b/doc/CHANGES @@ -1,4 +1,4 @@ -LIST OF CHANGES FROM LAST RELEASE: <$Revision: 1.273 $> +LIST OF CHANGES FROM LAST RELEASE: <$Revision: 1.274 $> [Note: This file does not mention every change made to the NetBSD source tree. @@ -615,3 +615,5 @@ Changes from NetBSD 1.6 to NetBSD 2.0: GCC: Import GCC 3.3.3-20040209. [mrg 20040210] sh3: Switch to GCC 3.3. [uwe 20040222] hpcsh: Enable building of Xhpc server for hpcsh. [uwe 20040222] + progress(1): Allow printing custom text before (left of) the progress + bar. [hubertf 20040309] diff --git a/usr.bin/ftp/progressbar.c b/usr.bin/ftp/progressbar.c index f096ffc139ca..9c09147cd6f2 100644 --- a/usr.bin/ftp/progressbar.c +++ b/usr.bin/ftp/progressbar.c @@ -1,4 +1,4 @@ -/* $NetBSD: progressbar.c,v 1.4 2003/07/17 12:06:18 lukem Exp $ */ +/* $NetBSD: progressbar.c,v 1.5 2004/03/09 17:04:24 hubertf Exp $ */ /*- * Copyright (c) 1997-2003 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ #include #ifndef lint -__RCSID("$NetBSD: progressbar.c,v 1.4 2003/07/17 12:06:18 lukem Exp $"); +__RCSID("$NetBSD: progressbar.c,v 1.5 2004/03/09 17:04:24 hubertf Exp $"); #endif /* not lint */ /* @@ -52,6 +52,7 @@ __RCSID("$NetBSD: progressbar.c,v 1.4 2003/07/17 12:06:18 lukem Exp $"); #include #include #include +#include #include #include #include @@ -200,6 +201,8 @@ progressmeter(int flag) return; len += snprintf(buf + len, BUFLEFT, "\r"); + if (prefix) + len += snprintf(buf + len, BUFLEFT, "%s", prefix); if (filesize > 0) { ratio = (int)((double)cursize * 100.0 / (double)filesize); ratio = MAX(ratio, 0); @@ -211,6 +214,8 @@ progressmeter(int flag) * the number of stars won't exceed the buffer size */ barlength = MIN(sizeof(buf) - 1, ttywidth) - BAROVERHEAD; + if (prefix) + barlength -= strlen(prefix); if (barlength > 0) { i = barlength * ratio / 100; len += snprintf(buf + len, BUFLEFT, diff --git a/usr.bin/ftp/progressbar.h b/usr.bin/ftp/progressbar.h index b7ca63f41a6d..b8e416e80c36 100644 --- a/usr.bin/ftp/progressbar.h +++ b/usr.bin/ftp/progressbar.h @@ -1,4 +1,4 @@ -/* $NetBSD: progressbar.h,v 1.3 2003/02/28 09:53:49 lukem Exp $ */ +/* $NetBSD: progressbar.h,v 1.4 2004/03/09 17:04:24 hubertf Exp $ */ /*- * Copyright (c) 1996-2003 The NetBSD Foundation, Inc. @@ -58,6 +58,7 @@ GLOBAL int ttywidth; /* width of tty */ GLOBAL off_t bytes; /* current # of bytes read */ GLOBAL off_t filesize; /* size of file being transferred */ GLOBAL off_t restart_point; /* offset to restart transfer */ +GLOBAL char *prefix; /* Text written left of progress bar */ #ifndef STANDALONE_PROGRESS diff --git a/usr.bin/progress/progress.1 b/usr.bin/progress/progress.1 index 239e557e557f..59a87c05caa8 100644 --- a/usr.bin/progress/progress.1 +++ b/usr.bin/progress/progress.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: progress.1,v 1.5 2003/02/14 15:59:18 grant Exp $ +.\" $NetBSD: progress.1,v 1.6 2004/03/09 17:04:24 hubertf Exp $ .\" .\" Copyright (c) 2003 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -30,7 +30,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd January 21, 2003 +.Dd March 5, 2004 .Dt PROGRESS 1 .Os .Sh NAME @@ -41,6 +41,7 @@ .Op Fl z .Op Fl f Ar file .Op Fl l Ar length +.Op Fl p Ar prefix .Ar cmd .Op Ar args ... .Sh DESCRIPTION @@ -72,6 +73,10 @@ instead of standard input. Use the specified length for the time estimate, rather than attempting to .Xr fstat 2 the input. +.It Fl p Ar prefix +Print the given +.Dq prefix +text before (left of) the progress bar. .It Fl z Filter the input through .Xr gzip 1 . diff --git a/usr.bin/progress/progress.c b/usr.bin/progress/progress.c index d47e46e65fea..eaa331477b62 100644 --- a/usr.bin/progress/progress.c +++ b/usr.bin/progress/progress.c @@ -1,4 +1,4 @@ -/* $NetBSD: progress.c,v 1.7 2003/02/12 00:58:34 ross Exp $ */ +/* $NetBSD: progress.c,v 1.8 2004/03/09 17:04:24 hubertf Exp $ */ /*- * Copyright (c) 2003 The NetBSD Foundation, Inc. @@ -34,7 +34,7 @@ #include #ifndef lint -__RCSID("$NetBSD: progress.c,v 1.7 2003/02/12 00:58:34 ross Exp $"); +__RCSID("$NetBSD: progress.c,v 1.8 2004/03/09 17:04:24 hubertf Exp $"); #endif /* not lint */ #include @@ -73,7 +73,7 @@ static void usage(void) { fprintf(stderr, - "usage: %s [-z] [-f file] [-l length] cmd [args...]\n", + "usage: %s [-z] [-f file] [-l length] [-p prefix] cmd [args...]\n", getprogname()); exit(1); } @@ -96,8 +96,9 @@ main(int argc, char *argv[]) /* defaults: Read from stdin, 0 filesize (no completion estimate) */ fd = STDIN_FILENO; filesize = 0; + prefix=NULL; - while ((ch = getopt(argc, argv, "f:l:z")) != -1) + while ((ch = getopt(argc, argv, "f:l:p:z")) != -1) switch (ch) { case 'f': infile = optarg; @@ -106,6 +107,9 @@ main(int argc, char *argv[]) lflag++; filesize = strtoull(optarg, NULL, 0); break; + case 'p': + prefix = optarg; + break; case 'z': zflag++; break;