|
|
1.1 root 1: /* UNIX DEPENDENT PROCEDURES */
2:
3:
4: /* DEFAULT RULES FOR UNIX */
5:
6: char *builtin[] =
7: {
8: #ifdef pwb
9: ".SUFFIXES : .L .out .o .c .f .e .r .y .yr .ye .l .s .z .x .t .h",
10: #else
11: ".SUFFIXES : .out .o .c .f .e .r .y .yr .ye .l .s",
12: #endif
13: "YACC=yacc",
14: "YACCR=yacc -r",
15: "YACCE=yacc -e",
16: "YFLAGS=",
17: "LEX=lex",
18: "LFLAGS=",
19: "CC=cc",
20: #ifdef vax
21: "AS=as",
22: #else
23: "AS=as -",
24: #endif
25: "CFLAGS=",
26: "RC=f77",
27: "RFLAGS=",
28: "EC=f77",
29: "EFLAGS=",
30: "FFLAGS=",
31: "LOADLIBES=",
32: #ifdef pwb
33: "SCOMP=scomp",
34: "SCFLAGS=",
35: "CMDICT=cmdict",
36: "CMFLAGS=",
37: #endif
38:
39: ".c.o :",
40: "\t$(CC) $(CFLAGS) -c $<",
41:
42: ".e.o .r.o .f.o :",
43: "\t$(EC) $(RFLAGS) $(EFLAGS) $(FFLAGS) -c $<",
44:
45: ".s.o :",
46: "\t$(AS) -o $@ $<",
47:
48: ".y.o :",
49: "\t$(YACC) $(YFLAGS) $<",
50: "\t$(CC) $(CFLAGS) -c y.tab.c",
51: "\trm y.tab.c",
52: "\tmv y.tab.o $@",
53:
54: ".yr.o:",
55: "\t$(YACCR) $(YFLAGS) $<",
56: "\t$(RC) $(RFLAGS) -c y.tab.r",
57: "\trm y.tab.r",
58: "\tmv y.tab.o $@",
59:
60: ".ye.o :",
61: "\t$(YACCE) $(YFLAGS) $<",
62: "\t$(EC) $(RFLAGS) -c y.tab.e",
63: "\trm y.tab.e",
64: "\tmv y.tab.o $@",
65:
66: ".l.o :",
67: "\t$(LEX) $(LFLAGS) $<",
68: "\t$(CC) $(CFLAGS) -c lex.yy.c",
69: "\trm lex.yy.c",
70: "\tmv lex.yy.o $@",
71:
72: ".y.c :",
73: "\t$(YACC) $(YFLAGS) $<",
74: "\tmv y.tab.c $@",
75:
76: ".l.c :",
77: "\t$(LEX) $(LFLAGS) $<",
78: "\tmv lex.yy.c $@",
79:
80: ".yr.r:",
81: "\t$(YACCR) $(YFLAGS) $<",
82: "\tmv y.tab.r $@",
83:
84: ".ye.e :",
85: "\t$(YACCE) $(YFLAGS) $<",
86: "\tmv y.tab.e $@",
87:
88: #ifdef pwb
89: ".o.L .c.L .t.L:",
90: "\t$(SCOMP) $(SCFLAGS) $<",
91:
92: ".t.o:",
93: "\t$(SCOMP) $(SCFLAGS) -c $<",
94:
95: ".t.c:",
96: "\t$(SCOMP) $(SCFLAGS) -t $<",
97:
98: ".h.z .t.z:",
99: "\t$(CMDICT) $(CMFLAGS) $<",
100:
101: ".h.x .t.x:",
102: "\t$(CMDICT) $(CMFLAGS) -c $<",
103: #endif
104:
105: ".s.out .c.out .o.out :",
106: "\t$(CC) $(CFLAGS) $< $(LOADLIBES) -o $@",
107:
108: ".f.out .r.out .e.out :",
109: "\t$(EC) $(EFLAGS) $(RFLAGS) $(FFLAGS) $< $(LOADLIBES) -o $@",
110: "\t-rm $*.o",
111:
112: ".y.out :",
113: "\t$(YACC) $(YFLAGS) $<",
114: "\t$(CC) $(CFLAGS) y.tab.c $(LOADLIBES) -ly -o $@",
115: "\trm y.tab.c",
116:
117: ".l.out :",
118: "\t$(LEX) $(LFLAGS) $<",
119: "\t$(CC) $(CFLAGS) lex.yy.c $(LOADLIBES) -ll -o $@",
120: "\trm lex.yy.c",
121:
122: 0 };
123:
124: #include "defs"
125: #include <sys/types.h>
126:
127:
128: TIMETYPE exists(filename)
129: char *filename;
130: {
131: #include <sys/stat.h>
132: struct stat buf;
133: register char *s;
134: TIMETYPE lookarch();
135:
136: for(s = filename ; *s!='\0' && *s!='(' ; ++s)
137: ;
138:
139: if(*s == '(')
140: return(lookarch(filename));
141:
142: if(stat(filename,&buf) < 0)
143: return(0);
144: else return(buf.st_mtime);
145: }
146:
147:
148: TIMETYPE prestime()
149: {
150: TIMETYPE t;
151: time(&t);
152: return(t);
153: }
154:
155:
156:
157: #include <sys/dir.h>
158: FSTATIC char n15[15];
159: FSTATIC char *n15end = &n15[14];
160:
161:
162:
163: struct depblock *srchdir(pat, mkchain, nextdbl)
164: register char *pat; /* pattern to be matched in directory */
165: int mkchain; /* nonzero if results to be remembered */
166: struct depblock *nextdbl; /* final value for chain */
167: {
168: FILE * dirf;
169: int i, nread, cldir;
170: char *dirname, *dirpref, *endir, *filepat, *p, temp[100];
171: char fullname[100], *p1, *p2;
172: struct nameblock *q;
173: struct depblock *thisdbl;
174: struct opendir *od;
175: struct pattern *patp;
176:
177: struct direct entry[32];
178:
179:
180: thisdbl = 0;
181:
182: if(mkchain == NO)
183: for(patp=firstpat ; patp ; patp = patp->nxtpattern)
184: if(! unequal(pat, patp->patval)) return(0);
185:
186: patp = ALLOC(pattern);
187: patp->nxtpattern = firstpat;
188: firstpat = patp;
189: patp->patval = copys(pat);
190:
191: endir = 0;
192:
193: for(p=pat; *p!='\0'; ++p)
194: if(*p=='/') endir = p;
195:
196: if(endir==0)
197: {
198: dirname = ".";
199: dirpref = "";
200: filepat = pat;
201: }
202: else {
203: dirname = pat;
204: *endir = '\0';
205: dirpref = concat(dirname, "/", temp);
206: filepat = endir+1;
207: }
208:
209: dirf = NULL;
210: cldir = NO;
211:
212: for(od = firstod ; od; od = od->nxtopendir)
213: if(! unequal(dirname, od->dirn) )
214: {
215: dirf = od->dirfc;
216: fseek(dirf,0L,0); /* start over at the beginning */
217: break;
218: }
219:
220: if(dirf == NULL)
221: {
222: dirf = fopen(dirname, "r");
223: if(nopdir >= MAXDIR)
224: cldir = YES;
225: else {
226: ++nopdir;
227: od = ALLOC(opendir);
228: od->nxtopendir = firstod;
229: firstod = od;
230: od->dirfc = dirf;
231: od->dirn = copys(dirname);
232: }
233: }
234:
235: if(dirf == NULL)
236: {
237: fprintf(stderr, "Directory %s: ", dirname);
238: fatal("Cannot open");
239: }
240:
241: else do
242: {
243: nread = fread( (char *) &entry[0], sizeof(struct direct), 32, dirf) ;
244: for(i=0; i<nread; ++i)
245: if(entry[i].d_ino!= 0)
246: {
247: p1 = entry[i].d_name;
248: p2 = n15;
249: while( (p2<n15end) &&
250: (*p2++ = *p1++)!='\0' );
251: if( amatch(n15,filepat) )
252: {
253: concat(dirpref,n15,fullname);
254: if( (q=srchname(fullname)) ==0)
255: q = makename(copys(fullname));
256: if(mkchain)
257: {
258: thisdbl = ALLOC(depblock);
259: thisdbl->nxtdepblock = nextdbl;
260: thisdbl->depname = q;
261: nextdbl = thisdbl;
262: }
263: }
264: }
265:
266: } while(nread==32);
267:
268: if(endir != 0) *endir = '/';
269:
270: if(cldir)
271: fclose(dirf);
272: return(thisdbl);
273: }
274:
275: /* stolen from glob through find */
276:
277: static amatch(s, p)
278: char *s, *p;
279: {
280: register int cc, scc, k;
281: int c, lc;
282:
283: scc = *s;
284: lc = 077777;
285: switch (c = *p) {
286:
287: case '[':
288: k = 0;
289: while (cc = *++p) {
290: switch (cc) {
291:
292: case ']':
293: if (k)
294: return(amatch(++s, ++p));
295: else
296: return(0);
297:
298: case '-':
299: k |= (lc <= scc) & (scc <= (cc=p[1]) ) ;
300: }
301: if (scc==(lc=cc)) k++;
302: }
303: return(0);
304:
305: case '?':
306: caseq:
307: if(scc) return(amatch(++s, ++p));
308: return(0);
309: case '*':
310: return(umatch(s, ++p));
311: case 0:
312: return(!scc);
313: }
314: if (c==scc) goto caseq;
315: return(0);
316: }
317:
318: static umatch(s, p)
319: char *s, *p;
320: {
321: if(*p==0) return(1);
322: while(*s)
323: if (amatch(s++,p)) return(1);
324: return(0);
325: }
326:
327: #ifdef METERFILE
328: #include <pwd.h>
329: int meteron = 0; /* default: metering off */
330:
331: meter(file)
332: char *file;
333: {
334: TIMETYPE tvec;
335: char *p, *ctime();
336: FILE * mout;
337: struct passwd *pwd, *getpwuid();
338:
339: if(file==0 || meteron==0) return;
340:
341: pwd = getpwuid(getuid());
342:
343: time(&tvec);
344:
345: if( (mout=fopen(file,"a")) != NULL )
346: {
347: p = ctime(&tvec);
348: p[16] = '\0';
349: fprintf(mout,"User %s, %s\n",pwd->pw_name,p+4);
350: fclose(mout);
351: }
352: }
353: #endif
354:
355:
356: /* look inside archives for notations a(b) and a((b))
357: a(b) is file member b in archive a
358: a((b)) is entry point _b in object archive a
359: */
360: #include <ar.h>
361: #include <a.out.h>
362:
363: static struct ar_hdr arhead;
364: FILE *arfd;
365: long int arpos, arlen;
366:
367: static struct exec objhead;
368:
369: static struct nlist objentry;
370:
371:
372: TIMETYPE lookarch(filename)
373: char *filename;
374: {
375: char *p, *q, *send, s[15];
376: int i, nc, nsym, objarch;
377:
378: for(p = filename; *p!= '(' ; ++p)
379: ;
380: *p = '\0';
381: openarch(filename);
382: *p++ = '(';
383:
384: if(*p == '(')
385: {
386: objarch = YES;
387: nc = 8;
388: ++p;
389: }
390: else
391: {
392: objarch = NO;
393: nc = 14;
394: }
395: send = s + nc;
396:
397: for( q = s ; q<send && *p!='\0' && *p!=')' ; *q++ = *p++ )
398: ;
399: while(q < send)
400: *q++ = '\0';
401: while(getarch())
402: {
403: if(objarch)
404: {
405: getobj();
406: nsym = objhead.a_syms / sizeof(objentry);
407: for(i = 0; i<nsym ; ++i)
408: {
409: fread( (char *) &objentry, sizeof(objentry),1,arfd);
410: if( (objentry.n_type & N_EXT)
411: && ((objentry.n_type & ~N_EXT) || objentry.n_value)
412: && eqstr(objentry.n_name,s,nc))
413: {
414: clarch();
415: return(arhead.ar_date);
416: }
417: }
418: }
419:
420: else if( eqstr(arhead.ar_name, s, nc))
421: {
422: clarch();
423: return( arhead.ar_date);
424: }
425: }
426:
427: clarch();
428: return( 0L);
429: }
430:
431:
432: clarch()
433: {
434: fclose( arfd );
435: }
436:
437:
438: openarch(f)
439: register char *f;
440: {
441: int word;
442: #include <sys/stat.h>
443: struct stat buf;
444:
445: stat(f, &buf);
446: arlen = buf.st_size;
447:
448: arfd = fopen(f, "r");
449: if(arfd == NULL)
450: fatal1("cannot open %s", f);
451: fread( (char *) &word, sizeof(word), 1, arfd);
452: if(word != ARMAG)
453: fatal1("%s is not an archive", f);
454: arpos = 0;
455: arhead.ar_size = 2 - sizeof(arhead);
456: }
457:
458:
459:
460: getarch()
461: {
462: arpos += sizeof(arhead);
463: arpos += (arhead.ar_size + 1 ) & ~1L;
464: if(arpos >= arlen)
465: return(0);
466: fseek(arfd, arpos, 0);
467: fread( (char *) &arhead, sizeof(arhead), 1, arfd);
468: return(1);
469: }
470:
471:
472: getobj()
473: {
474: long int skip;
475:
476: fread( (char *) &objhead, sizeof(objhead), 1, arfd);
477: if( objhead.a_magic != A_MAGIC1 &&
478: objhead.a_magic != A_MAGIC2 &&
479: objhead.a_magic != A_MAGIC3 &&
480: objhead.a_magic != A_MAGIC4 )
481: fatal1("%s is not an object module", arhead.ar_name);
482: skip = objhead.a_text + objhead.a_data;
483: #ifdef vax
484: skip += objhead.a_trsize + objhead.a_drsize;
485: #else
486: if(! objhead.a_flag )
487: skip *= 2;
488: #endif
489: fseek(arfd, skip, 1);
490: }
491:
492:
493: eqstr(a,b,n)
494: register char *a, *b;
495: int n;
496: {
497: register int i;
498: for(i = 0 ; i < n ; ++i)
499: if(*a++ != *b++)
500: return(NO);
501: return(YES);
502: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.