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

  1. /***
  2. *mbsupr.c - Convert string upper case (MBCS)
  3. *
  4. *       Copyright (c) 1985-1997, Microsoft Corporation.  All rights reserved.
  5. *
  6. *Purpose:
  7. *       Convert string upper 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. * _mbsupr - Convert string upper case (MBCS)
  27. *
  28. *Purpose:
  29. *       Converts all the lower case characters in a string
  30. *       to upper case in place.   Handles MBCS chars correctly.
  31. *
  32. *Entry:
  33. *       unsigned char *string = pointer to string
  34. *
  35. *Exit:
  36. *       Returns a pointer to the input string; no error return.
  37. *
  38. *Exceptions:
  39. *
  40. *******************************************************************************/
  41.  
  42. unsigned char * __cdecl _mbsupr(
  43.     unsigned char *string
  44.     )
  45. {
  46.         unsigned char *cp;
  47.  
  48.         _mlock(_MB_CP_LOCK);
  49.  
  50.         for (cp=string; *cp; cp++)
  51.         {
  52.             if (_ISLEADBYTE(*cp))
  53.             {
  54.  
  55. #if defined (_WIN32)
  56.  
  57.                 int retval;
  58.                 unsigned char ret[4];
  59.  
  60.                 if ((retval = __crtLCMapStringA(__mblcid,
  61.                                                 LCMAP_UPPERCASE,
  62.                                                 cp,
  63.                                                 2,
  64.                                                 ret,
  65.                                                 2,
  66.                                                 __mbcodepage,
  67.                                                 TRUE)) == 0)
  68.                 {
  69.                     _munlock(_MB_CP_LOCK);
  70.                     return NULL;
  71.                 }
  72.  
  73.                 *cp = ret[0];
  74.  
  75.                 if (retval > 1)
  76.                     *(++cp) = ret[1];
  77.  
  78. #else  /* defined (_WIN32) */
  79.  
  80.                 int mbval = ((*cp) << 8) + *(cp+1);
  81.  
  82.                 cp++;
  83.                 if (     mbval >= _MBLOWERLOW1
  84.                     &&   mbval <= _MBLOWERHIGH1 )
  85.                     *cp -= _MBCASEDIFF1;
  86.  
  87.                 else if (mbval >= _MBLOWERLOW2
  88.                     &&   mbval <= _MBLOWERHIGH2 )
  89.                     *cp -= _MBCASEDIFF2;
  90.  
  91. #endif  /* defined (_WIN32) */
  92.  
  93.             }
  94.             else
  95.                 /* single byte, macro version */
  96.                 *cp = (unsigned char) _mbbtoupper(*cp);
  97.         }
  98.  
  99.         _munlock(_MB_CP_LOCK);
  100.         return string ;
  101. }
  102.  
  103. #endif  /* _MBCS */
  104.