]>
Commit | Line | Data |
---|---|---|
68687902 | 1 | /* |
2 | * $Source$ | |
3 | * $Author$ | |
4 | * $Header$ | |
5 | * | |
6 | * Copyright (C) 1987 by the Massachusetts Institute of Technology | |
babbc197 | 7 | * For copying and distribution information, please see the file |
8 | * <mit-copyright.h>. | |
68687902 | 9 | * |
10 | * Miscellaneous string functions. | |
11 | */ | |
12 | ||
13 | #ifndef lint | |
14 | static char *rcsid_strs_c = "$Header$"; | |
15 | #endif lint | |
16 | ||
babbc197 | 17 | #include <mit-copyright.h> |
0fed7e9b | 18 | #include <sys/types.h> |
19 | #include <strings.h> | |
20 | #include <ctype.h> | |
21 | ||
22 | extern char *malloc(), *realloc(); | |
68687902 | 23 | |
24 | /* | |
25 | * Random string functions which should be in the C library.. | |
26 | */ | |
27 | ||
28 | /* | |
29 | * Make a copy of a string. | |
30 | */ | |
31 | char * | |
32 | strsave(s) | |
33 | char *s; | |
34 | { | |
0fed7e9b | 35 | register int len; |
36 | register char *p; | |
37 | /* Kludge for sloppy string semantics */ | |
38 | if (!s) { | |
39 | printf("NULL != \"\" !!!!\r\n"); | |
40 | p = malloc(1); | |
070955b9 | 41 | *p = '\0'; |
0fed7e9b | 42 | return p; |
43 | } | |
44 | len = strlen(s) + 1; | |
45 | p = malloc((u_int)len); | |
68687902 | 46 | if (p) bcopy(s, p, len); |
47 | return p; | |
48 | } | |
49 | /* | |
50 | * Trim whitespace off both ends of a string. | |
51 | */ | |
9ca8ff13 | 52 | char *strtrim(save) |
53 | register char *save; | |
68687902 | 54 | { |
9ca8ff13 | 55 | register char *t, *s; |
56 | ||
57 | s = save; | |
68687902 | 58 | while (isspace(*s)) s++; |
59 | /* skip to end of string */ | |
9ca8ff13 | 60 | if (*s == '\0') { |
61 | *save = '\0'; | |
62 | return(save); | |
63 | } | |
68687902 | 64 | |
65 | for (t = s; *t; t++) continue; | |
66 | while (t > s) { | |
67 | --t; | |
68 | if (!isspace(*t)) { | |
69 | t++; | |
70 | break; | |
71 | } | |
72 | } | |
73 | *t = '\0'; | |
74 | return s; | |
75 | } | |
76 | ||
77 | /* | |
78 | * Case insensitive string compare. | |
79 | */ | |
80 | ||
81 | int cistrcmp(cp1, cp2) | |
82 | char *cp1, *cp2; | |
83 | { | |
84 | register int c1, c2; | |
85 | ||
86 | do { | |
87 | if (isupper(c1 = (*cp1++))) c1 = tolower(c1); | |
88 | if (isupper(c2 = (*cp2++))) c2 = tolower(c2); | |
89 | if (c1 != c2) return c1-c2; | |
90 | } while (c1 && c2); | |
91 | return 0; | |
92 | } | |
93 |