1298Seric # include <sysexits.h> 2298Seric # include "useful.h" 32900Seric # include <ctype.h> 4298Seric 5*2992Seric static char SccsId[] = "@(#)util.c 3.3 03/07/81"; 6409Seric 7298Seric /* 8298Seric ** STRIPQUOTES -- Strip quotes & quote bits from a string. 9298Seric ** 10298Seric ** Runs through a string and strips off unquoted quote 11298Seric ** characters and quote bits. This is done in place. 12298Seric ** 13298Seric ** Parameters: 14298Seric ** s -- the string to strip. 15298Seric ** 16298Seric ** Returns: 17298Seric ** none. 18298Seric ** 19298Seric ** Side Effects: 20298Seric ** none. 21298Seric ** 22298Seric ** Called By: 23298Seric ** deliver 24298Seric */ 25298Seric 26298Seric stripquotes(s) 27298Seric char *s; 28298Seric { 29298Seric register char *p; 30298Seric register char *q; 31298Seric register char c; 32298Seric 33298Seric for (p = q = s; (c = *p++) != '\0'; ) 34298Seric { 35298Seric if (c != '"') 36298Seric *q++ = c & 0177; 37298Seric } 38298Seric *q = '\0'; 39298Seric } 40298Seric /* 412900Seric ** CAPITALIZE -- return a copy of a string, properly capitalized. 422900Seric ** 432900Seric ** Parameters: 442900Seric ** s -- the string to capitalize. 452900Seric ** 462900Seric ** Returns: 472900Seric ** a pointer to a properly capitalized string. 482900Seric ** 492900Seric ** Side Effects: 502900Seric ** none. 512900Seric */ 522900Seric 532900Seric char * 542900Seric capitalize(s) 552900Seric register char *s; 562900Seric { 572900Seric static char buf[50]; 582900Seric register char *p; 592900Seric 602900Seric p = buf; 612900Seric 622900Seric for (;;) 632900Seric { 642900Seric while (!isalpha(*s) && *s != '\0') 652900Seric *p++ = *s++; 662900Seric if (*s == '\0') 672900Seric break; 682900Seric *p++ = toupper(*s++); 692900Seric while (isalpha(*s)) 702900Seric *p++ = *s++; 712900Seric } 722900Seric 732900Seric *p = '\0'; 742900Seric return (buf); 752900Seric } 762900Seric /* 77298Seric ** XALLOC -- Allocate memory and bitch wildly on failure. 78298Seric ** 79298Seric ** THIS IS A CLUDGE. This should be made to give a proper 80298Seric ** error -- but after all, what can we do? 81298Seric ** 82298Seric ** Parameters: 83298Seric ** sz -- size of area to allocate. 84298Seric ** 85298Seric ** Returns: 86298Seric ** pointer to data region. 87298Seric ** 88298Seric ** Side Effects: 89298Seric ** Memory is allocated. 90298Seric */ 91298Seric 92298Seric char * 93298Seric xalloc(sz) 94298Seric register unsigned int sz; 95298Seric { 96298Seric register char *p; 97298Seric extern char *malloc(); 98298Seric 99298Seric p = malloc(sz); 100298Seric if (p == NULL) 101298Seric { 102298Seric syserr("Out of memory!!"); 1031598Seric exit(EX_UNAVAILABLE); 104298Seric } 105298Seric return (p); 106298Seric } 107298Seric /* 1082900Seric ** NEWSTR -- make copy of string. 1092900Seric ** 1102900Seric ** Space is allocated for it using xalloc. 1112900Seric ** 1122900Seric ** Parameters: 1132900Seric ** string to copy. 1142900Seric ** 1152900Seric ** Returns: 1162900Seric ** pointer to new string. 1172900Seric ** 1182900Seric ** Side Effects: 1192900Seric ** none. 1202900Seric */ 1212900Seric 1222900Seric char * 1232900Seric newstr(s) 1242900Seric register char *s; 1252900Seric { 1262900Seric register char *p; 127*2992Seric extern char *strcpy(); 1282900Seric 129*2992Seric p = xalloc((unsigned) (strlen(s) + 1)); 1302900Seric strcpy(p, s); 1312900Seric return (p); 1322900Seric } 133