home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume3 / libc_term / get_hosp_num.c < prev    next >
C/C++ Source or Header  |  1986-11-30  |  2KB  |  147 lines

  1. #include <curses.h>
  2. #include <ctype.h>
  3. #include "c_term.h"
  4.  
  5. void get_hosp_num (HospNum)
  6. char *HospNum;
  7.  
  8. /*
  9.  ---------------------------------------------------------------------------
  10.  
  11.    Last revision - 
  12.     6 January 1985 - GWS
  13.     Change it to use curses
  14.  
  15.     16 November 1984 - GWS
  16.     Ignore XON, XOFF
  17.  
  18.      11 April 1984 - GWS
  19.  
  20.  
  21.    NAME
  22.      get_hosp_num - "crash-proof" routine for terminal input of ##-##-##
  23.  
  24.    SYNOPSIS
  25.     void get_hosp_num(HospNum)
  26.     char *HospNum;
  27.  
  28.    DESCRIPTION
  29.     This routine prompts and nudges the user through entry of a
  30.     hospital number in the proper format.
  31.  
  32.    SEE ALSO
  33.  
  34.  
  35.    DIAGNOSTICS
  36.     none 
  37.  
  38.    BUGS
  39.     Doesn't do any validity checking on the number, only the format. 
  40.  
  41.    AUTHOR
  42.      George W. Sherouse
  43.      9 April 1984
  44.  
  45.  ---------------------------------------------------------------------------
  46. */
  47.  
  48. {
  49.     int c;
  50.     int count,
  51.        where_y,
  52.     where_x,
  53.     x,
  54.     y;
  55.  
  56.     getyx(stdscr, where_y, where_x);
  57.     standout();
  58.  
  59.     printw("  -  -  ");
  60.     move(where_y, where_x);
  61.     refresh();
  62.  
  63.     count = 0;
  64.     while (1)
  65.     {
  66.     switch (count)
  67.     {
  68.     case 2:
  69.     case 5:
  70.         printw("-");
  71.         HospNum[count++] = '-';
  72.         break;
  73.     default:
  74.         switch (c = (getchar() & 0177))
  75.         {
  76. #ifdef ABORT_CHAR
  77.         case ABORT_CHAR:
  78.         clear();
  79.         standend();
  80.         mvprintw(0, 0, "Program aborted at your request...");
  81.         move(LINES - 1, 0);
  82.         refresh();
  83.         endwin();
  84.         exit(0);
  85.         break;
  86. #endif ABORT_CHAR
  87.  
  88.         case '\015':
  89.         if (count == 8)
  90.         {
  91.             HospNum[8] = (char) 0;
  92.             standend();
  93.             mvprintw(where_y, where_x, HospNum);
  94.             refresh();
  95.             return;
  96.         }
  97.         else
  98.         {
  99.             fprintf(stderr, "%c", '\007');
  100.             break;
  101.         }
  102.         case 030:
  103.         mvprintw(where_y, where_x, "  -  -  ");
  104.         move(where_y, where_x);
  105.         count = 0;
  106.         break;
  107.         case '\021':
  108.         case '\023':
  109.         break;
  110.         default:
  111.         if (c == erase_char && count)
  112.         {
  113.             switch (count)
  114.             {
  115.             case 3:
  116.             case 6:
  117.             getyx(stdscr, y, x);
  118.             move(y, x - 1);
  119.             count--;
  120.             case 1:
  121.             case 2:
  122.             case 4:
  123.             case 5:
  124.             case 7:
  125.             case 8:
  126.             getyx(stdscr, y, x);
  127.             mvprintw(y, x - 1, " ");
  128.             move(y, x - 1);
  129.             HospNum[--count] = 0;
  130.             break;
  131.             }
  132.             break;
  133.         }
  134.  
  135.         if (isdigit(c) && count < 8)
  136.         {
  137.             printw("%c", c);
  138.             HospNum[count++] = (char) c;
  139.         }
  140.         else
  141.             fprintf(stderr, "%c", '\007');
  142.         }
  143.     }
  144.     refresh();
  145.     }
  146. }
  147.