Source code of Windows XP (NT5)
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.

131 lines
3.5 KiB

  1. /***
  2. *mbslwr.c - Convert string lower case (MBCS)
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Convert string lower case (MBCS)
  8. *
  9. *Revision History:
  10. * 11-19-92 KRS Ported from 16-bit sources.
  11. * 09-29-93 CFW Merge _KANJI and _MBCS_OS
  12. * 10-05-93 GJF Replaced _CRTAPI1 with __cdecl.
  13. * 04-12-94 CFW Make function generic.
  14. * 04-15-93 CFW Add _MB_CP_LOCK.
  15. * 05-16-94 CFW Use _mbbtolower/upper.
  16. * 05-17-94 CFW Enable non-Win32.
  17. * 03-13-95 JCF Add (unsigned char) in _MB* compare with *(cp+1).
  18. * 05-31-95 CFW Fix horrible Mac bug.
  19. * 03-17-97 RDK Added error flag to __crtLCMapStringA.
  20. * 09-26-97 BWT Fix POSIX
  21. * 04-07-98 GJF Revised multithread support based on threadmbcinfo
  22. * structs
  23. * 05-17-99 PML Remove all Macintosh support.
  24. *
  25. *******************************************************************************/
  26. #ifdef _MBCS
  27. #include <awint.h>
  28. #include <mtdll.h>
  29. #include <cruntime.h>
  30. #include <ctype.h>
  31. #include <mbdata.h>
  32. #include <mbstring.h>
  33. #include <mbctype.h>
  34. /***
  35. * _mbslwr - Convert string lower case (MBCS)
  36. *
  37. *Purpose:
  38. * Convrts all the upper case characters in a string
  39. * to lower case in place. MBCS chars are handled
  40. * correctly.
  41. *
  42. *Entry:
  43. * unsigned char *string = pointer to string
  44. *
  45. *Exit:
  46. * Returns a pointer to the input string; no error return.
  47. *
  48. *Exceptions:
  49. *
  50. *******************************************************************************/
  51. unsigned char * __cdecl _mbslwr(
  52. unsigned char *string
  53. )
  54. {
  55. unsigned char *cp;
  56. #ifdef _MT
  57. pthreadmbcinfo ptmbci = _getptd()->ptmbcinfo;
  58. if ( ptmbci != __ptmbcinfo )
  59. ptmbci = __updatetmbcinfo();
  60. #endif
  61. for (cp=string; *cp; cp++)
  62. {
  63. #ifdef _MT
  64. if ( __ismbblead_mt(ptmbci, *cp) )
  65. #else
  66. if ( _ismbblead(*cp) )
  67. #endif
  68. {
  69. #if !defined(_POSIX_)
  70. int retval;
  71. unsigned char ret[4];
  72. #ifdef _MT
  73. if ((retval = __crtLCMapStringA( ptmbci->mblcid,
  74. #else
  75. if ( (retval = __crtLCMapStringA( __mblcid,
  76. #endif
  77. LCMAP_LOWERCASE,
  78. cp,
  79. 2,
  80. ret,
  81. 2,
  82. #ifdef _MT
  83. ptmbci->mbcodepage,
  84. #else
  85. __mbcodepage,
  86. #endif
  87. TRUE )) == 0 )
  88. return NULL;
  89. *cp = ret[0];
  90. if (retval > 1)
  91. *(++cp) = ret[1];
  92. #else /* !_POSIX_ */
  93. int mbval = ((*cp) << 8) + *(cp+1);
  94. cp++;
  95. if ( mbval >= _MBUPPERLOW1
  96. && mbval <= _MBUPPERHIGH1 )
  97. *cp += _MBCASEDIFF1;
  98. else if (mbval >= _MBUPPERLOW2
  99. && mbval <= _MBUPPERHIGH2 )
  100. *cp += _MBCASEDIFF2;
  101. #endif /* !_POSIX_ */
  102. }
  103. else
  104. /* single byte, macro version */
  105. #ifdef _MT
  106. *cp = (unsigned char) __mbbtolower_mt(ptmbci, *cp);
  107. #else
  108. *cp = (unsigned char) _mbbtolower(*cp);
  109. #endif
  110. }
  111. return string ;
  112. }
  113. #endif /* _MBCS */