Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20030807205029

Diff

Diff from 1.6 to:

Annotations

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

Annotated File View

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