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

  1. /***
  2. *wcscoll.c - Collate wide-character locale strings
  3. *
  4. *       Copyright (c) 1988-1998, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       Compare two wchar_t strings using the locale LC_COLLATE information.
  8. *
  9. *******************************************************************************/
  10.  
  11.  
  12. #include <cruntime.h>
  13. #include <windows.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include <locale.h>
  17. #include <setlocal.h>
  18. #include <mtdll.h>
  19. #include <errno.h>
  20. #include <awint.h>
  21.  
  22. /***
  23. *int wcscoll() - Collate wide-character locale strings
  24. *
  25. *Purpose:
  26. *       Compare two wchar_t strings using the locale LC_COLLATE information.
  27. *       In the C locale, wcscmp() is used to make the comparison.
  28. *
  29. *Entry:
  30. *       const wchar_t *s1 = pointer to the first string
  31. *       const wchar_t *s2 = pointer to the second string
  32. *
  33. *Exit:
  34. *       -1 = first string less than second string
  35. *        0 = strings are equal
  36. *        1 = first string greater than second string
  37. *       This range of return values may differ from other *cmp/*coll functions.
  38. *
  39. *Exceptions:
  40. *       _NLSCMPERROR    = error
  41. *       errno = EINVAL
  42. *
  43. *******************************************************************************/
  44.  
  45. int __cdecl wcscoll (
  46.         const wchar_t *_string1,
  47.         const wchar_t *_string2
  48.         )
  49. {
  50.  
  51.         int ret;
  52. #if defined (_MT)
  53.         int local_lock_flag;
  54. #endif  /* defined (_MT) */
  55.  
  56.         if (__lc_handle[LC_COLLATE] == _CLOCALEHANDLE) {
  57.                 return (wcscmp(_string1, _string2));
  58.         }
  59.  
  60.         _lock_locale( local_lock_flag )
  61.  
  62. #if defined (_MT)
  63.         if (__lc_handle[LC_COLLATE] == _CLOCALEHANDLE) {
  64.                 _unlock_locale( local_lock_flag )
  65.                 return (wcscmp(_string1, _string2));
  66.         }
  67. #endif  /* defined (_MT) */
  68.  
  69.         if ( 0 == (ret = __crtCompareStringW( __lc_handle[LC_COLLATE],
  70.                                               SORT_STRINGSORT,
  71.                                               _string1,
  72.                                               -1,
  73.                                               _string2,
  74.                                               -1,
  75.                                               __lc_collate_cp)) )
  76.         {
  77.                 _unlock_locale( local_lock_flag )
  78.                 errno = EINVAL;
  79.                 return _NLSCMPERROR;
  80.         }
  81.  
  82.         _unlock_locale( local_lock_flag )
  83.         return (ret - 2);
  84.  
  85. }
  86.  
  87.