Aucf-cs.493
net.sources
utcsrgv!utzoo!decvax!duke!ucf-cs!whm
Sat Apr  3 02:58:29 1982
Free Software
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");
}

-----------------------------------------------------------------
gopher://quux.org/ conversion by John Goerzen <[email protected]>
of http://communication.ucsd.edu/A-News/


This Usenet Oldnews Archive
article may be copied and distributed freely, provided:

1. There is no money collected for the text(s) of the articles.

2. The following notice remains appended to each copy:

The Usenet Oldnews Archive: Compilation Copyright (C) 1981, 1996
Bruce Jones, Henry Spencer, David Wiseman.