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 ***"
25 #define HELP " Press backspace to delete a character. Press Ctrl-C to start over."
28 #define HELP " Press the key marked <X| 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;
39 /* Set up the windows and subwindows on the display */
43 initscr (); /* Start up curses */
45 if (COLS < MIN_COLS || LINES < MIN_LINES) {
46 fprintf (stderr, "Screen must be at least %d x %d\n", MIN_LINES, MIN_COLS);
50 noecho (); /* And the tty input */
52 freopen ("/dev/null", "w", stderr);/* Toss the standard error output */
54 /* Make sure the place is clean */
57 /* Set up the top-level windows */
58 /* First line is the header */
59 displayw = subwin (stdscr, 12, 0, 2, 0);/* Lines 2-13 */
60 scrollok (displayw, TRUE);
62 queryw = subwin (stdscr, 1, 0, 15, 0);/* Line 15 */
63 scrollok (queryw, TRUE);
65 dataw = subwin (stdscr, 5, 0, 17, 0);/* Lines 17-21 */
67 /* Set up the data windows */
68 fnamew = subwin (stdscr, 1, 0, 17, DESC_WIDTH);
69 midw = subwin (stdscr, 1, 0, 18, DESC_WIDTH);
70 lnamew = subwin (stdscr, 1, 0, 19, DESC_WIDTH);
71 idw = subwin (stdscr, 1, 0, 20, DESC_WIDTH);
72 loginw = subwin (stdscr, 1, 0, 21, DESC_WIDTH);
76 /* Clear and restore the display */
80 /* Put back the borders */
87 /* Put in the window dressing */
89 waddstr (dataw, "First Name:\n");
90 waddstr (dataw, "Middle Initial:\n");
91 waddstr (dataw, "Family Name:\n");
92 waddstr (dataw, "MIT ID #:\n\n");
93 waddstr (dataw, "Username:\n");
96 /* Set up the header */
97 mvaddstr (0, (COLS - strlen (HEADER)) / 2, HEADER);
98 mvaddstr (23, 0, HELP);
105 /* Make a one-line border on line l of stdscr */
112 for (i = 0; i < COLS - 1; i++) {
117 /* This replaces several "useful" display functions in the old userreg */
119 mvwprintw (fnamew, 0, 0, "%-24s", user.u_first);
120 mvwprintw (midw, 0, 0, "%-24s", user.u_mid_init);
121 mvwprintw (lnamew, 0, 0, "%-24s", user.u_last);
122 mvwprintw (idw, 0, 0, "%-24s", typed_mit_id);
123 mvwprintw (loginw, 0, 0, "%-24s", user.u_login);
129 /* Input and input_no_echo exist only to save on retyping */
130 input (prompt, buf, maxsize, timeout, emptyok)
133 int maxsize, timeout, emptyok;
135 query_user (prompt, buf, maxsize, timeout, TRUE, emptyok, TRUE);
138 input_no_echo (prompt, buf, maxsize, timeout)
141 int maxsize, timeout;
143 query_user (prompt, buf, maxsize, timeout, FALSE, FALSE, TRUE);
147 /* make the user press any key to continue */
153 query_user ("Press RETURN or ENTER to continue", buf, 1,
154 15 * 60, FALSE, TRUE, FALSE);
158 /* Gets input through the query buffer */
159 /* Exit(1)'s on read errors */
160 /* Signals SIGALRM after 'timeout' seconds */
161 query_user (prompt, buf, maxsize, timeout, echop, emptyok, valuep)
164 int maxsize, timeout;
165 bool echop, emptyok, valuep;
172 /* Set up interval timer */
173 it.it_interval.tv_sec = 0;
174 it.it_interval.tv_usec = 0;
175 it.it_value.tv_sec = timeout;
176 it.it_value.tv_usec = 0;
177 setitimer (ITIMER_REAL, &it, (struct itimerval *) 0);
179 /* Erase the query window and put up a prompt */
181 mvwaddstr (queryw, 0, 0, prompt);
182 waddch (queryw, ' '); /* Put in a space, as Blox does */
186 while ((c = getchar ()) != '\r') {
188 case '\025': /* Ctl-U */
192 /* 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) {
227 "You are not allowed to type more than %d characters for this answer.\n",
235 if (emptyok && valuep &&
236 (askyn("Do you really want this field left blank (y/n)? ") == NO))
239 wprintw(displayw, "You must enter something here.\n");
246 /* Input is complete so disable interval timer. */
247 it.it_interval.tv_sec = 0;
248 it.it_interval.tv_usec = 0;
249 it.it_value.tv_sec = 0;
250 it.it_value.tv_usec = 0;
251 setitimer (ITIMER_REAL, &it, (struct itimerval *) 0);
253 buf[i] = '\0'; /* Put a null on the end */
255 werase (queryw); /* Clean up the query window */
258 return; /* And get out of here. */
272 mvwaddstr (queryw, 0, 0, prompt);
275 xpos = queryw->_curx;
276 ypos = queryw->_cury;
277 answer = 2; /* No answer. */
279 /* Reset interval timer for y/n question. */
280 it.it_interval.tv_sec = 0;
281 it.it_interval.tv_usec = 0;
282 it.it_value.tv_sec = YN_TIMEOUT;
283 it.it_value.tv_usec = 0;
284 setitimer (ITIMER_REAL, &it, (struct itimerval *) 0);
286 while ((c = getchar ()) != '\r') { /* 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 */
317 /* if (getuid() != 0) */
318 { clear(); /* Exit if not root. */
323 default: /* Ignore everything else. */
328 if (answer == 2) /* No answer. */
329 { display_text_line(0);
330 display_text_line("Please answer y or n.");
337 /* Display_text_line puts up a line of text in the display window */
338 /* Special case: if line is 0, clear the display area */
339 display_text_line (line)
343 waddstr (displayw, line);
344 waddch (displayw, '\n');
353 /* Display_text displays a canned message from a file */
354 display_text (filename)
361 if ((fp = fopen (filename, "r")) == NULL) {
362 wprintw (displayw, "Can't open file %s for reading.\n", filename);
366 while (fgets (buf, 100, fp)) {
367 /* get rid of the newline */
368 buf[strlen (buf) - 1] = 0;
369 display_text_line (buf);
375 /* Clear_display wipes the display and turns off curses */
389 it.it_interval.tv_sec = 0;
390 it.it_interval.tv_usec = 0;
391 it.it_value.tv_sec = TIMER_TIMEOUT;
392 it.it_value.tv_usec = 0;
393 setitimer (ITIMER_REAL, &it, (struct itimerval *) 0);
400 it.it_interval.tv_sec = 0;
401 it.it_interval.tv_usec = 0;
402 it.it_value.tv_sec = 0;
403 it.it_value.tv_usec = 0;
404 setitimer (ITIMER_REAL, &it, (struct itimerval *) 0);