int _rfc_casecmp(const char *s1, const char *s2) { while ((*s1) && (*s2) && (rfc_toupper(*s1) == rfc_toupper(*s2))) { ++s1; ++s2; } return rfc_toupper(*s1) - rfc_toupper(*s2); }
int _rfc_ncasecmp(const char *s1, const char *s2, size_t n) { if (!n) return 0; while (--n && (*s1) && (*s2) && (rfc_toupper(*s1) == rfc_toupper(*s2))) { ++s1; ++s2; } return rfc_toupper(*s1) - rfc_toupper(*s2); }
int _rfc_casecmp(const char *s1, const char *s2) { register unsigned char *str1 = (unsigned char *) s1; register unsigned char *str2 = (unsigned char *) s2; register int res; while ((res = rfc_toupper(*str1) - rfc_toupper(*str2)) == 0) { if (*str1 == '\0') return 0; str1++; str2++; } return (res); }
int _rfc_ncasecmp(const char *str1, const char *str2, int n) { register unsigned char *s1 = (unsigned char *) str1; register unsigned char *s2 = (unsigned char *) str2; register int res; while ((res = rfc_toupper(*s1) - rfc_toupper(*s2)) == 0) { s1++; s2++; n--; if (n == 0 || (*s1 == '\0' && *s2 == '\0')) return 0; } return (res); }
int wild_match(register unsigned char *m, register unsigned char *n) #endif { unsigned char *ma = m, *lsm = 0, *lsn = 0, *lpm = 0, *lpn = 0; int match = 1, saved = 0; register unsigned int sofar = 0; #ifdef WILDT int space; #endif /* take care of null strings (should never match) */ if ((m == 0) || (n == 0) || (!*n)) return NOMATCH; /* (!*m) test used to be here, too, but I got rid of it. After all, * If (!*n) was false, there must be a character in the name (the * second string), so if the mask is empty it is a non-match. Since * the algorithm handles this correctly without testing for it here * and this shouldn't be called with null masks anyway, it should be * a bit faster this way */ while (*n) { /* Used to test for (!*m) here, but this scheme seems to work better */ #ifdef WILDT if (*m == WILDT) { /* Match >=1 space */ space = 0; /* Don't need any spaces */ do { m++; space++; } /* Tally 1 more space ... */ while ((*m == WILDT) || (*m == ' ')); /* for each space or ~ */ sofar += space; /* Each counts as exact */ while (*n == ' ') { n++; space--; } /* Do we have enough? */ if (space <= 0) continue; /* Had enough spaces! */ } /* Do the fallback */ else { #endif switch (*m) { case 0: do m--; /* Search backwards */ while ((m > ma) && (*m == '?')); /* For first non-? char */ if ((m > ma) ? ((*m == '*') && (m[-1] != QUOTE)) : (*m == '*')) return MATCH; /* nonquoted * = match */ break; case WILDP: while (*(++m) == WILDP); /* Zap redundant %s */ if (*m != WILDS) { /* Don't both if next=* */ if (*n != ' ') { /* WILDS can't match ' ' */ lpm = m; lpn = n; /* Save '%' fallback spot */ saved += sofar; sofar = 0; /* And save tally count */ } continue; /* Done with '%' */ } /* FALL THROUGH */ case WILDS: do m++; /* Zap redundant wilds */ while ((*m == WILDS) || (*m == WILDP)); lsm = m; lsn = n; lpm = 0; /* Save '*' fallback spot */ match += (saved + sofar); /* Save tally count */ saved = sofar = 0; continue; /* Done with '*' */ case WILDQ: m++; n++; continue; /* Match one char */ case QUOTE: m++; /* Handle quoting */ } if (rfc_toupper(*m) == rfc_toupper(*n)) { /* If matching */ m++; n++; sofar++; continue; /* Tally the match */ } #ifdef WILDT } #endif if (lpm) { /* Try to fallback on '%' */ n = ++lpn; m = lpm; sofar = 0; /* Restore position */ if ((*n | 32) == 32) lpm = 0; /* Can't match 0 or ' ' */ continue; /* Next char, please */ } if (lsm) { /* Try to fallback on '*' */ n = ++lsn; m = lsm; /* Restore position */ /* Used to test for (!*n) here but it wasn't necessary so it's gone */ saved = sofar = 0; continue; /* Next char, please */ } return NOMATCH; /* No fallbacks=No match */ } while ((*m == WILDS) || (*m == WILDP)) m++; /* Zap leftover %s & *s */ return (*m) ? NOMATCH : MATCH; /* End of both = match */ }