Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:stefan:20071122214239

Diff

Diff from 1.77 to:

Annotations

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

Annotated File View

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