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

  1. /***
  2. *ismbbyte.c - Function versions of MBCS ctype macros
  3. *
  4. *       Copyright (c) 1988-1997, Microsoft Corporation.  All rights reserved.
  5. *
  6. *Purpose:
  7. *       This files provides function versions of the character
  8. *       classification a*d conversion macros in mbctype.h.
  9. *
  10. *******************************************************************************/
  11.  
  12. #ifdef _MBCS
  13.  
  14. #include <cruntime.h>
  15. #include <ctype.h>
  16. #include <mbdata.h>
  17. #include <mbctype.h>
  18. #include <mbstring.h>
  19.  
  20. /* defined in mbctype.h
  21. ; Define masks
  22.  
  23. ; set bit masks for the possible kanji character types
  24. ; (all MBCS bit masks start with "_M")
  25.  
  26. _MS             equ     01h     ; MBCS non-ascii single byte char
  27. _MP             equ     02h     ; MBCS punct
  28. _M1             equ     04h     ; MBCS 1st (lead) byte
  29. _M2             equ     08h     ; MBCS 2nd byte
  30.  
  31. */
  32.  
  33. /* defined in ctype.h
  34. ; set bit masks for the possible character types
  35.  
  36. _UPPER          equ     01h     ; upper case letter
  37. _LOWER          equ     02h     ; lower case letter
  38. _DIGIT          equ     04h     ; digit[0-9]
  39. _SPACE          equ     08h     ; tab, carriage return, newline,
  40.                                 ; vertical tab or form feed
  41. _PUNCT          equ     10h     ; punctuation character
  42. _CONTROL        equ     20h     ; control character
  43. _BLANK          equ     40h     ; space char
  44. _HEX            equ     80h     ; hexadecimal digit
  45.  
  46. */
  47.  
  48. /* defined in ctype.h, mbdata.h
  49.         extrn   __mbctype:byte          ; MBCS ctype table
  50.         extrn   __ctype_:byte           ; ANSI/ASCII ctype table
  51. */
  52.  
  53.  
  54. /***
  55. * ismbbyte - Function versions of mbctype macros
  56. *
  57. *Purpose:
  58. *
  59. *Entry:
  60. *       int = character to be tested
  61. *Exit:
  62. *       ax = non-zero = character is of the requested type
  63. *          =        0 = character is NOT of the requested type
  64. *
  65. *Uses:
  66. *
  67. *Exceptions:
  68. *
  69. *******************************************************************************/
  70.  
  71. int __cdecl x_ismbbtype(unsigned int, int, int);
  72.  
  73.  
  74. /* ismbbk functions */
  75.  
  76. int (__cdecl _ismbbkalnum) (unsigned int tst)
  77. {
  78.         return x_ismbbtype(tst,0,_MS);
  79. }
  80.  
  81. int (__cdecl _ismbbkprint) (unsigned int tst)
  82. {
  83.         return x_ismbbtype(tst,0,(_MS | _MP));
  84. }
  85.  
  86. int (__cdecl _ismbbkpunct) (unsigned int tst)
  87. {
  88.         return x_ismbbtype(tst,0,_MP);
  89. }
  90.  
  91.  
  92. /* ismbb functions */
  93.  
  94. int (__cdecl _ismbbalnum) (unsigned int tst)
  95. {
  96.         return x_ismbbtype(tst,(_ALPHA | _DIGIT), _MS);
  97. }
  98.  
  99. int (__cdecl _ismbbalpha) (unsigned int tst)
  100. {
  101.         return x_ismbbtype(tst,_ALPHA, _MS);
  102. }
  103.  
  104. int (__cdecl _ismbbgraph) (unsigned int tst)
  105. {
  106.         return x_ismbbtype(tst,(_PUNCT | _ALPHA | _DIGIT),(_MS | _MP));
  107. }
  108.  
  109. int (__cdecl _ismbbprint) (unsigned int tst)
  110. {
  111.         return x_ismbbtype(tst,(_BLANK | _PUNCT | _ALPHA | _DIGIT),(_MS | _MP));
  112. }
  113.  
  114. int (__cdecl _ismbbpunct) (unsigned int tst)
  115. {
  116.         return x_ismbbtype(tst,_PUNCT, _MP);
  117. }
  118.  
  119.  
  120. /* lead and trail */
  121.  
  122. int (__cdecl _ismbblead) (unsigned int tst)
  123. {
  124.         return x_ismbbtype(tst,0,_M1);
  125. }
  126.  
  127. int (__cdecl _ismbbtrail) (unsigned int tst)
  128. {
  129.         return x_ismbbtype(tst,0,_M2);
  130. }
  131.  
  132.  
  133. /* 932 specific */
  134.  
  135. int (__cdecl _ismbbkana) (unsigned int tst)
  136. {
  137.         return (__mbcodepage == _KANJI_CP && x_ismbbtype(tst,0,(_MS | _MP)));
  138. }
  139.  
  140. /***
  141. * Common code
  142. *
  143. *      cmask = mask for _ctype[] table
  144. *      kmask = mask for _mbctype[] table
  145. *
  146. *******************************************************************************/
  147.  
  148. static int __cdecl x_ismbbtype (unsigned int tst, int cmask, int kmask)
  149. {
  150.         tst = (unsigned int)(unsigned char)tst;         /* get input character
  151.                                                    and make sure < 256 */
  152.  
  153.         return  ((*(_mbctype+1+tst)) & kmask) ||
  154.                 ((cmask) ? ((*(_ctype+1+tst)) & cmask) : 0);
  155. }
  156.  
  157. #endif  /* _MBCS */
  158.