home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume3 / lib_term / GetHospNum.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  2.1 KB  |  138 lines

  1. #include <stdio.h>
  2. #include <ctype.h>
  3.  
  4. void GetHospNum(HospNum)
  5. char *HospNum;
  6.  
  7. /*
  8.  ---------------------------------------------------------------------------
  9.  
  10.    Last revision - 
  11.     16 November 1984 - GWS
  12.     Ignore XON, XOFF
  13.  
  14.      11 April 1984 - GWS
  15.  
  16.  
  17.    NAME
  18.      GetHospNum - "crash-proof" routine for terminal input of ##-##-##
  19.  
  20.    SYNOPSIS
  21.     void GetHospNum(HospNum)
  22.     char *HospNum;
  23.  
  24.    DESCRIPTION
  25.     This routine prompts and nudges the user through entry of a
  26.     hospital number in the proper format.
  27.  
  28.    SEE ALSO
  29.  
  30.  
  31.    DIAGNOSTICS
  32.     none 
  33.  
  34.    BUGS
  35.     Doesn't do any validity checking on the number, only the format. 
  36.  
  37.    AUTHOR
  38.      George W. Sherouse
  39.      9 April 1984
  40.  
  41.  ---------------------------------------------------------------------------
  42. */
  43.  
  44. {
  45.     int c;
  46.     char erase;
  47.     int count;
  48.     int cookie;
  49.  
  50.     void underline();
  51.     int tgetnum();
  52.     char TermSetUp();
  53.     void TermRewind();
  54.  
  55.     if ((cookie = tgetnum("ug")) < 0)
  56.     cookie = 0;
  57.  
  58.     underline(1);
  59.  
  60.     printf("  -  -  ");
  61.     if (cookie)
  62.     {
  63.     underline(0);
  64.     TermRewind(cookie);
  65.     }
  66.     TermRewind(8);
  67.  
  68.     erase = TermSetUp();    /* set no echo, single char input */
  69.                     /* get erase character */
  70.     count = 0;
  71.     while (1)
  72.     {
  73.     switch (count)
  74.     {
  75.     case 2:
  76.     case 5:
  77.         printf("-");
  78.         HospNum[count++] = '-';
  79.         break;
  80.     default:
  81.         switch (c = (getchar() & 0177))
  82.         {
  83.         case '\015':
  84.         if (count == 8)
  85.         {
  86.             HospNum[8] = (char) 0;
  87.             underline(0);
  88.             TermSetUp();
  89.             return;
  90.         }
  91.         else
  92.         {
  93.             printf("%c", '\007');
  94.             break;
  95.         }
  96.         case 030:
  97.         TermRewind(count);
  98.         printf("  -  -  ");
  99.         count = 0;
  100.         TermRewind(8);
  101.         break;
  102.         case '\021':
  103.         case '\023':
  104.         break;
  105.         default:
  106.         if (c == erase && count)
  107.         {
  108.             switch (count)
  109.             {
  110.             case 3:
  111.             case 6:
  112.             printf("\b");
  113.             count--;
  114.             case 1:
  115.             case 2:
  116.             case 4:
  117.             case 5:
  118.             case 7:
  119.             case 8:
  120.             printf("\b \b");
  121.             HospNum[--count] = 0;
  122.             break;
  123.             }
  124.             break;
  125.         }
  126.  
  127.         if (isdigit(c) && count < 8)
  128.         {
  129.             printf("%c", c);
  130.             HospNum[count++] = (char) c;
  131.         }
  132.         else
  133.             printf("%c", '\007');
  134.         }
  135.     }
  136.     }
  137. }
  138.