Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20070924154200

Diff

Diff from 1.60 to:

Annotations

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

Annotated File View

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