Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20070929132240

Diff

Diff from 1.63 to:

Annotations

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

Annotated File View

ragge
1.63
1 /*      $Id: cc.c,v 1.63 2007/09/29 13:22:40 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";
437                 }
ragge
1.45
438                 for (j = 0j < xnumj++)
439                         av[na++] = xlist[j];
ragge
1.25
440                 av[na++] = tmp4;
ragge
1.3
441                 if (pflag || exfail)
442                         {
ragge
1.1
443                         cflag++;
444                         continue;
ragge
1.3
445                         }
ragge
1.16
446                 if(sflag) {
447                         if (outfile)
448                                 assource = tmp3 = outfile;
449                         else
450                                 assource = tmp3 = setsuf(clist[i], 's');
451                 }
ragge
1.25
452                 av[na++] = tmp3;
453 #if 0
ragge
1.3
454                 if (proflag) {
455                         av[3] = "-XP";
456                         av[4] = 0;
457                 } else
458                         av[3] = 0;
ragge
1.25
459 #endif
460                 av[na++] = NULL;
ragge
1.3
461                 if (callsys(pass0av)) {
ragge
1.1
462                         cflag++;
463                         eflag++;
464                         continue;
465                 }
466                 if (sflag)
467                         continue;
ragge
1.18
468
469                 /*
470                  * Assembler
471                  */
ragge
1.1
472         assemble:
ragge
1.49
473                 na = 0;
474                 av[na++] = "as";
ragge
1.60
475                 if (vflag)
476                         av[na++] = "-v";
ragge
1.49
477                 if (kflag)
478                         av[na++] = "-k";
479                 av[na++] = "-o";
ragge
1.18
480                 if (outfile && cflag)
ragge
1.49
481                         av[na++] = outfile;
ragge
1.18
482                 else
ragge
1.49
483                         av[na++] = setsuf(clist[i], 'o');
484                 av[na++] = onlyas ? tmp4 : assource;
485                 if (dflag)
486                         av[na++] = alist;
487                 av[na++] = 0;
ragge
1.21
488                 if (callsys("/bin/as"av)) {
ragge
1.1
489                         cflag++;
490                         eflag++;
ragge
1.7
491                         cunlink(tmp4);
ragge
1.1
492                         continue;
493                 }
ragge
1.7
494                 cunlink(tmp4);
ragge
1.1
495         }
ragge
1.18
496
ragge
1.51
497         if (Eflag || Mflag)
ragge
1.37
498                 dexit(eflag);
499
ragge
1.18
500         /*
501          * Linker
502          */
ragge
1.1
503 nocom:
504         if (cflag==0 && nl!=0) {
ragge
1.6
505                 j = 0;
506                 av[j++] = "ld";
ragge
1.60
507                 if (vflag)
508                         av[j++] = "-v";
ragge
1.6
509                 av[j++] = "-X";
510                 av[j++] = "-d";
511                 av[j++] = "-e";
ragge
1.48
512                 av[j++] = STARTLABEL;
ragge
1.14
513                 if (Bstatic == 0) { /* Dynamic linkage */
ragge
1.24
514                         for (i = 0dynlinker[i]; i++)
515                                 av[j++] = dynlinker[i];
ragge
1.54
516                 } else
517                         av[j++] = "-Bstatic";
ragge
1.1
518                 if (outfile) {
ragge
1.3
519                         av[j++] = "-o";
520                         av[j++] = outfile;
521                 }
ragge
1.14
522                 if (!nostartfiles) {
ragge
1.24
523                         av[j++] = crt0file;
524                         for (i = 0startfiles[i]; i++)
525                                 av[j++] = startfiles[i];
ragge
1.14
526                 }
ragge
1.24
527                 i = 0;
ragge
1.14
528                 while(i<nl) {
ragge
1.3
529                         av[j++] = llist[i++];
ragge
1.14
530                         if (j >= MAXAV)
ragge
1.36
531                                 error("Too many ld options");
ragge
1.14
532                 }
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.36
580         exit(eval);
ragge
1.1
581 }
582
ragge
1.36
583 static void
584 ccerror(char *sva_list ap)
ragge
1.1
585 {
ragge
1.36
586         vfprintf(Eflag ? stderr : stdoutsap);
ragge
1.8
587         putc('\n'Eflagstderr : stdout);
ragge
1.1
588         exfail++;
589         cflag++;
590         eflag++;
591 }
592
ragge
1.36
593 /*
594  * complain a bit.
595  */
596 void
597 error(char *s, ...)
598 {
599         va_list ap;
600
601         va_start(aps);
602         ccerror(sap);
603         va_end(ap);
604 }
605
606 /*
607  * complain a bit and then exit.
608  */
ragge
1.18
609 void
ragge
1.36
610 errorx(int evalchar *s, ...)
ragge
1.18
611 {
ragge
1.36
612         va_list ap;
613
614         va_start(aps);
615         ccerror(sap);
616         va_end(ap);
617         dexit(eval);
ragge
1.18
618 }
ragge
1.3
619
ragge
1.4
620 int
ragge
1.3
621 getsuf(as)
622 char as[];
ragge
1.1
623 {
624         register char *s;
625
ragge
1.4
626         if ((s = strrchr(as'.')) && s[1] != '\0' && s[2] == '\0')
627                 return s[1];
ragge
1.3
628         return(0);
ragge
1.1
629 }
630
ragge
1.36
631 /*
632  * Get basename of string s and change its suffix to ch.
633  */
ragge
1.1
634 char *
ragge
1.36
635 setsuf(char *schar ch)
ragge
1.1
636 {
ragge
1.36
637         s = copy(basename(s));
pj
1.31
638         s[strlen(s) - 1] = ch;
ragge
1.36
639         return(s);
ragge
1.1
640 }
641
ragge
1.4
642 int
ragge
1.56
643 callsys(char f[], char *v[])
644 {
645         int status;
646         pid_t t;
ragge
1.4
647         char *s;
ragge
1.5
648
649         if (vflag) {
ragge
1.41
650                 fprintf(stderr"%s "f);
651                 for (t = 1v[t]; t++)
ragge
1.6
652                         fprintf(stderr"%s "v[t]);
653                 fprintf(stderr"\n");
ragge
1.5
654         }
ragge
1.1
655
ragge
1.3
656         if ((t=fork())==0) {
ragge
1.47
657                 if (Bflag) {
ragge
1.56
658                         size_t len = strlen(Bflag) + 8;
ragge
1.53
659                         char *a = malloc(len);
ragge
1.56
660                         if (a == NULL)
661                                 errorx(1"callsys: malloc failed\n");
ragge
1.47
662                         if ((s = strrchr(f'/'))) {
ragge
1.53
663                                 strlcpy(aBflaglen);
664                                 strlcat(aslen);
ragge
1.47
665                                 execv(av);
666                         }
667                 }
ragge
1.1
668                 execv(fv);
ragge
1.4
669                 if ((s = strrchr(f'/')))
670                         execvp(s+1v);
ragge
1.1
671                 printf("Can't find %s\n"f);
ragge
1.3
672                 exit(100);
673         } else
674                 if (t == -1) {
675                         printf("Try again\n");
676                         return(100);
677                 }
678         while(t!=wait(&status));
ragge
1.1
679         if ((t=(status&0377)) != 0 && t!=14) {
ragge
1.3
680                 if (t!=2)               /* interrupt */
ragge
1.36
681                         errorx(8"Fatal error in %s"f);
682                 dexit(eflag);
ragge
1.1
683         }
ragge
1.3
684         return((status>>8) & 0377);
ragge
1.1
685 }
686
ragge
1.3
687 char *
pj
1.28
688 copy(char *as)
ragge
1.3
689 {
pj
1.28
690         char *p;
691
ragge
1.36
692         if ((p = strdup(as)) == NULL)
693                 errorx(8"no space for file names");
ragge
1.3
694
pj
1.28
695         return p;
ragge
1.3
696 }
697
ragge
1.4
698 int
ragge
1.3
699 nodup(los)
700 char **l, *os;
ragge
1.1
701 {
702         register char *t, *s;
703         register int c;
704
705         s = os;
706         if (getsuf(s) != 'o')
ragge
1.3
707                 return(1);
ragge
1.4
708         while((t = *l++)) {
709                 while((c = *s++))
ragge
1.1
710                         if (c != *t++)
711                                 break;
ragge
1.3
712                 if (*t=='\0' && c=='\0')
713                         return(0);
ragge
1.1
714                 s = os;
715         }
ragge
1.3
716         return(1);
ragge
1.1
717 }
718
ragge
1.4
719 int
ragge
1.3
720 cunlink(f)
721 char *f;
ragge
1.1
722 {
ragge
1.13
723         if (f==0 || Xflag)
ragge
1.3
724                 return(0);
725         return(unlink(f));
ragge
1.1
726 }
pj
1.30
727
728 char *
729 gettmp()
730 {
731         char *sfn = strdup("/tmp/ctm.XXXXXX");
732         int fd = -1;
733
734         if ((fd = mkstemp(sfn)) == -1) {
735                 fprintf(stderr"%s: %s\n"sfnstrerror(errno));
736                 exit(8);
737         }
738         close(fd);
739
740         return sfn;
741 }
FishEye: Open Source License registered to PCC.
Your maintenance has expired. You can renew your license at http://www.atlassian.com/fisheye/renew
Atlassian FishEye, CVS analysis. (Version:1.6.3 Build:build-336 2008-11-04) - Administration - Page generated 2014-10-02 08:23 +0200