* -v enables verbose & progress, -V disables both

* set setvbuf(ttyout, NULL, _IOLBF, 0) and remove a bunch of fflush(ttyout).
* use fwrite() instead of write() for progressmeter (don't intermix stdio
  with non stdio ops)
This commit is contained in:
lukem 1999-01-24 02:39:29 +00:00
parent a58f271406
commit 0bd80459cb
6 changed files with 42 additions and 53 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: cmds.c,v 1.45 1999/01/24 00:51:08 lukem Exp $ */ /* $NetBSD: cmds.c,v 1.46 1999/01/24 02:39:29 lukem Exp $ */
/*- /*-
* Copyright (c) 1998 The NetBSD Foundation, Inc. * Copyright (c) 1998 The NetBSD Foundation, Inc.
@ -75,7 +75,7 @@
#if 0 #if 0
static char sccsid[] = "@(#)cmds.c 8.6 (Berkeley) 10/9/94"; static char sccsid[] = "@(#)cmds.c 8.6 (Berkeley) 10/9/94";
#else #else
__RCSID("$NetBSD: cmds.c,v 1.45 1999/01/24 00:51:08 lukem Exp $"); __RCSID("$NetBSD: cmds.c,v 1.46 1999/01/24 02:39:29 lukem Exp $");
#endif #endif
#endif /* not lint */ #endif /* not lint */
@ -589,7 +589,6 @@ mabort(signo)
alarmtimer(0); alarmtimer(0);
putc('\n', ttyout); putc('\n', ttyout);
(void)fflush(ttyout);
if (mflag && fromatty) { if (mflag && fromatty) {
ointer = interactive; ointer = interactive;
oconf = confirmrest; oconf = confirmrest;
@ -756,13 +755,10 @@ togglevar(argc, argv, var, mesg)
*var = 0; *var = 0;
} else { } else {
fprintf(ttyout, "usage: %s [ on | off ]\n", argv[0]); fprintf(ttyout, "usage: %s [ on | off ]\n", argv[0]);
(void)fflush(ttyout);
return (-1); return (-1);
} }
if (mesg) { if (mesg)
fprintf(ttyout, "%s %s.\n", mesg, onoff(*var)); fprintf(ttyout, "%s %s.\n", mesg, onoff(*var));
(void)fflush(ttyout);
}
return (*var); return (*var);
} }
@ -1209,9 +1205,6 @@ ls(argc, argv)
goto freels; goto freels;
} }
recvrequest(cmd, argv[2], argv[1], "w", 0, 0); recvrequest(cmd, argv[2], argv[1], "w", 0, 0);
/* flush results in case commands are coming from a pipe */
fflush(ttyout);
freels: freels:
if (argv[2] != globargv2) /* free up after globulize() */ if (argv[2] != globargv2) /* free up after globulize() */
free(argv[2]); free(argv[2]);
@ -1307,7 +1300,6 @@ shell(argc, argv)
if (debug) { if (debug) {
fputs(shell, ttyout); fputs(shell, ttyout);
putc('\n', ttyout); putc('\n', ttyout);
(void)fflush(ttyout);
} }
if (argc > 1) { if (argc > 1) {
execl(shell, shellnam, "-c", altarg, (char *)0); execl(shell, shellnam, "-c", altarg, (char *)0);
@ -1690,19 +1682,16 @@ doproxy(argc, argv)
c = getcmd(argv[1]); c = getcmd(argv[1]);
if (c == (struct cmd *) -1) { if (c == (struct cmd *) -1) {
fputs("?Ambiguous command.\n", ttyout); fputs("?Ambiguous command.\n", ttyout);
(void)fflush(ttyout);
code = -1; code = -1;
return; return;
} }
if (c == 0) { if (c == 0) {
fputs("?Invalid command.\n", ttyout); fputs("?Invalid command.\n", ttyout);
(void)fflush(ttyout);
code = -1; code = -1;
return; return;
} }
if (!c->c_proxy) { if (!c->c_proxy) {
fputs("?Invalid proxy command.\n", ttyout); fputs("?Invalid proxy command.\n", ttyout);
(void)fflush(ttyout);
code = -1; code = -1;
return; return;
} }
@ -1714,7 +1703,6 @@ doproxy(argc, argv)
pswitch(1); pswitch(1);
if (c->c_conn && !connected) { if (c->c_conn && !connected) {
fputs("Not connected.\n", ttyout); fputs("Not connected.\n", ttyout);
(void)fflush(ttyout);
pswitch(0); pswitch(0);
(void)signal(SIGINT, oldintr); (void)signal(SIGINT, oldintr);
code = -1; code = -1;

View File

@ -1,4 +1,4 @@
/* $NetBSD: fetch.c,v 1.47 1999/01/23 15:46:24 lukem Exp $ */ /* $NetBSD: fetch.c,v 1.48 1999/01/24 02:39:30 lukem Exp $ */
/*- /*-
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@ -38,7 +38,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#ifndef lint #ifndef lint
__RCSID("$NetBSD: fetch.c,v 1.47 1999/01/23 15:46:24 lukem Exp $"); __RCSID("$NetBSD: fetch.c,v 1.48 1999/01/24 02:39:30 lukem Exp $");
#endif /* not lint */ #endif /* not lint */
/* /*
@ -883,7 +883,6 @@ fetch_url(url, outfile, proxyenv, proxyauth, wwwauth)
if (bytes < mark) if (bytes < mark)
(void)putc('#', ttyout); (void)putc('#', ttyout);
(void)putc('\n', ttyout); (void)putc('\n', ttyout);
(void)fflush(ttyout);
} }
if (ferror(fin)) { if (ferror(fin)) {
warn("Reading file"); warn("Reading file");
@ -948,7 +947,6 @@ aborthttp(notused)
alarmtimer(0); alarmtimer(0);
fputs("\nHTTP fetch aborted.\n", ttyout); fputs("\nHTTP fetch aborted.\n", ttyout);
(void)fflush(ttyout);
longjmp(httpabort, 1); longjmp(httpabort, 1);
} }

View File

@ -1,4 +1,4 @@
.\" $NetBSD: ftp.1,v 1.31 1999/01/23 15:46:24 lukem Exp $ .\" $NetBSD: ftp.1,v 1.32 1999/01/24 02:39:30 lukem Exp $
.\" .\"
.\" Copyright (c) 1985, 1989, 1990, 1993 .\" Copyright (c) 1985, 1989, 1990, 1993
.\" The Regents of the University of California. All rights reserved. .\" The Regents of the University of California. All rights reserved.
@ -173,15 +173,24 @@ seconds.
.It Fl t .It Fl t
Enables packet tracing. Enables packet tracing.
.It Fl v .It Fl v
Enable verbose mode. Enable
This is the default if input is from a terminal. .Ic verbose
and
.Ic progress .
This is the default if output is to a terminal (and in the case of
.Ic progress ,
.Nm
is the foreground process).
Forces Forces
.Nm .Nm
to show all responses from the remote server, as well to show all responses from the remote server, as well
as report on data transfer statistics. as report on data transfer statistics.
.It Fl V .It Fl V
Disable verbose mode, overriding the default of enabled when input Disable
is from a terminal. .Ic verbose
and
.Ic progress ,
overriding the default of enabled when output is to a terminal.
.El .El
.Pp .Pp
The client host with which The client host with which
@ -719,7 +728,7 @@ Retrieve
and display with the program defined in and display with the program defined in
.Ev PAGER .Ev PAGER
(which defaults to (which defaults to
.Xr less 1 ). .Xr more 1 ).
.It Ic passive .It Ic passive
Toggle passive mode. If passive mode is turned on Toggle passive mode. If passive mode is turned on
(default is off), the ftp client will (default is off), the ftp client will

View File

@ -1,4 +1,4 @@
/* $NetBSD: ftp.c,v 1.39 1999/01/05 23:33:44 lukem Exp $ */ /* $NetBSD: ftp.c,v 1.40 1999/01/24 02:39:30 lukem Exp $ */
/* /*
* Copyright (c) 1985, 1989, 1993, 1994 * Copyright (c) 1985, 1989, 1993, 1994
@ -38,7 +38,7 @@
#if 0 #if 0
static char sccsid[] = "@(#)ftp.c 8.6 (Berkeley) 10/27/94"; static char sccsid[] = "@(#)ftp.c 8.6 (Berkeley) 10/27/94";
#else #else
__RCSID("$NetBSD: ftp.c,v 1.39 1999/01/05 23:33:44 lukem Exp $"); __RCSID("$NetBSD: ftp.c,v 1.40 1999/01/24 02:39:30 lukem Exp $");
#endif #endif
#endif /* not lint */ #endif /* not lint */
@ -202,7 +202,6 @@ cmdabort(notused)
alarmtimer(0); alarmtimer(0);
putc('\n', ttyout); putc('\n', ttyout);
(void)fflush(ttyout);
abrtflag++; abrtflag++;
if (ptflag) if (ptflag)
longjmp(ptabort, 1); longjmp(ptabort, 1);
@ -241,7 +240,6 @@ command(va_alist)
vfprintf(ttyout, fmt, ap); vfprintf(ttyout, fmt, ap);
va_end(ap); va_end(ap);
putc('\n', ttyout); putc('\n', ttyout);
(void)fflush(ttyout);
} }
if (cout == NULL) { if (cout == NULL) {
warnx("No control connection for command."); warnx("No control connection for command.");
@ -317,7 +315,6 @@ getreply(expecteof)
fputs( fputs(
"421 Service not available, remote server has closed connection.\n", "421 Service not available, remote server has closed connection.\n",
ttyout); ttyout);
(void)fflush(ttyout);
} }
code = 421; code = 421;
return (4); return (4);
@ -409,7 +406,6 @@ abortsend(notused)
mflag = 0; mflag = 0;
abrtflag = 0; abrtflag = 0;
fputs("\nsend aborted\nwaiting for remote to finish abort.\n", ttyout); fputs("\nsend aborted\nwaiting for remote to finish abort.\n", ttyout);
(void)fflush(ttyout);
longjmp(sendabort, 1); longjmp(sendabort, 1);
} }
@ -607,7 +603,6 @@ sendrequest(cmd, local, remote, printnames)
if (bytes < mark) if (bytes < mark)
(void)putc('#', ttyout); (void)putc('#', ttyout);
(void)putc('\n', ttyout); (void)putc('\n', ttyout);
(void)fflush(ttyout);
} }
if (c < 0) if (c < 0)
warn("local: %s", local); warn("local: %s", local);
@ -645,7 +640,6 @@ sendrequest(cmd, local, remote, printnames)
if (bytes < hashbytes) if (bytes < hashbytes)
(void)putc('#', ttyout); (void)putc('#', ttyout);
(void)putc('\n', ttyout); (void)putc('\n', ttyout);
(void)fflush(ttyout);
} }
if (ferror(fin)) if (ferror(fin))
warn("local: %s", local); warn("local: %s", local);
@ -706,7 +700,6 @@ abortrecv(notused)
abrtflag = 0; abrtflag = 0;
fputs("\nreceive aborted\nwaiting for remote to finish abort.\n", fputs("\nreceive aborted\nwaiting for remote to finish abort.\n",
ttyout); ttyout);
(void)fflush(ttyout);
longjmp(recvabort, 1); longjmp(recvabort, 1);
} }
@ -933,7 +926,6 @@ recvrequest(cmd, local, remote, lmode, printnames, ignorespecial)
if (bytes < mark) if (bytes < mark)
(void)putc('#', ttyout); (void)putc('#', ttyout);
(void)putc('\n', ttyout); (void)putc('\n', ttyout);
(void)fflush(ttyout);
} }
if (c < 0) { if (c < 0) {
if (errno != EPIPE) if (errno != EPIPE)
@ -1011,7 +1003,6 @@ break2:
if (bytes < hashbytes) if (bytes < hashbytes)
(void)putc('#', ttyout); (void)putc('#', ttyout);
(void)putc('\n', ttyout); (void)putc('\n', ttyout);
(void)fflush(ttyout);
} }
if (ferror(din)) { if (ferror(din)) {
if (errno != EPIPE) if (errno != EPIPE)
@ -1379,7 +1370,6 @@ abortpt(notused)
alarmtimer(0); alarmtimer(0);
putc('\n', ttyout); putc('\n', ttyout);
(void)fflush(ttyout);
ptabflg++; ptabflg++;
mflag = 0; mflag = 0;
abrtflag = 0; abrtflag = 0;

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.36 1999/01/23 15:46:25 lukem Exp $ */ /* $NetBSD: main.c,v 1.37 1999/01/24 02:39:30 lukem Exp $ */
/* /*
* Copyright (c) 1985, 1989, 1993, 1994 * Copyright (c) 1985, 1989, 1993, 1994
@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1985, 1989, 1993, 1994\n\
#if 0 #if 0
static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 10/9/94"; static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 10/9/94";
#else #else
__RCSID("$NetBSD: main.c,v 1.36 1999/01/23 15:46:25 lukem Exp $"); __RCSID("$NetBSD: main.c,v 1.37 1999/01/24 02:39:30 lukem Exp $");
#endif #endif
#endif /* not lint */ #endif /* not lint */
@ -174,18 +174,17 @@ main(argc, argv)
else else
dumbterm = 0; dumbterm = 0;
fromatty = isatty(fileno(stdin)); fromatty = isatty(fileno(stdin));
if (fromatty) { ttyout = stdout;
if (isatty(fileno(ttyout))) {
verbose = 1; /* verbose if from a tty */ verbose = 1; /* verbose if from a tty */
#ifndef SMALL #ifndef SMALL
if (! dumbterm) if (! dumbterm) {
editing = 1; /* editing mode on if tty is usable */ editing = 1; /* editing mode on if tty is usable */
if (foregroundproc())
progress = 1; /* progress bar on if fg */
}
#endif #endif
} }
ttyout = stdout;
#ifndef SMALL
if (isatty(fileno(ttyout)) && !dumbterm && foregroundproc())
progress = 1; /* progress bar on if tty is usable */
#endif
while ((ch = getopt(argc, argv, "Aadefgino:pP:r:tvV")) != -1) { while ((ch = getopt(argc, argv, "Aadefgino:pP:r:tvV")) != -1) {
switch (ch) { switch (ch) {
@ -256,17 +255,19 @@ main(argc, argv)
break; break;
case 'v': case 'v':
verbose = 1; progress = verbose = 1;
break; break;
case 'V': case 'V':
verbose = 0; progress = verbose = 0;
break; break;
default: default:
usage(); usage();
} }
} }
/* set line buffering on ttyout */
setvbuf(ttyout, NULL, _IOLBF, 0);
argc -= optind; argc -= optind;
argv += optind; argv += optind;

View File

@ -1,13 +1,16 @@
/* $NetBSD: util.c,v 1.40 1999/01/05 22:54:49 lukem Exp $ */ /* $NetBSD: util.c,v 1.41 1999/01/24 02:39:30 lukem Exp $ */
/*- /*-
* Copyright (c) 1998 The NetBSD Foundation, Inc. * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
* All rights reserved. * All rights reserved.
* *
* This code is derived from software contributed to The NetBSD Foundation * This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
* NASA Ames Research Center. * NASA Ames Research Center.
* *
* This code is derived from software contributed to The NetBSD Foundation
* by Luke Mewburn.
*
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
@ -72,7 +75,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#ifndef lint #ifndef lint
__RCSID("$NetBSD: util.c,v 1.40 1999/01/05 22:54:49 lukem Exp $"); __RCSID("$NetBSD: util.c,v 1.41 1999/01/24 02:39:30 lukem Exp $");
#endif /* not lint */ #endif /* not lint */
/* /*
@ -882,7 +885,7 @@ progressmeter(flag)
"%02d:%02d ETA", i / 60, i % 60); "%02d:%02d ETA", i / 60, i % 60);
} }
} }
(void)write(fileno(ttyout), buf, len); (void)fwrite(buf, sizeof(char), len, ttyout);
if (flag == -1) { if (flag == -1) {
(void)xsignal(SIGALRM, updateprogressmeter); (void)xsignal(SIGALRM, updateprogressmeter);
@ -980,7 +983,7 @@ ptransfer(siginfo)
" (stalled)"); " (stalled)");
} }
len += snprintf(buf + len, sizeof(buf) - len, "\n"); len += snprintf(buf + len, sizeof(buf) - len, "\n");
(void)write(siginfo ? STDERR_FILENO : fileno(ttyout), buf, len); (void)fwrite(buf, sizeof(char), len, siginfo ? stderr : ttyout);
#endif /* SMALL */ #endif /* SMALL */
} }