1 static int filename(char *name, char *base) {
2 int status = 0;
3 static char *stemp, *itemp;
4
5 if (base == 0)
6 base = basepath(name);
7 switch (suffix(name, suffixes, 4)) {
8 case 0: /* C source files */
9 compose(cpp, plist, append(name, 0), 0);
10 if (Eflag) {
11 status = callsys(av);
12 break;
13 }
14 if (itemp == NULL)
15 itemp = tempname(first(suffixes[1]));
16 compose(cpp, plist, append(name, 0), append(itemp, 0));
17 status = callsys(av);
18 if (status == 0)
19 return filename(itemp, base);
20 break;
21 case 1: /* preprocessed source files */
22 if (Eflag)
23 break;
24 if (Sflag)
25 status = compile(name, outfile ? outfile : concat(base, first(suffixes[2])));
26 else if ((status = compile(name, stemp?stemp:(stemp=tempname(first(suffixes[2]))))) == 0)
27 return filename(stemp, base);
28 break;
29 case 2: /* assembly language files */
30 if (Eflag)
31 break;
32 if (!Sflag) {
33 char *ofile;
34 if (cflag && outfile)
35 ofile = outfile;
36 else if (cflag)
37 ofile = concat(base, first(suffixes[3]));
38 else
39 ofile = tempname(first(suffixes[3]));
40 compose(as, alist, append(name, 0), append(ofile, 0));
41 status = callsys(av);
42 if (!find(ofile, llist[1]))
43 llist[1] = append(ofile, llist[1]);
44 }
45 break;
46 case 3: /* object files */
47 if (!find(name, llist[1]))
48 llist[1] = append(name, llist[1]);
49 break;
50 default:
51 if (Eflag) {
52 compose(cpp, plist, append(name, 0), 0);
53 status = callsys(av);
54 }
55 llist[1] = append(name, llist[1]);
56 break;
57 }
58 if (status)
59 errcnt++;
60 return status;
61 }