Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20030807154837

Diff

Diff from 1.5 to:

Annotations

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

Annotated File View

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