1298Seric # include <sysexits.h> 2298Seric # include "useful.h" 3298Seric 4*409Seric static char SccsId[] = "@(#)util.c 1.2 07/25/80"; 5*409Seric 6298Seric /* 7298Seric ** UTIL.C -- General Purpose Routines 8298Seric ** 9298Seric ** Defines: 10298Seric ** stripquotes 11298Seric ** xalloc 12298Seric ** any 13298Seric */ 14298Seric /* 15298Seric ** STRIPQUOTES -- Strip quotes & quote bits from a string. 16298Seric ** 17298Seric ** Runs through a string and strips off unquoted quote 18298Seric ** characters and quote bits. This is done in place. 19298Seric ** 20298Seric ** Parameters: 21298Seric ** s -- the string to strip. 22298Seric ** 23298Seric ** Returns: 24298Seric ** none. 25298Seric ** 26298Seric ** Side Effects: 27298Seric ** none. 28298Seric ** 29298Seric ** Requires: 30298Seric ** none. 31298Seric ** 32298Seric ** Called By: 33298Seric ** deliver 34298Seric ** 35298Seric ** History: 36298Seric ** 3/5/80 -- written. 37298Seric */ 38298Seric 39298Seric stripquotes(s) 40298Seric char *s; 41298Seric { 42298Seric register char *p; 43298Seric register char *q; 44298Seric register char c; 45298Seric 46298Seric for (p = q = s; (c = *p++) != '\0'; ) 47298Seric { 48298Seric if (c != '"') 49298Seric *q++ = c & 0177; 50298Seric } 51298Seric *q = '\0'; 52298Seric } 53298Seric /* 54298Seric ** XALLOC -- Allocate memory and bitch wildly on failure. 55298Seric ** 56298Seric ** THIS IS A CLUDGE. This should be made to give a proper 57298Seric ** error -- but after all, what can we do? 58298Seric ** 59298Seric ** Parameters: 60298Seric ** sz -- size of area to allocate. 61298Seric ** 62298Seric ** Returns: 63298Seric ** pointer to data region. 64298Seric ** 65298Seric ** Side Effects: 66298Seric ** Memory is allocated. 67298Seric ** 68298Seric ** Requires: 69298Seric ** malloc 70298Seric ** syserr 71298Seric ** exit 72298Seric ** 73298Seric ** Called By: 74298Seric ** lots of people. 75298Seric ** 76298Seric ** History: 77298Seric ** 12/31/79 -- written. 78298Seric */ 79298Seric 80298Seric char * 81298Seric xalloc(sz) 82298Seric register unsigned int sz; 83298Seric { 84298Seric register char *p; 85298Seric extern char *malloc(); 86298Seric 87298Seric p = malloc(sz); 88298Seric if (p == NULL) 89298Seric { 90298Seric syserr("Out of memory!!"); 91298Seric exit(EX_UNAVAIL); 92298Seric } 93298Seric return (p); 94298Seric } 95298Seric /* 96298Seric ** ANY -- Return TRUE if the character exists in the string. 97298Seric ** 98298Seric ** Parameters: 99298Seric ** c -- the character. 100298Seric ** s -- the string 101298Seric ** (sounds like an avant garde script) 102298Seric ** 103298Seric ** Returns: 104298Seric ** TRUE -- if c could be found in s. 105298Seric ** FALSE -- otherwise. 106298Seric ** 107298Seric ** Side Effects: 108298Seric ** none. 109298Seric ** 110298Seric ** Requires: 111298Seric ** none. 112298Seric ** 113298Seric ** Called By: 114298Seric ** prescan 115298Seric ** 116298Seric ** History: 117298Seric ** 3/5/80 -- written. 118298Seric */ 119298Seric 120298Seric any(c, s) 121298Seric register char c; 122298Seric register char *s; 123298Seric { 124298Seric register char c2; 125298Seric 126298Seric while ((c2 = *s++) != '\0') 127298Seric if (c2 == c) 128298Seric return (TRUE); 129298Seric return (FALSE); 130298Seric } 131