Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20030807115449

Diff

Diff from 1.3 to:

Annotations

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

Annotated File View

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