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