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

  1. /***
  2. *stricoll.c - Collate locale strings without regard to case
  3. *
  4. *       Copyright (c) 1988-1998, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       Compare two strings using the locale LC_COLLATE information.
  8. *
  9. *******************************************************************************/
  10.  
  11. #include <cruntime.h>
  12. #include <string.h>
  13.  
  14. #ifdef _WIN32
  15. #include <windows.h>
  16. #include <stdlib.h>
  17. #include <malloc.h>
  18. #include <locale.h>
  19. #include <setlocal.h>
  20. #include <mtdll.h>
  21. #include <errno.h>
  22. #include <awint.h>
  23. #endif  /* _WIN32 */
  24.  
  25. /***
  26. *int _stricoll() - Collate locale strings without regard to case
  27. *
  28. *Purpose:
  29. *       Compare two strings using the locale LC_COLLATE information
  30. *       without regard to case.
  31. *
  32. *Entry:
  33. *       const char *s1 = pointer to the first string
  34. *       const char *s2 = pointer to the second string
  35. *
  36. *Exit:
  37. *       Less than 0    = first string less than second string
  38. *       0              = strings are equal
  39. *       Greater than 0 = first string greater than second string
  40. *
  41. *Exceptions:
  42. *       _NLSCMPERROR    = error
  43. *       errno = EINVAL
  44. *
  45. *******************************************************************************/
  46.  
  47. int __cdecl _stricoll (
  48.         const char *_string1,
  49.         const char *_string2
  50.         )
  51. {
  52. #if defined (_WIN32)
  53.  
  54.         int ret;
  55. #if defined (_MT)
  56.         int local_lock_flag;
  57. #endif  /* defined (_MT) */
  58.  
  59.         if (__lc_handle[LC_COLLATE] == _CLOCALEHANDLE) {
  60.                 return _strcmpi(_string1, _string2);
  61.         }
  62.  
  63.         _lock_locale( local_lock_flag)
  64.  
  65. #if defined (_MT)
  66.         if (__lc_handle[LC_COLLATE] == _CLOCALEHANDLE) {
  67.                 _unlock_locale( local_lock_flag )
  68.                 return _strcmpi(_string1, _string2);
  69.         }
  70. #endif  /* defined (_MT) */
  71.  
  72.         if ( 0 == (ret = __crtCompareStringA( __lc_handle[LC_COLLATE],
  73.                                               SORT_STRINGSORT | NORM_IGNORECASE,
  74.                                               _string1,
  75.                                               -1,
  76.                                               _string2,
  77.                                               -1,
  78.                                               __lc_collate_cp )) )
  79.             goto error_cleanup;
  80.  
  81.         _unlock_locale( local_lock_flag )
  82.         return (ret - 2);
  83.  
  84. error_cleanup:
  85.         _unlock_locale( local_lock_flag )
  86.         errno = EINVAL;
  87.         return _NLSCMPERROR;
  88.  
  89. #else  /* defined (_WIN32) */
  90.  
  91.         return _strcmpi(_string1, _string2);
  92.  
  93. #endif  /* defined (_WIN32) */
  94. }
  95.