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