forked from qrush/unix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfc.c
127 lines (115 loc) · 1.79 KB
/
fc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/* fortran command */
char ts[500];
char *tsp ts;
char *av[50];
char *llist[50];
main(argc, argv)
char *argv[]; {
char *t;
int nl, cflag, i, j;
llist[0] = 0;
i = nl = cflag = 0;
while(++i < argc) {
if (getsuf(t=copy(argv[i])) == 'f') {
printf("%s:\n", t);
av[0] = "fc";
av[1] = t;
av[2] = 0;
if(callsys("/usr/fort/fc1", av) == 0) {
av[0] = "as";
av[1] = "-";
av[2] = "f.tmp1";
av[3] = 0;
callsys("/bin/as", av);
setsuf(t);
unlink(t);
if(link("a.out", t) | unlink("a.out")) {
printf("move failed: %s\n", t);
return;
}
} else {
cflag++;
goto loop;
}
} else if (*t == '-' & t[1] =='c') {
cflag++;
goto loop;
}
if (nodup(llist, t)) {
llist[nl++] = t;
llist[nl] = 0;
}
loop:;
}
unlink("f.tmp1");
if (cflag | nl==0) return;
i = 0;
av[0] = "ld";
av[1] = "/lib/fr0.o";
j = 2;
while(i<nl)
av[j++] = llist[i++];
av[j++] = "-lf";
av[j++] = "/lib/filib.a";
av[j++] = "-l";
av[j++] = 0;
callsys("/bin/ld", av);
}
getsuf(s)
char s[]; {
int c;
char t, *os;
c = 0;
os = s;
while(t = *s++)
if (t=='/')
c = 0;
else
c++;
s =- 3;
if (c<=8 & c>2 & *s++=='.' & *s=='f')
return('f');
return(0);
}
setsuf(s)
char s[]; {
while(*s++);
s[-2] = 'o';
}
callsys(f, v)
char f[], *v[]; {
int t, status;
if ((t=fork())==0) {
execv(f, v);
printf("Can't find %s\n", f);
exit(-1);
} else
if (t == -1) {
printf("Try again\n");
exit(-1);
}
while(t!=wait(&status));
if ((status&0377) != 0)
exit(-1);
return((status>>8) & 0377);
}
copy(s)
char s[]; {
char *otsp;
otsp = tsp;
while(*tsp++ = *s++);
return(otsp);
}
nodup(l, s)
char *l[], s[]; {
char *t, *os, c;
os = s;
while(t = *l++) {
s = os;
while(c = *s++)
if (c != *t++) goto ll;
if (*t++ == '\0') return (0);
ll:;
}
return(1);
}