|
|
1.1 root 1: /*
2: * ask a question yes or no via stderr.
3: */
4: #include <misc.h>
5:
6: yn(question)
7: char * question;
8: {
9: char reply[80];
10:
11: for (;;) {
12: fprintf(stderr, "%r <y/n> ", &question);
13: fflush(stderr);
14: if (NULL == gets(reply))
15: fatal("unexpected eof on stdin");
16: switch (*reply) {
17: case 'Y':
18: case 'y':
19: return (1);
20: case 'n':
21: case 'N':
22: return (0);
23: }
24: printf("You must answer Y or N\n");
25: }
26: }
27: #ifdef TEST
28: /*
29: * This test is a usefull program.
30: *
31: * Inquire on all items in argv and then put out the approved ones.
32: * An example of use is.
33: * pr `yn *.[ch]`
34: * This would inquire on all .c and .h files and send them through pr.
35: */
36: main(argc, argv)
37: register char *argv[];
38: {
39: register char *arg;
40:
41: while (NULL != (arg = *++argv))
42: if (yn("%s", arg))
43: puts(arg);
44: }
45: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.