home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_C / FGIN131.ZIP / SOURCE.ZIP / WAITFOR.C < prev   
C/C++ Source or Header  |  1994-02-11  |  2KB  |  88 lines

  1. /****************************************************************************\
  2.  
  3. \****************************************************************************/
  4. #include "fginput.h"
  5. #include "internal.h"
  6.  
  7. static char to_upper(char);
  8.  
  9. /****************************************************************************\
  10.  
  11.     int wait_key_masked(char mask)
  12.  
  13.             This function simply waits for a key to be pressed that is
  14.         allowed by the masking character.  See FGINPUT.DOC for further info
  15.  
  16. \****************************************************************************/
  17. int wait_key_masked(char mask)
  18. {
  19.  
  20.     int Ch;
  21.  
  22.     asm mov ax,0x0C00;    //Clear keyboard
  23.     asm int 0x21;
  24.  
  25.  
  26.     do {
  27.  
  28.         Ch=wait_key();
  29.         if ((Ch&0xF00))
  30.             return(Ch);    //Allow any extended key
  31.  
  32.         if (Ch==CR||Ch==ESC||Ch==BS||Ch==TAB||Ch==' ')
  33.             return(Ch); //Always allow CR, ESC, BS, TAB and space
  34.  
  35.         switch (mask) {
  36.             case 'X':    //Allow any key, force to upper case
  37.                 Ch=to_upper(Ch);
  38.             case 'x':    //Allow any key
  39.                 return(Ch);
  40.             case '#':    //Allow only 0 thru 9 and +-,./
  41.                 if (Ch>32&&Ch<48) return(Ch);
  42.             case '9':    //Allow only 0 thru 9
  43.                 if (Ch>47&&Ch<58) return(Ch);
  44.                 break;
  45.             case 'N':    //Allow a - z, A - Z, 0 - 9, +-,./ and force to upper
  46.                 Ch=to_upper(Ch);
  47.             case 'n':   //Allow a - z, A - Z, 0 - 9, +-,./
  48.                 if (Ch>32&&Ch<58) return(Ch);
  49.             case 'A':    //Allow a - z, A - Z and force to upper
  50.                 if (mask!='n') Ch=to_upper(Ch);
  51.             case 'a':    //Allow a - z, A - Z
  52.                 if (Ch>64&&Ch<91)  return(Ch);
  53.                 if (Ch>96&&Ch<123) return(Ch);
  54.                 break;
  55.             case 'Y':
  56.                 Ch=to_upper(Ch);
  57.                 if (Ch=='Y'||Ch=='N') return(Ch);
  58.                 break;
  59.         }//switch (mask)
  60.  
  61.     }while(1);    //Wait for key that fits mask
  62.  
  63. }
  64.  
  65. /****************************************************************************\
  66.  
  67.     static char to_upper(char ch)
  68.  
  69.             This function does the same thing as the Borland function
  70.         toupper().  The difference is that when you include <ctype.h>
  71.         you get a somewhat large index table that I think is redundant.
  72.  
  73.             If your program only uses toupper(), you are linking in a bunch
  74.         of un-needed junk.  On the other hand, if you use many of the
  75.         other ctype functions, you can benefit from all that junk.
  76.  
  77. \****************************************************************************/
  78. static char to_upper(char ch)
  79. {
  80.  
  81.     if (ch>='a'&&ch<='z') return(ch&0x5F);
  82.     else return(ch);
  83.  
  84. }
  85.  
  86.  
  87.  
  88.