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