Free Software
utzoo!decvax!duke!ucf-cs!whm
utzoo!decvax!duke!ucf-cs!whm
Sat Apr 3 02:58:29 AEST 1982
Here's a program that you may find to be useful.
Bill Mitchell
Univ. of Central Florida
----------------------------------------------------------------------------
/*
* ok - selectively echo command line arguments
*
* Usage:
* ok [-y] arguments
*
* Each command line argument is printed on stderr followed by a question
* mark. If the response to the prompt is a "y", the argument will be
* printed on stdout. If the response to the prompt is a ".", the
* program will stop and the arguments previously selected will be
* flushed into stdout. If the response is a "*", all of the arguments
* yet to be selected will be selected and flushed onto stdout along
* with previous selections. If the response is a <cr>, the argument
* will not be selected unless -y was specified in which case a <cr>
* indicates to select the given argument.
*
* Ok is typically used to put a rudimentary type of confirmation on
* commands without confirmation options. Examples of use:
* tar c `ok *.c`
* pr `ok *`
*
* Author/Acknowledgements:
* Bill Mitchell
*
* Created from a dim memory of the Amdahl Unix "pick"(?) command.
*
* Bugs
* Written hastily for a specialized application.
* This should be a manual page instead of a bunch of comments.
* The whole program should be replaced by a shell function.
*/
#include <stdio.h>
main(argc,argv)
int argc; char **argv;
{
char **ap,c;
char ans[10];
int allflag, nb;
char def = 'n';
if (strcmp(argv[1],"-y") == 0) {
def = 'y';
argv++;
}
for (ap = ++argv; *ap != 0; ap++) {
if (allflag) {
fprintf(stdout,"%s ",*ap);
continue;
}
fprintf(stderr,"%s? ",*ap);
fflush(stderr);
nb = read(0,ans,10);
c = (nb == 1) ? def : ans[0];
if (c == '.')
break;
if (c == '*')
allflag++;
if ((c == 'y') || allflag)
fprintf(stdout,"%s ",*ap);
}
fprintf(stdout,"\n");
}
More information about the Comp.sources.unix
mailing list