Annotation of libwww/Library/src/HTString.c, revision 2.5
1.1 timbl 1: /* Case-independent string comparison HTString.c
2: **
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
7: ** 6 Oct 92 (TBL) Moved WWW_TraceFlag in here to be in library
8: */
9: #include <ctype.h>
10: #include "HTUtils.h"
11: #include "tcp.h"
12:
13: PUBLIC int WWW_TraceFlag = 0; /* Global trace flag for ALL W3 code */
14:
15: #ifndef VC
16: #define VC "unknown"
17: #endif
18:
19: PUBLIC CONST char * HTLibraryVersion = VC; /* String for help screen etc */
20:
21: #ifndef VM /* VM has these already it seems */
22:
23: /* Strings of any length
24: ** ---------------------
25: */
26: PUBLIC int strcasecomp ARGS2 (CONST char*,a, CONST char *,b)
27: {
28: CONST char *p =a;
29: CONST char *q =b;
30: for(p=a, q=b; *p && *q; p++, q++) {
31: int diff = TOLOWER(*p) - TOLOWER(*q);
32: if (diff) return diff;
33: }
34: if (*p) return 1; /* p was longer than q */
35: if (*q) return -1; /* p was shorter than q */
36: return 0; /* Exact match */
37: }
38:
39:
40: /* With count limit
41: ** ----------------
42: */
43: PUBLIC int strncasecomp ARGS3(CONST char*,a, CONST char *,b, int,n)
44: {
45: CONST char *p =a;
46: CONST char *q =b;
47:
48: for(p=a, q=b;; p++, q++) {
49: int diff;
50: if (p == a+n) return 0; /* Match up to n characters */
51: if (!(*p && *q)) return *p - *q;
52: diff = TOLOWER(*p) - TOLOWER(*q);
53: if (diff) return diff;
54: }
55: /*NOTREACHED*/
56: }
57: #endif
58:
59: /* Allocate a new copy of a string, and returns it
60: */
61: PUBLIC char * HTSACopy
62: ARGS2 (char **,dest, CONST char *,src)
63: {
64: if (*dest) free(*dest);
65: if (! src)
66: *dest = NULL;
67: else {
68: *dest = (char *) malloc (strlen(src) + 1);
69: if (*dest == NULL) outofmem(__FILE__, "HTSACopy");
70: strcpy (*dest, src);
71: }
72: return *dest;
73: }
74:
75: PUBLIC char * HTSACat
76: ARGS2 (char **,dest, CONST char *,src)
77: {
78: if (src && *src) {
79: if (*dest) {
80: int length = strlen (*dest);
81: *dest = (char *) realloc (*dest, length + strlen(src) + 1);
82: if (*dest == NULL) outofmem(__FILE__, "HTSACat");
83: strcpy (*dest + length, src);
84: } else {
85: *dest = (char *) malloc (strlen(src) + 1);
86: if (*dest == NULL) outofmem(__FILE__, "HTSACat");
87: strcpy (*dest, src);
88: }
89: }
90: return *dest;
91: }
Webmaster