home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / mbslwr.c < prev    next >
C/C++ Source or Header  |  1998-06-17  |  3KB  |  104 lines

  1. /***
  2. *mbslwr.c - Convert string lower case (MBCS)
  3. *
  4. *       Copyright (c) 1985-1997, Microsoft Corporation.  All rights reserved.
  5. *
  6. *Purpose:
  7. *       Convert string lower case (MBCS)
  8. *
  9. *******************************************************************************/
  10.  
  11. #ifdef _MBCS
  12.  
  13. #if defined (_WIN32)
  14. #include <awint.h>
  15. #endif  /* defined (_WIN32) */
  16.  
  17. #include <mtdll.h>
  18. #include <cruntime.h>
  19. #include <ctype.h>
  20. #include <mbdata.h>
  21. #include <mbstring.h>
  22. #include <mbctype.h>
  23.  
  24.  
  25. /***
  26. * _mbslwr - Convert string lower case (MBCS)
  27. *
  28. *Purpose:
  29. *       Convrts all the upper case characters in a string
  30. *       to lower case in place.  MBCS chars are handled
  31. *       correctly.
  32. *
  33. *Entry:
  34. *       unsigned char *string = pointer to string
  35. *
  36. *Exit:
  37. *       Returns a pointer to the input string; no error return.
  38. *
  39. *Exceptions:
  40. *
  41. *******************************************************************************/
  42.  
  43. unsigned char * __cdecl _mbslwr(
  44.     unsigned char *string
  45.     )
  46. {
  47.         unsigned char *cp;
  48.  
  49.         _mlock(_MB_CP_LOCK);
  50.  
  51.         for (cp=string; *cp; cp++)
  52.         {
  53.             if (_ISLEADBYTE(*cp))
  54.             {
  55.  
  56. #if defined (_WIN32)
  57.  
  58.                 int retval;
  59.                 unsigned char ret[4];
  60.  
  61.                 if ((retval = __crtLCMapStringA(__mblcid,
  62.                                                 LCMAP_LOWERCASE,
  63.                                                 cp,
  64.                                                 2,
  65.                                                 ret,
  66.                                                 2,
  67.                                                 __mbcodepage,
  68.                                                 TRUE)) == 0)
  69.                 {
  70.                     _munlock(_MB_CP_LOCK);
  71.                     return NULL;
  72.                 }
  73.  
  74.                 *cp = ret[0];
  75.  
  76.                 if (retval > 1)
  77.                     *(++cp) = ret[1];
  78.  
  79. #else  /* defined (_WIN32) */
  80.  
  81.                 int mbval = ((*cp) << 8) + *(cp+1);
  82.  
  83.                 cp++;
  84.                 if (     mbval >= _MBUPPERLOW1
  85.                     &&   mbval <= _MBUPPERHIGH1 )
  86.                     *cp += _MBCASEDIFF1;
  87.  
  88.                 else if (mbval >= _MBUPPERLOW2
  89.                     &&   mbval <= _MBUPPERHIGH2 )
  90.                     *cp += _MBCASEDIFF2;
  91. #endif  /* defined (_WIN32) */
  92.  
  93.             }
  94.             else
  95.                 /* single byte, macro version */
  96.                 *cp = (unsigned char) _mbbtolower(*cp);
  97.         }
  98.  
  99.         _munlock(_MB_CP_LOCK);
  100.         return string ;
  101. }
  102.  
  103. #endif  /* _MBCS */
  104.