7 * (c) Copyright 1988 by the Massachusetts Institute of Technology.
8 * For copying and distribution information, please see the file
13 static char *rcsid_display_c = "$Header$";
16 #include <mit-copyright.h>
23 #define HEADER "*** Athena User Account Registration ***"
24 #define HELP " Press backspace to delete a character. Press Ctrl-C to start over."
25 #define BORDER_CHAR '-'
29 WINDOW * displayw, *queryw;
30 WINDOW * dataw, *helpw;
31 WINDOW * fnamew, *midw, *lnamew, *idw, *loginw;
32 extern char typed_mit_id[100];
34 /* Set up the windows and subwindows on the display */
39 initscr(); /* Start up curses */
41 if (COLS < MIN_COLS || LINES < MIN_LINES)
43 fprintf(stderr, "Screen must be at least %d x %d\n",
48 noecho(); /* And the tty input */
50 freopen("/dev/null", "w", stderr);/* Toss the standard error output */
52 /* Make sure the place is clean */
55 /* Set up the top-level windows */
56 /* First line is the header */
57 displayw = subwin(stdscr, 12, 0, 2, 0);/* Lines 2-13 */
58 scrollok(displayw, TRUE);
60 queryw = subwin(stdscr, 1, 0, 15, 0);/* Line 15 */
61 scrollok(queryw, TRUE);
63 dataw = subwin(stdscr, 5, 0, 17, 0);/* Lines 17-21 */
65 /* Set up the data windows */
66 fnamew = subwin(stdscr, 1, 0, 17, DESC_WIDTH);
67 midw = subwin(stdscr, 1, 0, 18, DESC_WIDTH);
68 lnamew = subwin(stdscr, 1, 0, 19, DESC_WIDTH);
69 idw = subwin(stdscr, 1, 0, 20, DESC_WIDTH);
70 loginw = subwin(stdscr, 1, 0, 21, DESC_WIDTH);
73 /* Clear and restore the display */
78 /* Put back the borders */
84 /* Put in the window dressing */
86 waddstr(dataw, "First Name:\n");
87 waddstr(dataw, "Middle Initial:\n");
88 waddstr(dataw, "Family Name:\n");
89 waddstr(dataw, "MIT ID #:\n\n");
90 waddstr(dataw, "Username:\n");
93 /* Set up the header */
94 mvaddstr(0, (COLS - strlen (HEADER)) / 2, HEADER);
95 mvaddstr(23, 0, HELP);
102 /* Make a one-line border on line l of stdscr */
108 for(i = 0; i < COLS - 1; i++)
112 /* This replaces several "useful" display functions in the old userreg */
115 mvwprintw(fnamew, 0, 0, "%-24s", user.u_first);
117 mvwprintw(midw, 0, 0, "%-24s", user.u_mid_init);
119 mvwprintw(lnamew, 0, 0, "%-24s", user.u_last);
121 mvwprintw(idw, 0, 0, "%-24s", typed_mit_id);
123 mvwprintw(loginw, 0, 0, "%-24s", user.u_login);
128 /* Input and input_no_echo exist only to save on retyping */
129 input(char *prompt, char *buf, int maxsize, int timeout, int emptyok)
131 query_user(prompt, buf, maxsize, timeout, TRUE, emptyok, TRUE);
134 input_no_echo(char *prompt, char *buf, int maxsize, int timeout)
136 query_user(prompt, buf, maxsize, timeout, FALSE, FALSE, TRUE);
140 /* make the user press any key to continue */
146 query_user("Press RETURN or ENTER to continue", buf, 1,
147 15 * 60, FALSE, TRUE, FALSE);
151 /* Gets input through the query buffer */
152 /* Exit(1)'s on read errors */
153 /* Signals SIGALRM after 'timeout' seconds */
154 query_user(char *prompt, char *buf, int maxsize, int timeout,
155 int echop, int emptyok, int valuep)
162 /* Set up interval timer */
163 it.it_interval.tv_sec = 0;
164 it.it_interval.tv_usec = 0;
165 it.it_value.tv_sec = timeout;
166 it.it_value.tv_usec = 0;
167 setitimer(ITIMER_REAL, &it, NULL);
169 /* Erase the query window and put up a prompt */
171 mvwaddstr(queryw, 0, 0, prompt);
172 waddch(queryw, ' '); /* Put in a space, as Blox does */
176 while ((c = getchar()) != '\r' && c != '\n')
180 case '\025': /* Ctl-U */
183 /* We're in raw mode, so EOF means disaster */
187 case '\177': /* Delete */
188 case '\010': /* Backspace */
196 wmove(queryw, y, x - 1);
202 case '\003': /* Ctrl-C */
208 if (c >= ' ') /* Ignore all other control chars */
219 if (valuep && i >= maxsize)
222 wprintw(displayw, "You are not allowed to type more than %d "
223 "characters for this answer.\n", maxsize - 1);
231 if (emptyok && valuep &&
232 (askyn("Do you really want this field left blank (y/n)? ") == NO))
236 wprintw(displayw, "You must enter something here.\n");
243 /* Input is complete so disable interval timer. */
244 it.it_interval.tv_sec = 0;
245 it.it_interval.tv_usec = 0;
246 it.it_value.tv_sec = 0;
247 it.it_value.tv_usec = 0;
248 setitimer(ITIMER_REAL, &it, NULL);
250 buf[i] = '\0'; /* Put a null on the end */
252 werase(queryw); /* Clean up the query window */
255 return; /* And get out of here. */
258 int askyn(char *prompt)
267 mvwaddstr(queryw, 0, 0, prompt);
270 getyx(queryw, ypos, xpos);
271 answer = 2; /* No answer. */
273 /* Reset interval timer for y/n question. */
274 it.it_interval.tv_sec = 0;
275 it.it_interval.tv_usec = 0;
276 it.it_value.tv_sec = YN_TIMEOUT;
277 it.it_value.tv_usec = 0;
278 setitimer(ITIMER_REAL, &it, NULL);
280 while ((c = getchar ()) != '\r' && c != '\n') /* Wait for CR. */
286 wmove(queryw, ypos, xpos);
288 waddstr(queryw, "no");
294 wmove(queryw, ypos, xpos);
296 waddstr(queryw, "yes");
300 case '\177': /* Delete */
301 case '\010': /* Backspace */
302 case '\025': /* Ctl-U */
303 wmove(queryw, ypos, xpos);
306 answer = 2; /* No answer. */
309 /* We're in raw mode, so EOF means disaster */
312 case '\003': /* Ctrl-C */
317 default: /* Ignore everything else. */
322 if (answer == 2) /* No answer. */
324 display_text_line(0);
325 display_text_line("Please answer y or n.");
332 /* Display_text_line puts up a line of text in the display window */
333 /* Special case: if line is 0, clear the display area */
334 display_text_line(char *line)
338 waddstr(displayw, line);
339 waddch(displayw, '\n');
346 /* Display_text displays a canned message from a file. The string
347 * will get imbedded in any %s's in the text.
349 display_text(char *filename, char *string)
352 char buf[100], buf1[110];
355 if (!(fp = fopen (filename, "r")))
357 wprintw (displayw, "Can't open file %s for reading.\n", filename);
361 while (fgets (buf, 100, fp))
363 /* get rid of the newline */
364 buf[strlen(buf) - 1] = '\0';
365 sprintf(buf1, buf, string);
366 waddstr(displayw, buf1);
367 waddch(displayw, '\n');
374 /* Clear_display wipes the display and turns off curses */
375 restore_display(void)
388 it.it_interval.tv_sec = 0;
389 it.it_interval.tv_usec = 0;
390 it.it_value.tv_sec = TIMER_TIMEOUT;
391 it.it_value.tv_usec = 0;
392 setitimer(ITIMER_REAL, &it, NULL);
399 it.it_interval.tv_sec = 0;
400 it.it_interval.tv_usec = 0;
401 it.it_value.tv_sec = 0;
402 it.it_value.tv_usec = 0;
403 setitimer(ITIMER_REAL, &it, NULL);