|
|
1.1 root 1: /* interact.c -- routines for interacting with the user.
2: * part of uucheckname.
3: */
4: #include "uucheck.h"
5: #include "uucheckname.h"
6:
7: /* Get a yes or no from the user. Reprompt as necessary, give up after
8: * PATIENCE number of tries.
9: * Understands a wide variety of variations.
10: * Returns TRUE on yes, FALSE on no.
11: */
12: #define PATIENCE 10
13:
14: boolean
15: get_yes_or_no()
16: {
17: boolean have_answer = FALSE;
18: boolean answer;
19: unsigned int give_up_count = 0;
20:
21: while (!have_answer && give_up_count < PATIENCE) {
22: gets(bigbuf);
23:
24: if (lookup(bigbuf, yes_table) != NULL) {
25: answer = TRUE;
26: have_answer = TRUE;
27: } else if (lookup(bigbuf, no_table) != NULL) {
28: answer = FALSE;
29: have_answer = TRUE;
30: } /* if lookup bigbuf in yes_table, else no_table */
31:
32: /* If we still don't have a valid answer, prompt for one. */
33: if (!have_answer && ++give_up_count < PATIENCE) {
34: printf("Please enter y or n: ");
35: } /* if (!have_answer) */
36:
37: } /* while (!have_answer) */
38:
39: if (!have_answer) {
40: printf("PATIENCE exceeded; assuming \"no\" :-(.\n");
41: answer = FALSE;
42: } /* if (!have_answer) */
43:
44: return(answer);
45: } /* get_yes_or_no() */
46:
47: void
48: recreate_uucpname()
49: {
50: FILE *fp;
51:
52: MESSAGE("Recreating uucpname.\n");
53: printf("Please enter a new uucpname: ");
54: gets(bigbuf);
55: /* Open /etc/uucpname and write out the new name. */
56: if ((fp = fopen(NAMEFILE, "w")) == (FILE *) NULL) {
57: /* Remember, we should be root here. */
58: FATAL("How strange! I can't open %s for writing!\n", NAMEFILE);
59: } /* If can not open NAMEFILE. */
60: strcat(bigbuf, "\n");
61: fputs(bigbuf, fp);
62: fclose(fp);
63: /* Now re-check that name. */
64: error = FALSE;
65: warning = FALSE;
66: uucheckname();
67: } /* recreate_uucpname() */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.