1 /* Case-independent string comparison HTString.c
3 ** Original version came with listserv implementation.
4 ** Version TBL Oct 91 replaces one which modified the strings.
5 ** 02-Dec-91 (JFG) Added stralloccopy and stralloccat
6 ** 23 Jan 92 (TBL) Changed strallocc* to 8 char HTSAC* for VM and suchlike
12 #ifndef VM /* VM has these already it seems */
14 /* Strings of any length
15 ** ---------------------
17 PUBLIC int strcasecomp ARGS2 (CONST char*,a, CONST char *,b)
21 for(p=a, q=b; *p && *q; p++, q++) {
22 int diff = TOLOWER(*p) - TOLOWER(*q);
23 if (diff) return diff;
25 if (*p) return 1; /* p was longer than q */
26 if (*q) return -1; /* p was shorter than q */
27 return 0; /* Exact match */
34 PUBLIC int strncasecomp ARGS3(CONST char*,a, CONST char *,b, int,n)
39 for(p=a, q=b;; p++, q++) {
41 if (p == a+n) return 0; /* Match up to n characters */
42 if (!(*p && *q)) return *p - *q;
43 diff = TOLOWER(*p) - TOLOWER(*q);
44 if (diff) return diff;
50 /* Allocate a new copy of a string, and returns it
52 PUBLIC char * HTSACopy
53 ARGS2 (char **,dest, CONST char *,src)
55 if (*dest) free(*dest);
59 *dest = (char *) malloc (strlen(src) + 1);
60 if (*dest == NULL) outofmem(__FILE__, "HTSACopy");
67 ARGS2 (char **,dest, CONST char *,src)
71 int length = strlen (*dest);
72 *dest = (char *) realloc (*dest, length + strlen(src) + 1);
73 if (*dest == NULL) outofmem(__FILE__, "HTSACat");
74 strcpy (*dest + length, src);
76 *dest = (char *) malloc (strlen(src) + 1);
77 if (*dest == NULL) outofmem(__FILE__, "HTSACat");