Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20071001152935

Diff

Diff from 1.64 to:

Annotations

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

Annotated File View

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