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