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