Quick Search:

Mode

Context

Displaying 3 lines of context. None | Less | More | Full

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.35
 
1.36
 
MAIN:ragge:20041230152313
 
cc.c
_>4747  * This file should be rewritten readable.
 4848  */
 4949 #include <sys/types.h>
<> 50+#include <sys/wait.h>
5051 
 5152 #include <stdio.h>
 5253 #include <ctype.h>
     
 !
5556 #include <fcntl.h>
 5657 #include <unistd.h>
 5758 #include <stdlib.h>
<>58 -#include <sys/wait.h>
  59+#include <stdarg.h>
  60+#include <libgen.h>
5961 
 6062 #include "ccconfig.h"
 6163 /* C command */
     
 !
8284 char *copy(char *as),*setsuf(char *as, char ch);
 8385 int getsuf(char []);
 8486 int main(int, char *[]);
<>85 -void error(char *, char *);
 86 -void errorx(char *, char *, int);
  87+void error(char *, ...);
  88+void errorx(int eval, char *, ...);
8789 int nodup(char **, char *);
 8890 int callsys(char [], char *[]);
 8991 int cunlink(char *);
<>90 -void dexit(void);
  92+void dexit(int eval);
9193 void idexit(int);
 9294 char *gettmp();
 9395 char    *av[MAXAV];
     
 !
127129         char *t, *u;
 128130         char *assource;
 129131         char **pv, *ptemp[MAXOPT], **pvt;
<>130 -        int nc, nl, i, j, c, f20, nxo, na;
  132+        int nc, nl, i, j, c, nxo, na;
131133 
<>132 -        i = nc = nl = f20 = nxo = 0;
  134+        i = nc = nl = nxo = 0;
133135         pv = ptemp;
 134136         while(++i < argc) {
 135137                 if (argv[i][0] == '-')
     
 !
192194                         break;
 193195                 case 'o':
 194196                         if (outfile)
<>195 -                                errorx("too many -o", "", 8);
  197+                                errorx(8, "too many -o");
196198                         outfile = argv[++i];
 197199                         break;
 198200                 case 'O':
     
 !
217219                                 pref = "/lib/crt2.o";
 218220                         else {
 219221                                 pref = "/lib/crt20.o";
<>220 -                                f20 = 1;
221222                         }
 222223                         break;
 223224 #endif
     
 !
228229                         *pv++ = argv[i];
 229230                         if (pv >= ptemp+MAXOPT)
 230231                                 {
<>231 -                                error("Too many DIUC options", 0);
  232+                                error("Too many DIUC options");
232233                                 --pv;
 233234                                 }
 234235                         break;
     
 !
256257                                 clist[nc++] = t;
 257258                                 if (nc>=MAXFIL)
 258259                                         {
<>259 -                                        error("Too many source files",0);
  260+                                        error("Too many source files");
260261                                         exit(1);
 261262                                         }
 262263                                 t = setsuf(t, 'o');
     
 !
265266                                 llist[nl++] = t;
 266267                                 if (nl >= MAXLIB)
 267268                                         {
<>268 -                                        error("Too many object/library files",0);
  269+                                        error("Too many object/library files");
269270                                         exit(1);
 270271                                         }
 271272                                 if (getsuf(t)=='o')
     
 !
275276         }
 276277         /* Sanity checking */
 277278         if (nc == 0 && nl == 0)
<>278 -                errorx("no input files", "", 8);
  279+                errorx(8, "no input files");
279280         if (outfile && (cflag || sflag) && nc > 1)
<>280 -                errorx("-o given with -c || -S and more than one file", "", 8);
  281+                errorx(8, "-o given with -c || -S and more than one file");
281282         if (outfile && clist[0] && strcmp(outfile, clist[0]) == 0)
<>282 -                errorx("output file will be clobbered", "", 8);
  283+                errorx(8, "output file will be clobbered");
283284 
 284285         if (gflag) Oflag = 0;
 285286 #if 0
     
 !
334335                 if (callsys(passp, av))
 335336                         {exfail++; eflag++;}
 336337                 if (Eflag)
<>337 -                        dexit();
  338+                        dexit(eflag);
338339                 if (xflag)
 339340                         goto assemble;
 340341 
     
 !
427428                 while(i<nl) {
 428429                         av[j++] = llist[i++];
 429430                         if (j >= MAXAV)
<>430 -                                error("Too many ld options", 0);
  431+                                error("Too many ld options");
431432                 }
 432433 #if 0
 433434                 if (gflag)
     
 !
438439                         for (i = 0; endfiles[i]; i++)
 439440                                 av[j++] = endfiles[i];
 440441                 }
<>441 -                if(f20)
 442 -                        av[j++] = "-l2";
443442                 av[j++] = 0;
 444443                 eflag |= callsys("/bin/ld", av);
 445444                 if (nc==1 && nxo==1 && eflag==0)
 446445                         cunlink(setsuf(clist[0], 'o'));
 447446         }
<>448 -        dexit();
  447+        dexit(eflag);
449448         return 0;
 450449 }
 451450 
<> 451+/*
  452+ * exit and cleanup after interrupt.
  453+ */
452454 void
 453455 idexit(int arg)
 454456 {
<>455 -        eflag = 100;
 456 -        dexit();
  457+        dexit(100);
457458 }
 458459 
<> 460+/*
  461+ * exit and cleanup.
  462+ */
459463 void
<>460 -dexit()
  464+dexit(int eval)
461465 {
 462466         if (!pflag && !Xflag) {
 463467                 if (sflag==0)
 464468                         cunlink(tmp3);
 465469                 cunlink(tmp4);
 466470         }
<>467 -        exit(eflag);
  471+        exit(eval);
468472 }
 469473 
<>470 -void
 471 -error(char *s, char *x)
  474+static void
  475+ccerror(char *s, va_list ap)
472476 {
<>473 -        fprintf(Eflag?stderr:stdout , s, x);
  477+        vfprintf(Eflag ? stderr : stdout, s, ap);
474478         putc('\n', Eflag? stderr : stdout);
 475479         exfail++;
 476480         cflag++;
 477481         eflag++;
 478482 }
 479483 
<> 484+/*
  485+ * complain a bit.
  486+ */
480487 void
<>481 -errorx(char *s, char *x, int eval)
  488+error(char *s, ...)
482489 {
<>483 -        error(s, x);
 484 -        exit(eval);
  490+        va_list ap;
  491+
  492+        va_start(ap, s);
  493+        ccerror(s, ap);
  494+        va_end(ap);
485495 }
 486496 
<> 497+/*
  498+ * complain a bit and then exit.
  499+ */
  500+void
  501+errorx(int eval, char *s, ...)
  502+{
  503+        va_list ap;
  504+
  505+        va_start(ap, s);
  506+        ccerror(s, ap);
  507+        va_end(ap);
  508+        dexit(eval);
  509+}
  510+
487511 int
 488512 getsuf(as)
 489513 char as[];
     
 !
495519         return(0);
 496520 }
 497521 
<> 522+/*
  523+ * Get basename of string s and change its suffix to ch.
  524+ */
498525 char *
<>499 -setsuf(char *as, char ch)
  526+setsuf(char *s, char ch)
500527 {
<>501 -        char *s, *s1;
 502 -
 503 -        s = s1 = as;
 504 -        while(*s)
 505 -                if (*s++ == '/')
 506 -                        s1 = s;
 507 -
 508 -        s = copy(s1);
  528+        s = copy(basename(s));
509529         s[strlen(s) - 1] = ch;
<>510 -        return(s1);
  530+        return(s);
511531 }
 512532 
 513533 int
     
 !
536556         while(t!=wait(&status));
 537557         if ((t=(status&0377)) != 0 && t!=14) {
 538558                 if (t!=2)               /* interrupt */
<>539 -                        {
 540 -                        printf("Fatal error in %s\n", f);
 541 -                        eflag = 8;
 542 -                        }
 543 -                dexit();
  559+                        errorx(8, "Fatal error in %s", f);
  560+                dexit(eflag);
544561         }
 545562         return((status>>8) & 0377);
 546563 }
     
 !
550567 {
 551568         char *p;
 552569 
<>553 -        if ((p = strdup(as)) == NULL) {
 554 -                error("no space for file names", 0);
 555 -                eflag = 8;
 556 -                dexit();
 557 -        }
  570+        if ((p = strdup(as)) == NULL)
  571+                errorx(8, "no space for file names");
<_558572 
 559573         return p;
 560574 }
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-02 14:30 +0200