Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20070926144847

Diff

Diff from 1.61 to:

Annotations

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

Annotated File View

ragge
1.61
1 /*      $Id: cc.c,v 1.61 2007/09/26 14:48:47 ragge Exp $        */
ragge
1.3
2 /*
3  * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * Redistributions of source code and documentation must retain the above
10  * copyright notice, this list of conditions and the following disclaimer.
11  * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditionsand the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * All advertising materials mentioning features or use of this software
15  * must display the following acknowledgement:
16  *      This product includes software developed or owned by Caldera
17  *      International, Inc.
18  * Neither the name of Caldera International, Inc. nor the names of other
19  * contributors may be used to endorse or promote products derived from
20  * this software without specific prior written permission.
21  *
22  * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
23  * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED.  IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE
27  * FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT,
31  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
ragge
1.2
35
ragge
1.1
36 /*
ragge
1.3
37  * Front-end to the C compiler.
ragge
1.18
38  *
39  * Brief description of its syntax:
40  * - Files that end with .c are passed via cpp->ccom->as->ld
ragge
1.59
41  * - Files that end with .i are passed via ccom->as->ld
ragge
1.18
42  * - Files that end with .s are passed as->ld
43  * - Files that end with .o are passed directly to ld
44  * - Multiple files may be given on the command line.
45  * - Unrecognized options are all sent directly to ld.
46  * -c or -S cannot be combined with -o if multiple files are given.
47  *
48  * This file should be rewritten readable.
ragge
1.1
49  */
ragge
1.9
50 #include <sys/types.h>
ragge
1.36
51 #include <sys/wait.h>
ragge
1.2
52
ragge
1.1
53 #include <stdio.h>
54 #include <ctype.h>
55 #include <signal.h>
ragge
1.4
56 #include <string.h>
57 #include <fcntl.h>
58 #include <unistd.h>
59 #include <stdlib.h>
ragge
1.36
60 #include <stdarg.h>
61 #include <libgen.h>
pj
1.38
62 #include <errno.h>
ragge
1.24
63
ragge
1.39
64 #include "../../config.h"
65
ragge
1.24
66 #include "ccconfig.h"
ragge
1.3
67 /* C command */
ragge
1.1
68
ragge
1.20
69 #define MKS(x) _MKS(x)
70 #define _MKS(x) #x
71
72 /*
73  * Many specific definitions, should be declared elsewhere.
74  */
ragge
1.55
75 #define STDINC    "/usr/include/"
ragge
1.20
76
ragge
1.3
77 #define SBSIZE 10000
ragge
1.12
78 #define MAXINC 100
ragge
1.3
79 #define MAXFIL 100
ragge
1.12
80 #define MAXLIB 10000
ragge
1.14
81 #define MAXAV  10000
ragge
1.3
82 #define MAXOPT 100
83 char    *tmp3;
84 char    *tmp4;
ragge
1.1
85 char    *outfile;
pj
1.31
86 char *copy(char *as),*setsuf(char *aschar ch);
ragge
1.4
87 int getsuf(char []);
88 int main(intchar *[]);
ragge
1.36
89 void error(char *, ...);
90 void errorx(int evalchar *, ...);
ragge
1.4
91 int nodup(char **, char *);
92 int callsys(char [], char *[]);
93 int cunlink(char *);
ragge
1.36
94 void dexit(int eval);
ragge
1.4
95 void idexit(int);
pj
1.30
96 char *gettmp();
ragge
1.14
97 char    *av[MAXAV];
ragge
1.3
98 char    *clist[MAXFIL];
99 char    *llist[MAXLIB];
ragge
1.4
100 char    alist[20];
ragge
1.43
101 char    *xlist[100];
102 int     xnum;
103 int     dflag;
ragge
1.3
104 int     pflag;
105 int     sflag;
106 int     cflag;
107 int     eflag;
108 int     gflag;
ragge
1.5
109 int     vflag;
ragge
1.7
110 int     tflag;
ragge
1.8
111 int     Eflag;
ragge
1.4
112 int     Oflag;
ragge
1.58
113 int     kflag;  /* generate PIC/pic code */
114 #define F_PIC   1
115 #define F_pic   2
ragge
1.51
116 int     Mflag;  /* dependencies only */
ragge
1.52
117 int     pgflag;
ragge
1.1
118 int     exfail;
ragge
1.10
119 int     Xflag;
ragge
1.14
120 int     nostartfilesBstatic;
ragge
1.52
121 int     nostdincnostdlib;
ragge
1.43
122 int     onlyas;
ragge
1.52
123 int     pthreads;
ragge
1.14
124
ragge
1.23
125 char    *pass0 = LIBEXECDIR "/ccom";
126 char    *passp = LIBEXECDIR "/cpp";
ragge
1.47
127 char    *Bflag;
ragge
1.25
128 char *cppadd[] = CPPADD;
129 char *dynlinker[] = DYNLINKER;
130 char *crt0file = CRT0FILE;
131 char *startfiles[] = STARTFILES;
132 char *endfiles[] = ENDFILES;
133 char *cppmdadd[] = CPPMDADD;
ragge
1.50
134 #ifdef LIBCLIBS
135 char *libclibs[] = LIBCLIBS;
136 #else
137 char *libclibs[] = { "-lc"NULL };
138 #endif
ragge
1.48
139 #ifndef STARTLABEL
140 #define STARTLABEL "__start"
141 #endif
ragge
1.1
142
ragge
1.4
143 int
pj
1.26
144 main(int argcchar *argv[])
145 {
ragge
1.15
146         char *t, *u;
ragge
1.1
147         char *assource;
ragge
1.3
148         char **pv, *ptemp[MAXOPT], **pvt;
ragge
1.36
149         int ncnlijcnxona;
ragge
1.3
150
ragge
1.36
151         i = nc = nl = nxo = 0;
ragge
1.3
152         pv = ptemp;
153         while(++i < argc) {
ragge
1.18
154                 if (argv[i][0] == '-')
155                 switch (argv[i][1]) {
ragge
1.3
156                 default:
157                         goto passa;
ragge
1.22
158
ragge
1.47
159                 case 'B'/* other search paths for binaries */
160                         Bflag = &argv[i][2];
ragge
1.22
161                         break;
162
ragge
1.10
163                 case 'X':
164                         Xflag++;
165                         break;
ragge
1.15
166                 case 'W'/* Ignore (most of) W-flags */
167                         if (strncmp(argv[i], "-Wl,"4) == 0) {
168                                 /* options to the linker */
169                                 t = &argv[i][4];
170                                 while ((u = strchr(t','))) {
171                                         *u++ = 0;
172                                         llist[nl++] = t;
173                                         t = u;
174                                 }
175                                 llist[nl++] = t;
176                         }
177                         break;
178
ragge
1.49
179                 case 'f'/* GCC compatibility flags */
180                         if (strcmp(argv[i], "-fPIC") == 0)
ragge
1.58
181                                 kflag = F_PIC;
182                         if (strcmp(argv[i], "-fpic") == 0)
183                                 kflag = F_pic;
ragge
1.49
184                         /* silently ignore the rest */
ragge
1.6
185                         break;
ragge
1.14
186
ragge
1.25
187                 case 'g'/* create debug output */
188                         gflag++;
189                         break;
190
ragge
1.20
191                 case 'i':
192                         if (strcmp(argv[i], "-isystem") == 0) {
ragge
1.52
193                                 *pv++ = "-S";
194                                 *pv++ = argv[++i];
195                         } else if (strcmp(argv[i], "-include") == 0) {
196                                 *pv++ = "-i";
197                                 *pv++ = argv[++i];
ragge
1.20
198                         } else
199                                 goto passa;
200                         break;
201
ragge
1.49
202                 case 'k'/* generate PIC code */
ragge
1.58
203                         kflag = F_pic;
ragge
1.49
204                         break;
205
ragge
1.14
206                 case 'n'/* handle -n flags */
207                         if (strcmp(argv[i], "-nostdinc") == 0)
ragge
1.20
208                                 nostdinc++;
ragge
1.52
209                         if (strcmp(argv[i], "-nostdlib") == 0) {
210                                 nostdlib++;
211                                 nostartfiles++;
212                         } else if (strcmp(argv[i], "-nostartfiles") == 0)
ragge
1.14
213                                 nostartfiles = 1;
214                         else
215                                 goto passa;
216                         break;
217
ragge
1.52
218                 case 'p':
219                         if (strcmp(argv[i], "-pg") == 0)
220                                 pgflag++;
221                         else if (strcmp(argv[i], "-pthread") == 0)
222                                 pthreads++;
223                         else
224                                 errorx(1"unknown option %s"argv[i]);
225                         break;
226
ragge
1.7
227                 case 'x':
ragge
1.43
228                         xlist[xnum++] = argv[i];
ragge
1.7
229                         break;
230                 case 't':
231                         tflag++;
232                         break;
ragge
1.1
233                 case 'S':
234                         sflag++;
235                         cflag++;
ragge
1.3
236                         break;
ragge
1.1
237                 case 'o':
ragge
1.18
238                         if (outfile)
ragge
1.36
239                                 errorx(8"too many -o");
ragge
1.18
240                         outfile = argv[++i];
ragge
1.3
241                         break;
ragge
1.1
242                 case 'O':
ragge
1.4
243                         Oflag++;
ragge
1.3
244                         break;
ragge
1.1
245                 case 'E':
ragge
1.8
246                         Eflag++;
247                         break;
ragge
1.1
248                 case 'P':
249                         pflag++;
ragge
1.3
250                         *pv++ = argv[i];
ragge
1.1
251                 case 'c':
252                         cflag++;
ragge
1.3
253                         break;
254
ragge
1.24
255 #if 0
ragge
1.3
256                 case '2':
257                         if(argv[i][2] == '\0')
258                                 pref = "/lib/crt2.o";
259                         else {
260                                 pref = "/lib/crt20.o";
261                         }
262                         break;
ragge
1.24
263 #endif
ragge
1.1
264                 case 'D':
265                 case 'I':
266                 case 'U':
267                 case 'C':
ragge
1.20
268                         *pv++ = argv[i];
ragge
1.52
269                         if (argv[i][2] == 0)
270                                 *pv++ = argv[++i];
ragge
1.3
271                         if (pv >= ptemp+MAXOPT)
272                                 {
ragge
1.36
273                                 error("Too many DIUC options");
ragge
1.3
274                                 --pv;
275                                 }
276                         break;
277
ragge
1.51
278                 case 'M':
279                         Mflag++;
280                         break;
281
ragge
1.1
282                 case 'd':
ragge
1.3
283                         dflag++;
ragge
1.4
284                         strncpy(alistargv[i], 19);
ragge
1.3
285                         break;
ragge
1.5
286                 case 'v':
ragge
1.39
287                         printf("%s\n"VERSSTR);
ragge
1.5
288                         vflag++;
289                         break;
ragge
1.14
290
291                 case 's':
292                         if (strcmp(argv[i], "-static") == 0)
293                                 Bstatic = 1;
294                         else
295                                 goto passa;
296                         break;
ragge
1.3
297                 } else {
298                 passa:
299                         t = argv[i];
ragge
1.11
300                         if (*argv[i] == '-' && argv[i][1] == 'L')
301                                 ;
ragge
1.59
302                         else if((c=getsuf(t))=='c' || c=='S' || c=='i' ||
ragge
1.51
303                             c=='s'|| Eflag) {
ragge
1.3
304                                 clist[nc++] = t;
305                                 if (nc>=MAXFIL)
306                                         {
ragge
1.36
307                                         error("Too many source files");
ragge
1.3
308                                         exit(1);
309                                         }
310                                 t = setsuf(t'o');
311                         }
312                         if (nodup(llistt)) {
313                                 llist[nl++] = t;
314                                 if (nl >= MAXLIB)
315                                         {
ragge
1.36
316                                         error("Too many object/library files");
ragge
1.3
317                                         exit(1);
318                                         }
319                                 if (getsuf(t)=='o')
320                                         nxo++;
ragge
1.1
321                         }
322                 }
323         }
ragge
1.18
324         /* Sanity checking */
325         if (nc == 0 && nl == 0)
ragge
1.36
326                 errorx(8"no input files");
ragge
1.61
327         if (outfile && (cflag || sflag || Eflag) && nc > 1)
328                 errorx(8"-o given with -c || -E || -S and more than one file");
ragge
1.19
329         if (outfile && clist[0] && strcmp(outfileclist[0]) == 0)
ragge
1.36
330                 errorx(8"output file will be clobbered");
ragge
1.59
331 #if 0
332         for(i=0j=0i<nci++) {
333                 if((c=getsuf(clist[i]))=='c' || c=='S') {
334                         j++;
335                         break;
336                 }
337         }
338         if (j==0 && Eflag)
339                 errorx(8"no file to be preprocessed");
340 #endif
ragge
1.18
341
ragge
1.4
342         if (gflagOflag = 0;
ragge
1.24
343 #if 0
344         if (proflag)
ragge
1.3
345                 pref = "/lib/mcrt0.o";
ragge
1.24
346 #endif
ragge
1.3
347         if(nc==0)
348                 goto nocom;
349         if (pflag==0) {
pj
1.30
350                 tmp3 = gettmp();
351                 tmp4 = gettmp();
ragge
1.1
352         }
ragge
1.3
353         if (signal(SIGINTSIG_IGN) != SIG_IGN/* interrupt */
ragge
1.1
354                 signal(SIGINTidexit);
ragge
1.3
355         if (signal(SIGTERMSIG_IGN) != SIG_IGN)        /* terminate */
ragge
1.1
356                 signal(SIGTERMidexit);
ragge
1.3
357         pvt = pv;
ragge
1.1
358         for (i=0i<nci++) {
ragge
1.18
359                 /*
360                  * C preprocessor
361                  */
ragge
1.37
362                 if (nc>1 && !Eflag)
ragge
1.1
363                         printf("%s:\n"clist[i]);
ragge
1.43
364                 onlyas = 0;
pj
1.32
365                 assource = tmp3;
ragge
1.59
366                 if (getsuf(clist[i])=='i') {
367                         if(Eflag)
368                                 continue;
369                         goto com;
370                 } else if (getsuf(clist[i])=='s') {
ragge
1.1
371                         assource = clist[i];
ragge
1.43
372                         onlyas = 1;
373                         goto assemble;
374                 } else if (getsuf(clist[i])=='S') {
375                         assource = clist[i];
376                         onlyas = 1;
pj
1.32
377                 }
ragge
1.1
378                 if (pflag)
379                         tmp4 = setsuf(clist[i], 'i');
ragge
1.5
380                 na = 0;
381                 av[na++] = "cpp";
ragge
1.60
382                 if (vflag)
383                         av[na++] = "-v";
ragge
1.20
384                 av[na++] = "-D__PCC__=" MKS(PCC_MAJOR);
ragge
1.40
385                 av[na++] = "-D__PCC_MINOR__=" MKS(PCC_MINOR);
386                 av[na++] = "-D__PCC_MINORMINOR__=" MKS(PCC_MINORMINOR);
ragge
1.52
387                 if (getsuf(clist[i])=='S')
388                         av[na++] = "-D__ASSEMBLER__";
389                 if (pthreads)
390                         av[na++] = "-D_PTHREADS";
ragge
1.51
391                 if (Mflag)
392                         av[na++] = "-M";
ragge
1.57
393                 if (dflag)
394                         av[na++] = alist;
ragge
1.5
395                 for (j = 0cppadd[j]; j++)
396                         av[na++] = cppadd[j];
ragge
1.24
397                 for (j = 0cppmdadd[j]; j++)
398                         av[na++] = cppmdadd[j];
ragge
1.7
399                 if (tflag)
ragge
1.20
400                         av[na++] = "-t";
ragge
1.7
401                 for(pv=ptemppv <pvtpv++)
402                         av[na++] = *pv;
ragge
1.52
403                 if (!nostdinc)
404                         av[na++] = "-S"av[na++] = STDINC;
ragge
1.5
405                 av[na++] = clist[i];
ragge
1.51
406                 if (!Eflag && !Mflag)
ragge
1.20
407                         av[na++] = tmp4;
ragge
1.61
408                 if (Eflag && outfile)
409                          av[na++] = outfile;
ragge
1.3
410                 av[na++]=0;
411                 if (callsys(passpav))
412                         {exfail++; eflag++;}
ragge
1.51
413                 if (Eflag || Mflag)
ragge
1.37
414                         continue;
ragge
1.43
415                 if (onlyas)
ragge
1.7
416                         goto assemble;
ragge
1.18
417
418                 /*
419                  * C compiler
420                  */
ragge
1.59
421         com:
ragge
1.25
422                 na = 0;
423                 av[na++]= "ccom";
ragge
1.60
424                 if (vflag)
425                         av[na++] = "-v";
ragge
1.25
426                 if (gflag)
427                         av[na++] = "-g";
ragge
1.49
428                 if (kflag)
429                         av[na++] = "-k";
ragge
1.44
430                 if (Oflag) {
431                         av[na++] = "-xtemps";
432                 }
ragge
1.45
433                 for (j = 0j < xnumj++)
434                         av[na++] = xlist[j];
ragge
1.25
435                 av[na++] = tmp4;
ragge
1.3
436                 if (pflag || exfail)
437                         {
ragge
1.1
438                         cflag++;
439                         continue;
ragge
1.3
440                         }
ragge
1.16
441                 if(sflag) {
442                         if (outfile)
443                                 assource = tmp3 = outfile;
444                         else
445                                 assource = tmp3 = setsuf(clist[i], 's');
446                 }
ragge
1.25
447                 av[na++] = tmp3;
448 #if 0
ragge
1.3
449                 if (proflag) {
450                         av[3] = "-XP";
451                         av[4] = 0;
452                 } else
453                         av[3] = 0;
ragge
1.25
454 #endif
455                 av[na++] = NULL;
ragge
1.3
456                 if (callsys(pass0av)) {
ragge
1.1
457                         cflag++;
458                         eflag++;
459                         continue;
460                 }
461                 if (sflag)
462                         continue;
ragge
1.18
463
464                 /*
465                  * Assembler
466                  */
ragge
1.1
467         assemble:
ragge
1.49
468                 na = 0;
469                 av[na++] = "as";
ragge
1.60
470                 if (vflag)
471                         av[na++] = "-v";
ragge
1.49
472                 if (kflag)
473                         av[na++] = "-k";
474                 av[na++] = "-o";
ragge
1.18
475                 if (outfile && cflag)
ragge
1.49
476                         av[na++] = outfile;
ragge
1.18
477                 else
ragge
1.49
478                         av[na++] = setsuf(clist[i], 'o');
479                 av[na++] = onlyas ? tmp4 : assource;
480                 if (dflag)
481                         av[na++] = alist;
482                 av[na++] = 0;
ragge
1.21
483                 if (callsys("/bin/as"av)) {
ragge
1.1
484                         cflag++;
485                         eflag++;
ragge
1.7
486                         cunlink(tmp4);
ragge
1.1
487                         continue;
488                 }
ragge
1.7
489                 cunlink(tmp4);
ragge
1.1
490         }
ragge
1.18
491
ragge
1.51
492         if (Eflag || Mflag)
ragge
1.37
493                 dexit(eflag);
494
ragge
1.18
495         /*
496          * Linker
497          */
ragge
1.1
498 nocom:
499         if (cflag==0 && nl!=0) {
ragge
1.6
500                 j = 0;
501                 av[j++] = "ld";
ragge
1.60
502                 if (vflag)
503                         av[j++] = "-v";
ragge
1.6
504                 av[j++] = "-X";
505                 av[j++] = "-d";
506                 av[j++] = "-e";
ragge
1.48
507                 av[j++] = STARTLABEL;
ragge
1.14
508                 if (Bstatic == 0) { /* Dynamic linkage */
ragge
1.24
509                         for (i = 0dynlinker[i]; i++)
510                                 av[j++] = dynlinker[i];
ragge
1.54
511                 } else
512                         av[j++] = "-Bstatic";
ragge
1.1
513                 if (outfile) {
ragge
1.3
514                         av[j++] = "-o";
515                         av[j++] = outfile;
516                 }
ragge
1.14
517                 if (!nostartfiles) {
ragge
1.24
518                         av[j++] = crt0file;
519                         for (i = 0startfiles[i]; i++)
520                                 av[j++] = startfiles[i];
ragge
1.14
521                 }
ragge
1.24
522                 i = 0;
ragge
1.14
523                 while(i<nl) {
ragge
1.3
524                         av[j++] = llist[i++];
ragge
1.14
525                         if (j >= MAXAV)
ragge
1.36
526                                 error("Too many ld options");
ragge
1.14
527                 }
ragge
1.11
528 #if 0
ragge
1.3
529                 if (gflag)
530                         av[j++] = "-lg";
ragge
1.11
531 #endif
ragge
1.52
532                 if (pthreads)
533                         av[j++] = "-lpthread";
534                 if (!nostdlib)
535                         for (i = 0libclibs[i]; i++)
536                                 av[j++] = libclibs[i];
ragge
1.14
537                 if (!nostartfiles) {
ragge
1.24
538                         for (i = 0endfiles[i]; i++)
539                                 av[j++] = endfiles[i];
ragge
1.14
540                 }
ragge
1.3
541                 av[j++] = 0;
542                 eflag |= callsys("/bin/ld"av);
ragge
1.1
543                 if (nc==1 && nxo==1 && eflag==0)
ragge
1.3
544                         cunlink(setsuf(clist[0], 'o'));
ragge
1.46
545                 else if (nc > 0 && eflag == 0) {
546                         /* remove .o files XXX ugly */
547                         for (i = 0i < nci++)
548                                 cunlink(setsuf(clist[i], 'o'));
549                 }
ragge
1.1
550         }
ragge
1.36
551         dexit(eflag);
ragge
1.4
552         return 0;
ragge
1.1
553 }
554
ragge
1.36
555 /*
556  * exit and cleanup after interrupt.
557  */
ragge
1.4
558 void
559 idexit(int arg)
ragge
1.1
560 {
ragge
1.36
561         dexit(100);
ragge
1.1
562 }
563
ragge
1.36
564 /*
565  * exit and cleanup.
566  */
ragge
1.4
567 void
ragge
1.36
568 dexit(int eval)
ragge
1.1
569 {
ragge
1.10
570         if (!pflag && !Xflag) {
ragge
1.1
571                 if (sflag==0)
572                         cunlink(tmp3);
573                 cunlink(tmp4);
574         }
ragge
1.36
575         exit(eval);
ragge
1.1
576 }
577
ragge
1.36
578 static void
579 ccerror(char *sva_list ap)
ragge
1.1
580 {
ragge
1.36
581         vfprintf(Eflag ? stderr : stdoutsap);
ragge
1.8
582         putc('\n'Eflagstderr : stdout);
ragge
1.1
583         exfail++;
584         cflag++;
585         eflag++;
586 }
587
ragge
1.36
588 /*
589  * complain a bit.
590  */
591 void
592 error(char *s, ...)
593 {
594         va_list ap;
595
596         va_start(aps);
597         ccerror(sap);
598         va_end(ap);
599 }
600
601 /*
602  * complain a bit and then exit.
603  */
ragge
1.18
604 void
ragge
1.36
605 errorx(int evalchar *s, ...)
ragge
1.18
606 {
ragge
1.36
607         va_list ap;
608
609         va_start(aps);
610         ccerror(sap);
611         va_end(ap);
612         dexit(eval);
ragge
1.18
613 }
ragge
1.3
614
ragge
1.4
615 int
ragge
1.3
616 getsuf(as)
617 char as[];
ragge
1.1
618 {
619         register char *s;
620
ragge
1.4
621         if ((s = strrchr(as'.')) && s[1] != '\0' && s[2] == '\0')
622                 return s[1];
ragge
1.3
623         return(0);
ragge
1.1
624 }
625
ragge
1.36
626 /*
627  * Get basename of string s and change its suffix to ch.
628  */
ragge
1.1
629 char *
ragge
1.36
630 setsuf(char *schar ch)
ragge
1.1
631 {
ragge
1.36
632         s = copy(basename(s));
pj
1.31
633         s[strlen(s) - 1] = ch;
ragge
1.36
634         return(s);
ragge
1.1
635 }
636
ragge
1.4
637 int
ragge
1.56
638 callsys(char f[], char *v[])
639 {
640         int status;
641         pid_t t;
ragge
1.4
642         char *s;
ragge
1.5
643
644         if (vflag) {
ragge
1.41
645                 fprintf(stderr"%s "f);
646                 for (t = 1v[t]; t++)
ragge
1.6
647                         fprintf(stderr"%s "v[t]);
648                 fprintf(stderr"\n");
ragge
1.5
649         }
ragge
1.1
650
ragge
1.3
651         if ((t=fork())==0) {
ragge
1.47
652                 if (Bflag) {
ragge
1.56
653                         size_t len = strlen(Bflag) + 8;
ragge
1.53
654                         char *a = malloc(len);
ragge
1.56
655                         if (a == NULL)
656                                 errorx(1"callsys: malloc failed\n");
ragge
1.47
657                         if ((s = strrchr(f'/'))) {
ragge
1.53
658                                 strlcpy(aBflaglen);
659                                 strlcat(aslen);
ragge
1.47
660                                 execv(av);
661                         }
662                 }
ragge
1.1
663                 execv(fv);
ragge
1.4
664                 if ((s = strrchr(f'/')))
665                         execvp(s+1v);
ragge
1.1
666                 printf("Can't find %s\n"f);
ragge
1.3
667                 exit(100);
668         } else
669                 if (t == -1) {
670                         printf("Try again\n");
671                         return(100);
672                 }
673         while(t!=wait(&status));
ragge
1.1
674         if ((t=(status&0377)) != 0 && t!=14) {
ragge
1.3
675                 if (t!=2)               /* interrupt */
ragge
1.36
676                         errorx(8"Fatal error in %s"f);
677                 dexit(eflag);
ragge
1.1
678         }
ragge
1.3
679         return((status>>8) & 0377);
ragge
1.1
680 }
681
ragge
1.3
682 char *
pj
1.28
683 copy(char *as)
ragge
1.3
684 {
pj
1.28
685         char *p;
686
ragge
1.36
687         if ((p = strdup(as)) == NULL)
688                 errorx(8"no space for file names");
ragge
1.3
689
pj
1.28
690         return p;
ragge
1.3
691 }
692
ragge
1.4
693 int
ragge
1.3
694 nodup(los)
695 char **l, *os;
ragge
1.1
696 {
697         register char *t, *s;
698         register int c;
699
700         s = os;
701         if (getsuf(s) != 'o')
ragge
1.3
702                 return(1);
ragge
1.4
703         while((t = *l++)) {
704                 while((c = *s++))
ragge
1.1
705                         if (c != *t++)
706                                 break;
ragge
1.3
707                 if (*t=='\0' && c=='\0')
708                         return(0);
ragge
1.1
709                 s = os;
710         }
ragge
1.3
711         return(1);
ragge
1.1
712 }
713
ragge
1.4
714 int
ragge
1.3
715 cunlink(f)
716 char *f;
ragge
1.1
717 {
ragge
1.13
718         if (f==0 || Xflag)
ragge
1.3
719                 return(0);
720         return(unlink(f));
ragge
1.1
721 }
pj
1.30
722
723 char *
724 gettmp()
725 {
726         char *sfn = strdup("/tmp/ctm.XXXXXX");
727         int fd = -1;
728
729         if ((fd = mkstemp(sfn)) == -1) {
730                 fprintf(stderr"%s: %s\n"sfnstrerror(errno));
731                 exit(8);
732         }
733         close(fd);
734
735         return sfn;
736 }
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-02 13:47 +0200