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.6 KiB

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