Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20070916192533

Diff

Diff from 1.55 to:

Annotations

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

Annotated File View

ragge
1.55
1 /*      $Id: cc.c,v 1.55 2007/09/16 19:25:36 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  */
ragge
1.55
74 #define STDINC    "/usr/include/"
ragge
1.20
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.54
479                 } else
480                         av[j++] = "-Bstatic";
ragge
1.1
481                 if (outfile) {
ragge
1.3
482                         av[j++] = "-o";
483                         av[j++] = outfile;
484                 }
ragge
1.14
485                 if (!nostartfiles) {
ragge
1.24
486                         av[j++] = crt0file;
487                         for (i = 0startfiles[i]; i++)
488                                 av[j++] = startfiles[i];
ragge
1.14
489                 }
ragge
1.24
490                 i = 0;
ragge
1.14
491                 while(i<nl) {
ragge
1.3
492                         av[j++] = llist[i++];
ragge
1.14
493                         if (j >= MAXAV)
ragge
1.36
494                                 error("Too many ld options");
ragge
1.14
495                 }
ragge
1.11
496 #if 0
ragge
1.3
497                 if (gflag)
498                         av[j++] = "-lg";
ragge
1.11
499 #endif
ragge
1.52
500                 if (pthreads)
501                         av[j++] = "-lpthread";
502                 if (!nostdlib)
503                         for (i = 0libclibs[i]; i++)
504                                 av[j++] = libclibs[i];
ragge
1.14
505                 if (!nostartfiles) {
ragge
1.24
506                         for (i = 0endfiles[i]; i++)
507                                 av[j++] = endfiles[i];
ragge
1.14
508                 }
ragge
1.3
509                 av[j++] = 0;
510                 eflag |= callsys("/bin/ld"av);
ragge
1.1
511                 if (nc==1 && nxo==1 && eflag==0)
ragge
1.3
512                         cunlink(setsuf(clist[0], 'o'));
ragge
1.46
513                 else if (nc > 0 && eflag == 0) {
514                         /* remove .o files XXX ugly */
515                         for (i = 0i < nci++)
516                                 cunlink(setsuf(clist[i], 'o'));
517                 }
ragge
1.1
518         }
ragge
1.36
519         dexit(eflag);
ragge
1.4
520         return 0;
ragge
1.1
521 }
522
ragge
1.36
523 /*
524  * exit and cleanup after interrupt.
525  */
ragge
1.4
526 void
527 idexit(int arg)
ragge
1.1
528 {
ragge
1.36
529         dexit(100);
ragge
1.1
530 }
531
ragge
1.36
532 /*
533  * exit and cleanup.
534  */
ragge
1.4
535 void
ragge
1.36
536 dexit(int eval)
ragge
1.1
537 {
ragge
1.10
538         if (!pflag && !Xflag) {
ragge
1.1
539                 if (sflag==0)
540                         cunlink(tmp3);
541                 cunlink(tmp4);
542         }
ragge
1.36
543         exit(eval);
ragge
1.1
544 }
545
ragge
1.36
546 static void
547 ccerror(char *sva_list ap)
ragge
1.1
548 {
ragge
1.36
549         vfprintf(Eflag ? stderr : stdoutsap);
ragge
1.8
550         putc('\n'Eflagstderr : stdout);
ragge
1.1
551         exfail++;
552         cflag++;
553         eflag++;
554 }
555
ragge
1.36
556 /*
557  * complain a bit.
558  */
559 void
560 error(char *s, ...)
561 {
562         va_list ap;
563
564         va_start(aps);
565         ccerror(sap);
566         va_end(ap);
567 }
568
569 /*
570  * complain a bit and then exit.
571  */
ragge
1.18
572 void
ragge
1.36
573 errorx(int evalchar *s, ...)
ragge
1.18
574 {
ragge
1.36
575         va_list ap;
576
577         va_start(aps);
578         ccerror(sap);
579         va_end(ap);
580         dexit(eval);
ragge
1.18
581 }
ragge
1.3
582
ragge
1.4
583 int
ragge
1.3
584 getsuf(as)
585 char as[];
ragge
1.1
586 {
587         register char *s;
588
ragge
1.4
589         if ((s = strrchr(as'.')) && s[1] != '\0' && s[2] == '\0')
590                 return s[1];
ragge
1.3
591         return(0);
ragge
1.1
592 }
593
ragge
1.36
594 /*
595  * Get basename of string s and change its suffix to ch.
596  */
ragge
1.1
597 char *
ragge
1.36
598 setsuf(char *schar ch)
ragge
1.1
599 {
ragge
1.36
600         s = copy(basename(s));
pj
1.31
601         s[strlen(s) - 1] = ch;
ragge
1.36
602         return(s);
ragge
1.1
603 }
604
ragge
1.4
605 int
ragge
1.3
606 callsys(fv)
607 char f[], *v[]; {
ragge
1.1
608         int tstatus;
ragge
1.4
609         char *s;
ragge
1.5
610
611         if (vflag) {
ragge
1.41
612                 fprintf(stderr"%s "f);
613                 for (t = 1v[t]; t++)
ragge
1.6
614                         fprintf(stderr"%s "v[t]);
615                 fprintf(stderr"\n");
ragge
1.5
616         }
ragge
1.1
617
ragge
1.3
618         if ((t=fork())==0) {
ragge
1.47
619                 if (Bflag) {
ragge
1.53
620                         int len = strlen(Bflag) + 8;
621                         char *a = malloc(len);
ragge
1.47
622                         if ((s = strrchr(f'/'))) {
ragge
1.53
623                                 strlcpy(aBflaglen);
624                                 strlcat(aslen);
ragge
1.47
625                                 execv(av);
626                         }
627                 }
ragge
1.1
628                 execv(fv);
ragge
1.4
629                 if ((s = strrchr(f'/')))
630                         execvp(s+1v);
ragge
1.1
631                 printf("Can't find %s\n"f);
ragge
1.3
632                 exit(100);
633         } else
634                 if (t == -1) {
635                         printf("Try again\n");
636                         return(100);
637                 }
638         while(t!=wait(&status));
ragge
1.1
639         if ((t=(status&0377)) != 0 && t!=14) {
ragge
1.3
640                 if (t!=2)               /* interrupt */
ragge
1.36
641                         errorx(8"Fatal error in %s"f);
642                 dexit(eflag);
ragge
1.1
643         }
ragge
1.3
644         return((status>>8) & 0377);
ragge
1.1
645 }
646
ragge
1.3
647 char *
pj
1.28
648 copy(char *as)
ragge
1.3
649 {
pj
1.28
650         char *p;
651
ragge
1.36
652         if ((p = strdup(as)) == NULL)
653                 errorx(8"no space for file names");
ragge
1.3
654
pj
1.28
655         return p;
ragge
1.3
656 }
657
ragge
1.4
658 int
ragge
1.3
659 nodup(los)
660 char **l, *os;
ragge
1.1
661 {
662         register char *t, *s;
663         register int c;
664
665         s = os;
666         if (getsuf(s) != 'o')
ragge
1.3
667                 return(1);
ragge
1.4
668         while((t = *l++)) {
669                 while((c = *s++))
ragge
1.1
670                         if (c != *t++)
671                                 break;
ragge
1.3
672                 if (*t=='\0' && c=='\0')
673                         return(0);
ragge
1.1
674                 s = os;
675         }
ragge
1.3
676         return(1);
ragge
1.1
677 }
678
ragge
1.4
679 int
ragge
1.3
680 cunlink(f)
681 char *f;
ragge
1.1
682 {
ragge
1.13
683         if (f==0 || Xflag)
ragge
1.3
684                 return(0);
685         return(unlink(f));
ragge
1.1
686 }
pj
1.30
687
688 char *
689 gettmp()
690 {
691         char *sfn = strdup("/tmp/ctm.XXXXXX");
692         int fd = -1;
693
694         if ((fd = mkstemp(sfn)) == -1) {
695                 fprintf(stderr"%s: %s\n"sfnstrerror(errno));
696                 exit(8);
697         }
698         close(fd);
699
700         return sfn;
701 }
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-08-20 08:53 +0200