* -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.
@ -75,7 +75,7 @@
#if 0
static char sccsid[] = "@(#)cmds.c 8.6 (Berkeley) 10/9/94";
#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 /* not lint */
@ -589,7 +589,6 @@ mabort(signo)
alarmtimer(0);
putc('\n', ttyout);
(void)fflush(ttyout);
if (mflag && fromatty) {
ointer = interactive;
oconf = confirmrest;
@ -756,13 +755,10 @@ togglevar(argc, argv, var, mesg)
*var = 0;
} else {
fprintf(ttyout, "usage: %s [ on | off ]\n", argv[0]);
(void)fflush(ttyout);
return (-1);
}
if (mesg) {
if (mesg)
fprintf(ttyout, "%s %s.\n", mesg, onoff(*var));
(void)fflush(ttyout);
}
return (*var);
}
@ -1209,9 +1205,6 @@ ls(argc, argv)
goto freels;
}
recvrequest(cmd, argv[2], argv[1], "w", 0, 0);
/* flush results in case commands are coming from a pipe */
fflush(ttyout);
freels:
if (argv[2] != globargv2) /* free up after globulize() */
free(argv[2]);
@ -1307,7 +1300,6 @@ shell(argc, argv)
if (debug) {
fputs(shell, ttyout);
putc('\n', ttyout);
(void)fflush(ttyout);
}
if (argc > 1) {
execl(shell, shellnam, "-c", altarg, (char *)0);
@ -1690,19 +1682,16 @@ doproxy(argc, argv)
c = getcmd(argv[1]);
if (c == (struct cmd *) -1) {
fputs("?Ambiguous command.\n", ttyout);
(void)fflush(ttyout);
code = -1;
return;
}
if (c == 0) {
fputs("?Invalid command.\n", ttyout);
(void)fflush(ttyout);
code = -1;
return;
}
if (!c->c_proxy) {
fputs("?Invalid proxy command.\n", ttyout);
(void)fflush(ttyout);
code = -1;
return;
}
@ -1714,7 +1703,6 @@ doproxy(argc, argv)
pswitch(1);
if (c->c_conn && !connected) {
fputs("Not connected.\n", ttyout);
(void)fflush(ttyout);
pswitch(0);
(void)signal(SIGINT, oldintr);
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.
@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#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 */
/*
@ -883,7 +883,6 @@ fetch_url(url, outfile, proxyenv, proxyauth, wwwauth)
if (bytes < mark)
(void)putc('#', ttyout);
(void)putc('\n', ttyout);
(void)fflush(ttyout);
}
if (ferror(fin)) {
warn("Reading file");
@ -948,7 +947,6 @@ aborthttp(notused)
alarmtimer(0);
fputs("\nHTTP fetch aborted.\n", ttyout);
(void)fflush(ttyout);
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
.\" The Regents of the University of California. All rights reserved.
@ -173,15 +173,24 @@ seconds.
.It Fl t
Enables packet tracing.
.It Fl v
Enable verbose mode.
This is the default if input is from a terminal.
Enable
.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
.Nm
to show all responses from the remote server, as well
as report on data transfer statistics.
.It Fl V
Disable verbose mode, overriding the default of enabled when input
is from a terminal.
Disable
.Ic verbose
and
.Ic progress ,
overriding the default of enabled when output is to a terminal.
.El
.Pp
The client host with which
@ -719,7 +728,7 @@ Retrieve
and display with the program defined in
.Ev PAGER
(which defaults to
.Xr less 1 ).
.Xr more 1 ).
.It Ic passive
Toggle passive mode. If passive mode is turned on
(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
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)ftp.c 8.6 (Berkeley) 10/27/94";
#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 /* not lint */
@ -202,7 +202,6 @@ cmdabort(notused)
alarmtimer(0);
putc('\n', ttyout);
(void)fflush(ttyout);
abrtflag++;
if (ptflag)
longjmp(ptabort, 1);
@ -241,7 +240,6 @@ command(va_alist)
vfprintf(ttyout, fmt, ap);
va_end(ap);
putc('\n', ttyout);
(void)fflush(ttyout);
}
if (cout == NULL) {
warnx("No control connection for command.");
@ -317,7 +315,6 @@ getreply(expecteof)
fputs(
"421 Service not available, remote server has closed connection.\n",
ttyout);
(void)fflush(ttyout);
}
code = 421;
return (4);
@ -409,7 +406,6 @@ abortsend(notused)
mflag = 0;
abrtflag = 0;
fputs("\nsend aborted\nwaiting for remote to finish abort.\n", ttyout);
(void)fflush(ttyout);
longjmp(sendabort, 1);
}
@ -607,7 +603,6 @@ sendrequest(cmd, local, remote, printnames)
if (bytes < mark)
(void)putc('#', ttyout);
(void)putc('\n', ttyout);
(void)fflush(ttyout);
}
if (c < 0)
warn("local: %s", local);
@ -645,7 +640,6 @@ sendrequest(cmd, local, remote, printnames)
if (bytes < hashbytes)
(void)putc('#', ttyout);
(void)putc('\n', ttyout);
(void)fflush(ttyout);
}
if (ferror(fin))
warn("local: %s", local);
@ -706,7 +700,6 @@ abortrecv(notused)
abrtflag = 0;
fputs("\nreceive aborted\nwaiting for remote to finish abort.\n",
ttyout);
(void)fflush(ttyout);
longjmp(recvabort, 1);
}
@ -933,7 +926,6 @@ recvrequest(cmd, local, remote, lmode, printnames, ignorespecial)
if (bytes < mark)
(void)putc('#', ttyout);
(void)putc('\n', ttyout);
(void)fflush(ttyout);
}
if (c < 0) {
if (errno != EPIPE)
@ -1011,7 +1003,6 @@ break2:
if (bytes < hashbytes)
(void)putc('#', ttyout);
(void)putc('\n', ttyout);
(void)fflush(ttyout);
}
if (ferror(din)) {
if (errno != EPIPE)
@ -1379,7 +1370,6 @@ abortpt(notused)
alarmtimer(0);
putc('\n', ttyout);
(void)fflush(ttyout);
ptabflg++;
mflag = 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
@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1985, 1989, 1993, 1994\n\
#if 0
static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 10/9/94";
#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 /* not lint */
@ -174,18 +174,17 @@ main(argc, argv)
else
dumbterm = 0;
fromatty = isatty(fileno(stdin));
if (fromatty) {
ttyout = stdout;
if (isatty(fileno(ttyout))) {
verbose = 1; /* verbose if from a tty */
#ifndef SMALL
if (! dumbterm)
if (! dumbterm) {
editing = 1; /* editing mode on if tty is usable */
if (foregroundproc())
progress = 1; /* progress bar on if fg */
}
#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) {
switch (ch) {
@ -256,17 +255,19 @@ main(argc, argv)
break;
case 'v':
verbose = 1;
progress = verbose = 1;
break;
case 'V':
verbose = 0;
progress = verbose = 0;
break;
default:
usage();
}
}
/* set line buffering on ttyout */
setvbuf(ttyout, NULL, _IOLBF, 0);
argc -= 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.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
* 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
* modification, are permitted provided that the following conditions
* are met:
@ -72,7 +75,7 @@
#include <sys/cdefs.h>
#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 */
/*
@ -882,7 +885,7 @@ progressmeter(flag)
"%02d:%02d ETA", i / 60, i % 60);
}
}
(void)write(fileno(ttyout), buf, len);
(void)fwrite(buf, sizeof(char), len, ttyout);
if (flag == -1) {
(void)xsignal(SIGALRM, updateprogressmeter);
@ -980,7 +983,7 @@ ptransfer(siginfo)
" (stalled)");
}
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 */
}