BSD 4_1_snap release
[unix-history] / usr / src / cmd / pxp / subr.c
CommitLineData
4b9ccde7 1static char *sccsid = "@(#)subr.c 1.2 (Berkeley) 3/5/81";
ab8e76f3
BJ
2/* Copyright (c) 1979 Regents of the University of California */
3/*
4 * pi - Pascal interpreter code translator
5 *
6 * Charles Haley, Bill Joy UCB
7 * Version 1.2 January 1979
8 *
9 *
10 * pxp - Pascal execution profiler
11 *
12 * Bill Joy UCB
13 * Version 1.2 January 1979
14 */
15
16#include "0.h"
17
18#ifndef PI1
19/*
20 * Does the string fp end in '.' and the character c ?
21 */
22dotted(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 */
35togopt(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 the current file.
47 */
48#include <sys/types.h>
49#include <stat.h>
50gettime()
51{
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 */
61myctime(tv)
62 long *tv;
63{
64 register char *cp, *dp;
65 char *cpp;
66 register i;
67 static char mycbuf[26];
68
69 cpp = ctime(tv);
70 dp = mycbuf;
71 cp = cpp;
72 cpp[16] = 0;
73 while (*dp++ = *cp++);
74 dp--;
75 cp = cpp+19;
76 cpp[24] = 0;
77 while (*dp++ = *cp++);
78 return (mycbuf);
79}
80
81/*
82 * Is "fp" in the command line list of names ?
83 */
84inpflist(fp)
85 char *fp;
86{
87 register i, *pfp;
88
89 pfp = pflist;
90 for (i = pflstc; i > 0; i--)
91 if (strcmp(fp, *pfp++) == 0)
92 return (1);
93 return (0);
94}
95#endif
96
ab8e76f3
BJ
97/*
98 * Boom!
99 */
100Perror(file, error)
101 char *file, *error;
102{
103
4b9ccde7 104 fprintf( stderr , "%s: %s\n" , file , error );
ab8e76f3
BJ
105}
106
107char *
108alloc(size)
109 int size;
110{
111
112 return (calloc(size, 1));
113}
114
115copy(to, from, bytes)
116 register char *to, *from;
117 register int bytes;
118{
119
120 if (bytes != 0)
121 do
122 *to++ = *from++;
123 while (--bytes);
124}
125
126/*
127 * Is ch one of the characters in the string cp ?
128 */
129any(cp, ch)
130 register char *cp;
131 char ch;
132{
133
134 while (*cp)
135 if (*cp++ == ch)
136 return (1);
137 return (0);
138}
139
140opush(c)
141 register CHAR c;
142{
143
144 c =- 'a';
145 optstk[c] =<< 1;
146 optstk[c] =| opts[c];
147 opts[c] = 1;
148#ifdef PI0
149 send(ROPUSH, c);
150#endif
151}
152
153opop(c)
154 register CHAR c;
155{
156
157 c =- 'a';
158 opts[c] = optstk[c] & 1;
159 optstk[c] =>> 1;
160#ifdef PI0
161 send(ROPOP, c);
162#endif
163}