Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:gmcgarry:20080220010808

Diff

Diff from 1.81 to:

Annotations

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

Annotated File View

gmcgarry
1.81
1 /*      $Id: cc.c,v 1.81 2008/02/20 01:08:08 gmcgarry 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.18
38  *
39  * Brief description of its syntax:
40  * - Files that end with .c are passed via cpp->ccom->as->ld
ragge
1.59
41  * - Files that end with .i are passed via ccom->as->ld
ragge
1.18
42  * - Files that end with .s are passed as->ld
43  * - Files that end with .o are passed directly to ld
44  * - Multiple files may be given on the command line.
45  * - Unrecognized options are all sent directly to ld.
46  * -c or -S cannot be combined with -o if multiple files are given.
47  *
48  * This file should be rewritten readable.
ragge
1.1
49  */
ragge
1.80
50 #include "config.h"
51
ragge
1.9
52 #include <sys/types.h>
ragge
1.36
53 #include <sys/wait.h>
ragge
1.2
54
ragge
1.1
55 #include <ctype.h>
stefan
1.72
56 #include <errno.h>
57 #include <fcntl.h>
58 #include <libgen.h>
ragge
1.1
59 #include <signal.h>
stefan
1.72
60 #include <stdarg.h>
61 #include <stdio.h>
62 #include <stdlib.h>
ragge
1.4
63 #include <string.h>
64 #include <unistd.h>
ragge
1.24
65
66 #include "ccconfig.h"
ragge
1.3
67 /* C command */
ragge
1.1
68
ragge
1.20
69 #define MKS(x) _MKS(x)
70 #define _MKS(x) #x
71
72 /*
73  * Many specific definitions, should be declared elsewhere.
74  */
gmcgarry
1.79
75
76 #ifndef STDINC
77 #define STDINC          "/usr/include/"
78 #endif
79
80 #ifndef PREPROCESSOR
81 #define PREPROCESSOR    "cpp"
82 #endif
83
84 #ifndef COMPILER
85 #define COMPILER        "ccom";
86 #endif
87
88 #ifndef ASSEMBLER
89 #define ASSEMBLER       "as"
90 #endif
91
92 #ifndef LINKER
93 #define LINKER          "ld"
94 #endif
ragge
1.20
95
ragge
1.62
96 #define MAXFIL 10000
ragge
1.12
97 #define MAXLIB 10000
ragge
1.14
98 #define MAXAV  10000
ragge
1.3
99 #define MAXOPT 100
100 char    *tmp3;
101 char    *tmp4;
ragge
1.1
102 char    *outfile;
stefan
1.72
103 char *copy(char *),*setsuf(char *, char);
104 int getsuf(char *);
ragge
1.4
105 int main(intchar *[]);
ragge
1.36
106 void error(char *, ...);
stefan
1.72
107 void errorx(intchar *, ...);
ragge
1.4
108 int callsys(char [], char *[]);
109 int cunlink(char *);
stefan
1.72
110 void dexit(int);
ragge
1.4
111 void idexit(int);
pj
1.30
112 char *gettmp();
ragge
1.14
113 char    *av[MAXAV];
ragge
1.3
114 char    *clist[MAXFIL];
115 char    *llist[MAXLIB];
ragge
1.4
116 char    alist[20];
ragge
1.43
117 char    *xlist[100];
118 int     xnum;
gmcgarry
1.78
119 char    *mlist[100];
120 int     nm;
ragge
1.63
121 int     Cflag;
ragge
1.43
122 int     dflag;
ragge
1.3
123 int     pflag;
124 int     sflag;
125 int     cflag;
126 int     eflag;
127 int     gflag;
ragge
1.5
128 int     vflag;
ragge
1.7
129 int     tflag;
ragge
1.8
130 int     Eflag;
ragge
1.4
131 int     Oflag;
ragge
1.58
132 int     kflag;  /* generate PIC/pic code */
133 #define F_PIC   1
134 #define F_pic   2
ragge
1.51
135 int     Mflag;  /* dependencies only */
ragge
1.52
136 int     pgflag;
ragge
1.1
137 int     exfail;
ragge
1.10
138 int     Xflag;
ragge
1.14
139 int     nostartfilesBstatic;
ragge
1.52
140 int     nostdincnostdlib;
ragge
1.43
141 int     onlyas;
ragge
1.52
142 int     pthreads;
ragge
1.14
143
gmcgarry
1.79
144 char    *passp = LIBEXECDIR "/" PREPROCESSOR;
145 char    *pass0 = LIBEXECDIR "/" COMPILER;
146 char    *as = ASSEMBLER;
147 char    *ld = LINKER;
ragge
1.47
148 char    *Bflag;
ragge
1.25
149 char *cppadd[] = CPPADD;
150 char *dynlinker[] = DYNLINKER;
151 char *crt0file = CRT0FILE;
gmcgarry
1.81
152 char *crt0file_profile = CRT0FILE_PROFILE;
ragge
1.25
153 char *startfiles[] = STARTFILES;
154 char *endfiles[] = ENDFILES;
155 char *cppmdadd[] = CPPMDADD;
ragge
1.50
156 #ifdef LIBCLIBS
157 char *libclibs[] = LIBCLIBS;
158 #else
159 char *libclibs[] = { "-lc"NULL };
160 #endif
gmcgarry
1.81
161 #ifdef LIBCLIBS_PROFILE
162 char *libclibs_profile[] = LIBCLIBS_PROFILE;
163 #else
164 char *libclibs_profile[] = { "-lc_p"NULL };
165 #endif
ragge
1.48
166 #ifndef STARTLABEL
167 #define STARTLABEL "__start"
168 #endif
ragge
1.1
169
ragge
1.4
170 int
pj
1.26
171 main(int argcchar *argv[])
172 {
ragge
1.15
173         char *t, *u;
ragge
1.1
174         char *assource;
ragge
1.3
175         char **pv, *ptemp[MAXOPT], **pvt;
ragge
1.36
176         int ncnlijcnxona;
ragge
1.3
177
ragge
1.36
178         i = nc = nl = nxo = 0;
ragge
1.3
179         pv = ptemp;
180         while(++i < argc) {
ragge
1.66
181                 if (argv[i][0] == '-') {
182                         switch (argv[i][1]) {
183                         default:
184                                 goto passa;
185 #ifdef notyet
186         /* must add library options first (-L/-l/...) */
187                                 error("unrecognized option `-%c'"argv[i][1]);
188                                 break;
189 #endif
ragge
1.22
190
ragge
1.66
191                         case 'B'/* other search paths for binaries */
192                                 Bflag = &argv[i][2];
193                                 break;
ragge
1.22
194
ragge
1.66
195                         case 'X':
196                                 Xflag++;
197                                 break;
198                         case 'W'/* Ignore (most of) W-flags */
199                                 if (strncmp(argv[i], "-Wl,"4) == 0) {
200                                         /* options to the linker */
201                                         t = &argv[i][4];
202                                         while ((u = strchr(t','))) {
203                                                 *u++ = 0;
204                                                 llist[nl++] = t;
205                                                 t = u;
206                                         }
ragge
1.15
207                                         llist[nl++] = t;
208                                 }
ragge
1.66
209                                 break;
ragge
1.15
210
ragge
1.66
211                         case 'f'/* GCC compatibility flags */
212                                 if (strcmp(argv[i], "-fPIC") == 0)
213                                         kflag = F_PIC;
214                                 if (strcmp(argv[i], "-fpic") == 0)
215                                         kflag = F_pic;
216                                 /* silently ignore the rest */
217                                 break;
ragge
1.14
218
ragge
1.66
219                         case 'g'/* create debug output */
220                                 gflag++;
221                                 break;
ragge
1.25
222
ragge
1.66
223                         case 'i':
224                                 if (strcmp(argv[i], "-isystem") == 0) {
225                                         *pv++ = "-S";
226                                         *pv++ = argv[++i];
227                                 } else if (strcmp(argv[i], "-include") == 0) {
228                                         *pv++ = "-i";
229                                         *pv++ = argv[++i];
230                                 } else
231                                         goto passa;
232                                 break;
ragge
1.20
233
ragge
1.66
234                         case 'k'/* generate PIC code */
235                                 kflag = F_pic;
236                                 break;
ragge
1.49
237
gmcgarry
1.78
238                         case 'm'/* target-dependent options */
239                                 mlist[nm++] = argv[i];
240                                 break;
241
ragge
1.66
242                         case 'n'/* handle -n flags */
243                                 if (strcmp(argv[i], "-nostdinc") == 0)
244                                         nostdinc++;
245                                 else if (strcmp(argv[i], "-nostdlib") == 0) {
246                                         nostdlib++;
247                                         nostartfiles++;
248                                 } else if (strcmp(argv[i], "-nostartfiles") == 0)
249                                         nostartfiles = 1;
250                                 else
251                                         goto passa;
252                                 break;
ragge
1.14
253
ragge
1.66
254                         case 'p':
255                                 if (strcmp(argv[i], "-pg") == 0)
256                                         pgflag++;
257                                 else if (strcmp(argv[i], "-pthread") == 0)
258                                         pthreads++;
gmcgarry
1.81
259                                 else if (strcmp(argv[i], "-pipe") == 0) {
260                                 } else
ragge
1.66
261                                         errorx(1"unknown option %s"argv[i]);
262                                 break;
ragge
1.52
263
ragge
1.66
264                         case 'x':
265                                 xlist[xnum++] = argv[i];
266                                 break;
267                         case 't':
268                                 tflag++;
269                                 break;
270                         case 'S':
271                                 sflag++;
272                                 cflag++;
273                                 break;
274                         case 'o':
275                                 if (outfile)
276                                         errorx(8"too many -o");
277                                 outfile = argv[++i];
278                                 break;
279                         case 'O':
280                                 Oflag++;
281                                 break;
282                         case 'E':
283                                 Eflag++;
284                                 break;
285                         case 'P':
286                                 pflag++;
287                                 *pv++ = argv[i];
288                         case 'c':
289                                 cflag++;
290                                 break;
ragge
1.3
291
ragge
1.24
292 #if 0
ragge
1.66
293                         case '2':
294                                 if(argv[i][2] == '\0')
295                                         pref = "/lib/crt2.o";
296                                 else {
297                                         pref = "/lib/crt20.o";
298                                 }
299                                 break;
ragge
1.24
300 #endif
ragge
1.66
301                         case 'C':
302                                 Cflag = 1;
303                                 break;
304                         case 'D':
305                         case 'I':
306                         case 'U':
307                                 *pv++ = argv[i];
308                                 if (argv[i][2] == 0)
309                                         *pv++ = argv[++i];
310                                 if (pv >= ptemp+MAXOPT) {
311                                         error("Too many DIU options");
312                                         --pv;
ragge
1.3
313                                 }
ragge
1.66
314                                 break;
ragge
1.3
315
ragge
1.66
316                         case 'M':
317                                 Mflag++;
318                                 break;
ragge
1.51
319
ragge
1.66
320                         case 'd':
321                                 dflag++;
ragge
1.67
322                                 strlcpy(alistargv[i], sizeof (alist));
ragge
1.66
323                                 break;
324                         case 'v':
325                                 printf("%s\n"VERSSTR);
326                                 vflag++;
327                                 break;
ragge
1.14
328
ragge
1.66
329                         case 's':
330                                 if (strcmp(argv[i], "-static") == 0)
331                                         Bstatic = 1;
332                                 else
333                                         goto passa;
334                                 break;
335                         }
ragge
1.3
336                 } else {
337                 passa:
338                         t = argv[i];
ragge
1.11
339                         if (*argv[i] == '-' && argv[i][1] == 'L')
340                                 ;
ragge
1.59
341                         else if((c=getsuf(t))=='c' || c=='S' || c=='i' ||
ragge
1.51
342                             c=='s'|| Eflag) {
ragge
1.3
343                                 clist[nc++] = t;
ragge
1.66
344                                 if (nc>=MAXFIL) {
ragge
1.36
345                                         error("Too many source files");
ragge
1.3
346                                         exit(1);
ragge
1.66
347                                 }
ragge
1.3
348                                 t = setsuf(t'o');
349                         }
stefan
1.76
350
351                         /* Check for duplicate .o files. */
352                         for (j = getsuf(t) == 'o' ? 0 : nlj < nlj++) {
353                                 if (strcmp(llist[j], t) == 0)
354                                         break;
355                         }
356                         if (j == nl) {
ragge
1.3
357                                 llist[nl++] = t;
ragge
1.66
358                                 if (nl >= MAXLIB) {
ragge
1.36
359                                         error("Too many object/library files");
ragge
1.3
360                                         exit(1);
ragge
1.66
361                                 }
ragge
1.3
362                                 if (getsuf(t)=='o')
363                                         nxo++;
ragge
1.1
364                         }
365                 }
366         }
ragge
1.18
367         /* Sanity checking */
368         if (nc == 0 && nl == 0)
ragge
1.36
369                 errorx(8"no input files");
ragge
1.61
370         if (outfile && (cflag || sflag || Eflag) && nc > 1)
371                 errorx(8"-o given with -c || -E || -S and more than one file");
ragge
1.19
372         if (outfile && clist[0] && strcmp(outfileclist[0]) == 0)
ragge
1.36
373                 errorx(8"output file will be clobbered");
ragge
1.4
374         if (gflagOflag = 0;
ragge
1.24
375 #if 0
376         if (proflag)
ragge
1.3
377                 pref = "/lib/mcrt0.o";
ragge
1.24
378 #endif
ragge
1.3
379         if(nc==0)
380                 goto nocom;
381         if (pflag==0) {
stefan
1.74
382                 if (!sflag)
383                         tmp3 = gettmp();
pj
1.30
384                 tmp4 = gettmp();
ragge
1.1
385         }
ragge
1.3
386         if (signal(SIGINTSIG_IGN) != SIG_IGN/* interrupt */
ragge
1.1
387                 signal(SIGINTidexit);
ragge
1.3
388         if (signal(SIGTERMSIG_IGN) != SIG_IGN)        /* terminate */
ragge
1.1
389                 signal(SIGTERMidexit);
ragge
1.3
390         pvt = pv;
ragge
1.1
391         for (i=0i<nci++) {
ragge
1.18
392                 /*
393                  * C preprocessor
394                  */
ragge
1.37
395                 if (nc>1 && !Eflag)
ragge
1.1
396                         printf("%s:\n"clist[i]);
ragge
1.43
397                 onlyas = 0;
pj
1.32
398                 assource = tmp3;
ragge
1.59
399                 if (getsuf(clist[i])=='i') {
400                         if(Eflag)
401                                 continue;
402                         goto com;
403                 } else if (getsuf(clist[i])=='s') {
ragge
1.1
404                         assource = clist[i];
ragge
1.43
405                         goto assemble;
stefan
1.73
406                 } else if (getsuf(clist[i])=='S')
ragge
1.43
407                         onlyas = 1;
ragge
1.1
408                 if (pflag)
409                         tmp4 = setsuf(clist[i], 'i');
ragge
1.5
410                 na = 0;
411                 av[na++] = "cpp";
ragge
1.60
412                 if (vflag)
413                         av[na++] = "-v";
ragge
1.20
414                 av[na++] = "-D__PCC__=" MKS(PCC_MAJOR);
ragge
1.40
415                 av[na++] = "-D__PCC_MINOR__=" MKS(PCC_MINOR);
416                 av[na++] = "-D__PCC_MINORMINOR__=" MKS(PCC_MINORMINOR);
ragge
1.52
417                 if (getsuf(clist[i])=='S')
418                         av[na++] = "-D__ASSEMBLER__";
419                 if (pthreads)
420                         av[na++] = "-D_PTHREADS";
ragge
1.63
421                 if (Cflag)
422                         av[na++] = "-C";
ragge
1.51
423                 if (Mflag)
424                         av[na++] = "-M";
ragge
1.57
425                 if (dflag)
426                         av[na++] = alist;
ragge
1.5
427                 for (j = 0cppadd[j]; j++)
428                         av[na++] = cppadd[j];
ragge
1.24
429                 for (j = 0cppmdadd[j]; j++)
430                         av[na++] = cppmdadd[j];
ragge
1.7
431                 if (tflag)
ragge
1.20
432                         av[na++] = "-t";
ragge
1.7
433                 for(pv=ptemppv <pvtpv++)
434                         av[na++] = *pv;
ragge
1.52
435                 if (!nostdinc)
436                         av[na++] = "-S"av[na++] = STDINC;
ragge
1.5
437                 av[na++] = clist[i];
ragge
1.51
438                 if (!Eflag && !Mflag)
ragge
1.20
439                         av[na++] = tmp4;
ragge
1.61
440                 if (Eflag && outfile)
441                          av[na++] = outfile;
ragge
1.3
442                 av[na++]=0;
443                 if (callsys(passpav))
444                         {exfail++; eflag++;}
ragge
1.51
445                 if (Eflag || Mflag)
ragge
1.37
446                         continue;
stefan
1.73
447                 if (onlyas) {
448                         assource = tmp4;
ragge
1.7
449                         goto assemble;
stefan
1.73
450                 }
ragge
1.18
451
452                 /*
453                  * C compiler
454                  */
ragge
1.59
455         com:
ragge
1.25
456                 na = 0;
457                 av[na++]= "ccom";
ragge
1.60
458                 if (vflag)
459                         av[na++] = "-v";
gmcgarry
1.81
460                 if (pgflag)
461                         av[na++] = "-p";
ragge
1.25
462                 if (gflag)
463                         av[na++] = "-g";
ragge
1.49
464                 if (kflag)
465                         av[na++] = "-k";
ragge
1.44
466                 if (Oflag) {
467                         av[na++] = "-xtemps";
ragge
1.64
468                         av[na++] = "-xdeljumps";
ragge
1.44
469                 }
ragge
1.45
470                 for (j = 0j < xnumj++)
471                         av[na++] = xlist[j];
gmcgarry
1.78
472                 for (j = 0j < nmj++)
473                         av[na++] = mlist[j];
ragge
1.68
474                 if (getsuf(clist[i])=='i')
475                         av[na++] = clist[i];
476                 else
477                         av[na++] = tmp4/* created by cpp */
ragge
1.3
478                 if (pflag || exfail)
479                         {
ragge
1.1
480                         cflag++;
481                         continue;
ragge
1.3
482                         }
ragge
1.16
483                 if(sflag) {
484                         if (outfile)
stefan
1.77
485                                 tmp3 = outfile;
ragge
1.16
486                         else
stefan
1.77
487                                 tmp3 = setsuf(clist[i], 's');
ragge
1.16
488                 }
ragge
1.25
489                 av[na++] = tmp3;
490 #if 0
ragge
1.3
491                 if (proflag) {
492                         av[3] = "-XP";
493                         av[4] = 0;
494                 } else
495                         av[3] = 0;
ragge
1.25
496 #endif
497                 av[na++] = NULL;
ragge
1.3
498                 if (callsys(pass0av)) {
ragge
1.1
499                         cflag++;
500                         eflag++;
501                         continue;
502                 }
503                 if (sflag)
504                         continue;
ragge
1.18
505
506                 /*
507                  * Assembler
508                  */
ragge
1.1
509         assemble:
ragge
1.49
510                 na = 0;
gmcgarry
1.79
511                 av[na++] = as;
ragge
1.60
512                 if (vflag)
513                         av[na++] = "-v";
ragge
1.49
514                 if (kflag)
515                         av[na++] = "-k";
516                 av[na++] = "-o";
ragge
1.18
517                 if (outfile && cflag)
ragge
1.49
518                         av[na++] = outfile;
ragge
1.18
519                 else
ragge
1.49
520                         av[na++] = setsuf(clist[i], 'o');
stefan
1.73
521                 av[na++] = assource;
ragge
1.49
522                 if (dflag)
523                         av[na++] = alist;
524                 av[na++] = 0;
gmcgarry
1.79
525                 if (callsys(asav)) {
ragge
1.1
526                         cflag++;
527                         eflag++;
ragge
1.7
528                         cunlink(tmp4);
ragge
1.1
529                         continue;
530                 }
ragge
1.7
531                 cunlink(tmp4);
ragge
1.1
532         }
ragge
1.18
533
ragge
1.51
534         if (Eflag || Mflag)
ragge
1.37
535                 dexit(eflag);
536
ragge
1.18
537         /*
538          * Linker
539          */
ragge
1.1
540 nocom:
541         if (cflag==0 && nl!=0) {
ragge
1.6
542                 j = 0;
gmcgarry
1.79
543                 av[j++] = ld;
ragge
1.60
544                 if (vflag)
545                         av[j++] = "-v";
ragge
1.6
546                 av[j++] = "-X";
547                 av[j++] = "-d";
548                 av[j++] = "-e";
ragge
1.48
549                 av[j++] = STARTLABEL;
ragge
1.14
550                 if (Bstatic == 0) { /* Dynamic linkage */
ragge
1.24
551                         for (i = 0dynlinker[i]; i++)
552                                 av[j++] = dynlinker[i];
ragge
1.54
553                 } else
554                         av[j++] = "-Bstatic";
ragge
1.1
555                 if (outfile) {
ragge
1.3
556                         av[j++] = "-o";
557                         av[j++] = outfile;
558                 }
ragge
1.14
559                 if (!nostartfiles) {
gmcgarry
1.81
560                         av[j++] = pgflag ? crt0file_profile : crt0file;
ragge
1.24
561                         for (i = 0startfiles[i]; i++)
562                                 av[j++] = startfiles[i];
ragge
1.14
563                 }
ragge
1.24
564                 i = 0;
ragge
1.14
565                 while(i<nl) {
ragge
1.3
566                         av[j++] = llist[i++];
ragge
1.14
567                         if (j >= MAXAV)
ragge
1.36
568                                 error("Too many ld options");
ragge
1.14
569                 }
ragge
1.65
570                 if (gflag)
571                         av[j++] = "-g";
ragge
1.11
572 #if 0
ragge
1.3
573                 if (gflag)
574                         av[j++] = "-lg";
ragge
1.11
575 #endif
ragge
1.52
576                 if (pthreads)
577                         av[j++] = "-lpthread";
gmcgarry
1.81
578                 if (!nostdlib) {
579                         if (pgflag) {
580                                 for (i = 0libclibs_profile[i]; i++)
581                                         av[j++] = libclibs_profile[i];
582                         } else {
583                                 for (i = 0libclibs[i]; i++)
584                                         av[j++] = libclibs[i];
585                         }
586                 }
ragge
1.14
587                 if (!nostartfiles) {
ragge
1.24
588                         for (i = 0endfiles[i]; i++)
589                                 av[j++] = endfiles[i];
ragge
1.14
590                 }
ragge
1.3
591                 av[j++] = 0;
gmcgarry
1.79
592                 eflag |= callsys(ldav);
ragge
1.1
593                 if (nc==1 && nxo==1 && eflag==0)
ragge
1.3
594                         cunlink(setsuf(clist[0], 'o'));
ragge
1.46
595                 else if (nc > 0 && eflag == 0) {
596                         /* remove .o files XXX ugly */
597                         for (i = 0i < nci++)
598                                 cunlink(setsuf(clist[i], 'o'));
599                 }
ragge
1.1
600         }
ragge
1.36
601         dexit(eflag);
ragge
1.4
602         return 0;
ragge
1.1
603 }
604
ragge
1.36
605 /*
606  * exit and cleanup after interrupt.
607  */
ragge
1.4
608 void
609 idexit(int arg)
ragge
1.1
610 {
ragge
1.36
611         dexit(100);
ragge
1.1
612 }
613
ragge
1.36
614 /*
615  * exit and cleanup.
616  */
ragge
1.4
617 void
ragge
1.36
618 dexit(int eval)
ragge
1.1
619 {
ragge
1.10
620         if (!pflag && !Xflag) {
ragge
1.1
621                 if (sflag==0)
622                         cunlink(tmp3);
623                 cunlink(tmp4);
624         }
ragge
1.70
625         if (eval == 100)
626                 _exit(eval);
ragge
1.36
627         exit(eval);
ragge
1.1
628 }
629
ragge
1.36
630 static void
631 ccerror(char *sva_list ap)
ragge
1.1
632 {
ragge
1.36
633         vfprintf(Eflag ? stderr : stdoutsap);
ragge
1.8
634         putc('\n'Eflagstderr : stdout);
ragge
1.1
635         exfail++;
636         cflag++;
637         eflag++;
638 }
639
ragge
1.36
640 /*
641  * complain a bit.
642  */
643 void
644 error(char *s, ...)
645 {
646         va_list ap;
647
648         va_start(aps);
649         ccerror(sap);
650         va_end(ap);
651 }
652
653 /*
654  * complain a bit and then exit.
655  */
ragge
1.18
656 void
ragge
1.36
657 errorx(int evalchar *s, ...)
ragge
1.18
658 {
ragge
1.36
659         va_list ap;
660
661         va_start(aps);
662         ccerror(sap);
663         va_end(ap);
664         dexit(eval);
ragge
1.18
665 }
ragge
1.3
666
ragge
1.4
667 int
stefan
1.72
668 getsuf(char *as)
ragge
1.1
669 {
670         register char *s;
671
ragge
1.4
672         if ((s = strrchr(as'.')) && s[1] != '\0' && s[2] == '\0')
673                 return s[1];
ragge
1.3
674         return(0);
ragge
1.1
675 }
676
ragge
1.36
677 /*
678  * Get basename of string s and change its suffix to ch.
679  */
ragge
1.1
680 char *
ragge
1.36
681 setsuf(char *schar ch)
ragge
1.1
682 {
ragge
1.36
683         s = copy(basename(s));
pj
1.31
684         s[strlen(s) - 1] = ch;
ragge
1.36
685         return(s);
ragge
1.1
686 }
687
ragge
1.4
688 int
ragge
1.56
689 callsys(char f[], char *v[])
690 {
stefan
1.75
691         int tstatus = 0;
692         pid_t p;
ragge
1.4
693         char *s;
ragge
1.5
694
695         if (vflag) {
ragge
1.41
696                 fprintf(stderr"%s "f);
697                 for (t = 1v[t]; t++)
ragge
1.6
698                         fprintf(stderr"%s "v[t]);
699                 fprintf(stderr"\n");
ragge
1.5
700         }
ragge
1.1
701
stefan
1.75
702         if ((p = fork()) == 0) {
ragge
1.47
703                 if (Bflag) {
ragge
1.56
704                         size_t len = strlen(Bflag) + 8;
ragge
1.53
705                         char *a = malloc(len);
stefan
1.71
706                         if (a == NULL) {
707                                 error("callsys: malloc failed");
708                                 exit(1);
709                         }
ragge
1.47
710                         if ((s = strrchr(f'/'))) {
ragge
1.53
711                                 strlcpy(aBflaglen);
712                                 strlcat(aslen);
ragge
1.47
713                                 execv(av);
714                         }
715                 }
gmcgarry
1.79
716                 execvp(fv);
ragge
1.4
717                 if ((s = strrchr(f'/')))
718                         execvp(s+1v);
stefan
1.75
719                 fprintf(stderr"Can't find %s\n"f);
720                 _exit(100);
721         } else {
722                 if (p == -1) {
ragge
1.3
723                         printf("Try again\n");
724                         return(100);
725                 }
stefan
1.75
726         }
727         while (waitpid(p, &status0) == -1 && errno == EINTR)
728                 ;
729         if (WIFEXITED(status))
730                 return (WEXITSTATUS(status));
731         if (WIFSIGNALED(status))
ragge
1.36
732                 dexit(eflag);
stefan
1.75
733         errorx(8"Fatal error in %s"f);
ragge
1.1
734 }
735
ragge
1.3
736 char *
pj
1.28
737 copy(char *as)
ragge
1.3
738 {
pj
1.28
739         char *p;
740
ragge
1.36
741         if ((p = strdup(as)) == NULL)
742                 errorx(8"no space for file names");
ragge
1.3
743
pj
1.28
744         return p;
ragge
1.3
745 }
746
ragge
1.4
747 int
stefan
1.72
748 cunlink(char *f)
ragge
1.1
749 {
ragge
1.13
750         if (f==0 || Xflag)
ragge
1.3
751                 return(0);
752         return(unlink(f));
ragge
1.1
753 }
pj
1.30
754
755 char *
stefan
1.69
756 gettmp(void)
pj
1.30
757 {
stefan
1.69
758         char *sfn = copy("/tmp/ctm.XXXXXX");
pj
1.30
759         int fd = -1;
760
761         if ((fd = mkstemp(sfn)) == -1) {
762                 fprintf(stderr"%s: %s\n"sfnstrerror(errno));
763                 exit(8);
764         }
765         close(fd);
766
767         return sfn;
768 }
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-10-31 23:51 +0100