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

  1. /***
  2. *mbtoupr.c - Convert character to upper case (MBCS)
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Convert character to upper case (MBCS)
  8. *
  9. *Revision History:
  10. * 11-19-92 KRS Ported from 16-bit sources.
  11. * 08-20-93 CFW Change short params to int for 32-bit tree.
  12. * 09-29-93 CFW Merge _KANJI and _MBCS_OS
  13. * 10-06-93 GJF Replaced _CRTAPI1 with __cdecl.
  14. * 04-12-94 CFW Make function generic.
  15. * 04-21-94 CFW Return bad chars unchanged.
  16. * 05-16-94 CFW Use _mbbtolower/upper.
  17. * 05-17-94 CFW Enable non-Win32.
  18. * 03-17-97 RDK Added error flag to __crtLCMapStringA.
  19. * 09-26-97 BWT Fix POSIX
  20. * 04-21-98 GJF Implemented multithread support based on threadmbcinfo
  21. * structs
  22. * 05-17-99 PML Remove all Macintosh support.
  23. *
  24. *******************************************************************************/
  25. #ifdef _MBCS
  26. #if !defined(_POSIX_)
  27. #include <awint.h>
  28. #include <mtdll.h>
  29. #endif /* !_POSIX_ */
  30. #include <cruntime.h>
  31. #include <ctype.h>
  32. #include <mbdata.h>
  33. #include <mbctype.h>
  34. #include <mbstring.h>
  35. /***
  36. * _mbctoupper - Convert character to upper case (MBCS)
  37. *
  38. *Purpose:
  39. * If the given character is lower case, convert to upper case.
  40. * Handles MBCS chars 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 convert
  48. *
  49. *Exit:
  50. * Returns converted character
  51. *
  52. *Exceptions:
  53. *
  54. *******************************************************************************/
  55. unsigned int __cdecl _mbctoupper(unsigned int c)
  56. {
  57. unsigned char val[2];
  58. #if !defined(_POSIX_)
  59. unsigned char ret[4];
  60. #endif /* !_POSIX_ */
  61. #ifdef _MT
  62. pthreadmbcinfo ptmbci = _getptd()->ptmbcinfo;
  63. if ( ptmbci != __ptmbcinfo )
  64. ptmbci = __updatetmbcinfo();
  65. #endif
  66. if (c > 0x00FF)
  67. {
  68. val[0] = (c >> 8) & 0xFF;
  69. val[1] = c & 0xFF;
  70. #ifdef _MT
  71. if ( !__ismbblead_mt(ptmbci, val[0]) )
  72. #else
  73. if ( !_ismbblead(val[0]) )
  74. #endif
  75. return c;
  76. #if !defined(_POSIX_)
  77. #ifdef _MT
  78. if ( __crtLCMapStringA( ptmbci->mblcid,
  79. #else
  80. if ( __crtLCMapStringA( __mblcid,
  81. #endif
  82. LCMAP_UPPERCASE,
  83. val,
  84. 2,
  85. ret,
  86. 2,
  87. #ifdef _MT
  88. ptmbci->mbcodepage,
  89. #else
  90. __mbcodepage,
  91. #endif
  92. TRUE ) == 0 )
  93. return c;
  94. c = ret[1];
  95. c += ret[0] << 8;
  96. return c;
  97. #else /* !_POSIX_ */
  98. if (c >= _MBLOWERLOW1 && c <= _MBLOWERHIGH1)
  99. c -= _MBCASEDIFF1;
  100. else if (c >= _MBLOWERLOW2 && c <= _MBLOWERHIGH2)
  101. c -= _MBCASEDIFF2;
  102. return c;
  103. #endif /* !_POSIX_ */
  104. }
  105. else
  106. #ifdef _MT
  107. return (unsigned int)__mbbtoupper_mt(ptmbci, (int)c);
  108. #else
  109. return (unsigned int)_mbbtoupper((int)c);
  110. #endif
  111. }
  112. #endif /* _MBCS */