Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20030807150307

Diff

Diff from 1.4 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/pcc/pcc/cc/cc/cc.c

Annotated File View

ragge
1.4
1 /*      $Id: cc.c,v 1.4 2003/08/07 15:03:07 ragge Exp $ */
ragge
1.3
2 /*
3  * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * Redistributions of source code and documentation must retain the above
10  * copyright notice, this list of conditions and the following disclaimer.
11  * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditionsand the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * All advertising materials mentioning features or use of this software
15  * must display the following acknowledgement:
16  *      This product includes software developed or owned by Caldera
17  *      International, Inc.
18  * Neither the name of Caldera International, Inc. nor the names of other
19  * contributors may be used to endorse or promote products derived from
20  * this software without specific prior written permission.
21  *
22  * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
23  * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED.  IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE
27  * FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT,
31  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
ragge
1.2
35
ragge
1.1
36 /*
ragge
1.3
37  * Front-end to the C compiler.
ragge
1.1
38  */
ragge
1.2
39
ragge
1.1
40 #include <stdio.h>
41 #include <ctype.h>
42 #include <signal.h>
ragge
1.4
43 #include <string.h>
44 #include <fcntl.h>
45 #include <unistd.h>
46 #include <stdlib.h>
47 #include <sys/wait.h>
ragge
1.3
48 /* C command */
ragge
1.1
49
ragge
1.3
50 #define SBSIZE 10000
51 #define MAXINC 10
52 #define MAXFIL 100
53 #define MAXLIB 100
54 #define MAXOPT 100
55 char    *tmp0;
56 char    *tmp1;
57 char    *tmp2;
58 char    *tmp3;
59 char    *tmp4;
60 char    *tmp5;
ragge
1.1
61 char    *outfile;
ragge
1.4
62 char *copy(char []),*setsuf(char [], int);
63 int getsuf(char []);
64 int main(intchar *[]);
65 void error(char *, char *);
66 int nodup(char **, char *);
67 int callsys(char [], char *[]);
68 int cunlink(char *);
69 void dexit(void);
70 void idexit(int);
ragge
1.3
71 # define CHSPACE 1000
72 char    ts[CHSPACE+50];
73 char    *tsa = ts;
74 char    *tsp = ts;
75 char    *av[50];
76 char    *clist[MAXFIL];
77 char    *llist[MAXLIB];
ragge
1.4
78 char    alist[20];
ragge
1.3
79 int dflag;
80 int     pflag;
81 int     sflag;
82 int     cflag;
83 int     eflag;
84 int     gflag;
85 int     exflag;
ragge
1.4
86 int     Oflag;
ragge
1.3
87 int     proflag;
88 int     noflflag;
ragge
1.1
89 int     exfail;
ragge
1.4
90 char    *pass0 = "/lib/ccom";
91 char    *passp = "/usr/libexec/cpp";
92 char    *pref = "/usr/lib/crt0.o";
ragge
1.1
93
ragge
1.4
94 int
ragge
1.3
95 main(argcargv)
96 char *argv[]; {
ragge
1.1
97         char *t;
ragge
1.3
98         char *savetsp;
ragge
1.1
99         char *assource;
ragge
1.3
100         char **pv, *ptemp[MAXOPT], **pvt;
ragge
1.4
101         int ncnlijcf20nxonatt;
102         FILE *f;
ragge
1.3
103
104         i = nc = nl = f20 = nxo = 0;
105         pv = ptemp;
106         while(++i < argc) {
107                 if(*argv[i] == '-'switch (argv[i][1]) {
108                 default:
109                         goto passa;
ragge
1.1
110                 case 'S':
111                         sflag++;
112                         cflag++;
ragge
1.3
113                         break;
ragge
1.1
114                 case 'o':
115                         if (++i < argc) {
116                                 outfile = argv[i];
ragge
1.4
117                                 if ((tt=getsuf(outfile))=='c'||tt=='o') {
ragge
1.3
118                                         error("Would overwrite %s"outfile);
ragge
1.1
119                                         exit(8);
120                                 }
121                         }
ragge
1.3
122                         break;
ragge
1.1
123                 case 'O':
ragge
1.4
124                         Oflag++;
ragge
1.3
125                         break;
ragge
1.1
126                 case 'p':
127                         proflag++;
ragge
1.3
128                         break;
ragge
1.1
129                 case 'g':
ragge
1.3
130                         gflag++;
131                         break;
ragge
1.1
132                 case 'E':
133                         exflag++;
134                 case 'P':
135                         pflag++;
ragge
1.3
136                         *pv++ = argv[i];
ragge
1.1
137                 case 'c':
138                         cflag++;
ragge
1.3
139                         break;
140
141                 case '2':
142                         if(argv[i][2] == '\0')
143                                 pref = "/lib/crt2.o";
144                         else {
145                                 pref = "/lib/crt20.o";
146                                 f20 = 1;
147                         }
148                         break;
ragge
1.1
149                 case 'D':
150                 case 'I':
151                 case 'U':
152                 case 'C':
ragge
1.3
153                         *pv++ = argv[i];
154                         if (pv >= ptemp+MAXOPT)
155                                 {
156                                 error("Too many DIUC options"0);
157                                 --pv;
158                                 }
159                         break;
160
ragge
1.1
161                 case 'd':
ragge
1.3
162                         dflag++;
ragge
1.4
163                         strncpy(alistargv[i], 19);
ragge
1.3
164                         break;
165                 } else {
166                 passa:
167                         t = argv[i];
168                         if((c=getsuf(t))=='c' || c=='s'|| exflag) {
169                                 clist[nc++] = t;
170                                 if (nc>=MAXFIL)
171                                         {
172                                         error("Too many source files",0);
173                                         exit(1);
174                                         }
175                                 t = setsuf(t'o');
176                         }
177                         if (nodup(llistt)) {
178                                 llist[nl++] = t;
179                                 if (nl >= MAXLIB)
180                                         {
181                                         error("Too many object/library files",0);
182                                         exit(1);
183                                         }
184                                 if (getsuf(t)=='o')
185                                         nxo++;
ragge
1.1
186                         }
187                 }
188         }
ragge
1.4
189         if (gflagOflag = 0;
ragge
1.3
190         if (noflflag)
191                 pref = proflag ? "/lib/fmcrt0.o" : "/lib/fcrt0.o";
192         else if (proflag)
193                 pref = "/lib/mcrt0.o";
194         if(nc==0)
195                 goto nocom;
196         if (pflag==0) {
197                 tmp0 = copy("/tmp/ctm0a");
ragge
1.4
198                 while((f=fopen(tmp0"r")) != NULL) {
199                         fclose(f);
ragge
1.3
200                         tmp0[9]++;
ragge
1.1
201                 }
ragge
1.3
202                 while((creat(tmp00400))<0)
203                         tmp0[9]++;
ragge
1.1
204         }
ragge
1.3
205         if (signal(SIGINTSIG_IGN) != SIG_IGN/* interrupt */
ragge
1.1
206                 signal(SIGINTidexit);
ragge
1.3
207         if (signal(SIGTERMSIG_IGN) != SIG_IGN)        /* terminate */
ragge
1.1
208                 signal(SIGTERMidexit);
ragge
1.3
209         (tmp1 = copy(tmp0))[8] = '1';
210         (tmp2 = copy(tmp0))[8] = '2';
211         (tmp3 = copy(tmp0))[8] = '3';
ragge
1.1
212         if (pflag==0)
ragge
1.3
213                 (tmp4 = copy(tmp0))[8] = '4';
214         pvt = pv;
ragge
1.1
215         for (i=0i<nci++) {
ragge
1.3
216                 if (nc>1)
ragge
1.1
217                         printf("%s:\n"clist[i]);
ragge
1.3
218                 if (getsuf(clist[i])=='s') {
ragge
1.1
219                         assource = clist[i];
220                         goto assemble;
221                 } else
222                         assource = tmp3;
223                 if (pflag)
224                         tmp4 = setsuf(clist[i], 'i');
ragge
1.3
225                 savetsp = tsp;
226                 av[0] = "cpp";
227                 av[1] = clist[i];
228                 av[2] = exflag ? "-" : tmp4;
229                 na = 3;
230                 for(pv=ptemppv <pvtpv++)
231                         av[na++] = *pv;
232                 av[na++]=0;
233                 if (callsys(passpav))
234                         {exfail++; eflag++;}
235                 av[1] =tmp4;
236                 tsp = savetsp;
237                 av[0]= "ccom";
238                 if (pflag || exfail)
239                         {
ragge
1.1
240                         cflag++;
241                         continue;
ragge
1.3
242                         }
243                 if(sflag)
244                         assource = tmp3 = setsuf(clist[i], 's');
245                 av[2] = tmp3;
246                 if (proflag) {
247                         av[3] = "-XP";
248                         av[4] = 0;
249                 } else
250                         av[3] = 0;
251                 if (gflag) {
252                         int i;
253                         i = av[3] ? 4 : 3;
254                         av[i++] = "-Xg";
255                         av[i] = 0;
ragge
1.1
256                 }
ragge
1.3
257                 if (callsys(pass0av)) {
ragge
1.1
258                         cflag++;
259                         eflag++;
260                         continue;
261                 }
262                 if (sflag)
263                         continue;
264         assemble:
ragge
1.3
265                 av[0] = "as";
266                 av[1] = "-o";
267                 av[2] = setsuf(clist[i], 'o');
268                 av[3] = assource;
269                 if (dflag) {
270                         av[4] = alist;
271                         av[5] = 0;
272                 } else
273                         av[4] = 0;
274                 cunlink(tmp1);
275                 cunlink(tmp2);
276                 cunlink(tmp4);
277                 if (callsys("/bin/as"av) > 1) {
ragge
1.1
278                         cflag++;
279                         eflag++;
280                         continue;
281                 }
282         }
283 nocom:
284         if (cflag==0 && nl!=0) {
285                 i = 0;
ragge
1.3
286                 av[0] = "ld";
287                 av[1] = "-X";
288                 av[2] = pref;
289                 j = 3;
ragge
1.1
290                 if (outfile) {
ragge
1.3
291                         av[j++] = "-o";
292                         av[j++] = outfile;
293                 }
294                 while(i<nl)
295                         av[j++] = llist[i++];
296                 if (gflag)
297                         av[j++] = "-lg";
298                 if(f20)
299                         av[j++] = "-l2";
300                 else {
301                         av[j++] = "/lib/libc.a";
302                         av[j++] = "-l";
ragge
1.1
303                 }
ragge
1.3
304                 av[j++] = 0;
305                 eflag |= callsys("/bin/ld"av);
ragge
1.1
306                 if (nc==1 && nxo==1 && eflag==0)
ragge
1.3
307                         cunlink(setsuf(clist[0], 'o'));
ragge
1.1
308         }
309         dexit();
ragge
1.4
310         return 0;
ragge
1.1
311 }
312
ragge
1.4
313 void
314 idexit(int arg)
ragge
1.1
315 {
316         eflag = 100;
317         dexit();
318 }
319
ragge
1.4
320 void
ragge
1.3
321 dexit()
ragge
1.1
322 {
323         if (!pflag) {
324                 cunlink(tmp1);
325                 cunlink(tmp2);
326                 if (sflag==0)
327                         cunlink(tmp3);
328                 cunlink(tmp4);
329                 cunlink(tmp5);
ragge
1.3
330                 cunlink(tmp0);
ragge
1.1
331         }
332         exit(eflag);
333 }
334
ragge
1.4
335 void
336 error(char *schar *x)
ragge
1.1
337 {
ragge
1.3
338         fprintf(exflag?stderr:stdout , sx);
339         putc('\n'exflagstderr : stdout);
ragge
1.1
340         exfail++;
341         cflag++;
342         eflag++;
343 }
344
ragge
1.3
345
346
347
ragge
1.4
348 int
ragge
1.3
349 getsuf(as)
350 char as[];
ragge
1.1
351 {
352         register char *s;
353
ragge
1.4
354         if ((s = strrchr(as'.')) && s[1] != '\0' && s[2] == '\0')
355                 return s[1];
ragge
1.3
356         return(0);
ragge
1.1
357 }
358
359 char *
ragge
1.3
360 setsuf(asch)
361 char as[];
ragge
1.1
362 {
363         register char *s, *s1;
364
ragge
1.3
365         s = s1 = copy(as);
366         while(*s)
ragge
1.1
367                 if (*s++ == '/')
368                         s1 = s;
369         s[-1] = ch;
ragge
1.3
370         return(s1);
ragge
1.1
371 }
372
ragge
1.4
373 int
ragge
1.3
374 callsys(fv)
375 char f[], *v[]; {
ragge
1.1
376         int tstatus;
ragge
1.4
377         char *s;
ragge
1.1
378
ragge
1.3
379         if ((t=fork())==0) {
ragge
1.1
380                 execv(fv);
ragge
1.4
381                 if ((s = strrchr(f'/')))
382                         execvp(s+1v);
ragge
1.1
383                 printf("Can't find %s\n"f);
ragge
1.3
384                 exit(100);
385         } else
386                 if (t == -1) {
387                         printf("Try again\n");
388                         return(100);
389                 }
390         while(t!=wait(&status));
ragge
1.1
391         if ((t=(status&0377)) != 0 && t!=14) {
ragge
1.3
392                 if (t!=2)               /* interrupt */
393                         {
ragge
1.1
394                         printf("Fatal error in %s\n"f);
395                         eflag = 8;
ragge
1.3
396                         }
ragge
1.1
397                 dexit();
398         }
ragge
1.3
399         return((status>>8) & 0377);
ragge
1.1
400 }
401
ragge
1.3
402 char *
403 copy(as)
404 char as[];
405 {
406         register char *otsp, *s;
407
408         otsp = tsp;
409         s = as;
ragge
1.4
410         while((*tsp++ = *s++));
ragge
1.3
411         if (tsp >tsa+CHSPACE)
412                 {
ragge
1.4
413                 tsp = tsa = calloc(CHSPACE+50,1);
414                 if (tsa== 0){
415                         error("no space for file names"0);
416                         eflag = 8;
417                         dexit();
ragge
1.3
418                         }
419                 }
420         return(otsp);
421 }
422
ragge
1.4
423 int
ragge
1.3
424 nodup(los)
425 char **l, *os;
ragge
1.1
426 {
427         register char *t, *s;
428         register int c;
429
430         s = os;
431         if (getsuf(s) != 'o')
ragge
1.3
432                 return(1);
ragge
1.4
433         while((t = *l++)) {
434                 while((c = *s++))
ragge
1.1
435                         if (c != *t++)
436                                 break;
ragge
1.3
437                 if (*t=='\0' && c=='\0')
438                         return(0);
ragge
1.1
439                 s = os;
440         }
ragge
1.3
441         return(1);
ragge
1.1
442 }
443
ragge
1.4
444 int
ragge
1.3
445 cunlink(f)
446 char *f;
ragge
1.1
447 {
ragge
1.3
448         if (f==0)
449                 return(0);
450         return(unlink(f));
ragge
1.1
451 }
FishEye: Open Source License registered to PCC.
Your maintenance has expired. You can renew your license at http://www.atlassian.com/fisheye/renew
Atlassian FishEye, CVS analysis. (Version:1.6.3 Build:build-336 2008-11-04) - Administration - Page generated 2014-08-21 02:23 +0200