Commit | Line | Data |
---|---|---|
0fc6e47b | 1 | /*- |
ad787160 C |
2 | * Copyright (c) 1980, 1993 |
3 | * The Regents of the University of California. All rights reserved. | |
0fc6e47b | 4 | * |
ad787160 C |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions | |
7 | * are met: | |
8 | * 1. Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * 2. Redistributions in binary form must reproduce the above copyright | |
11 | * notice, this list of conditions and the following disclaimer in the | |
12 | * documentation and/or other materials provided with the distribution. | |
13 | * 3. All advertising materials mentioning features or use of this software | |
14 | * must display the following acknowledgement: | |
15 | * This product includes software developed by the University of | |
16 | * California, Berkeley and its contributors. | |
17 | * 4. Neither the name of the University nor the names of its contributors | |
18 | * may be used to endorse or promote products derived from this software | |
19 | * without specific prior written permission. | |
20 | * | |
21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
31 | * SUCH DAMAGE. | |
252367af | 32 | */ |
fae9e27f | 33 | |
72fbef68 | 34 | #ifndef lint |
ad787160 | 35 | static char sccsid[] = "@(#)subr.c 8.1 (Berkeley) 6/6/93"; |
0fc6e47b | 36 | #endif /* not lint */ |
fae9e27f PK |
37 | |
38 | #include "whoami.h" | |
39 | #include "0.h" | |
40 | ||
41 | #ifndef PI1 | |
42 | /* | |
43 | * Does the string fp end in '.' and the character c ? | |
44 | */ | |
45 | dotted(fp, c) | |
46 | register char *fp; | |
47 | char c; | |
48 | { | |
49 | register int i; | |
50 | ||
51 | i = strlen(fp); | |
52 | return (i > 1 && fp[i - 2] == '.' && fp[i - 1] == c); | |
53 | } | |
54 | ||
55 | /* | |
56 | * Toggle the option c. | |
57 | */ | |
58 | togopt(c) | |
59 | char c; | |
60 | { | |
61 | register char *tp; | |
62 | ||
63 | tp = &opt( c ); | |
64 | *tp = 1 - *tp; | |
65 | } | |
66 | ||
67 | /* | |
68 | * Set the time vector "tvec" to the | |
69 | * modification time stamp of a file. | |
70 | */ | |
71 | gettime( filename ) | |
72 | char *filename; | |
73 | { | |
71a477a6 | 74 | #include <sys/stat.h> |
fae9e27f PK |
75 | struct stat stb; |
76 | ||
77 | stat(filename, &stb); | |
78 | tvec = stb.st_mtime; | |
79 | } | |
80 | ||
81 | /* | |
82 | * Convert a "ctime" into a Pascal styple time line | |
83 | */ | |
84 | char * | |
85 | myctime(tv) | |
86 | int *tv; | |
87 | { | |
88 | register char *cp, *dp; | |
72fbef68 | 89 | extern char *ctime(); |
fae9e27f | 90 | char *cpp; |
fae9e27f PK |
91 | static char mycbuf[26]; |
92 | ||
93 | cpp = ctime(tv); | |
94 | dp = mycbuf; | |
95 | cp = cpp; | |
96 | cpp[16] = 0; | |
97 | while (*dp++ = *cp++); | |
98 | dp--; | |
99 | cp = cpp+19; | |
100 | cpp[24] = 0; | |
101 | while (*dp++ = *cp++); | |
102 | return (mycbuf); | |
103 | } | |
104 | ||
105 | /* | |
106 | * Is "fp" in the command line list of names ? | |
107 | */ | |
108 | inpflist(fp) | |
109 | char *fp; | |
110 | { | |
72fbef68 RT |
111 | register i; |
112 | register char **pfp; | |
fae9e27f PK |
113 | |
114 | pfp = pflist; | |
115 | for (i = pflstc; i > 0; i--) | |
72fbef68 | 116 | if (pstrcmp(fp, *pfp++) == 0) |
fae9e27f PK |
117 | return (1); |
118 | return (0); | |
119 | } | |
120 | #endif | |
121 | ||
fae9e27f PK |
122 | /* |
123 | * Boom! | |
124 | */ | |
125 | Perror(file, error) | |
126 | char *file, *error; | |
127 | { | |
128 | ||
eb72e605 | 129 | fprintf( stderr , "%s: %s\n" , file , error ); |
fae9e27f PK |
130 | } |
131 | ||
132 | int * | |
72fbef68 | 133 | pcalloc(num, size) |
fae9e27f PK |
134 | int num, size; |
135 | { | |
72fbef68 | 136 | register int *p1, *p2, nbyte; |
fae9e27f PK |
137 | |
138 | nbyte = (num*size+( ( sizeof ( int ) ) - 1 ) ) & ~( ( sizeof ( int ) ) - 1 ); | |
72fbef68 | 139 | if ((p1 = (int *) malloc((unsigned) nbyte)) == 0) |
df51413a | 140 | return (0); |
72fbef68 | 141 | p2 = p1; |
fae9e27f PK |
142 | nbyte /= sizeof ( int ); |
143 | do { | |
144 | *p2++ = 0; | |
145 | } while (--nbyte); | |
146 | return (p1); | |
147 | } | |
148 | ||
149 | /* | |
150 | * Compare strings: s1>s2: >0 s1==s2: 0 s1<s2: <0 | |
151 | */ | |
72fbef68 | 152 | pstrcmp(s1, s2) |
fae9e27f PK |
153 | register char *s1, *s2; |
154 | { | |
155 | ||
156 | while (*s1 == *s2++) | |
157 | if (*s1++=='\0') | |
158 | return (0); | |
159 | return (*s1 - *--s2); | |
160 | } | |
161 | ||
162 | /* | |
163 | * Copy string s2 to s1. | |
164 | * S1 must be large enough. | |
165 | * Return s1. | |
166 | */ | |
72fbef68 RT |
167 | char * |
168 | pstrcpy(s1, s2) | |
fae9e27f PK |
169 | register char *s1, *s2; |
170 | { | |
72fbef68 | 171 | register char *os1; |
fae9e27f PK |
172 | |
173 | os1 = s1; | |
174 | while (*s1++ = *s2++) | |
175 | continue; | |
176 | return (os1); | |
177 | } | |
178 | ||
179 | /* | |
180 | * Strlen is currently a freebie of perror | |
181 | * Take the length of a string. | |
182 | * Note that this does not include the trailing null! | |
183 | strlen(cp) | |
184 | register char *cp; | |
185 | { | |
186 | register int i; | |
187 | ||
188 | for (i = 0; *cp != 0; cp++) | |
189 | i++; | |
190 | return (i); | |
191 | } | |
192 | */ | |
193 | copy(to, from, bytes) | |
194 | register char *to, *from; | |
195 | register int bytes; | |
196 | { | |
197 | ||
198 | if (bytes != 0) | |
199 | do | |
200 | *to++ = *from++; | |
201 | while (--bytes); | |
202 | } | |
203 | ||
204 | /* | |
205 | * Is ch one of the characters in the string cp ? | |
206 | */ | |
207 | any(cp, ch) | |
208 | register char *cp; | |
209 | char ch; | |
210 | { | |
211 | ||
212 | while (*cp) | |
213 | if (*cp++ == ch) | |
214 | return (1); | |
215 | return (0); | |
216 | } | |
217 | ||
218 | opush(c) | |
219 | register CHAR c; | |
220 | { | |
221 | ||
222 | c -= 'A'; | |
223 | optstk[c] <<= 1; | |
224 | optstk[c] |= opts[c]; | |
225 | opts[c] = 1; | |
226 | #ifdef PI0 | |
227 | send(ROPUSH, c); | |
228 | #endif | |
229 | } | |
230 | ||
231 | opop(c) | |
232 | register CHAR c; | |
233 | { | |
234 | ||
235 | c -= 'A'; | |
236 | opts[c] = optstk[c] & 1; | |
237 | optstk[c] >>= 1; | |
238 | #ifdef PI0 | |
239 | send(ROPOP, c); | |
240 | #endif | |
241 | } |