Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20071004065634

Diff

Diff from 1.67 to:

Annotations

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

Annotated File View

ragge
1.67
1 /*      $Id: cc.c,v 1.67 2007/10/04 06:56:34 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.25
444                 av[na++] = tmp4;
ragge
1.3
445                 if (pflag || exfail)
446                         {
ragge
1.1
447                         cflag++;
448                         continue;
ragge
1.3
449                         }
ragge
1.16
450                 if(sflag) {
451                         if (outfile)
452                                 assource = tmp3 = outfile;
453                         else
454                                 assource = tmp3 = setsuf(clist[i], 's');
455                 }
ragge
1.25
456                 av[na++] = tmp3;
457 #if 0
ragge
1.3
458                 if (proflag) {
459                         av[3] = "-XP";
460                         av[4] = 0;
461                 } else
462                         av[3] = 0;
ragge
1.25
463 #endif
464                 av[na++] = NULL;
ragge
1.3
465                 if (callsys(pass0av)) {
ragge
1.1
466                         cflag++;
467                         eflag++;
468                         continue;
469                 }
470                 if (sflag)
471                         continue;
ragge
1.18
472
473                 /*
474                  * Assembler
475                  */
ragge
1.1
476         assemble:
ragge
1.49
477                 na = 0;
478                 av[na++] = "as";
ragge
1.60
479                 if (vflag)
480                         av[na++] = "-v";
ragge
1.49
481                 if (kflag)
482                         av[na++] = "-k";
483                 av[na++] = "-o";
ragge
1.18
484                 if (outfile && cflag)
ragge
1.49
485                         av[na++] = outfile;
ragge
1.18
486                 else
ragge
1.49
487                         av[na++] = setsuf(clist[i], 'o');
488                 av[na++] = onlyas ? tmp4 : assource;
489                 if (dflag)
490                         av[na++] = alist;
491                 av[na++] = 0;
ragge
1.21
492                 if (callsys("/bin/as"av)) {
ragge
1.1
493                         cflag++;
494                         eflag++;
ragge
1.7
495                         cunlink(tmp4);
ragge
1.1
496                         continue;
497                 }
ragge
1.7
498                 cunlink(tmp4);
ragge
1.1
499         }
ragge
1.18
500
ragge
1.51
501         if (Eflag || Mflag)
ragge
1.37
502                 dexit(eflag);
503
ragge
1.18
504         /*
505          * Linker
506          */
ragge
1.1
507 nocom:
508         if (cflag==0 && nl!=0) {
ragge
1.6
509                 j = 0;
510                 av[j++] = "ld";
ragge
1.60
511                 if (vflag)
512                         av[j++] = "-v";
ragge
1.6
513                 av[j++] = "-X";
514                 av[j++] = "-d";
515                 av[j++] = "-e";
ragge
1.48
516                 av[j++] = STARTLABEL;
ragge
1.14
517                 if (Bstatic == 0) { /* Dynamic linkage */
ragge
1.24
518                         for (i = 0dynlinker[i]; i++)
519                                 av[j++] = dynlinker[i];
ragge
1.54
520                 } else
521                         av[j++] = "-Bstatic";
ragge
1.1
522                 if (outfile) {
ragge
1.3
523                         av[j++] = "-o";
524                         av[j++] = outfile;
525                 }
ragge
1.14
526                 if (!nostartfiles) {
ragge
1.24
527                         av[j++] = crt0file;
528                         for (i = 0startfiles[i]; i++)
529                                 av[j++] = startfiles[i];
ragge
1.14
530                 }
ragge
1.24
531                 i = 0;
ragge
1.14
532                 while(i<nl) {
ragge
1.3
533                         av[j++] = llist[i++];
ragge
1.14
534                         if (j >= MAXAV)
ragge
1.36
535                                 error("Too many ld options");
ragge
1.14
536                 }
ragge
1.65
537                 if (gflag)
538                         av[j++] = "-g";
ragge
1.11
539 #if 0
ragge
1.3
540                 if (gflag)
541                         av[j++] = "-lg";
ragge
1.11
542 #endif
ragge
1.52
543                 if (pthreads)
544                         av[j++] = "-lpthread";
545                 if (!nostdlib)
546                         for (i = 0libclibs[i]; i++)
547                                 av[j++] = libclibs[i];
ragge
1.14
548                 if (!nostartfiles) {
ragge
1.24
549                         for (i = 0endfiles[i]; i++)
550                                 av[j++] = endfiles[i];
ragge
1.14
551                 }
ragge
1.3
552                 av[j++] = 0;
553                 eflag |= callsys("/bin/ld"av);
ragge
1.1
554                 if (nc==1 && nxo==1 && eflag==0)
ragge
1.3
555                         cunlink(setsuf(clist[0], 'o'));
ragge
1.46
556                 else if (nc > 0 && eflag == 0) {
557                         /* remove .o files XXX ugly */
558                         for (i = 0i < nci++)
559                                 cunlink(setsuf(clist[i], 'o'));
560                 }
ragge
1.1
561         }
ragge
1.36
562         dexit(eflag);
ragge
1.4
563         return 0;
ragge
1.1
564 }
565
ragge
1.36
566 /*
567  * exit and cleanup after interrupt.
568  */
ragge
1.4
569 void
570 idexit(int arg)
ragge
1.1
571 {
ragge
1.36
572         dexit(100);
ragge
1.1
573 }
574
ragge
1.36
575 /*
576  * exit and cleanup.
577  */
ragge
1.4
578 void
ragge
1.36
579 dexit(int eval)
ragge
1.1
580 {
ragge
1.10
581         if (!pflag && !Xflag) {
ragge
1.1
582                 if (sflag==0)
583                         cunlink(tmp3);
584                 cunlink(tmp4);
585         }
ragge
1.36
586         exit(eval);
ragge
1.1
587 }
588
ragge
1.36
589 static void
590 ccerror(char *sva_list ap)
ragge
1.1
591 {
ragge
1.36
592         vfprintf(Eflag ? stderr : stdoutsap);
ragge
1.8
593         putc('\n'Eflagstderr : stdout);
ragge
1.1
594         exfail++;
595         cflag++;
596         eflag++;
597 }
598
ragge
1.36
599 /*
600  * complain a bit.
601  */
602 void
603 error(char *s, ...)
604 {
605         va_list ap;
606
607         va_start(aps);
608         ccerror(sap);
609         va_end(ap);
610 }
611
612 /*
613  * complain a bit and then exit.
614  */
ragge
1.18
615 void
ragge
1.36
616 errorx(int evalchar *s, ...)
ragge
1.18
617 {
ragge
1.36
618         va_list ap;
619
620         va_start(aps);
621         ccerror(sap);
622         va_end(ap);
623         dexit(eval);
ragge
1.18
624 }
ragge
1.3
625
ragge
1.4
626 int
ragge
1.3
627 getsuf(as)
628 char as[];
ragge
1.1
629 {
630         register char *s;
631
ragge
1.4
632         if ((s = strrchr(as'.')) && s[1] != '\0' && s[2] == '\0')
633                 return s[1];
ragge
1.3
634         return(0);
ragge
1.1
635 }
636
ragge
1.36
637 /*
638  * Get basename of string s and change its suffix to ch.
639  */
ragge
1.1
640 char *
ragge
1.36
641 setsuf(char *schar ch)
ragge
1.1
642 {
ragge
1.36
643         s = copy(basename(s));
pj
1.31
644         s[strlen(s) - 1] = ch;
ragge
1.36
645         return(s);
ragge
1.1
646 }
647
ragge
1.4
648 int
ragge
1.56
649 callsys(char f[], char *v[])
650 {
651         int status;
652         pid_t t;
ragge
1.4
653         char *s;
ragge
1.5
654
655         if (vflag) {
ragge
1.41
656                 fprintf(stderr"%s "f);
657                 for (t = 1v[t]; t++)
ragge
1.6
658                         fprintf(stderr"%s "v[t]);
659                 fprintf(stderr"\n");
ragge
1.5
660         }
ragge
1.1
661
ragge
1.3
662         if ((t=fork())==0) {
ragge
1.47
663                 if (Bflag) {
ragge
1.56
664                         size_t len = strlen(Bflag) + 8;
ragge
1.53
665                         char *a = malloc(len);
ragge
1.56
666                         if (a == NULL)
667                                 errorx(1"callsys: malloc failed\n");
ragge
1.47
668                         if ((s = strrchr(f'/'))) {
ragge
1.53
669                                 strlcpy(aBflaglen);
670                                 strlcat(aslen);
ragge
1.47
671                                 execv(av);
672                         }
673                 }
ragge
1.1
674                 execv(fv);
ragge
1.4
675                 if ((s = strrchr(f'/')))
676                         execvp(s+1v);
ragge
1.1
677                 printf("Can't find %s\n"f);
ragge
1.3
678                 exit(100);
679         } else
680                 if (t == -1) {
681                         printf("Try again\n");
682                         return(100);
683                 }
684         while(t!=wait(&status));
ragge
1.1
685         if ((t=(status&0377)) != 0 && t!=14) {
ragge
1.3
686                 if (t!=2)               /* interrupt */
ragge
1.36
687                         errorx(8"Fatal error in %s"f);
688                 dexit(eflag);
ragge
1.1
689         }
ragge
1.3
690         return((status>>8) & 0377);
ragge
1.1
691 }
692
ragge
1.3
693 char *
pj
1.28
694 copy(char *as)
ragge
1.3
695 {
pj
1.28
696         char *p;
697
ragge
1.36
698         if ((p = strdup(as)) == NULL)
699                 errorx(8"no space for file names");
ragge
1.3
700
pj
1.28
701         return p;
ragge
1.3
702 }
703
ragge
1.4
704 int
ragge
1.3
705 nodup(los)
706 char **l, *os;
ragge
1.1
707 {
708         register char *t, *s;
709         register int c;
710
711         s = os;
712         if (getsuf(s) != 'o')
ragge
1.3
713                 return(1);
ragge
1.4
714         while((t = *l++)) {
715                 while((c = *s++))
ragge
1.1
716                         if (c != *t++)
717                                 break;
ragge
1.3
718                 if (*t=='\0' && c=='\0')
719                         return(0);
ragge
1.1
720                 s = os;
721         }
ragge
1.3
722         return(1);
ragge
1.1
723 }
724
ragge
1.4
725 int
ragge
1.3
726 cunlink(f)
727 char *f;
ragge
1.1
728 {
ragge
1.13
729         if (f==0 || Xflag)
ragge
1.3
730                 return(0);
731         return(unlink(f));
ragge
1.1
732 }
pj
1.30
733
734 char *
735 gettmp()
736 {
737         char *sfn = strdup("/tmp/ctm.XXXXXX");
738         int fd = -1;
739
740         if ((fd = mkstemp(sfn)) == -1) {
741                 fprintf(stderr"%s: %s\n"sfnstrerror(errno));
742                 exit(8);
743         }
744         close(fd);
745
746         return sfn;
747 }
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 07:14 +0100