Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:stefan:20071022213844

Diff

Diff from 1.73 to:

Annotations

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

Annotated File View

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