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

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