3 * Display function for userreg client
5 * Copyright (C) 1988-1998 by the Massachusetts Institute of Technology.
6 * For copying and distribution information, please see the file
10 #include <mit-copyright.h>
24 void make_border(int l);
25 void query_user(char *prompt, char *buf, int maxsize, int timeout,
26 int echop, int emptyok, int valuep);
29 #define HEADER "*** Athena User Account Registration ***"
30 #define HELP " Press backspace to delete a character. Press Ctrl-C to start over."
31 #define BORDER_CHAR '-'
35 WINDOW *displayw, *queryw;
36 WINDOW *dataw, *helpw;
37 WINDOW *fnamew, *midw, *lnamew, *idw, *loginw;
38 extern char typed_mit_id[100];
40 /* Set up the windows and subwindows on the display */
41 void setup_display(void)
43 initscr(); /* Start up curses */
45 if (COLS < MIN_COLS || LINES < MIN_LINES)
47 fprintf(stderr, "Screen must be at least %d x %d\n",
52 noecho(); /* And the tty input */
54 freopen("/dev/null", "w", stderr);/* Toss the standard error output */
56 /* Make sure the place is clean */
59 /* Set up the top-level windows */
60 /* First line is the header */
61 displayw = subwin(stdscr, 12, 0, 2, 0);/* Lines 2-13 */
62 scrollok(displayw, TRUE);
64 queryw = subwin(stdscr, 1, 0, 15, 0);/* Line 15 */
65 scrollok(queryw, TRUE);
67 dataw = subwin(stdscr, 5, 0, 17, 0);/* Lines 17-21 */
69 /* Set up the data windows */
70 fnamew = subwin(stdscr, 1, 0, 17, DESC_WIDTH);
71 midw = subwin(stdscr, 1, 0, 18, DESC_WIDTH);
72 lnamew = subwin(stdscr, 1, 0, 19, DESC_WIDTH);
73 idw = subwin(stdscr, 1, 0, 20, DESC_WIDTH);
74 loginw = subwin(stdscr, 1, 0, 21, DESC_WIDTH);
77 /* Clear and restore the display */
78 void reset_display(void)
82 /* Put back the borders */
88 /* Put in the window dressing */
90 waddstr(dataw, "First Name:\n");
91 waddstr(dataw, "Middle Initial:\n");
92 waddstr(dataw, "Family Name:\n");
93 waddstr(dataw, "MIT ID #:\n\n");
94 waddstr(dataw, "Username:\n");
97 /* Set up the header */
98 mvaddstr(0, (COLS - strlen (HEADER)) / 2, HEADER);
99 mvaddstr(23, 0, HELP);
106 /* Make a one-line border on line l of stdscr */
107 void make_border(int l)
112 for(i = 0; i < COLS - 1; i++)
116 /* This replaces several "useful" display functions in the old userreg */
119 mvwprintw(fnamew, 0, 0, "%-24s", user.u_first);
121 mvwprintw(midw, 0, 0, "%-24s", user.u_mid_init);
123 mvwprintw(lnamew, 0, 0, "%-24s", user.u_last);
125 mvwprintw(idw, 0, 0, "%-24s", typed_mit_id);
127 mvwprintw(loginw, 0, 0, "%-24s", user.u_login);
132 /* Input and input_no_echo exist only to save on retyping */
133 void input(char *prompt, char *buf, int maxsize, int timeout, int emptyok)
135 query_user(prompt, buf, maxsize, timeout, TRUE, emptyok, TRUE);
138 void input_no_echo(char *prompt, char *buf, int maxsize, int timeout)
140 query_user(prompt, buf, maxsize, timeout, FALSE, FALSE, TRUE);
144 /* make the user press any key to continue */
145 void wait_for_user(void)
150 query_user("Press RETURN or ENTER to continue", buf, 1,
151 15 * 60, FALSE, TRUE, FALSE);
155 /* Gets input through the query buffer */
156 /* Exit(1)'s on read errors */
157 /* Signals SIGALRM after 'timeout' seconds */
158 void query_user(char *prompt, char *buf, int maxsize, int timeout,
159 int echop, int emptyok, int valuep)
166 /* Set up interval timer */
167 it.it_interval.tv_sec = 0;
168 it.it_interval.tv_usec = 0;
169 it.it_value.tv_sec = timeout;
170 it.it_value.tv_usec = 0;
171 setitimer(ITIMER_REAL, &it, NULL);
173 /* Erase the query window and put up a prompt */
175 mvwaddstr(queryw, 0, 0, prompt);
176 waddch(queryw, ' '); /* Put in a space, as Blox does */
180 while ((c = getchar()) != '\r' && c != '\n')
184 case '\025': /* Ctl-U */
187 /* We're in raw mode, so EOF means disaster */
191 case '\177': /* Delete */
192 case '\010': /* Backspace */
200 wmove(queryw, y, x - 1);
206 case '\003': /* Ctrl-C */
212 if (c >= ' ') /* Ignore all other control chars */
223 if (valuep && i >= maxsize)
226 wprintw(displayw, "You are not allowed to type more than %d "
227 "characters for this answer.\n", maxsize - 1);
235 if (emptyok && valuep &&
236 (askyn("Do you really want this field left blank (y/n)? ") == NO))
240 wprintw(displayw, "You must enter something here.\n");
247 /* Input is complete so disable interval timer. */
248 it.it_interval.tv_sec = 0;
249 it.it_interval.tv_usec = 0;
250 it.it_value.tv_sec = 0;
251 it.it_value.tv_usec = 0;
252 setitimer(ITIMER_REAL, &it, NULL);
254 buf[i] = '\0'; /* Put a null on the end */
256 werase(queryw); /* Clean up the query window */
259 return; /* And get out of here. */
262 int askyn(char *prompt)
271 mvwaddstr(queryw, 0, 0, prompt);
274 getyx(queryw, ypos, xpos);
275 answer = 2; /* No answer. */
277 /* Reset interval timer for y/n question. */
278 it.it_interval.tv_sec = 0;
279 it.it_interval.tv_usec = 0;
280 it.it_value.tv_sec = YN_TIMEOUT;
281 it.it_value.tv_usec = 0;
282 setitimer(ITIMER_REAL, &it, NULL);
284 while ((c = getchar ()) != '\r' && c != '\n') /* Wait for CR. */
290 wmove(queryw, ypos, xpos);
292 waddstr(queryw, "no");
298 wmove(queryw, ypos, xpos);
300 waddstr(queryw, "yes");
304 case '\177': /* Delete */
305 case '\010': /* Backspace */
306 case '\025': /* Ctl-U */
307 wmove(queryw, ypos, xpos);
310 answer = 2; /* No answer. */
313 /* We're in raw mode, so EOF means disaster */
316 case '\003': /* Ctrl-C */
321 default: /* Ignore everything else. */
326 if (answer == 2) /* No answer. */
328 display_text_line(0);
329 display_text_line("Please answer y or n.");
336 /* Display_text_line puts up a line of text in the display window */
337 /* Special case: if line is 0, clear the display area */
338 void display_text_line(char *line)
342 waddstr(displayw, line);
343 waddch(displayw, '\n');
350 /* Display_text displays a canned message from a file. The string
351 * will get imbedded in any %s's in the text.
353 void display_text(char *filename, char *string)
356 char buf[100], buf1[110];
359 if (!(fp = fopen (filename, "r")))
361 wprintw (displayw, "Can't open file %s for reading.\n", filename);
365 while (fgets (buf, 100, fp))
367 /* get rid of the newline */
368 buf[strlen(buf) - 1] = '\0';
369 sprintf(buf1, buf, string);
370 waddstr(displayw, buf1);
371 waddch(displayw, '\n');
378 /* Clear_display wipes the display and turns off curses */
379 void restore_display(void)
392 it.it_interval.tv_sec = 0;
393 it.it_interval.tv_usec = 0;
394 it.it_value.tv_sec = TIMER_TIMEOUT;
395 it.it_value.tv_usec = 0;
396 setitimer(ITIMER_REAL, &it, NULL);
403 it.it_interval.tv_sec = 0;
404 it.it_interval.tv_usec = 0;
405 it.it_value.tv_sec = 0;
406 it.it_value.tv_usec = 0;
407 setitimer(ITIMER_REAL, &it, NULL);