Commit | Line | Data |
---|---|---|
b3cbe40f EA |
1 | # include <sysexits.h> |
2 | # include "useful.h" | |
1a12c7d6 | 3 | # include <ctype.h> |
b3cbe40f | 4 | |
21d76258 | 5 | static char SccsId[] = "@(#)util.c 3.2 %G%"; |
916b3375 | 6 | |
b3cbe40f | 7 | /* |
b3cbe40f EA |
8 | ** STRIPQUOTES -- Strip quotes & quote bits from a string. |
9 | ** | |
10 | ** Runs through a string and strips off unquoted quote | |
11 | ** characters and quote bits. This is done in place. | |
12 | ** | |
13 | ** Parameters: | |
14 | ** s -- the string to strip. | |
15 | ** | |
16 | ** Returns: | |
17 | ** none. | |
18 | ** | |
19 | ** Side Effects: | |
20 | ** none. | |
21 | ** | |
b3cbe40f EA |
22 | ** Called By: |
23 | ** deliver | |
b3cbe40f EA |
24 | */ |
25 | ||
26 | stripquotes(s) | |
27 | char *s; | |
28 | { | |
29 | register char *p; | |
30 | register char *q; | |
31 | register char c; | |
32 | ||
33 | for (p = q = s; (c = *p++) != '\0'; ) | |
34 | { | |
35 | if (c != '"') | |
36 | *q++ = c & 0177; | |
37 | } | |
38 | *q = '\0'; | |
39 | } | |
40 | \f/* | |
1a12c7d6 EA |
41 | ** CAPITALIZE -- return a copy of a string, properly capitalized. |
42 | ** | |
43 | ** Parameters: | |
44 | ** s -- the string to capitalize. | |
45 | ** | |
46 | ** Returns: | |
47 | ** a pointer to a properly capitalized string. | |
48 | ** | |
49 | ** Side Effects: | |
50 | ** none. | |
51 | */ | |
52 | ||
53 | char * | |
54 | capitalize(s) | |
55 | register char *s; | |
56 | { | |
57 | static char buf[50]; | |
58 | register char *p; | |
59 | ||
60 | p = buf; | |
61 | ||
62 | for (;;) | |
63 | { | |
64 | while (!isalpha(*s) && *s != '\0') | |
65 | *p++ = *s++; | |
66 | if (*s == '\0') | |
67 | break; | |
68 | *p++ = toupper(*s++); | |
69 | while (isalpha(*s)) | |
70 | *p++ = *s++; | |
71 | } | |
72 | ||
73 | *p = '\0'; | |
74 | return (buf); | |
75 | } | |
76 | \f/* | |
b3cbe40f EA |
77 | ** XALLOC -- Allocate memory and bitch wildly on failure. |
78 | ** | |
79 | ** THIS IS A CLUDGE. This should be made to give a proper | |
80 | ** error -- but after all, what can we do? | |
81 | ** | |
82 | ** Parameters: | |
83 | ** sz -- size of area to allocate. | |
84 | ** | |
85 | ** Returns: | |
86 | ** pointer to data region. | |
87 | ** | |
88 | ** Side Effects: | |
89 | ** Memory is allocated. | |
b3cbe40f EA |
90 | */ |
91 | ||
92 | char * | |
93 | xalloc(sz) | |
94 | register unsigned int sz; | |
95 | { | |
96 | register char *p; | |
97 | extern char *malloc(); | |
98 | ||
99 | p = malloc(sz); | |
100 | if (p == NULL) | |
101 | { | |
102 | syserr("Out of memory!!"); | |
21ec078e | 103 | exit(EX_UNAVAILABLE); |
b3cbe40f EA |
104 | } |
105 | return (p); | |
106 | } | |
107 | \f/* | |
1a12c7d6 EA |
108 | ** NEWSTR -- make copy of string. |
109 | ** | |
110 | ** Space is allocated for it using xalloc. | |
111 | ** | |
112 | ** Parameters: | |
113 | ** string to copy. | |
114 | ** | |
115 | ** Returns: | |
116 | ** pointer to new string. | |
117 | ** | |
118 | ** Side Effects: | |
119 | ** none. | |
120 | */ | |
121 | ||
122 | char * | |
123 | newstr(s) | |
124 | register char *s; | |
125 | { | |
126 | register char *p; | |
127 | ||
128 | p = xalloc(strlen(s) + 1); | |
129 | strcpy(p, s); | |
130 | return (p); | |
131 | } |