1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
/*
* Copyright 1988 by Rayan S. Zachariassen, all rights reserved.
* This will be free software, but only when it is finished.
*/
/*
* Useful string functions.
*/
#include "hostenv.h"
#include <stdio.h>
#include <sys/types.h>
#include <ctype.h>
#include "mailer.h"
#include "libz.h"
/* Like strcmp(), but case-independent */
int
cistrcmp(a, b)
register const char *a, *b;
{
unsigned char ac, bc;
while (*a && *b) {
ac = *a;
ac = isupper(ac) ? tolower(ac) : ac;
bc = *b;
bc = isupper(bc) ? tolower(bc) : bc;
if (ac != bc)
return ac - bc;
++a, ++b;
}
return *a - *b;
}
/*
* Like cistrcmp(),
* but tests if one string is a prefix of the other if string length < n
*/
int
cistrncmp(a, b, n)
register const char *a, *b;
int n;
{
unsigned char ac, bc;
while (n-- > 0) {
ac = *a;
ac = isupper(ac) ? tolower(ac) : ac;
bc = *b;
bc = isupper(bc) ? tolower(bc) : bc;
if (ac != bc)
return ac - bc;
++a, ++b;
}
return *a * *b;
}
/*
* Like cistrncmp(),
* but tests if part of one string is a prefix of the other to n characters.
*/
int
ci2strncmp(a, b, n)
register const char *a, *b;
int n;
{
unsigned char ac, bc;
while (n-- > 0) {
ac = *a;
ac = isupper(ac) ? tolower(ac) : ac;
bc = *b;
bc = isupper(bc) ? tolower(bc) : bc;
if (ac != bc) {
return ac - bc;
}
++a, ++b;
}
return 0;
}
|