|
|
1.1 root 1: /* Copyright (c) 1979 Regents of the University of California */
2: #include "whoami"
3: /*
4: * pi - Pascal interpreter code translator
5: *
6: * Charles Haley, Bill Joy UCB
7: * Version 1.2 November 1978
8: *
9: *
10: * pxp - Pascal execution profiler
11: *
12: * Bill Joy UCB
13: * Version 1.2 November 1978
14: */
15:
16: #include "0.h"
17:
18: #ifndef PI1
19: /*
20: * Does the string fp end in '.' and the character c ?
21: */
22: dotted(fp, c)
23: register char *fp;
24: char c;
25: {
26: register int i;
27:
28: i = strlen(fp);
29: return (i > 1 && fp[i - 2] == '.' && fp[i - 1] == c);
30: }
31:
32: /*
33: * Toggle the option c.
34: */
35: togopt(c)
36: char c;
37: {
38: register char *tp;
39:
40: tp = &opts[c-'a'];
41: *tp = 1 - *tp;
42: }
43:
44: /*
45: * Set the time vector "tvec" to the
46: * modification time stamp of a file.
47: */
48: gettime( filename )
49: char *filename;
50: {
51: #include <stat.h>
52: struct stat stb;
53:
54: stat(filename, &stb);
55: tvec = stb.st_mtime;
56: }
57:
58: /*
59: * Convert a "ctime" into a Pascal styple time line
60: */
61: char *
62: myctime(tv)
63: int *tv;
64: {
65: register char *cp, *dp;
66: char *cpp;
67: register i;
68: static char mycbuf[26];
69:
70: cpp = ctime(tv);
71: dp = mycbuf;
72: cp = cpp;
73: cpp[16] = 0;
74: while (*dp++ = *cp++);
75: dp--;
76: cp = cpp+19;
77: cpp[24] = 0;
78: while (*dp++ = *cp++);
79: return (mycbuf);
80: }
81:
82: /*
83: * Is "fp" in the command line list of names ?
84: */
85: inpflist(fp)
86: char *fp;
87: {
88: register i, *pfp;
89:
90: pfp = pflist;
91: for (i = pflstc; i > 0; i--)
92: if (strcmp(fp, *pfp++) == 0)
93: return (1);
94: return (0);
95: }
96: #endif
97:
98: extern int errno;
99: extern char *sys_errlist[];
100:
101: /*
102: * Boom!
103: */
104: Perror(file, error)
105: char *file, *error;
106: {
107:
108: errno = 0;
109: sys_errlist[0] = error;
110: perror(file);
111: }
112:
113: int *
114: calloc(num, size)
115: int num, size;
116: {
117: register int p1, *p2, nbyte;
118:
119: nbyte = (num*size+( ( sizeof ( int ) ) - 1 ) ) & ~( ( sizeof ( int ) ) - 1 );
120: if ((p1 = malloc(nbyte)) == -1 || p1==0)
121: return (-1);
122: p2 = p1;
123: nbyte /= sizeof ( int );
124: do {
125: *p2++ = 0;
126: } while (--nbyte);
127: return (p1);
128: }
129:
130: /*
131: * Compare strings: s1>s2: >0 s1==s2: 0 s1<s2: <0
132: */
133: strcmp(s1, s2)
134: register char *s1, *s2;
135: {
136:
137: while (*s1 == *s2++)
138: if (*s1++=='\0')
139: return (0);
140: return (*s1 - *--s2);
141: }
142:
143: /*
144: * Copy string s2 to s1.
145: * S1 must be large enough.
146: * Return s1.
147: */
148: strcpy(s1, s2)
149: register char *s1, *s2;
150: {
151: register os1;
152:
153: os1 = s1;
154: while (*s1++ = *s2++)
155: continue;
156: return (os1);
157: }
158:
159: /*
160: * Strlen is currently a freebie of perror
161: * Take the length of a string.
162: * Note that this does not include the trailing null!
163: strlen(cp)
164: register char *cp;
165: {
166: register int i;
167:
168: for (i = 0; *cp != 0; cp++)
169: i++;
170: return (i);
171: }
172: */
173: copy(to, from, bytes)
174: register char *to, *from;
175: register int bytes;
176: {
177:
178: if (bytes != 0)
179: do
180: *to++ = *from++;
181: while (--bytes);
182: }
183:
184: /*
185: * Is ch one of the characters in the string cp ?
186: */
187: any(cp, ch)
188: register char *cp;
189: char ch;
190: {
191:
192: while (*cp)
193: if (*cp++ == ch)
194: return (1);
195: return (0);
196: }
197:
198: opush(c)
199: register CHAR c;
200: {
201:
202: c -= 'a';
203: optstk[c] <<= 1;
204: optstk[c] |= opts[c];
205: opts[c] = 1;
206: #ifdef PI0
207: send(ROPUSH, c);
208: #endif
209: }
210:
211: opop(c)
212: register CHAR c;
213: {
214:
215: c -= 'a';
216: opts[c] = optstk[c] & 1;
217: optstk[c] >>= 1;
218: #ifdef PI0
219: send(ROPOP, c);
220: #endif
221: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.