9 static char *rcsid_display_c = "$Header$";
18 #define HEADER "*** Project Athena User Registration ***"
20 #define HELP " Press backspace to delete a character. Press Ctrl-C to start over."
23 #define HELP " Press the key marked <X| to delete a character. Press Ctrl-C to start over."
26 #define BORDER_CHAR '-'
30 WINDOW * displayw, *queryw;
31 WINDOW * dataw, *helpw;
32 WINDOW * fnamew, *midw, *lnamew, *idw, *loginw;
34 /* Set up the windows and subwindows on the display */
38 initscr (); /* Start up curses */
40 if (COLS < MIN_COLS || LINES < MIN_LINES) {
41 fprintf (stderr, "Screen must be at least %d x %d\n", MIN_LINES, MIN_COLS);
45 noecho (); /* And the tty input */
47 freopen ("/dev/null", "w", stderr);/* Toss the standard error output */
49 /* Make sure the place is clean */
52 /* Set up the top-level windows */
53 /* First line is the header */
54 displayw = subwin (stdscr, 12, 0, 2, 0);/* Lines 2-13 */
55 scrollok (displayw, TRUE);
57 queryw = subwin (stdscr, 1, 0, 15, 0);/* Line 15 */
58 scrollok (queryw, TRUE);
60 dataw = subwin (stdscr, 5, 0, 17, 0);/* Lines 17-21 */
62 /* Set up the data windows */
63 fnamew = subwin (stdscr, 1, 0, 17, DESC_WIDTH);
64 midw = subwin (stdscr, 1, 0, 18, DESC_WIDTH);
65 lnamew = subwin (stdscr, 1, 0, 19, DESC_WIDTH);
66 idw = subwin (stdscr, 1, 0, 20, DESC_WIDTH);
67 loginw = subwin (stdscr, 1, 0, 21, DESC_WIDTH);
71 /* Clear and restore the display */
75 /* Put back the borders */
82 /* Put in the window dressing */
84 waddstr (dataw, "First Name:\n");
85 waddstr (dataw, "Middle Initial:\n");
86 waddstr (dataw, "Family Name:\n");
87 waddstr (dataw, "MIT ID #:\n\n");
88 waddstr (dataw, "Username:\n");
91 /* Set up the header */
92 mvaddstr (0, (COLS - strlen (HEADER)) / 2, HEADER);
93 mvaddstr (23, 0, HELP);
100 /* Make a one-line border on line l of stdscr */
107 for (i = 0; i < COLS - 1; i++) {
112 /* This replaces several "useful" display functions in the old userreg */
114 mvwprintw (fnamew, 0, 0, "%-24s", user.u_first);
115 mvwprintw (midw, 0, 0, "%-24s", user.u_mid_init);
116 mvwprintw (lnamew, 0, 0, "%-24s", user.u_last);
117 mvwprintw (idw, 0, 0, "%-24s", typed_mit_id);
118 mvwprintw (loginw, 0, 0, "%-24s", user.u_login);
124 /* Input and input_no_echo exist only to save on retyping */
125 input (prompt, buf, maxsize, timeout, emptyok)
128 int maxsize, timeout, emptyok;
130 query_user (prompt, buf, maxsize, timeout, TRUE, emptyok, TRUE);
133 input_no_echo (prompt, buf, maxsize, timeout)
136 int maxsize, timeout;
138 query_user (prompt, buf, maxsize, timeout, FALSE, FALSE, TRUE);
142 /* make the user press any key to continue */
148 query_user ("Press RETURN or ENTER to continue", buf, 1,
149 15 * 60, FALSE, TRUE, FALSE);
153 /* Gets input through the query buffer */
154 /* Exit(1)'s on read errors */
155 /* Signals SIGALRM after 'timeout' seconds */
156 query_user (prompt, buf, maxsize, timeout, echop, emptyok, valuep)
159 int maxsize, timeout;
160 bool echop, emptyok, valuep;
167 /* Set up interval timer */
168 it.it_interval.tv_sec = 0;
169 it.it_interval.tv_usec = 0;
170 it.it_value.tv_sec = timeout;
171 it.it_value.tv_usec = 0;
172 setitimer (ITIMER_REAL, &it, (struct itimerval *) 0);
174 /* Erase the query window and put up a prompt */
176 mvwaddstr (queryw, 0, 0, prompt);
177 waddch (queryw, ' '); /* Put in a space, as Blox does */
181 while ((c = getchar ()) != '\r') {
183 case '\025': /* Ctl-U */
187 /* We're in raw mode, so EOF means disaster */
190 case '\177': /* Delete */
191 case '\010': /* Backspace */
195 wmove (queryw, queryw -> _cury, queryw -> _curx - 1);
201 case '\003': /* Ctrl-C */
203 { clear(); /* Exit if not root. */
211 if (c >= ' ') { /* Ignore all other control chars */
220 if (valuep && i >= maxsize) {
222 "You are not allowed to type more than %d characters for this answer.\n",
230 if (emptyok && valuep &&
231 (askyn("Do you really want this field left blank (y/n)? ") == NO))
234 wprintw(displayw, "You must enter something here.\n");
241 /* Input is complete so disable interval timer. */
242 it.it_interval.tv_sec = 0;
243 it.it_interval.tv_usec = 0;
244 it.it_value.tv_sec = 0;
245 it.it_value.tv_usec = 0;
246 setitimer (ITIMER_REAL, &it, (struct itimerval *) 0);
248 buf[i] = '\0'; /* Put a null on the end */
250 werase (queryw); /* Clean up the query window */
253 return; /* And get out of here. */
267 mvwaddstr (queryw, 0, 0, prompt);
270 xpos = queryw->_curx;
271 ypos = queryw->_cury;
272 answer = 2; /* No answer. */
274 /* Reset interval timer for y/n question. */
275 it.it_interval.tv_sec = 0;
276 it.it_interval.tv_usec = 0;
277 it.it_value.tv_sec = YN_TIMEOUT;
278 it.it_value.tv_usec = 0;
279 setitimer (ITIMER_REAL, &it, (struct itimerval *) 0);
281 while ((c = getchar ()) != '\r') { /* Wait for CR. */
285 wmove(queryw, ypos, xpos);
287 waddstr(queryw, "no");
293 wmove(queryw, ypos, xpos);
295 waddstr(queryw, "yes");
299 case '\177': /* Delete */
300 case '\010': /* Backspace */
301 case '\025': /* Ctl-U */
302 wmove(queryw, ypos, xpos);
305 answer = 2; /* No answer. */
308 /* We're in raw mode, so EOF means disaster */
311 case '\003': /* Ctrl-C */
312 /* if (getuid() != 0) */
313 { clear(); /* Exit if not root. */
318 default: /* Ignore everything else. */
323 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 (line)
338 waddstr (displayw, line);
339 waddch (displayw, '\n');
348 /* Display_text displays a canned message from a file */
349 display_text (filename)
356 if ((fp = fopen (filename, "r")) == NULL) {
357 wprintw (displayw, "Can't open file %s for reading.\n", filename);
361 while (fgets (buf, 100, fp)) {
362 /* get rid of the newline */
363 buf[strlen (buf) - 1] = 0;
364 display_text_line (buf);
370 /* Clear_display wipes the display and turns off curses */
384 it.it_interval.tv_sec = 0;
385 it.it_interval.tv_usec = 0;
386 it.it_value.tv_sec = TIMER_TIMEOUT;
387 it.it_value.tv_usec = 0;
388 setitimer (ITIMER_REAL, &it, (struct itimerval *) 0);
395 it.it_interval.tv_sec = 0;
396 it.it_interval.tv_usec = 0;
397 it.it_value.tv_sec = 0;
398 it.it_value.tv_usec = 0;
399 setitimer (ITIMER_REAL, &it, (struct itimerval *) 0);