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