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

  1. /***
  2. *stricmp.c - contains case-insensitive string comp routine _stricmp/_strcmpi
  3. *
  4. *       Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       contains _stricmp(), also known as _strcmpi()
  8. *
  9. *******************************************************************************/
  10.  
  11. #include <cruntime.h>
  12. #include <string.h>
  13.  
  14. #ifdef _WIN32
  15. #include <mtdll.h>
  16. #include <setlocal.h>
  17. #include <ctype.h>
  18. #include <locale.h>
  19. #endif  /* _WIN32 */
  20.  
  21. /***
  22. *int _stricmp(dst, src), _strcmpi(dst, src) - compare strings, ignore case
  23. *
  24. *Purpose:
  25. *       _stricmp/_strcmpi perform a case-insensitive string comparision.
  26. *       For differences, upper case letters are mapped to lower case.
  27. *       Thus, "abc_" < "ABCD" since "_" < "d".
  28. *
  29. *Entry:
  30. *       char *dst, *src - strings to compare
  31. *
  32. *Return:
  33. *       <0 if dst < src
  34. *        0 if dst = src
  35. *       >0 if dst > src
  36. *
  37. *Exceptions:
  38. *
  39. *******************************************************************************/
  40.  
  41. int __cdecl _stricmp (
  42.         const char * dst,
  43.         const char * src
  44.         )
  45. {
  46.         return( _strcmpi(dst,src) );
  47. }
  48.  
  49.  
  50. int __cdecl _strcmpi(const char * dst, const char * src)
  51. {
  52.         int f,l;
  53. #ifdef _MT
  54.         int local_lock_flag;
  55. #endif  /* _MT */
  56.  
  57. #if defined (_WIN32)
  58.         if ( __lc_handle[LC_CTYPE] == _CLOCALEHANDLE ) {
  59. #endif  /* defined (_WIN32) */
  60.             do {
  61.                 if ( ((f = (unsigned char)(*(dst++))) >= 'A') && (f <= 'Z') )
  62.                     f -= ('A' - 'a');
  63.  
  64.                 if ( ((l = (unsigned char)(*(src++))) >= 'A') && (l <= 'Z') )
  65.                     l -= ('A' - 'a');
  66.             } while ( f && (f == l) );
  67. #if defined (_WIN32)
  68.         }
  69.         else {
  70.             _lock_locale( local_lock_flag )
  71.             do {
  72.                 f = _tolower_lk( (unsigned char)(*(dst++)) );
  73.                 l = _tolower_lk( (unsigned char)(*(src++)) );
  74.             } while ( f && (f == l) );
  75.             _unlock_locale( local_lock_flag )
  76.         }
  77. #endif  /* defined (_WIN32) */
  78.  
  79.         return(f - l);
  80. }
  81.