home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_03_01 / 3n01032a < prev    next >
Text File  |  1991-11-26  |  3KB  |  72 lines

  1.  
  2. /*** Listing #3
  3. */
  4. /*** iDBCGetC - Retrieves character from kb buffer and reports status.
  5. *
  6. *   written by: John G. Nelson, Pacific Software Publishing Inc.
  7. *   copyright:  Pacific Software Publishing Inc.
  8. *   date:       11/90
  9. *   purpose:    To indicate type of character found in kb buffer
  10. *               (if any) and to return that character in a double
  11. *               byte character. If a double byte ANK character
  12. *               found, it is converted to its single byte ANK code.
  13. *   parameters: char *pdbcChar:  Pointer to a double byte character.
  14. *   return:     Function returns int corresponding
  15. *                   to one of following values:
  16. *               0:  Kb buffer is empty.
  17. *               1:  Single byte char found:
  18. *                   dbcChar[0]= 1 byte char.
  19. *                   dbcChar[1]= 0.
  20. *               2:  Double byte char found:
  21. *                   dbcChar[0]= 1st byte of char.
  22. *                   dbcChar[1]= 2nd byte of char.
  23. *               3:  Function key found:
  24. *                   dbcChar[0]= 0.
  25. *                   dbcChar[1]= Key scan code.
  26. */
  27. int iDBCGetC(
  28.     DBC  *pdbcChar)   /*  Pointer to double byte character */
  29.     {
  30.     union REGS reg;
  31.     unsigned char  bScan, bChar;
  32.  
  33.     if (!kbhit())  {
  34.         /* buffer is empty                                 */
  35.         pdbcChar[0] = 0;
  36.         pdbcChar[1] = 0;
  37.         return(0);
  38.     };
  39.  
  40.     /*  buffer has data                                    */
  41.     reg.h.ah = GETKEY;     /* remove key from buffer       */
  42.     int86(KEYBOARD, ®, ®);
  43.  
  44.     bScan       = reg.h.ah;   /* save scan code            */
  45.     bChar       = reg.h.al;   /* save character code       */
  46.     pdbcChar[0] = bChar;
  47.     pdbcChar[1] = bScan;
  48.  
  49.     /* check if function key is present                    */
  50.     if (bIsFuncKey(bScan))  {
  51.         /*  function key found                             */ 
  52.         pdbcChar[0] = 0;
  53.         pdbcChar[1] = bScan;
  54.         return(3);
  55.  
  56.     /*  check if kanji char read                           */
  57.     } else if (bIsDBC(pdbcChar))  {
  58.         /*  get second byte                                */
  59.         reg.h.ah =  GETKEY;
  60.         int86(KEYBOARD, ®, ®);
  61.         pdbcChar[1] = reg.h.al;  /* 2nd character code     */
  62.         return(2);
  63.  
  64.     /* single byte character found                         */ 
  65.     } else {
  66.         pdbcChar[1] = 0;
  67.         pdbcChar[0] = bChar;
  68.         return(1);
  69.     }
  70. } /* iDBCGetC */
  71.  
  72.