1 /* Copyright (c) 1979 Regents of the University of California */ 2 3 #ifndef lint 4 static char sccsid[] = "@(#)string.c 2.1 02/08/84"; 5 #endif 6 7 #include "whoami.h" 8 #include "0.h" 9 #ifndef PI01 10 #ifndef PXP 11 #include "send.h" 12 #endif 13 #endif 14 15 /* 16 * STRING SPACE DECLARATIONS 17 * 18 * Strng is the base of the current 19 * string space and strngp the 20 * base of the free area therein. 21 * Strp is the array of descriptors. 22 */ 23 #ifndef PI0 24 STATIC char strings[STRINC]; 25 STATIC char *strng = strings; 26 STATIC char *strngp = strings; 27 #else 28 char *strng, *strngp; 29 #endif 30 #ifndef PI01 31 #ifndef PXP 32 STATIC char *strp[20]; 33 STATIC char **stract strp; 34 int strmax; 35 #endif 36 #endif 37 38 #ifndef PI01 39 #ifndef PXP 40 #ifndef PI0 41 initstring() 42 #else 43 initstring(strings) 44 char *strings; 45 #endif 46 { 47 48 *stract++ = strings; 49 #ifdef PI0 50 strng = strngp = strings; 51 #endif 52 strmax = STRINC * 2; 53 } 54 #endif 55 #endif 56 57 /* 58 * Copy a string into the string area. 59 */ 60 char * 61 savestr(cp) 62 register char *cp; 63 { 64 register int i; 65 66 i = strlen(cp) + 1; 67 if (strngp + i >= strng + STRINC) { 68 strngp = malloc(STRINC); 69 if (strngp == 0) { 70 yerror("Ran out of memory (string)"); 71 pexit(DIED); 72 } 73 #ifndef PI01 74 #ifndef PXP 75 *stract++ = strngp; 76 strmax =+ STRINC; 77 #endif 78 #endif 79 strng = strngp; 80 } 81 (void) pstrcpy(strngp, cp); 82 cp = strngp; 83 strngp = cp + i; 84 #ifdef PI0 85 send(RSTRING, cp); 86 #endif 87 return (cp); 88 } 89 90 #ifndef PI1 91 #ifndef PXP 92 char * 93 esavestr(cp) 94 char *cp; 95 { 96 97 #ifdef PI0 98 send(REVENIT); 99 #endif 100 strngp = ( (char *) ( ( (int) (strngp + 1) ) &~ 1 ) ); 101 return (savestr(cp)); 102 } 103 #endif 104 #endif 105 106 #ifndef PI01 107 #ifndef PXP 108 soffset(cp) 109 register char *cp; 110 { 111 register char **sp; 112 register int i; 113 114 if (cp == NIL || cp == OCT || cp == HEX) 115 return (-cp); 116 for (i = STRINC, sp = strp; sp < stract; sp++) { 117 if (cp >= *sp && cp < (*sp + STRINC)) 118 return (i + (cp - *sp)); 119 i =+ STRINC; 120 } 121 i = nlfund(cp); 122 if (i != 0) 123 return (i); 124 panic("soffset"); 125 } 126 #ifdef PI1 127 sreloc(i) 128 register int i; 129 { 130 131 if (i == 0 || i == -OCT || i == -HEX) 132 return (-i); 133 if (i < STRINC) { 134 if (i >= INL) 135 panic("sreloc INL"); 136 i = nl[i].symbol; 137 if (i == 0) 138 panic("sreloc nl[i]"); 139 return (i); 140 } 141 if (i > strmax || i < 0) 142 panic("sreloc"); 143 return (strp[(i / STRINC) - 1] + (i % STRINC)); 144 } 145 146 evenit() 147 { 148 149 strngp = (strngp + 1) &~ 1; 150 } 151 #endif 152 #endif 153 #endif 154