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 "*** Project Athena User 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);
119 mvwprintw (midw, 0, 0, "%-24s", user.u_mid_init);
120 mvwprintw (lnamew, 0, 0, "%-24s", user.u_last);
121 mvwprintw (idw, 0, 0, "%-24s", typed_mit_id);
122 mvwprintw (loginw, 0, 0, "%-24s", user.u_login);
128 /* Input and input_no_echo exist only to save on retyping */
129 input (prompt, buf, maxsize, timeout, emptyok)
132 int maxsize, timeout, emptyok;
134 query_user (prompt, buf, maxsize, timeout, TRUE, emptyok, TRUE);
137 input_no_echo (prompt, buf, maxsize, timeout)
140 int maxsize, timeout;
142 query_user (prompt, buf, maxsize, timeout, FALSE, FALSE, TRUE);
146 /* make the user press any key to continue */
152 query_user ("Press RETURN or ENTER to continue", buf, 1,
153 15 * 60, FALSE, TRUE, FALSE);
157 /* Gets input through the query buffer */
158 /* Exit(1)'s on read errors */
159 /* Signals SIGALRM after 'timeout' seconds */
160 query_user (prompt, buf, maxsize, timeout, echop, emptyok, valuep)
163 int maxsize, timeout;
164 bool echop, emptyok, valuep;
171 /* Set up interval timer */
172 it.it_interval.tv_sec = 0;
173 it.it_interval.tv_usec = 0;
174 it.it_value.tv_sec = timeout;
175 it.it_value.tv_usec = 0;
176 setitimer (ITIMER_REAL, &it, (struct itimerval *) 0);
178 /* Erase the query window and put up a prompt */
180 mvwaddstr (queryw, 0, 0, prompt);
181 waddch (queryw, ' '); /* Put in a space, as Blox does */
185 while ((c = getchar ()) != '\r') {
187 case '\025': /* Ctl-U */
191 /* We're in raw mode, so EOF means disaster */
195 case '\177': /* Delete */
196 case '\010': /* Backspace */
200 wmove (queryw, queryw -> _cury, queryw -> _curx - 1);
206 case '\003': /* Ctrl-C */
208 { clear(); /* Exit if not root. */
216 if (c >= ' ') { /* Ignore all other control chars */
225 if (valuep && i >= maxsize) {
228 "You are not allowed to type more than %d characters for this answer.\n",
236 if (emptyok && valuep &&
237 (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, (struct itimerval *) 0);
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. */
273 mvwaddstr (queryw, 0, 0, prompt);
276 xpos = queryw->_curx;
277 ypos = queryw->_cury;
278 answer = 2; /* No answer. */
280 /* Reset interval timer for y/n question. */
281 it.it_interval.tv_sec = 0;
282 it.it_interval.tv_usec = 0;
283 it.it_value.tv_sec = YN_TIMEOUT;
284 it.it_value.tv_usec = 0;
285 setitimer (ITIMER_REAL, &it, (struct itimerval *) 0);
287 while ((c = getchar ()) != '\r') { /* Wait for CR. */
291 wmove(queryw, ypos, xpos);
293 waddstr(queryw, "no");
299 wmove(queryw, ypos, xpos);
301 waddstr(queryw, "yes");
305 case '\177': /* Delete */
306 case '\010': /* Backspace */
307 case '\025': /* Ctl-U */
308 wmove(queryw, ypos, xpos);
311 answer = 2; /* No answer. */
314 /* We're in raw mode, so EOF means disaster */
317 case '\003': /* Ctrl-C */
318 /* if (getuid() != 0) */
319 { clear(); /* Exit if not root. */
324 default: /* Ignore everything else. */
329 if (answer == 2) /* No answer. */
330 { display_text_line(0);
331 display_text_line("Please answer y or n.");
338 /* Display_text_line puts up a line of text in the display window */
339 /* Special case: if line is 0, clear the display area */
340 display_text_line (line)
344 waddstr (displayw, line);
345 waddch (displayw, '\n');
354 /* Display_text displays a canned message from a file */
355 display_text (filename)
362 if ((fp = fopen (filename, "r")) == NULL) {
363 wprintw (displayw, "Can't open file %s for reading.\n", filename);
367 while (fgets (buf, 100, fp)) {
368 /* get rid of the newline */
369 buf[strlen (buf) - 1] = 0;
370 display_text_line (buf);
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);