Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20030809155123

Diff

Diff from 1.8 to:

Annotations

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

Annotated File View

ragge
1.8
1 /*      $Id: cc.c,v 1.8 2003/08/09 15:51:23 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.5
50 #ifdef FOR_X86
51 char *cppadd[] = {
52         "-D__NetBSD__""-D__PCC__=1""-D__PCC_MINOR__=0",
53         "-D__ELF__""-Asystem(unix)""-Asystem(NetBSD)""-Acpu(i386)",
54         "-Amachine(i386)""-D__i386__""-D__OPTIMIZE__""-Di386",
ragge
1.7
55         "-nostdinc"NULL,
ragge
1.5
56 };
57 #endif
58
ragge
1.3
59 #define SBSIZE 10000
60 #define MAXINC 10
61 #define MAXFIL 100
62 #define MAXLIB 100
63 #define MAXOPT 100
64 char    *tmp0;
65 char    *tmp1;
66 char    *tmp2;
67 char    *tmp3;
68 char    *tmp4;
69 char    *tmp5;
ragge
1.1
70 char    *outfile;
ragge
1.4
71 char *copy(char []),*setsuf(char [], int);
72 int getsuf(char []);
73 int main(intchar *[]);
74 void error(char *, char *);
75 int nodup(char **, char *);
76 int callsys(char [], char *[]);
77 int cunlink(char *);
78 void dexit(void);
79 void idexit(int);
ragge
1.3
80 # define CHSPACE 1000
81 char    ts[CHSPACE+50];
82 char    *tsa = ts;
83 char    *tsp = ts;
84 char    *av[50];
85 char    *clist[MAXFIL];
86 char    *llist[MAXLIB];
ragge
1.4
87 char    alist[20];
ragge
1.3
88 int dflag;
ragge
1.7
89 int     xflag;
ragge
1.3
90 int     pflag;
91 int     sflag;
92 int     cflag;
93 int     eflag;
94 int     gflag;
ragge
1.5
95 int     vflag;
ragge
1.7
96 int     tflag;
ragge
1.8
97 int     Eflag;
ragge
1.4
98 int     Oflag;
ragge
1.3
99 int     proflag;
100 int     noflflag;
ragge
1.1
101 int     exfail;
ragge
1.4
102 char    *pass0 = "/lib/ccom";
ragge
1.5
103 char    *passp = "/usr/libexec/cpp0";
ragge
1.4
104 char    *pref = "/usr/lib/crt0.o";
ragge
1.1
105
ragge
1.4
106 int
ragge
1.3
107 main(argcargv)
108 char *argv[]; {
ragge
1.1
109         char *t;
ragge
1.3
110         char *savetsp;
ragge
1.1
111         char *assource;
ragge
1.3
112         char **pv, *ptemp[MAXOPT], **pvt;
ragge
1.4
113         int ncnlijcf20nxonatt;
114         FILE *f;
ragge
1.3
115
116         i = nc = nl = f20 = nxo = 0;
117         pv = ptemp;
118         while(++i < argc) {
119                 if(*argv[i] == '-'switch (argv[i][1]) {
120                 default:
121                         goto passa;
ragge
1.6
122                 case 'W'/* Ignore W-flags */
123                 case 'f'/* Ignore -ffreestanding */
124                 case 'n'/* Ignore -nostdinc */
125                         break;
ragge
1.7
126                 case 'x':
127                         xflag++;
128                         i++; /* skip args */
129                         break;
130                 case 't':
131                         tflag++;
132                         break;
ragge
1.1
133                 case 'S':
134                         sflag++;
135                         cflag++;
ragge
1.3
136                         break;
ragge
1.1
137                 case 'o':
138                         if (++i < argc) {
139                                 outfile = argv[i];
ragge
1.4
140                                 if ((tt=getsuf(outfile))=='c'||tt=='o') {
ragge
1.3
141                                         error("Would overwrite %s"outfile);
ragge
1.1
142                                         exit(8);
143                                 }
144                         }
ragge
1.3
145                         break;
ragge
1.1
146                 case 'O':
ragge
1.4
147                         Oflag++;
ragge
1.3
148                         break;
ragge
1.1
149                 case 'p':
150                         proflag++;
ragge
1.3
151                         break;
ragge
1.1
152                 case 'g':
ragge
1.3
153                         gflag++;
154                         break;
ragge
1.1
155                 case 'E':
ragge
1.8
156                         Eflag++;
157                         break;
ragge
1.1
158                 case 'P':
159                         pflag++;
ragge
1.3
160                         *pv++ = argv[i];
ragge
1.1
161                 case 'c':
162                         cflag++;
ragge
1.3
163                         break;
164
165                 case '2':
166                         if(argv[i][2] == '\0')
167                                 pref = "/lib/crt2.o";
168                         else {
169                                 pref = "/lib/crt20.o";
170                                 f20 = 1;
171                         }
172                         break;
ragge
1.1
173                 case 'D':
174                 case 'I':
175                 case 'U':
176                 case 'C':
ragge
1.3
177                         *pv++ = argv[i];
178                         if (pv >= ptemp+MAXOPT)
179                                 {
180                                 error("Too many DIUC options"0);
181                                 --pv;
182                                 }
183                         break;
184
ragge
1.1
185                 case 'd':
ragge
1.3
186                         dflag++;
ragge
1.4
187                         strncpy(alistargv[i], 19);
ragge
1.3
188                         break;
ragge
1.5
189                 case 'v':
190                         vflag++;
191                         break;
ragge
1.3
192                 } else {
193                 passa:
194                         t = argv[i];
ragge
1.8
195                         if((c=getsuf(t))=='c' || c=='s'|| Eflag) {
ragge
1.3
196                                 clist[nc++] = t;
197                                 if (nc>=MAXFIL)
198                                         {
199                                         error("Too many source files",0);
200                                         exit(1);
201                                         }
202                                 t = setsuf(t'o');
203                         }
204                         if (nodup(llistt)) {
205                                 llist[nl++] = t;
206                                 if (nl >= MAXLIB)
207                                         {
208                                         error("Too many object/library files",0);
209                                         exit(1);
210                                         }
211                                 if (getsuf(t)=='o')
212                                         nxo++;
ragge
1.1
213                         }
214                 }
215         }
ragge
1.4
216         if (gflagOflag = 0;
ragge
1.3
217         if (noflflag)
218                 pref = proflag ? "/lib/fmcrt0.o" : "/lib/fcrt0.o";
219         else if (proflag)
220                 pref = "/lib/mcrt0.o";
221         if(nc==0)
222                 goto nocom;
223         if (pflag==0) {
224                 tmp0 = copy("/tmp/ctm0a");
ragge
1.4
225                 while((f=fopen(tmp0"r")) != NULL) {
226                         fclose(f);
ragge
1.3
227                         tmp0[9]++;
ragge
1.1
228                 }
ragge
1.3
229                 while((creat(tmp00400))<0)
230                         tmp0[9]++;
ragge
1.1
231         }
ragge
1.3
232         if (signal(SIGINTSIG_IGN) != SIG_IGN/* interrupt */
ragge
1.1
233                 signal(SIGINTidexit);
ragge
1.3
234         if (signal(SIGTERMSIG_IGN) != SIG_IGN)        /* terminate */
ragge
1.1
235                 signal(SIGTERMidexit);
ragge
1.3
236         (tmp1 = copy(tmp0))[8] = '1';
237         (tmp2 = copy(tmp0))[8] = '2';
238         (tmp3 = copy(tmp0))[8] = '3';
ragge
1.1
239         if (pflag==0)
ragge
1.3
240                 (tmp4 = copy(tmp0))[8] = '4';
241         pvt = pv;
ragge
1.1
242         for (i=0i<nci++) {
ragge
1.3
243                 if (nc>1)
ragge
1.1
244                         printf("%s:\n"clist[i]);
ragge
1.3
245                 if (getsuf(clist[i])=='s') {
ragge
1.1
246                         assource = clist[i];
ragge
1.7
247                         if (!xflag)
248                                 goto assemble;
ragge
1.1
249                 } else
250                         assource = tmp3;
251                 if (pflag)
252                         tmp4 = setsuf(clist[i], 'i');
ragge
1.3
253                 savetsp = tsp;
ragge
1.5
254                 na = 0;
255                 av[na++] = "cpp";
ragge
1.7
256                 av[na++] = xflag ? "-lang-asm" : "-lang-c";
257                 av[na++] = "-$";
ragge
1.5
258                 for (j = 0cppadd[j]; j++)
259                         av[na++] = cppadd[j];
ragge
1.7
260                 if (tflag)
261                         av[na++] = "-traditional";
262                 for(pv=ptemppv <pvtpv++)
263                         av[na++] = *pv;
ragge
1.5
264                 av[na++] = clist[i];
ragge
1.8
265                 av[na++] = Eflag ? "-" : tmp4;
ragge
1.3
266                 av[na++]=0;
267                 if (callsys(passpav))
268                         {exfail++; eflag++;}
ragge
1.7
269                 if (xflag)
270                         goto assemble;
ragge
1.5
271                 av[0]= "ccom";
ragge
1.3
272                 av[1] =tmp4;
273                 tsp = savetsp;
274                 if (pflag || exfail)
275                         {
ragge
1.1
276                         cflag++;
277                         continue;
ragge
1.3
278                         }
279                 if(sflag)
280                         assource = tmp3 = setsuf(clist[i], 's');
281                 av[2] = tmp3;
282                 if (proflag) {
283                         av[3] = "-XP";
284                         av[4] = 0;
285                 } else
286                         av[3] = 0;
287                 if (gflag) {
288                         int i;
289                         i = av[3] ? 4 : 3;
290                         av[i++] = "-Xg";
291                         av[i] = 0;
ragge
1.1
292                 }
ragge
1.3
293                 if (callsys(pass0av)) {
ragge
1.1
294                         cflag++;
295                         eflag++;
296                         continue;
297                 }
298                 if (sflag)
299                         continue;
300         assemble:
ragge
1.3
301                 av[0] = "as";
302                 av[1] = "-o";
303                 av[2] = setsuf(clist[i], 'o');
ragge
1.7
304                 av[3] = xflag ? tmp4 : assource;
ragge
1.3
305                 if (dflag) {
306                         av[4] = alist;
307                         av[5] = 0;
308                 } else
309                         av[4] = 0;
310                 cunlink(tmp1);
311                 cunlink(tmp2);
312                 if (callsys("/bin/as"av) > 1) {
ragge
1.1
313                         cflag++;
314                         eflag++;
ragge
1.7
315                         cunlink(tmp4);
ragge
1.1
316                         continue;
317                 }
ragge
1.7
318                 cunlink(tmp4);
ragge
1.1
319         }
320 nocom:
321         if (cflag==0 && nl!=0) {
322                 i = 0;
ragge
1.6
323                 j = 0;
324                 av[j++] = "ld";
325                 av[j++] = "-X";
326                 av[j++] = "-d";
327                 av[j++] = "-e";
328                 av[j++] = "__start";
329                 av[j++] = "-static";
ragge
1.1
330                 if (outfile) {
ragge
1.3
331                         av[j++] = "-o";
332                         av[j++] = outfile;
333                 }
ragge
1.6
334                 av[j++] = pref;
335                 av[j++] = "/usr/lib/crti.o";
336                 av[j++] = "/usr/lib/crtbegin.o";
ragge
1.3
337                 while(i<nl)
338                         av[j++] = llist[i++];
339                 if (gflag)
340                         av[j++] = "-lg";
ragge
1.6
341                 av[j++] = "-lc";
342                 av[j++] = "/usr/lib/crtend.o";
343                 av[j++] = "/usr/lib/crtn.o";
ragge
1.3
344                 if(f20)
345                         av[j++] = "-l2";
346                 av[j++] = 0;
347                 eflag |= callsys("/bin/ld"av);
ragge
1.1
348                 if (nc==1 && nxo==1 && eflag==0)
ragge
1.3
349                         cunlink(setsuf(clist[0], 'o'));
ragge
1.1
350         }
351         dexit();
ragge
1.4
352         return 0;
ragge
1.1
353 }
354
ragge
1.4
355 void
356 idexit(int arg)
ragge
1.1
357 {
358         eflag = 100;
359         dexit();
360 }
361
ragge
1.4
362 void
ragge
1.3
363 dexit()
ragge
1.1
364 {
365         if (!pflag) {
366                 cunlink(tmp1);
367                 cunlink(tmp2);
368                 if (sflag==0)
369                         cunlink(tmp3);
370                 cunlink(tmp4);
371                 cunlink(tmp5);
ragge
1.3
372                 cunlink(tmp0);
ragge
1.1
373         }
374         exit(eflag);
375 }
376
ragge
1.4
377 void
378 error(char *schar *x)
ragge
1.1
379 {
ragge
1.8
380         fprintf(Eflag?stderr:stdout , sx);
381         putc('\n'Eflagstderr : stdout);
ragge
1.1
382         exfail++;
383         cflag++;
384         eflag++;
385 }
386
ragge
1.3
387
388
389
ragge
1.4
390 int
ragge
1.3
391 getsuf(as)
392 char as[];
ragge
1.1
393 {
394         register char *s;
395
ragge
1.4
396         if ((s = strrchr(as'.')) && s[1] != '\0' && s[2] == '\0')
397                 return s[1];
ragge
1.3
398         return(0);
ragge
1.1
399 }
400
401 char *
ragge
1.3
402 setsuf(asch)
403 char as[];
ragge
1.1
404 {
405         register char *s, *s1;
406
ragge
1.3
407         s = s1 = copy(as);
408         while(*s)
ragge
1.1
409                 if (*s++ == '/')
410                         s1 = s;
411         s[-1] = ch;
ragge
1.3
412         return(s1);
ragge
1.1
413 }
414
ragge
1.4
415 int
ragge
1.3
416 callsys(fv)
417 char f[], *v[]; {
ragge
1.1
418         int tstatus;
ragge
1.4
419         char *s;
ragge
1.5
420
421         if (vflag) {
422                 for (t = 0v[t]; t++)
ragge
1.6
423                         fprintf(stderr"%s "v[t]);
424                 fprintf(stderr"\n");
ragge
1.5
425         }
ragge
1.1
426
ragge
1.3
427         if ((t=fork())==0) {
ragge
1.1
428                 execv(fv);
ragge
1.4
429                 if ((s = strrchr(f'/')))
430                         execvp(s+1v);
ragge
1.1
431                 printf("Can't find %s\n"f);
ragge
1.3
432                 exit(100);
433         } else
434                 if (t == -1) {
435                         printf("Try again\n");
436                         return(100);
437                 }
438         while(t!=wait(&status));
ragge
1.1
439         if ((t=(status&0377)) != 0 && t!=14) {
ragge
1.3
440                 if (t!=2)               /* interrupt */
441                         {
ragge
1.1
442                         printf("Fatal error in %s\n"f);
443                         eflag = 8;
ragge
1.3
444                         }
ragge
1.1
445                 dexit();
446         }
ragge
1.3
447         return((status>>8) & 0377);
ragge
1.1
448 }
449
ragge
1.3
450 char *
451 copy(as)
452 char as[];
453 {
454         register char *otsp, *s;
455
456         otsp = tsp;
457         s = as;
ragge
1.4
458         while((*tsp++ = *s++));
ragge
1.3
459         if (tsp >tsa+CHSPACE)
460                 {
ragge
1.4
461                 tsp = tsa = calloc(CHSPACE+50,1);
462                 if (tsa== 0){
463                         error("no space for file names"0);
464                         eflag = 8;
465                         dexit();
ragge
1.3
466                         }
467                 }
468         return(otsp);
469 }
470
ragge
1.4
471 int
ragge
1.3
472 nodup(los)
473 char **l, *os;
ragge
1.1
474 {
475         register char *t, *s;
476         register int c;
477
478         s = os;
479         if (getsuf(s) != 'o')
ragge
1.3
480                 return(1);
ragge
1.4
481         while((t = *l++)) {
482                 while((c = *s++))
ragge
1.1
483                         if (c != *t++)
484                                 break;
ragge
1.3
485                 if (*t=='\0' && c=='\0')
486                         return(0);
ragge
1.1
487                 s = os;
488         }
ragge
1.3
489         return(1);
ragge
1.1
490 }
491
ragge
1.4
492 int
ragge
1.3
493 cunlink(f)
494 char *f;
ragge
1.1
495 {
ragge
1.3
496         if (f==0)
497                 return(0);
498         return(unlink(f));
ragge
1.1
499 }
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-09-16 13:26 +0200