Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20070917181612

Diff

Diff from 1.57 to:

Annotations

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

Annotated File View

ragge
1.57
1 /*      $Id: cc.c,v 1.57 2007/09/17 18:16:12 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.57
372                 if (dflag)
373                         av[na++] = alist;
ragge
1.5
374                 for (j = 0cppadd[j]; j++)
375                         av[na++] = cppadd[j];
ragge
1.24
376                 for (j = 0cppmdadd[j]; j++)
377                         av[na++] = cppmdadd[j];
ragge
1.7
378                 if (tflag)
ragge
1.20
379                         av[na++] = "-t";
ragge
1.7
380                 for(pv=ptemppv <pvtpv++)
381                         av[na++] = *pv;
ragge
1.52
382                 if (!nostdinc)
383                         av[na++] = "-S"av[na++] = STDINC;
ragge
1.5
384                 av[na++] = clist[i];
ragge
1.51
385                 if (!Eflag && !Mflag)
ragge
1.20
386                         av[na++] = tmp4;
ragge
1.3
387                 av[na++]=0;
388                 if (callsys(passpav))
389                         {exfail++; eflag++;}
ragge
1.51
390                 if (Eflag || Mflag)
ragge
1.37
391                         continue;
ragge
1.43
392                 if (onlyas)
ragge
1.7
393                         goto assemble;
ragge
1.18
394
395                 /*
396                  * C compiler
397                  */
ragge
1.25
398                 na = 0;
399                 av[na++]= "ccom";
400                 if (gflag)
401                         av[na++] = "-g";
ragge
1.49
402                 if (kflag)
403                         av[na++] = "-k";
ragge
1.44
404                 if (Oflag) {
405                         av[na++] = "-xtemps";
406                 }
ragge
1.45
407                 for (j = 0j < xnumj++)
408                         av[na++] = xlist[j];
ragge
1.25
409                 av[na++] = tmp4;
ragge
1.3
410                 if (pflag || exfail)
411                         {
ragge
1.1
412                         cflag++;
413                         continue;
ragge
1.3
414                         }
ragge
1.16
415                 if(sflag) {
416                         if (outfile)
417                                 assource = tmp3 = outfile;
418                         else
419                                 assource = tmp3 = setsuf(clist[i], 's');
420                 }
ragge
1.25
421                 av[na++] = tmp3;
422 #if 0
ragge
1.3
423                 if (proflag) {
424                         av[3] = "-XP";
425                         av[4] = 0;
426                 } else
427                         av[3] = 0;
ragge
1.25
428 #endif
429                 av[na++] = NULL;
ragge
1.3
430                 if (callsys(pass0av)) {
ragge
1.1
431                         cflag++;
432                         eflag++;
433                         continue;
434                 }
435                 if (sflag)
436                         continue;
ragge
1.18
437
438                 /*
439                  * Assembler
440                  */
ragge
1.1
441         assemble:
ragge
1.49
442                 na = 0;
443                 av[na++] = "as";
444                 if (kflag)
445                         av[na++] = "-k";
446                 av[na++] = "-o";
ragge
1.18
447                 if (outfile && cflag)
ragge
1.49
448                         av[na++] = outfile;
ragge
1.18
449                 else
ragge
1.49
450                         av[na++] = setsuf(clist[i], 'o');
451                 av[na++] = onlyas ? tmp4 : assource;
452                 if (dflag)
453                         av[na++] = alist;
454                 av[na++] = 0;
ragge
1.21
455                 if (callsys("/bin/as"av)) {
ragge
1.1
456                         cflag++;
457                         eflag++;
ragge
1.7
458                         cunlink(tmp4);
ragge
1.1
459                         continue;
460                 }
ragge
1.7
461                 cunlink(tmp4);
ragge
1.1
462         }
ragge
1.18
463
ragge
1.51
464         if (Eflag || Mflag)
ragge
1.37
465                 dexit(eflag);
466
ragge
1.18
467         /*
468          * Linker
469          */
ragge
1.1
470 nocom:
471         if (cflag==0 && nl!=0) {
ragge
1.6
472                 j = 0;
473                 av[j++] = "ld";
474                 av[j++] = "-X";
475                 av[j++] = "-d";
476                 av[j++] = "-e";
ragge
1.48
477                 av[j++] = STARTLABEL;
ragge
1.14
478                 if (Bstatic == 0) { /* Dynamic linkage */
ragge
1.24
479                         for (i = 0dynlinker[i]; i++)
480                                 av[j++] = dynlinker[i];
ragge
1.54
481                 } else
482                         av[j++] = "-Bstatic";
ragge
1.1
483                 if (outfile) {
ragge
1.3
484                         av[j++] = "-o";
485                         av[j++] = outfile;
486                 }
ragge
1.14
487                 if (!nostartfiles) {
ragge
1.24
488                         av[j++] = crt0file;
489                         for (i = 0startfiles[i]; i++)
490                                 av[j++] = startfiles[i];
ragge
1.14
491                 }
ragge
1.24
492                 i = 0;
ragge
1.14
493                 while(i<nl) {
ragge
1.3
494                         av[j++] = llist[i++];
ragge
1.14
495                         if (j >= MAXAV)
ragge
1.36
496                                 error("Too many ld options");
ragge
1.14
497                 }
ragge
1.11
498 #if 0
ragge
1.3
499                 if (gflag)
500                         av[j++] = "-lg";
ragge
1.11
501 #endif
ragge
1.52
502                 if (pthreads)
503                         av[j++] = "-lpthread";
504                 if (!nostdlib)
505                         for (i = 0libclibs[i]; i++)
506                                 av[j++] = libclibs[i];
ragge
1.14
507                 if (!nostartfiles) {
ragge
1.24
508                         for (i = 0endfiles[i]; i++)
509                                 av[j++] = endfiles[i];
ragge
1.14
510                 }
ragge
1.3
511                 av[j++] = 0;
512                 eflag |= callsys("/bin/ld"av);
ragge
1.1
513                 if (nc==1 && nxo==1 && eflag==0)
ragge
1.3
514                         cunlink(setsuf(clist[0], 'o'));
ragge
1.46
515                 else if (nc > 0 && eflag == 0) {
516                         /* remove .o files XXX ugly */
517                         for (i = 0i < nci++)
518                                 cunlink(setsuf(clist[i], 'o'));
519                 }
ragge
1.1
520         }
ragge
1.36
521         dexit(eflag);
ragge
1.4
522         return 0;
ragge
1.1
523 }
524
ragge
1.36
525 /*
526  * exit and cleanup after interrupt.
527  */
ragge
1.4
528 void
529 idexit(int arg)
ragge
1.1
530 {
ragge
1.36
531         dexit(100);
ragge
1.1
532 }
533
ragge
1.36
534 /*
535  * exit and cleanup.
536  */
ragge
1.4
537 void
ragge
1.36
538 dexit(int eval)
ragge
1.1
539 {
ragge
1.10
540         if (!pflag && !Xflag) {
ragge
1.1
541                 if (sflag==0)
542                         cunlink(tmp3);
543                 cunlink(tmp4);
544         }
ragge
1.36
545         exit(eval);
ragge
1.1
546 }
547
ragge
1.36
548 static void
549 ccerror(char *sva_list ap)
ragge
1.1
550 {
ragge
1.36
551         vfprintf(Eflag ? stderr : stdoutsap);
ragge
1.8
552         putc('\n'Eflagstderr : stdout);
ragge
1.1
553         exfail++;
554         cflag++;
555         eflag++;
556 }
557
ragge
1.36
558 /*
559  * complain a bit.
560  */
561 void
562 error(char *s, ...)
563 {
564         va_list ap;
565
566         va_start(aps);
567         ccerror(sap);
568         va_end(ap);
569 }
570
571 /*
572  * complain a bit and then exit.
573  */
ragge
1.18
574 void
ragge
1.36
575 errorx(int evalchar *s, ...)
ragge
1.18
576 {
ragge
1.36
577         va_list ap;
578
579         va_start(aps);
580         ccerror(sap);
581         va_end(ap);
582         dexit(eval);
ragge
1.18
583 }
ragge
1.3
584
ragge
1.4
585 int
ragge
1.3
586 getsuf(as)
587 char as[];
ragge
1.1
588 {
589         register char *s;
590
ragge
1.4
591         if ((s = strrchr(as'.')) && s[1] != '\0' && s[2] == '\0')
592                 return s[1];
ragge
1.3
593         return(0);
ragge
1.1
594 }
595
ragge
1.36
596 /*
597  * Get basename of string s and change its suffix to ch.
598  */
ragge
1.1
599 char *
ragge
1.36
600 setsuf(char *schar ch)
ragge
1.1
601 {
ragge
1.36
602         s = copy(basename(s));
pj
1.31
603         s[strlen(s) - 1] = ch;
ragge
1.36
604         return(s);
ragge
1.1
605 }
606
ragge
1.4
607 int
ragge
1.56
608 callsys(char f[], char *v[])
609 {
610         int status;
611         pid_t t;
ragge
1.4
612         char *s;
ragge
1.5
613
614         if (vflag) {
ragge
1.41
615                 fprintf(stderr"%s "f);
616                 for (t = 1v[t]; t++)
ragge
1.6
617                         fprintf(stderr"%s "v[t]);
618                 fprintf(stderr"\n");
ragge
1.5
619         }
ragge
1.1
620
ragge
1.3
621         if ((t=fork())==0) {
ragge
1.47
622                 if (Bflag) {
ragge
1.56
623                         size_t len = strlen(Bflag) + 8;
ragge
1.53
624                         char *a = malloc(len);
ragge
1.56
625                         if (a == NULL)
626                                 errorx(1"callsys: malloc failed\n");
ragge
1.47
627                         if ((s = strrchr(f'/'))) {
ragge
1.53
628                                 strlcpy(aBflaglen);
629                                 strlcat(aslen);
ragge
1.47
630                                 execv(av);
631                         }
632                 }
ragge
1.1
633                 execv(fv);
ragge
1.4
634                 if ((s = strrchr(f'/')))
635                         execvp(s+1v);
ragge
1.1
636                 printf("Can't find %s\n"f);
ragge
1.3
637                 exit(100);
638         } else
639                 if (t == -1) {
640                         printf("Try again\n");
641                         return(100);
642                 }
643         while(t!=wait(&status));
ragge
1.1
644         if ((t=(status&0377)) != 0 && t!=14) {
ragge
1.3
645                 if (t!=2)               /* interrupt */
ragge
1.36
646                         errorx(8"Fatal error in %s"f);
647                 dexit(eflag);
ragge
1.1
648         }
ragge
1.3
649         return((status>>8) & 0377);
ragge
1.1
650 }
651
ragge
1.3
652 char *
pj
1.28
653 copy(char *as)
ragge
1.3
654 {
pj
1.28
655         char *p;
656
ragge
1.36
657         if ((p = strdup(as)) == NULL)
658                 errorx(8"no space for file names");
ragge
1.3
659
pj
1.28
660         return p;
ragge
1.3
661 }
662
ragge
1.4
663 int
ragge
1.3
664 nodup(los)
665 char **l, *os;
ragge
1.1
666 {
667         register char *t, *s;
668         register int c;
669
670         s = os;
671         if (getsuf(s) != 'o')
ragge
1.3
672                 return(1);
ragge
1.4
673         while((t = *l++)) {
674                 while((c = *s++))
ragge
1.1
675                         if (c != *t++)
676                                 break;
ragge
1.3
677                 if (*t=='\0' && c=='\0')
678                         return(0);
ragge
1.1
679                 s = os;
680         }
ragge
1.3
681         return(1);
ragge
1.1
682 }
683
ragge
1.4
684 int
ragge
1.3
685 cunlink(f)
686 char *f;
ragge
1.1
687 {
ragge
1.13
688         if (f==0 || Xflag)
ragge
1.3
689                 return(0);
690         return(unlink(f));
ragge
1.1
691 }
pj
1.30
692
693 char *
694 gettmp()
695 {
696         char *sfn = strdup("/tmp/ctm.XXXXXX");
697         int fd = -1;
698
699         if ((fd = mkstemp(sfn)) == -1) {
700                 fprintf(stderr"%s: %s\n"sfnstrerror(errno));
701                 exit(8);
702         }
703         close(fd);
704
705         return sfn;
706 }
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-10-31 15:20 +0100