|
|
1.1 root 1: #include "mk.h"
2: #include <ar.h>
3:
4: #define AR 123456L
5:
6: extern long ftimeof(), atimeof();
7: extern void ftouch(), atouch();
8: extern void fdelete(), adelete();
9: static long split();
10:
11: struct ftype
12: {
13: long magic;
14: long (*time)();
15: void (*touch)();
16: void (*delete)();
17: } ftab[] =
18: {
19: { 0L, ftimeof, ftouch, fdelete },
20: { AR, atimeof, atouch, adelete },
21: { 0L, (long (*)())0 }
22: };
23:
24: long
25: timeof(name, force)
26: char *name;
27: {
28: char buf[BIGBLOCK], *part2;
29: register struct ftype *f;
30: long magic;
31:
32: magic = split(name, buf, &part2);
33: for(f = ftab; f->time; f++)
34: if(f->magic == magic)
35: return((*f->time)(force, name, buf, part2));
36: Fprint(2, "mk: '%s' appears to have an unknown magic number (%ld)\n", name, magic);
37: Exit();
38: return(0L); /* shut cyntax up */
39: }
40:
41: void
42: touch(name)
43: char *name;
44: {
45: char buf[BIGBLOCK], *part2;
46: register struct ftype *f;
47: long magic;
48:
49: magic = split(name, buf, &part2);
50: Fprint(1, "touch(%s)\n", name);
51: if(nflag)
52: return;
53: for(f = ftab; f->time; f++)
54: if(f->magic == magic){
55: (*f->touch)(name, buf, part2);
56: return;
57: }
58: Fprint(2, "mk: give me a break! I never heard of magic=%ld\n", magic);
59: Exit();
60: }
61:
62: void
63: delete(name)
64: char *name;
65: {
66: char buf[BIGBLOCK], *part2;
67: register struct ftype *f;
68: long magic;
69:
70: magic = split(name, buf, &part2);
71: for(f = ftab; f->time; f++)
72: if(f->magic == magic){
73: (*f->delete)(name, buf, part2);
74: return;
75: }
76: Fprint(2, "mk: give me a break! I never heard of magic=%ld\n", magic);
77: Exit();
78: }
79:
80: static long
81: type(file)
82: char *file;
83: {
84: int fd;
85: char buf[SARMAG];
86: short m;
87: long goo;
88:
89: if(access(file, 0) < 0){
90: if(symlook(file, S_BITCH, (char *)0) == 0){
91: Fprint(1, "%s doesn't exist: assuming it will be an archive\n", file);
92: (void)symlook(file, S_BITCH, file);
93: }
94: return(AR);
95: }
96: if((fd = open(file, 0)) < 0){
97: perror(file);
98: Exit();
99: }
100: if(read(fd, buf, SARMAG) != SARMAG){
101: close(fd);
102: return(-1L);
103: }
104: if(strncmp(ARMAG, buf, SARMAG) == 0)
105: goo = AR;
106: else {
107: lseek(fd, 0L, 0);
108: if(read(fd, (char *)&m, sizeof m) == sizeof m)
109: goo = m;
110: else
111: goo = -1;
112: }
113: close(fd);
114: return(goo);
115: }
116:
117: static long
118: split(name, buf, p2)
119: char *name, *buf, **p2;
120: {
121: register char *s;
122:
123: strcpy(buf, name);
124: if(s = strchr(buf, '(')){
125: *s++ = 0;
126: *p2 = s;
127: while(*s && (*s != ')'))
128: s++;
129: *s = 0;
130: return(type(buf));
131: } else
132: return(0L);
133: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.