Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
3.5 KiB

  1. /***
  2. *ismbgrph - Test if character is graphical (MBCS)
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Test if character is graphical (MBCS)
  8. *
  9. *Revision History:
  10. * 10-21-93 CFW Module created.
  11. * 11-09-93 CFW Add code page for __crtxxx().
  12. * 01-12-94 CFW Add lcid for __crtxxx().
  13. * 04-18-94 CFW Use _ALPHA rather than _UPPER|_LOWER.
  14. * 04-29-94 CFW Place c in char array.
  15. * 05-17-94 CFW Enable non-Win32.
  16. * 03-16-97 RDK Added error flag to __crtGetStringTypeA.
  17. * 09-11-97 GJF Replaced __mbcodepage == 0 with _ISNOTMBCP.
  18. * 09-26-97 BWT Fix POSIX
  19. * 03-31-98 GJF Implemented multithread support based on threadmbcinfo
  20. * structs
  21. * 05-17-99 PML Remove all Macintosh support.
  22. *
  23. *******************************************************************************/
  24. #ifdef _MBCS
  25. #if !defined(_POSIX_)
  26. #include <windows.h>
  27. #include <awint.h>
  28. #endif /* !_POSIX_ */
  29. #include <mtdll.h>
  30. #include <cruntime.h>
  31. #include <ctype.h>
  32. #include <mbdata.h>
  33. #include <mbctype.h>
  34. #include <mbstring.h>
  35. /***
  36. * _ismbcgraph - Test if character is graphical (MBCS)
  37. *
  38. *Purpose:
  39. * Test if the supplied character is graphical or not.
  40. * Handles MBCS characters correctly.
  41. *
  42. * Note: Use test against 0x00FF instead of _ISLEADBYTE
  43. * to ensure that we don't call SBCS routine with a two-byte
  44. * value.
  45. *
  46. *Entry:
  47. * unsigned int c = character to test
  48. *
  49. *Exit:
  50. * Returns TRUE if c is an graphical character; else FALSE
  51. *
  52. *Exceptions:
  53. *
  54. *******************************************************************************/
  55. int __cdecl _ismbcgraph(
  56. unsigned int c
  57. )
  58. {
  59. #ifdef _MT
  60. pthreadmbcinfo ptmbci = _getptd()->ptmbcinfo;
  61. if ( ptmbci != __ptmbcinfo )
  62. ptmbci = __updatetmbcinfo();
  63. #endif
  64. if (c > 0x00FF)
  65. {
  66. #if !defined(_POSIX_)
  67. char buf[2];
  68. unsigned short ctype[2] = {0};
  69. buf[0] = (c >> 8) & 0xFF;
  70. buf[1] = c & 0xFF;
  71. /* return FALSE if not in supported MB code page */
  72. #ifdef _MT
  73. if ( _ISNOTMBCP_MT(ptmbci) )
  74. #else
  75. if ( _ISNOTMBCP )
  76. #endif
  77. return 0;
  78. /*
  79. * Since 'c' could be two one-byte MB chars, we need room in the
  80. * ctype return array to handle this. In this case, the
  81. * second word in the return array will be non-zero.
  82. */
  83. if ( __crtGetStringTypeA( CT_CTYPE1,
  84. buf,
  85. 2,
  86. ctype,
  87. #ifdef _MT
  88. ptmbci->mbcodepage,
  89. ptmbci->mblcid,
  90. #else
  91. __mbcodepage,
  92. __mblcid,
  93. #endif
  94. TRUE) == 0 )
  95. return 0;
  96. /* ensure single MB character and test for type */
  97. return (ctype[1] == 0 && ctype[0] & (_PUNCT|_ALPHA|_DIGIT));
  98. #else /* !_POSIX_ */
  99. /* no hard-coded double-byte graphical info available */
  100. return _ismbcalnum(c) | _ismbcdigit(c);
  101. #endif /* !_POSIX_ */
  102. } else
  103. #ifdef _MT
  104. return __ismbbgraph_mt(ptmbci, c);
  105. #else
  106. return _ismbbgraph(c);
  107. #endif
  108. }
  109. #endif /* _MBCS */