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