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.

156 lines
4.3 KiB

  1. /***
  2. *towupper.c - convert wide character to upper case
  3. *
  4. * Copyright (c) 1991-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Defines towupper().
  8. *
  9. *Revision History:
  10. * 10-11-91 ETC Created.
  11. * 12-10-91 ETC Updated nlsapi; added multithread.
  12. * 04-06-92 KRS Make work without _INTL also.
  13. * 01-19-93 CFW Changed LCMapString to LCMapStringW.
  14. * 04-06-93 SKS Replace _CRTAPI* with _cdecl
  15. * 06-02-93 SRW ignore _INTL if _NTSUBSET_ defined.
  16. * 06-11-93 CFW Fix error handling bug.
  17. * 09-15-93 CFW Use ANSI conformant "__" names.
  18. * 09-22-93 CFW Use __crtxxx internal NLS API wrapper.
  19. * 09-29-93 GJF Merged NT SDK and Cuda versions.
  20. * 11-09-93 CFW Add code page for __crtxxx().
  21. * 01-14-94 SRW if _NTSUBSET_ defined call Rtl functions
  22. * 02-07-94 CFW POSIXify.
  23. * 09-06-94 CFW Remove _INTL switch.
  24. * 10-25-94 GJF Sped up for C locale. Added _towupper_lk. Also,
  25. * cleaned up pre-processor conditionals.
  26. * 09-26-95 GJF New locking macro, and scheme, for functions which
  27. * reference the locale.
  28. * 04-01-96 BWT POSIX work.
  29. * 06-25-96 GJF Removed DLL_FOR_WIN32S and cleaned up the format a
  30. * wee bit.
  31. * 08-27-98 GJF Revised multithread support based on threadlocinfo
  32. * struct.
  33. *
  34. *******************************************************************************/
  35. #if defined(_NTSUBSET_) || defined(_POSIX_)
  36. #include <nt.h>
  37. #include <ntrtl.h>
  38. #include <nturtl.h>
  39. #endif
  40. #include <cruntime.h>
  41. #include <ctype.h>
  42. #include <stdio.h>
  43. #include <locale.h>
  44. #include <setlocal.h>
  45. #include <mtdll.h>
  46. #include <awint.h>
  47. /***
  48. *wchar_t towupper(c) - convert wide character to upper case
  49. *
  50. *Purpose:
  51. * towupper() returns the uppercase equivalent of its argument
  52. *
  53. *Entry:
  54. * c - wchar_t value of character to be converted
  55. *
  56. *Exit:
  57. * if c is a lower case letter, returns wchar_t value of upper case
  58. * representation of c. otherwise, it returns c.
  59. *
  60. *Exceptions:
  61. *
  62. *******************************************************************************/
  63. wchar_t __cdecl towupper (
  64. wchar_t c
  65. )
  66. {
  67. #if !defined(_NTSUBSET_) && !defined(_POSIX_)
  68. #ifdef _MT
  69. pthreadlocinfo ptloci = _getptd()->ptlocinfo;
  70. if ( ptloci != __ptlocinfo )
  71. ptloci = __updatetlocinfo();
  72. if ( ptloci->lc_handle[LC_CTYPE] == _CLOCALEHANDLE )
  73. return __ascii_towupper(c);
  74. return __towupper_mt(ptloci, c);
  75. }
  76. /***
  77. *wchar_t __towupper_mt(ptloci, c) - convert wide character to upper case
  78. *
  79. *Purpose:
  80. * Multi-thread function only! Non-locking version of towupper.
  81. *
  82. *Entry:
  83. *
  84. *Exit:
  85. *
  86. *Exceptions:
  87. *
  88. *******************************************************************************/
  89. wchar_t __cdecl __towupper_mt (
  90. pthreadlocinfo ptloci,
  91. wchar_t c
  92. )
  93. {
  94. #endif /* _MT */
  95. wchar_t widechar;
  96. if (c == WEOF)
  97. return c;
  98. #ifndef _MT
  99. if ( __lc_handle[LC_CTYPE] == _CLOCALEHANDLE )
  100. return __ascii_towupper(c);
  101. #endif
  102. /* if checking case of c does not require API call, do it */
  103. if ( c < 256 ) {
  104. #ifdef _MT
  105. if ( !__iswlower_mt(ptloci, c) ) {
  106. #else
  107. if ( !iswlower(c) ) {
  108. #endif
  109. return c;
  110. }
  111. }
  112. /* convert wide char to uppercase */
  113. #ifdef _MT
  114. if ( 0 == __crtLCMapStringW( ptloci->lc_handle[LC_CTYPE],
  115. #else
  116. if ( 0 == __crtLCMapStringW( __lc_handle[LC_CTYPE],
  117. #endif
  118. LCMAP_UPPERCASE,
  119. (LPCWSTR)&c,
  120. 1,
  121. (LPWSTR)&widechar,
  122. 1,
  123. #ifdef _MT
  124. ptloci->lc_codepage ) )
  125. #else
  126. __lc_codepage ) )
  127. #endif
  128. {
  129. return c;
  130. }
  131. return widechar;
  132. #else /* _NTSUBSET_/_POSIX_ */
  133. return RtlUpcaseUnicodeChar( c );
  134. #endif /* _NTSUBSET_/_POSIX_ */
  135. }