Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20070915073738

Diff

Diff from 1.53 to:

Annotations

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

Annotated File View

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