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 #if defined(vax) || defined(mips)
25 #define HELP " Press the key above RETURN to delete a character. Press Ctrl-C to start over."
28 #define HELP " Press backspace to delete a character. Press Ctrl-C to start over."
30 #define BORDER_CHAR '-'
34 WINDOW * displayw, *queryw;
35 WINDOW * dataw, *helpw;
36 WINDOW * fnamew, *midw, *lnamew, *idw, *loginw;
38 /* Set up the windows and subwindows on the display */
42 initscr (); /* Start up curses */
44 if (COLS < MIN_COLS || LINES < MIN_LINES) {
45 fprintf (stderr, "Screen must be at least %d x %d\n", MIN_LINES, MIN_COLS);
49 noecho (); /* And the tty input */
51 freopen ("/dev/null", "w", stderr);/* Toss the standard error output */
53 /* Make sure the place is clean */
56 /* Set up the top-level windows */
57 /* First line is the header */
58 displayw = subwin (stdscr, 12, 0, 2, 0);/* Lines 2-13 */
59 scrollok (displayw, TRUE);
61 queryw = subwin (stdscr, 1, 0, 15, 0);/* Line 15 */
62 scrollok (queryw, TRUE);
64 dataw = subwin (stdscr, 5, 0, 17, 0);/* Lines 17-21 */
66 /* Set up the data windows */
67 fnamew = subwin (stdscr, 1, 0, 17, DESC_WIDTH);
68 midw = subwin (stdscr, 1, 0, 18, DESC_WIDTH);
69 lnamew = subwin (stdscr, 1, 0, 19, DESC_WIDTH);
70 idw = subwin (stdscr, 1, 0, 20, DESC_WIDTH);
71 loginw = subwin (stdscr, 1, 0, 21, DESC_WIDTH);
75 /* Clear and restore the display */
79 /* Put back the borders */
86 /* Put in the window dressing */
88 waddstr (dataw, "First Name:\n");
89 waddstr (dataw, "Middle Initial:\n");
90 waddstr (dataw, "Family Name:\n");
91 waddstr (dataw, "MIT ID #:\n\n");
92 waddstr (dataw, "Username:\n");
95 /* Set up the header */
96 mvaddstr (0, (COLS - strlen (HEADER)) / 2, HEADER);
97 mvaddstr (23, 0, HELP);
104 /* Make a one-line border on line l of stdscr */
111 for (i = 0; i < COLS - 1; i++) {
116 /* This replaces several "useful" display functions in the old userreg */
118 mvwprintw (fnamew, 0, 0, "%-24s", user.u_first);
120 mvwprintw (midw, 0, 0, "%-24s", user.u_mid_init);
122 mvwprintw (lnamew, 0, 0, "%-24s", user.u_last);
124 mvwprintw (idw, 0, 0, "%-24s", typed_mit_id);
126 mvwprintw (loginw, 0, 0, "%-24s", user.u_login);
131 /* Input and input_no_echo exist only to save on retyping */
132 input (prompt, buf, maxsize, timeout, emptyok)
135 int maxsize, timeout, emptyok;
137 query_user (prompt, buf, maxsize, timeout, TRUE, emptyok, TRUE);
140 input_no_echo (prompt, buf, maxsize, timeout)
143 int maxsize, timeout;
145 query_user (prompt, buf, maxsize, timeout, FALSE, FALSE, TRUE);
149 /* make the user press any key to continue */
155 query_user ("Press RETURN or ENTER to continue", buf, 1,
156 15 * 60, FALSE, TRUE, FALSE);
160 /* Gets input through the query buffer */
161 /* Exit(1)'s on read errors */
162 /* Signals SIGALRM after 'timeout' seconds */
163 query_user (prompt, buf, maxsize, timeout, echop, emptyok, valuep)
166 int maxsize, timeout;
167 int echop, emptyok, valuep;
174 /* Set up interval timer */
175 it.it_interval.tv_sec = 0;
176 it.it_interval.tv_usec = 0;
177 it.it_value.tv_sec = timeout;
178 it.it_value.tv_usec = 0;
179 setitimer (ITIMER_REAL, &it, (struct itimerval *) 0);
181 /* Erase the query window and put up a prompt */
183 mvwaddstr (queryw, 0, 0, prompt);
184 waddch (queryw, ' '); /* Put in a space, as Blox does */
188 while ((c = getchar ()) != '\r' && c != '\n') {
190 case '\025': /* Ctl-U */
193 /* We're in raw mode, so EOF means disaster */
197 case '\177': /* Delete */
198 case '\010': /* Backspace */
202 wmove (queryw, queryw -> _cury, queryw -> _curx - 1);
208 case '\003': /* Ctrl-C */
214 if (c >= ' ') { /* Ignore all other control chars */
223 if (valuep && i >= maxsize) {
226 "You are not allowed to type more than %d characters for this answer.\n",
234 if (emptyok && valuep &&
235 (askyn("Do you really want this field left blank (y/n)? ") == NO))
238 wprintw(displayw, "You must enter something here.\n");
245 /* Input is complete so disable interval timer. */
246 it.it_interval.tv_sec = 0;
247 it.it_interval.tv_usec = 0;
248 it.it_value.tv_sec = 0;
249 it.it_value.tv_usec = 0;
250 setitimer (ITIMER_REAL, &it, (struct itimerval *) 0);
252 buf[i] = '\0'; /* Put a null on the end */
254 werase (queryw); /* Clean up the query window */
257 return; /* And get out of here. */
271 mvwaddstr (queryw, 0, 0, prompt);
274 xpos = queryw->_curx;
275 ypos = queryw->_cury;
276 answer = 2; /* No answer. */
278 /* Reset interval timer for y/n question. */
279 it.it_interval.tv_sec = 0;
280 it.it_interval.tv_usec = 0;
281 it.it_value.tv_sec = YN_TIMEOUT;
282 it.it_value.tv_usec = 0;
283 setitimer (ITIMER_REAL, &it, (struct itimerval *) 0);
285 while ((c = getchar ()) != '\r' && c != '\n') { /* Wait for CR. */
289 wmove(queryw, ypos, xpos);
291 waddstr(queryw, "no");
297 wmove(queryw, ypos, xpos);
299 waddstr(queryw, "yes");
303 case '\177': /* Delete */
304 case '\010': /* Backspace */
305 case '\025': /* Ctl-U */
306 wmove(queryw, ypos, xpos);
309 answer = 2; /* No answer. */
312 /* We're in raw mode, so EOF means disaster */
315 case '\003': /* Ctrl-C */
320 default: /* Ignore everything else. */
325 if (answer == 2) /* No answer. */
326 { display_text_line(0);
327 display_text_line("Please answer y or n.");
334 /* Display_text_line puts up a line of text in the display window */
335 /* Special case: if line is 0, clear the display area */
336 display_text_line (line)
340 waddstr (displayw, line);
341 waddch (displayw, '\n');
348 /* Display_text displays a canned message from a file. The string
349 * will get imbedded in any %s's in the text.
351 display_text(filename, string)
356 char buf[100], buf1[110];
359 if ((fp = fopen (filename, "r")) == NULL) {
360 wprintw (displayw, "Can't open file %s for reading.\n", filename);
364 while (fgets (buf, 100, fp)) {
365 /* get rid of the newline */
366 buf[strlen (buf) - 1] = 0;
367 sprintf(buf1, buf, string);
368 waddstr(displayw, buf1);
369 waddch(displayw, '\n');
376 /* Clear_display wipes the display and turns off curses */
390 it.it_interval.tv_sec = 0;
391 it.it_interval.tv_usec = 0;
392 it.it_value.tv_sec = TIMER_TIMEOUT;
393 it.it_value.tv_usec = 0;
394 setitimer (ITIMER_REAL, &it, (struct itimerval *) 0);
401 it.it_interval.tv_sec = 0;
402 it.it_interval.tv_usec = 0;
403 it.it_value.tv_sec = 0;
404 it.it_value.tv_usec = 0;
405 setitimer (ITIMER_REAL, &it, (struct itimerval *) 0);