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