Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/progress progress(1) is a standalone version of luke...
details: https://anonhg.NetBSD.org/src/rev/4f8e3c845c2e
branches: trunk
changeset: 542107:4f8e3c845c2e
user: jhawk <jhawk%NetBSD.org@localhost>
date: Wed Jan 22 00:14:12 2003 +0000
description:
progress(1) is a standalone version of lukemftp's progress bar
(pulled in via reachover makefile) suitable for measuring the
input to arbitrary pipes.
This is intended for use by sysinst.
diffstat:
usr.bin/progress/Makefile | 9 +
usr.bin/progress/progress.1 | 139 ++++++++++++++++++++++++++++
usr.bin/progress/progress.c | 211 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 359 insertions(+), 0 deletions(-)
diffs (truncated from 371 to 300 lines):
diff -r 7c20d97c0152 -r 4f8e3c845c2e usr.bin/progress/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/progress/Makefile Wed Jan 22 00:14:12 2003 +0000
@@ -0,0 +1,9 @@
+# $NetBSD: Makefile,v 1.1 2003/01/22 00:14:12 jhawk Exp $
+PROG=progress
+SRCS=progress.c progressbar.c
+
+CPPFLAGS+=-I${NETBSDSRCDIR}/usr.bin/ftp -DSTANDALONE_PROGRESS
+
+.PATH: ${NETBSDSRCDIR}/usr.bin/ftp
+
+.include <bsd.prog.mk>
diff -r 7c20d97c0152 -r 4f8e3c845c2e usr.bin/progress/progress.1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/progress/progress.1 Wed Jan 22 00:14:12 2003 +0000
@@ -0,0 +1,139 @@
+.\" $NetBSD: progress.1,v 1.1 2003/01/22 00:14:12 jhawk Exp $
+.\"
+.\" Copyright (c) 2003 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by John Hawkinson.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. Neither the name of The NetBSD Foundation nor the names of its
+.\" contributors may be used to endorse or promote products derived
+.\" from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd January 21, 2003
+.Dt PROGRESS 1
+.Os
+.Sh NAME
+.Nm progress
+.Nd feed input to a command, displaying a progress bar
+.Sh SYNOPSIS
+.Nm
+.Op Fl z
+.Op Fl f Ar file
+.Op Fl l Ar length
+.Ar cmd
+.Op Ar args ...
+.Sh DESCRIPTION
+The
+.Nm
+utility opens a pipe to
+.Ar cmd
+and feeds an input stream into it, while displaying a progress bar to
+standard output.
+If no filename is specified,
+.Nm
+reads from standard input.
+Where feasible,
+.Nm
+.Xr fstat 2 Ns s
+the input to determine the length, so a time estimate can be calculated.
+.Pp
+If no length is specified or determined,
+.Nm
+simply displays a count of the data and the data rate.
+.Pp
+The options are as follows:
+.Bl -tag -width XlXlengthXX
+.It Fl f Ar file
+Read from the specified
+.Ar file
+instead of standard input.
+.It Fl l Ar length
+Use the specified length for the time estimate, rather than attempting to
+.Xr fstat 2
+the input.
+.It Fl z
+Filter the input through
+.Xr gzip 1 .
+If
+.Fl f
+is specified, calculate the length using
+.Ic gzip -l .
+.El
+.Sh EXIT STATUS
+.Nm
+exits 0 on success.
+.\" .Sh ENVIRONMENT
+.\" .Sh FILES
+.Sh EXAMPLES
+The command
+.Ic progress -zf file.tar.gz tar xf -
+will extract the
+.Pa file.tar.gz
+displaying the progress bar as time passes:
+.Bd -literal
+ 0% | | 0 0.00 KB/s --:-- ETA
+ 40% |********** | 273 KB 271.95 KB/s 00:01 ETA
+ 81% |************************* | 553 KB 274.61 KB/s 00:00 ETA
+100% |*********************************| 680 KB 264.59 KB/s 00:00 ETA
+.Ed
+.Pp
+If it is preferred to monitor the progress of the decompression
+process (unlikely), then
+.Ic progress -f file.tar.gz tar zxf -
+could be used.
+.\".Sh DIAGNOSTICS
+.Sh SEE ALSO
+.Xr ftp 1
+.\" .Sh STANDARDS
+.Sh HISTORY
+.Nm
+first appeared in
+.Nx 1.6.1 .
+The dynamic progress bar display code is part of
+.Pa lukemftp .
+.Sh AUTHORS
+.Nm
+was written by
+.An John Hawkinson Aq jhawk%NetBSD.ORG@localhost .
+.Xr ftp 1 Ns 's
+dynamic progress bar was written by Luke Mewburn.
+.Sh BUGS
+Since the progress bar is displayed asynchronously, it may be
+difficult to read some error messages, both those produced by the
+pipeline, as well as those produced by
+.Nm
+itself.
+.Pp
+Under special circumstances,
+.Nm
+may have its output pipe prematurely closed.
+For example:
+.Bd -literal
+# < /dev/zero progress dd of=/dev/null
+ 26923 KB 26.19 MB/s progress: wrote -1 of 512 bytes to output pipe: Bad address
+# 53847+0 records in
+53847+0 records out
+27569664 bytes transferred in 0.997 secs (27652621 bytes/sec)
+.Ed
+.\" .Sh SECURITY CONSIDERATIONS
diff -r 7c20d97c0152 -r 4f8e3c845c2e usr.bin/progress/progress.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/progress/progress.c Wed Jan 22 00:14:12 2003 +0000
@@ -0,0 +1,211 @@
+/* $NetBSD: progress.c,v 1.1 2003/01/22 00:14:12 jhawk Exp $ */
+
+/*-
+ * Copyright (c) 2003 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by John Hawkinson.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#ifndef lint
+__RCSID("$NetBSD: progress.c,v 1.1 2003/01/22 00:14:12 jhawk Exp $");
+#endif /* not lint */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <sys/time.h>
+#include <sys/wait.h>
+#include <netinet/in.h>
+#include <arpa/ftp.h>
+
+#include <ctype.h>
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <glob.h>
+#include <signal.h>
+#include <limits.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <termios.h>
+#include <time.h>
+#include <tzfile.h>
+#include <unistd.h>
+
+#define GLOBAL /* force GLOBAL decls in progressbar.h to be
+ * declared */
+#include "progressbar.h"
+
+static void usage(void);
+int main(int, char *[]);
+
+static void
+usage(void)
+{
+ fprintf(stderr,
+ "usage: %s [-z] [-f file] [-l length] cmd [args...]\n",
+ getprogname());
+ exit(1);
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ static char fb_buf[BUFSIZ];
+ char *infile = NULL;
+ pid_t pid;
+ int ch, fd, outpipe[2], waitstat;
+ int lflag = 0, zflag = 0;
+ ssize_t nr, nw, off;
+ struct stat statb;
+
+ setprogname(argv[0]);
+
+ /* defaults: Read from stdin, 0 filesize (no completion estimate) */
+ fd = STDIN_FILENO;
+ filesize = 0;
+
+ while ((ch = getopt(argc, argv, "f:l:z")) != -1)
+ switch (ch) {
+ case 'f':
+ infile = optarg;
+ break;
+ case 'l':
+ lflag++;
+ filesize = strtoull(optarg, NULL, 0);
+ break;
+ case 'z':
+ zflag++;
+ break;
+ default:
+ case '?':
+ usage();
+ /* NOTREACHED */
+ }
+ argc -= optind;
+ argv += optind;
+
+ if (argc < 1)
+ usage();
+ if (infile && (fd = open(infile, O_RDONLY, 0)) < 0)
+ err(1, "%s", infile);
+
+ /* stat() to get the filesize unless overridden, or -z */
+ if (!zflag && !lflag && (fstat(fd, &statb) == 0))
+ filesize = statb.st_size;
+
+ /* gzip -l the file if we have the name and -z is given */
+ if (zflag && !lflag && infile != NULL) {
+ FILE *gzipsizepipe;
+ char buf[256], *cmd;
+ long size;
+
+ /*
+ * Read second word of last line of gzip -l output. Looks like:
+ * % gzip -l ../etc.tgz
+ * compressed uncompressed ratio uncompressed_name
+ * 119737 696320 82.8% ../etc.tar
+ */
+
Home |
Main Index |
Thread Index |
Old Index