home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / ismbprn.c < prev    next >
C/C++ Source or Header  |  1998-06-17  |  2KB  |  89 lines

  1. /***
  2. *ismbprn.c - Test character for display character (MBCS)
  3. *
  4. *       Copyright (c) 1985-1997, Microsoft Corporation.  All rights reserved.
  5. *
  6. *Purpose:
  7. *       Test character for display character (MBCS)
  8. *
  9. *******************************************************************************/
  10.  
  11. #ifdef _MBCS
  12.  
  13. #if defined (_WIN32)
  14. #include <windows.h>
  15. #include <awint.h>
  16. #endif  /* defined (_WIN32) */
  17.  
  18. #include <cruntime.h>
  19. #include <ctype.h>
  20. #include <mbdata.h>
  21. #include <mbctype.h>
  22. #include <mbstring.h>
  23.  
  24.  
  25. /***
  26. * _ismbcprint - Test character for display character (MBCS)
  27. *
  28. *Purpose:
  29. *       Test if the character is a display character.
  30. *       Handles MBCS chars correctly.
  31. *
  32. *       Note:  Use test against 0x00FF to ensure that we don't
  33. *       call SBCS routine with a two-byte value.
  34. *
  35. *Entry:
  36. *       unsigned int c = character to test
  37. *
  38. *Exit:
  39. *       Returns TRUE if character is display character, else FALSE
  40. *
  41. *Exceptions:
  42. *
  43. *******************************************************************************/
  44.  
  45. int __cdecl _ismbcprint(
  46.         unsigned int c
  47.         )
  48. {
  49.         if (c > 0x00FF)
  50.         {
  51.  
  52. #if defined (_WIN32)
  53.  
  54.             char buf[2];
  55.             unsigned short ctype[2] = {0};
  56.  
  57.             buf[0] = (c >> 8) & 0xFF;
  58.             buf[1] = c & 0xFF;
  59.  
  60.             /* return FALSE if not in supported MB code page */
  61.             if ( _ISNOTMBCP )
  62.                 return 0;
  63.  
  64.             /*
  65.             * Since 'c' could be two one-byte MB chars, we need room in the
  66.             * ctype return array to handle this. In this case, the
  67.             * second word in the return array will be non-zero.
  68.             */
  69.  
  70.             if (__crtGetStringTypeA (CT_CTYPE1, buf,
  71.                     2, ctype, __mbcodepage, __mblcid, TRUE) == 0)
  72.                 return 0;
  73.  
  74.             /* ensure single MB character and test for type */
  75.             return (ctype[1] == 0 && ctype[0] & (_BLANK|_PUNCT|_ALPHA|_DIGIT));
  76.  
  77. #else  /* defined (_WIN32) */
  78.  
  79.             return _ismbcgraph(c);
  80.  
  81. #endif  /* defined (_WIN32) */
  82.  
  83.         } else
  84.  
  85.             return _ismbbprint(c);
  86. }
  87.  
  88. #endif  /* _MBCS */
  89.