]> andersk Git - moira.git/blobdiff - clients/userreg/display.c
Replaced all the EQUEL with ESQL. A few lines may not be proper
[moira.git] / clients / userreg / display.c
index 7070bb7c3fc61596f404c0d1adf1cda3aab06ed7..7a2147f674076108b12cfde65e4356d2d7e57004 100644 (file)
@@ -3,20 +3,30 @@
  *     $Author$
  *     $Locker$
  *     $Header$
+ *
+ *  (c) Copyright 1988 by the Massachusetts Institute of Technology.
+ *  For copying and distribution information, please see the file
+ *  <mit-copyright.h>.
  */
 
 #ifndef lint
 static char *rcsid_display_c = "$Header$";
 #endif lint
 
+#include <mit-copyright.h>
 #include <stdio.h>
 #include <curses.h>
 #include <sys/time.h>
 #include "userreg.h"
 
 #define DESC_WIDTH 18
-#define HEADER "*** Athena User Registration ***"
-#define HELP   " Press backspace to delete a character.  Press Ctrl-C to start over."
+#define HEADER "*** Athena User Account Registration ***"
+#if defined(vax) || defined(mips)
+#define HELP   " Press the key above RETURN to delete a character.  Press Ctrl-C to start over."
+#endif
+#ifndef HELP
+#define HELP   "    Press backspace to delete a character.  Press Ctrl-C to start over."
+#endif
 #define BORDER_CHAR '-'
 #define MIN_COLS 80
 #define MIN_LINES 24
@@ -30,15 +40,16 @@ setup_display () {
   FILE * freopen ();
 
   initscr ();                  /* Start up curses */
-  noecho ();                   /* And the tty input */
-  raw ();
-  freopen ("/dev/null", "w", stderr);/* Toss the standard error output */
 
   if (COLS < MIN_COLS || LINES < MIN_LINES) {
     fprintf (stderr, "Screen must be at least %d x %d\n", MIN_LINES, MIN_COLS);
     exit (1);
   }
 
+  noecho ();                   /* And the tty input */
+  raw ();
+  freopen ("/dev/null", "w", stderr);/* Toss the standard error output */
+
  /* Make sure the place is clean */
   clear ();
 
@@ -76,7 +87,7 @@ reset_display () {
   wmove (dataw, 0, 0);
   waddstr (dataw, "First Name:\n");
   waddstr (dataw, "Middle Initial:\n");
-  waddstr (dataw, "Last Name:\n");
+  waddstr (dataw, "Family Name:\n");
   waddstr (dataw, "MIT ID #:\n\n");
   waddstr (dataw, "Username:\n");
   wclrtoeol (dataw);
@@ -105,22 +116,25 @@ int   l;
 /* This replaces several "useful" display functions in the old userreg */
 redisp () {
   mvwprintw (fnamew, 0, 0, "%-24s", user.u_first);
+  wrefresh(fnamew);
   mvwprintw (midw, 0, 0, "%-24s", user.u_mid_init);
+  wrefresh(midw);
   mvwprintw (lnamew, 0, 0, "%-24s", user.u_last);
+  wrefresh(lnamew);
   mvwprintw (idw, 0, 0, "%-24s", typed_mit_id);
+  wrefresh(idw);
   mvwprintw (loginw, 0, 0, "%-24s", user.u_login);
-
-  wrefresh (dataw);
+  wrefresh(loginw);
 }
 
 
 /* Input and input_no_echo exist only to save on retyping */
-input (prompt, buf, maxsize, timeout)
+input (prompt, buf, maxsize, timeout, emptyok)
 char *prompt;
 char *buf;
-int   maxsize, timeout;
+int   maxsize, timeout, emptyok;
 {
-  query_user (prompt, buf, maxsize, timeout, TRUE);
+  query_user (prompt, buf, maxsize, timeout, TRUE, emptyok, TRUE);
 }
 
 input_no_echo (prompt, buf, maxsize, timeout)
@@ -128,21 +142,31 @@ char *prompt;
 char *buf;
 int   maxsize, timeout;
 {
-  query_user (prompt, buf, maxsize, timeout, FALSE);
+  query_user (prompt, buf, maxsize, timeout, FALSE, FALSE, TRUE);
 }
 
 
+/* make the user press any key to continue */
+wait_for_user ()
+{
+    char buf[BUFSIZ];
+
+    redisp();
+    query_user ("Press RETURN or ENTER to continue", buf, 1,
+               15 * 60, FALSE, TRUE, FALSE);
+}
+
 
 /* Gets input through the query buffer */
 /* Exit(1)'s on read errors */
 /* Signals SIGALRM after 'timeout' seconds */
-query_user (prompt, buf, maxsize, timeout, echop)
+query_user (prompt, buf, maxsize, timeout, echop, emptyok, valuep)
 char *prompt;
 char *buf;
 int   maxsize, timeout;
-bool echop;
+int echop, emptyok, valuep;
 {
-  char  c;
+  int  c;
   int   i;
   struct itimerval it;
 
@@ -161,15 +185,15 @@ retry:
   wrefresh (queryw);
 
   i = 0;
-  while ((c = getchar ()) != '\r') {
+  while ((c = getchar ()) != '\r' && c != '\n') {
    switch (c) {
      case '\025':              /* Ctl-U */
        goto retry;
-       break;
       case EOF:
        /* We're in raw mode, so EOF means disaster */
        exit(1);
        break;
+    delchar:
       case '\177':             /* Delete */
       case '\010':             /* Backspace */
        if (i) {
@@ -182,13 +206,9 @@ retry:
        }
        break;
       case '\003':             /* Ctrl-C */
-       if (getuid() != 0) 
-         { clear();            /* Exit if not root. */
-           restore_display();
-           exit(0);
-         }
-       else
-         restart();  
+       clear();
+       restore_display();
+       exit(0);
        break;
       default: 
        if (c >= ' ') {         /* Ignore all other control chars */
@@ -200,18 +220,26 @@ retry:
        }
        break;
     }
-    if (i >= maxsize) {
+    if (valuep && i >= maxsize) {
+      wfeep();
       wprintw (displayw,
   "You are not allowed to type more than %d characters for this answer.\n",
-         maxsize);
+         maxsize-1);
       wrefresh (displayw);
-      goto retry;
+      goto delchar;
     }
  }
 
-  if (i == 0)
-    if (askyn("Do you really want this field left blank (y/n)? ") == NO)
-      goto retry;
+  if (i == 0) {
+      if (emptyok && valuep &&
+         (askyn("Do you really want this field left blank (y/n)? ") == NO))
+       goto retry;
+      if (!emptyok) {
+         wprintw(displayw, "You must enter something here.\n");
+         wrefresh(displayw);
+         goto retry;
+      }
+  }
     
 
   /* Input is complete so disable interval timer. */
@@ -236,7 +264,7 @@ askyn(prompt)
   int ypos, xpos;
   int answer;
   struct itimerval it;
-  char c;
+  int c;
 
  start:
   werase (queryw);
@@ -254,7 +282,7 @@ askyn(prompt)
   it.it_value.tv_usec = 0;
   setitimer (ITIMER_REAL, &it, (struct itimerval *) 0);
     
-  while ((c = getchar ()) != '\r') {   /* Wait for CR. */
+  while ((c = getchar ()) != '\r' && c != '\n') {      /* Wait for CR. */
       switch (c) {
       case 'n':                        /* No. */
       case 'N':
@@ -285,11 +313,9 @@ askyn(prompt)
        exit(1);
        break;
       case '\003':             /* Ctrl-C */
-/*     if (getuid() != 0) */
-         { clear();            /* Exit if not root. */
-           restore_display();
-           exit(0);
-         }
+       clear();
+       restore_display();
+       exit(0);
        break;
       default:                 /* Ignore everything else. */
        break;
@@ -311,22 +337,23 @@ display_text_line (line)
 char *line;
 {
   if (line) {
-    waddstr (displayw, line);
-    waddch (displayw, '\n');
-    wrefresh (displayw);
-  }
-  else {
-    werase (displayw);
+      waddstr (displayw, line);
+      waddch (displayw, '\n');
+  } else {
+      werase (displayw);
   }
   wrefresh (displayw);
 }
 
-/* Display_text displays a canned message from a file */
-display_text (filename)
+/* Display_text displays a canned message from a file.  The string
+ * will get imbedded in any %s's in the text.
+ */
+display_text(filename, string)
 char *filename;
+char *string;
 {
   FILE * fp;
-  char  buf[100];
+  char  buf[100], buf1[110];
 
   werase (displayw);
   if ((fp = fopen (filename, "r")) == NULL) {
@@ -335,11 +362,14 @@ char *filename;
   }
 
   while (fgets (buf, 100, fp)) {
-  /* get rid of the newline */
-    buf[strlen (buf) - 1] = 0;
-    display_text_line (buf);
+      /* get rid of the newline */
+      buf[strlen (buf) - 1] = 0;
+      sprintf(buf1, buf, string);
+      waddstr(displayw, buf1);
+      waddch(displayw, '\n');
   }
 
+  wrefresh(displayw);
   fclose (fp);
 }
 
@@ -375,3 +405,9 @@ timer_off()
   setitimer (ITIMER_REAL, &it, (struct itimerval *) 0);
 }
 
+
+wfeep()
+{
+    char buf = '\007';
+    write(1, &buf, 1);
+}
This page took 0.035899 seconds and 4 git commands to generate.