Commit | Line | Data |
---|---|---|
b3e05d18 KM |
1 | /* Copyright (c) 1979 Regents of the University of California */ |
2 | ||
af054913 | 3 | static char sccsid[] = "@(#)langpats.c 1.12 %G%"; |
b3e05d18 KM |
4 | |
5 | #include <stdio.h> | |
6 | #include <ctype.h> | |
7 | /* | |
8 | * The hash table must be at least twice as big as the number | |
9 | * of patterns, preferably bigger. It must also be a prime number | |
10 | */ | |
11 | #define HSHSIZ 101 | |
12 | ||
af054913 KM |
13 | #ifdef vax |
14 | #define CALLTEMPLATE "calls\t$" | |
15 | #define TEMPLATESIZE 7 | |
16 | #endif vax | |
17 | ||
18 | #ifdef mc68000 | |
19 | #define CALLTEMPLATE "jbsr\t" | |
20 | #define TEMPLATESIZE 5 | |
21 | #endif mc68000 | |
22 | ||
b3e05d18 KM |
23 | struct pats { |
24 | char *name; | |
25 | char *replace; | |
26 | } ptab[] = { | |
27 | ||
af054913 | 28 | #ifdef vax |
a83071b9 KM |
29 | /* |
30 | * C library routines | |
31 | */ | |
25d46c52 KM |
32 | { "1,_fgetc\n", |
33 | " sobgeq *(sp),1f\n\ | |
b3e05d18 KM |
34 | calls $1,__filbuf\n\ |
35 | jbr 2f\n\ | |
36 | 1:\n\ | |
37 | addl3 $4,(sp)+,r1\n\ | |
38 | movzbl *(r1),r0\n\ | |
39 | incl (r1)\n\ | |
40 | 2:\n" }, | |
41 | ||
25d46c52 KM |
42 | { "2,_fputc\n", |
43 | " sobgeq *4(sp),1f\n\ | |
b3e05d18 KM |
44 | calls $2,__flsbuf\n\ |
45 | jbr 2f\n\ | |
46 | 1:\n\ | |
945bf1d0 KM |
47 | popr $0x3\n\ |
48 | movb r0,*4(r1)\n\ | |
49 | incl 4(r1)\n\ | |
b3e05d18 KM |
50 | 2:\n" }, |
51 | ||
a83071b9 KM |
52 | /* |
53 | * VAX special instructions | |
54 | */ | |
25d46c52 | 55 | { "3,_blkcpy\n", |
a83071b9 | 56 | " popr $0xa\n\ |
945bf1d0 | 57 | jbr 2f\n\ |
b3e05d18 | 58 | 1:\n\ |
b3e05d18 KM |
59 | subl2 r0,(sp)\n\ |
60 | movc3 r0,(r1),(r3)\n\ | |
945bf1d0 KM |
61 | 2:\n\ |
62 | movzwl $65535,r0\n\ | |
63 | cmpl (sp),r0\n\ | |
64 | jgtr 1b\n\ | |
9d34bc3a | 65 | movl (sp)+,r0\n\ |
b3e05d18 KM |
66 | movc3 r0,(r1),(r3)\n" }, |
67 | ||
25d46c52 | 68 | { "2,_blkclr\n", |
a83071b9 | 69 | " movl (sp)+,r3\n\ |
25d46c52 | 70 | jbr 2f\n\ |
b3e05d18 | 71 | 1:\n\ |
25d46c52 KM |
72 | subl2 r0,(sp)\n\ |
73 | movc5 $0,(r3),$0,r0,(r3)\n\ | |
74 | 2:\n\ | |
b3e05d18 KM |
75 | movzwl $65535,r0\n\ |
76 | cmpl (sp),r0\n\ | |
25d46c52 | 77 | jgtr 1b\n\ |
a83071b9 | 78 | movl (sp)+,r0\n\ |
25d46c52 | 79 | movc5 $0,(r3),$0,r0,(r3)\n" }, |
b3e05d18 | 80 | |
25d46c52 | 81 | { "3,_LOCC\n", |
945bf1d0 | 82 | " popr $0x30\n\ |
9d34bc3a | 83 | movl (sp)+,r1\n\ |
b3e05d18 KM |
84 | 1:\n\ |
85 | movzwl $65535,r0\n\ | |
945bf1d0 | 86 | cmpl r5,r0\n\ |
f703f747 | 87 | jleq 1f\n\ |
945bf1d0 KM |
88 | subl2 r0,r5\n\ |
89 | locc r4,r0,(r1)\n\ | |
f703f747 | 90 | jeql 1b\n\ |
945bf1d0 | 91 | addl2 r5,r0\n\ |
f703f747 | 92 | jbr 2f\n\ |
b3e05d18 | 93 | 1:\n\ |
945bf1d0 | 94 | locc r4,r5,(r1)\n\ |
b3e05d18 KM |
95 | 2:\n" }, |
96 | ||
b3df80a8 | 97 | { "2,_ROUND\n", |
b3e05d18 KM |
98 | " cvtrdl (sp)+,r0\n" }, |
99 | ||
b3df80a8 | 100 | { "2,_TRUNC\n", |
b3e05d18 KM |
101 | " cvtdl (sp)+,r0\n" }, |
102 | ||
a83071b9 KM |
103 | /* |
104 | * General Pascal library routines | |
105 | */ | |
106 | { "1,_ACTFILE\n", | |
107 | " movl (sp)+,r1\n\ | |
108 | movl 12(r1),r0\n" }, | |
109 | ||
6b4e6ddb KM |
110 | { "2,_FCALL\n", |
111 | " movl 4(sp),r0\n\ | |
9d34bc3a | 112 | movc3 4(r0),__disply+8,*(sp)+\n\ |
6b4e6ddb | 113 | movl (sp)+,r0\n\ |
9d34bc3a | 114 | movc3 4(r0),8(r0),__disply+8\n" }, |
b3e05d18 | 115 | |
25d46c52 | 116 | { "2,_FRTN\n", |
6b4e6ddb | 117 | " movl (sp)+,r0\n\ |
9d34bc3a | 118 | movc3 4(r0),*(sp)+,__disply+8\n" }, |
b3e05d18 | 119 | |
25d46c52 | 120 | { "3,_FSAV\n", |
b3e05d18 KM |
121 | " movl 8(sp),r0\n\ |
122 | movl (sp)+,(r0)\n\ | |
9d34bc3a KM |
123 | ashl $3,(sp)+,4(r0)\n\ |
124 | movc3 4(r0),__disply+8,8(r0)\n\ | |
125 | movl (sp)+,r0\n" }, | |
b3e05d18 | 126 | |
a83071b9 KM |
127 | /* |
128 | * Pascal relational comparisons | |
129 | */ | |
25d46c52 | 130 | { "3,_RELEQ\n", |
9d34bc3a KM |
131 | " popr $0xb\n\ |
132 | movl r0,r4\n\ | |
b3e05d18 | 133 | 1:\n\ |
f703f747 KM |
134 | movzwl $65535,r0\n\ |
135 | cmpl r4,r0\n\ | |
945bf1d0 | 136 | jleq 3f\n\ |
f703f747 KM |
137 | subl2 r0,r4\n\ |
138 | cmpc3 r0,(r1),(r3)\n\ | |
139 | jeql 1b\n\ | |
f703f747 | 140 | 2:\n\ |
945bf1d0 | 141 | clrl r0\n\ |
f703f747 KM |
142 | jbr 4f\n\ |
143 | 3:\n\ | |
945bf1d0 KM |
144 | cmpc3 r4,(r1),(r3)\n\ |
145 | jneq 2b\n\ | |
146 | incl r0\n\ | |
f703f747 | 147 | 4:\n" }, |
b3e05d18 | 148 | |
25d46c52 | 149 | { "3,_RELNE\n", |
9d34bc3a KM |
150 | " popr $0xb\n\ |
151 | movl r0,r4\n\ | |
b3e05d18 | 152 | 1:\n\ |
f703f747 KM |
153 | movzwl $65535,r0\n\ |
154 | cmpl r4,r0\n\ | |
945bf1d0 | 155 | jleq 3f\n\ |
f703f747 KM |
156 | subl2 r0,r4\n\ |
157 | cmpc3 r0,(r1),(r3)\n\ | |
158 | jeql 1b\n\ | |
f703f747 | 159 | 2:\n\ |
b3e05d18 | 160 | movl $1,r0\n\ |
945bf1d0 KM |
161 | jbr 4f\n\ |
162 | 3:\n\ | |
163 | cmpc3 r4,(r1),(r3)\n\ | |
164 | jneq 2b\n\ | |
f703f747 | 165 | 4:\n" }, |
b3e05d18 | 166 | |
25d46c52 | 167 | { "3,_RELSLT\n", |
9d34bc3a KM |
168 | " popr $0xb\n\ |
169 | movl r0,r4\n\ | |
945bf1d0 | 170 | jbr 2f\n\ |
b3e05d18 | 171 | 1:\n\ |
f703f747 KM |
172 | subl2 r0,r4\n\ |
173 | cmpc3 r0,(r1),(r3)\n\ | |
945bf1d0 | 174 | jneq 3f\n\ |
f703f747 | 175 | 2:\n\ |
945bf1d0 KM |
176 | movzwl $65535,r0\n\ |
177 | cmpl r4,r0\n\ | |
178 | jgtr 1b\n\ | |
f703f747 KM |
179 | cmpc3 r4,(r1),(r3)\n\ |
180 | 3:\n\ | |
181 | jlss 4f\n\ | |
182 | clrl r0\n\ | |
183 | jbr 5f\n\ | |
184 | 4:\n\ | |
b3e05d18 | 185 | movl $1,r0\n\ |
f703f747 | 186 | 5:\n" }, |
b3e05d18 | 187 | |
25d46c52 | 188 | { "3,_RELSLE\n", |
9d34bc3a KM |
189 | " popr $0xb\n\ |
190 | movl r0,r4\n\ | |
945bf1d0 | 191 | jbr 2f\n\ |
b3e05d18 | 192 | 1:\n\ |
f703f747 KM |
193 | subl2 r0,r4\n\ |
194 | cmpc3 r0,(r1),(r3)\n\ | |
945bf1d0 | 195 | jneq 3f\n\ |
f703f747 | 196 | 2:\n\ |
945bf1d0 KM |
197 | movzwl $65535,r0\n\ |
198 | cmpl r4,r0\n\ | |
199 | jgtr 1b\n\ | |
f703f747 KM |
200 | cmpc3 r4,(r1),(r3)\n\ |
201 | 3:\n\ | |
202 | jleq 4f\n\ | |
203 | clrl r0\n\ | |
204 | jbr 5f\n\ | |
205 | 4:\n\ | |
b3e05d18 | 206 | movl $1,r0\n\ |
f703f747 | 207 | 5:\n" }, |
b3e05d18 | 208 | |
25d46c52 | 209 | { "3,_RELSGT\n", |
9d34bc3a KM |
210 | " popr $0xb\n\ |
211 | movl r0,r4\n\ | |
945bf1d0 | 212 | jbr 2f\n\ |
b3e05d18 | 213 | 1:\n\ |
f703f747 KM |
214 | subl2 r0,r4\n\ |
215 | cmpc3 r0,(r1),(r3)\n\ | |
945bf1d0 | 216 | jneq 3f\n\ |
f703f747 | 217 | 2:\n\ |
945bf1d0 KM |
218 | movzwl $65535,r0\n\ |
219 | cmpl r4,r0\n\ | |
220 | jgtr 1b\n\ | |
f703f747 KM |
221 | cmpc3 r4,(r1),(r3)\n\ |
222 | 3:\n\ | |
223 | jgtr 4f\n\ | |
224 | clrl r0\n\ | |
225 | jbr 5f\n\ | |
226 | 4:\n\ | |
b3e05d18 | 227 | movl $1,r0\n\ |
f703f747 | 228 | 5:\n" }, |
b3e05d18 | 229 | |
25d46c52 | 230 | { "3,_RELSGE\n", |
9d34bc3a KM |
231 | " popr $0xb\n\ |
232 | movl r0,r4\n\ | |
945bf1d0 | 233 | jbr 2f\n\ |
b3e05d18 | 234 | 1:\n\ |
f703f747 KM |
235 | subl2 r0,r4\n\ |
236 | cmpc3 r0,(r1),(r3)\n\ | |
945bf1d0 | 237 | jneq 3f\n\ |
f703f747 | 238 | 2:\n\ |
945bf1d0 KM |
239 | movzwl $65535,r0\n\ |
240 | cmpl r4,r0\n\ | |
241 | jgtr 1b\n\ | |
f703f747 KM |
242 | cmpc3 r4,(r1),(r3)\n\ |
243 | 3:\n\ | |
244 | jgeq 4f\n\ | |
245 | clrl r0\n\ | |
246 | jbr 5f\n\ | |
247 | 4:\n\ | |
b3e05d18 | 248 | movl $1,r0\n\ |
f703f747 | 249 | 5:\n" }, |
b3e05d18 | 250 | |
a83071b9 KM |
251 | /* |
252 | * Pascal set operations. | |
253 | */ | |
25d46c52 | 254 | { "4,_ADDT\n", |
945bf1d0 | 255 | " popr $0x17\n\ |
b3e05d18 | 256 | movl r0,r3\n\ |
b3e05d18 KM |
257 | 1:\n\ |
258 | bisl3 (r1)+,(r2)+,(r3)+\n\ | |
259 | sobgtr r4,1b\n" }, | |
260 | ||
25d46c52 | 261 | { "4,_SUBT\n", |
945bf1d0 | 262 | " popr $0x17\n\ |
b3e05d18 | 263 | movl r0,r3\n\ |
b3e05d18 KM |
264 | 1:\n\ |
265 | bicl3 (r2)+,(r1)+,(r3)+\n\ | |
266 | sobgtr r4,1b\n" }, | |
267 | ||
25d46c52 | 268 | { "4,_MULT\n", |
945bf1d0 | 269 | " popr $0x17\n\ |
b3e05d18 | 270 | movl r0,r3\n\ |
b3e05d18 KM |
271 | 1:\n\ |
272 | mcoml (r1)+,r5\n\ | |
273 | bicl3 r5,(r2)+,(r3)+\n\ | |
274 | sobgtr r4,1b\n" }, | |
275 | ||
25d46c52 | 276 | { "4,_IN\n", |
0d53952d KM |
277 | " popr $0x1e\n\ |
278 | clrl r0\n\ | |
945bf1d0 KM |
279 | subl2 r2,r1\n\ |
280 | cmpl r1,r3\n\ | |
f703f747 | 281 | jgtru 1f\n\ |
945bf1d0 KM |
282 | jbc r1,(r4),1f\n\ |
283 | incl r0\n\ | |
a83071b9 KM |
284 | 1:\n" }, |
285 | ||
286 | /* | |
287 | * Pascal runtime checks | |
288 | */ | |
289 | { "1,_ASRT\n", | |
290 | " tstl (sp)+\n\ | |
291 | jneq 1f\n\ | |
292 | pushl $0\n\ | |
293 | pushl $_EASRT\n\ | |
294 | calls $2,_ERROR\n\ | |
295 | 1:\n" }, | |
296 | ||
297 | { "2,_ASRTS\n", | |
298 | " popr $0x03\n\ | |
299 | tstl r0\n\ | |
300 | jneq 1f\n\ | |
301 | pushl r1\n\ | |
302 | pushl $_EASRTS\n\ | |
303 | calls $2,_ERROR\n\ | |
304 | 1:\n" }, | |
305 | ||
306 | { "1,_CHR\n", | |
307 | " movl (sp)+,r0\n\ | |
308 | cmpl r0,$127\n\ | |
309 | jlequ 1f\n\ | |
310 | pushl r0\n\ | |
311 | pushl $_ECHR\n\ | |
312 | calls $2,_ERROR\n\ | |
313 | 1:\n" }, | |
314 | ||
315 | { "0,_LINO\n", | |
316 | " incl __stcnt\n\ | |
317 | cmpl __stcnt,__stlim\n\ | |
318 | jlss 1f\n\ | |
319 | pushl __stcnt\n\ | |
320 | pushl $_ELINO\n\ | |
321 | calls $2,_ERROR\n\ | |
322 | 1:\n" }, | |
323 | ||
324 | { "1,_NIL\n", | |
325 | " movl (sp)+,r0\n\ | |
326 | cmpl r0,__maxptr\n\ | |
327 | jgtr 1f\n\ | |
328 | cmpl r0,__minptr\n\ | |
329 | jgeq 2f\n\ | |
330 | 1:\n\ | |
331 | pushl $0\n\ | |
332 | pushl $_ENIL\n\ | |
333 | calls $2,_ERROR\n\ | |
334 | 2:\n" }, | |
335 | ||
336 | { "2,_RANDOM\n", | |
337 | " addl2 $8,sp\n\ | |
338 | emul __seed,$1103515245,$0,r0\n\ | |
339 | ediv $0x7fffffff,r0,r1,r0\n\ | |
340 | movl r0,__seed\n\ | |
341 | cvtld r0,r0\n\ | |
342 | divd2 $0d2.147483647e+09,r0\n" }, | |
343 | ||
344 | { "3,_RANG4\n", | |
345 | " popr $0x07\n\ | |
346 | cmpl r0,r1\n\ | |
347 | jlss 1f\n\ | |
348 | cmpl r0,r2\n\ | |
349 | jleq 2f\n\ | |
350 | 1:\n\ | |
351 | pushl r0\n\ | |
352 | pushl $_ERANG\n\ | |
353 | calls $2,_ERROR\n\ | |
354 | 2:\n" }, | |
355 | ||
356 | { "2,_RSNG4\n", | |
357 | " popr $0x03\n\ | |
358 | cmpl r0,r1\n\ | |
359 | jlequ 1f\n\ | |
360 | pushl r0\n\ | |
361 | pushl $_ERANG\n\ | |
362 | calls $2,_ERROR\n\ | |
363 | 1:\n" }, | |
364 | ||
365 | { "1,_SEED\n", | |
366 | " movl __seed,r0\n\ | |
367 | movl (sp)+,__seed\n" }, | |
368 | ||
369 | { "3,_SUBSC\n", | |
370 | " popr $0x07\n\ | |
371 | cmpl r0,r1\n\ | |
372 | jlss 1f\n\ | |
373 | cmpl r0,r2\n\ | |
374 | jleq 2f\n\ | |
375 | 1:\n\ | |
376 | pushl r0\n\ | |
377 | pushl $_ESUBSC\n\ | |
378 | calls $2,_ERROR\n\ | |
379 | 2:\n" }, | |
380 | ||
381 | { "2,_SUBSCZ\n", | |
382 | " popr $0x03\n\ | |
383 | cmpl r0,r1\n\ | |
384 | jlequ 1f\n\ | |
385 | pushl r0\n\ | |
386 | pushl $_ESUBSC\n\ | |
387 | calls $2,_ERROR\n\ | |
388 | 1:\n" }, | |
af054913 KM |
389 | #endif vax |
390 | ||
391 | #ifdef mc68000 | |
392 | { "NONE", "IMPLEMENTED" }, | |
393 | #endif mc68000 | |
a83071b9 | 394 | |
b3e05d18 KM |
395 | }; |
396 | ||
397 | struct pats *htbl[HSHSIZ]; | |
398 | ||
399 | ||
b3e05d18 KM |
400 | #define HASH(cp, hp) {\ |
401 | hash = 0; rehash = 1; ccp = cp; \ | |
402 | do { \ | |
403 | hash *= (int)*ccp++; \ | |
404 | } while (*ccp && *ccp != '\n'); \ | |
405 | hash >>= 7; hash %= HSHSIZ; hp = &htbl[hash]; size = ccp - cp + 1; \ | |
406 | } | |
407 | ||
408 | #define REHASH(hp) {\ | |
409 | hp += rehash; rehash += 2; \ | |
410 | if (hp >= &htbl[HSHSIZ]) \ | |
411 | hp -= HSHSIZ; \ | |
412 | } | |
413 | ||
414 | ||
415 | main(argc, argv) | |
416 | ||
417 | int argc; | |
418 | char **argv; | |
419 | { | |
420 | register struct pats *pp; | |
421 | register struct pats **hp; | |
6e4fa11e | 422 | register char *cp, *ccp, *lp; |
b3e05d18 KM |
423 | register int hash, rehash, size; |
424 | char line[BUFSIZ]; | |
6e4fa11e | 425 | extern char *index(); |
b3e05d18 KM |
426 | |
427 | if (argc > 1) | |
428 | freopen(argv[1], "r", stdin); | |
429 | if (argc > 2) | |
430 | freopen(argv[2], "w", stdout); | |
431 | /* | |
432 | * set up the hash table | |
433 | */ | |
434 | for(pp = ptab; pp < &ptab[sizeof ptab/sizeof ptab[0]]; pp++) { | |
435 | HASH(pp->name, hp); | |
436 | while (*hp) | |
437 | REHASH(hp); | |
438 | *hp = pp; | |
439 | } | |
440 | /* | |
441 | * check each line and replace as appropriate | |
442 | */ | |
443 | while (fgets(line, BUFSIZ, stdin)) { | |
6e4fa11e KM |
444 | lp = index(line, ':'); |
445 | for (cp = (lp != NULL) ? ++lp : line; *cp == '\t'; ) | |
b3e05d18 | 446 | cp++; |
af054913 | 447 | if (strcmpn(cp, CALLTEMPLATE, TEMPLATESIZE) != 0) { |
6e4fa11e KM |
448 | fputs(line, stdout); |
449 | continue; | |
450 | } | |
451 | cp += 7; | |
b3e05d18 KM |
452 | HASH(cp, hp); |
453 | while (*hp) { | |
6e4fa11e | 454 | if (strcmpn((*hp)->name, cp, size)==NULL) { |
6e4fa11e KM |
455 | if (lp != NULL) { |
456 | *lp++ = '\n'; | |
457 | *lp = '\0'; | |
458 | fputs(line, stdout); | |
459 | } | |
b3e05d18 KM |
460 | fputs((*hp)->replace, stdout); |
461 | goto nextline; | |
462 | } | |
463 | REHASH(hp); | |
464 | } | |
b3e05d18 KM |
465 | fputs(line, stdout); |
466 | nextline:; | |
467 | } | |
468 | exit(0); | |
469 | } |