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