Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:stefan:20071008145342

Diff

Diff from 1.69 to:

Annotations

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

Annotated File View

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