Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20071006080948

Diff

Diff from 1.68 to:

Annotations

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

Annotated File View

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