home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib25.zoo / stricmp.c < prev    next >
C/C++ Source or Header  |  1992-09-17  |  1KB  |  58 lines

  1. /* derived from strcmp from Henry Spencer's stringlib */
  2. /* modified by ERS */
  3. /* i-changes by Alexander Lehmann */
  4.  
  5. #include <string.h>
  6. #include <ctype.h>
  7.  
  8. /*
  9.  * stricmp - compare string s1 to s2 without case sensitivity
  10.  *           result is equivalent to strcmp(strupr(s1),s2)),
  11.  *           but doesn't change anything
  12.  */
  13.  
  14. #ifdef __GNUC__
  15. asm(".stabs \"_strcmpi\",5,0,0,_stricmp"); /* dept of clean tricks */
  16. #endif
  17.  
  18. int                             /* <0 for <, 0 for ==, >0 for > */
  19. stricmp(scan1, scan2)
  20. register const char *scan1;
  21. register const char *scan2;
  22. {
  23.         register char c1, c2;
  24.  
  25.         if (!scan1)
  26.                 return scan2 ? -1 : 0;
  27.         if (!scan2) return 1;
  28.  
  29.         do {
  30.                 c1 = *scan1++; c1=toupper(c1);
  31.                 c2 = *scan2++; c2=toupper(c2);
  32.         } while (c1 && c1 == c2);
  33.  
  34.         /*
  35.          * The following case analysis is necessary so that characters
  36.          * which look negative collate low against normal characters but
  37.          * high against the end-of-string NUL.
  38.          */
  39.         if (c1 == c2)
  40.                 return(0);
  41.         else if (c1 == '\0')
  42.                 return(-1);
  43.         else if (c2 == '\0')
  44.                 return(1);
  45.         else
  46.                 return(c1 - c2);
  47. }
  48.  
  49. #ifndef __GNUC__
  50. int
  51. strcmpi(scan1, scan2)
  52. register const char *scan1;
  53. register const char *scan2;
  54. {
  55.     return stricmp(scan1, scan2);
  56. }
  57. #endif
  58.