1: #
2: /*
3: * px - interpreter for Berkeley Pascal
4: * Version 1.0 August 1977
5: *
6: * Bill Joy, Charles Haley, Ken Thompson
7: */
8:
9: #include "0x.h"
10: #include "opcode.h"
11: #include "E.h"
12:
13: int display[20] { display };
14:
15: int onintr();
16:
17: main(ac, av)
18: int ac;
19: char *av[];
20: {
21: register char *cp;
22: register int bytes, rmdr;
23: int size, *bp, i, of;
24:
25: i = signal(2, 1);
26: argc = ac - 1, argv = av + 1;
27: randim = 1./randm;
28: setmem();
29: if (av[0][0] == '-' && av[0][1] == 'o') {
30: av[0] =+ 2;
31: file = av[0];
32: argv--, argc++;
33: discard++;
34: } else if (argc == 0)
35: file = *--argv = "obj", argc++;
36: else if (argv[0][0] == '-' && argv[0][1] == 0) {
37: argv[0][0] = 0;
38: file = 0;
39: argv[0] = argv[-1];
40: } else
41: file = *argv;
42: if (file) {
43: cp = file;
44: of = open(cp, 0);
45: if (discard)
46: unlink(cp);
47: } else
48: of = 3;
49: if ((i & 01) == 0)
50: signal(2, onintr);
51: if (of < 0) {
52: oops:
53: perror(cp);
54: exit(1);
55: }
56: if (file) {
57: #include <sys/types.h>
58: #include <sys/stat.h>
59: struct stat stb;
60: fstat(of, &stb);
61: size = stb.st_size;
62: } else
63: if (read(of, &size, 2) != 2) {
64: ferror("Improper argument");
65: exit(1);
66: }
67: if (size == 0) {
68: ferror("File is empty");
69: exit(1);
70: }
71: if (file) {
72: read(of, &i, 2);
73: if (i == 0407) {
74: size =- 1024;
75: lseek(of, (long)1024, 0);
76: } else
77: lseek(of, (long)0, 0);
78: }
79: bp = cp = alloc(size);
80: if (cp == -1) {
81: ferror("Too large");
82: exit(1);
83: }
84: rmdr = size;
85: while (rmdr != 0) {
86: i = (rmdr > 0 && rmdr < 512) ? rmdr : 512;
87: bytes = read(of, cp, i);
88: if (bytes <= 0) {
89: ferror("Unexpected end-of-file");
90: exit(1);
91: }
92: rmdr =- bytes;
93: cp =+ bytes;
94: }
95: if (read(of, cp, 1) == 1) {
96: ferror("Expected end-of-file");
97: exit(1);
98: }
99: close(of);
100: if (file == 0)
101: wait(&i);
102: if (*bp++ != 0404) {
103: ferror("Not a Pascal object file");
104: exit(1);
105: }
106: if (discard && bp[(bp[0] == O_PXPBUF ? bp[5] + 8 : bp[1]) / 2 + 1] != O_NODUMP)
107: write(2, "Execution begins...\n", 20);
108: interpret(bp, size);
109: }
110:
111: Perror(file, mesg)
112: char *file, *mesg;
113: {
114: extern int errno;
115: extern char *sys_errlist[];
116:
117: errno = 0;
118: sys_errlist[0] = mesg;
119: perror(file);
120: }
121:
122: /*
123: * Initialization of random number "constants"
124: */
125: long seed 7774755.;
126: double randa 62605.;
127: double randc 113218009.;
128: double randm 536870912.;
129:
130: /*
131: * Routine to put a string on the current
132: * pascal output given a pointer to the string
133: */
134: puts(str)
135: char *str;
136: {
137: register char *cp;
138:
139: cp = str;
140: while (*cp)
141: pputch(*cp++);
142: }
143:
144: ferror(cp)
145: char *cp;
146: {
147:
148: Perror(file, cp);
149: }
150:
151: onintr()
152: {
153: extern int draino[];
154:
155: if (dp == 0)
156: exit(1);
157: draino[0] = 512;
158: draino[1] = &draino[2];
159: error(EINTR);
160: }
Defined functions
main
defined in line
17;
never used
puts
defined in line
134; used 39 times
- in /usr/src/ucb/pascal/px/perror.c line
29-38(4),
44-47(2),
59-71(5),
81-108(10),
114-126(5),
132-138(3),
148,
159-161(2),
169-171(2),
190-193(3),
208,
218
Defined variables
seed
defined in line
125; used 7 times