Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20070918204110

Diff

Diff from 1.58 to:

Annotations

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

Annotated File View

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