home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d0xx / d043 / cc.lha / Cc / lattice / laterrs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-12-01  |  3.8 KB  |  199 lines

  1. /* Z editor options
  2. :ma=1
  3. :ts=6
  4. :bk=0
  5. :wm=0
  6. */
  7.  
  8. /*
  9.     This program, both executable and sources, are
  10.     Copyright 1986, Jay Ts,  Box 890 West Oneonta NY 13861.
  11.     You may copy, distribute, alter, and use them, but absolutely no
  12.     permission is granted to remove copyright notices from them or
  13.     distribute them, in whole or in part, as, or as part of, a
  14.     commercial product.
  15. */
  16.  
  17. #include "lc.h"
  18. #define MAXERRS 20    /* stop after this many errors were found */
  19.  
  20. /* 
  21.     Reformat Lattice's error messages from the
  22.     different phases of compilation
  23. */
  24.  
  25. int geterrs(fname,srcname,phase,lintflag)
  26. char *fname;
  27. char *srcname;
  28. int phase;
  29. int lintflag;
  30. {
  31.     FILE *fp;
  32.     int c;
  33.     int reterr = 0, numerrs = 0;
  34.     int i, firstline = 1, linenum, EWnum;
  35.     char ErrWarn[16];
  36.     long pos;
  37.     char *str;
  38.     char c2str[16], linkstr[16];
  39.     char s[256];
  40.  
  41.     strcpy(c2str,"Module size P=");
  42.     strcpy(linkstr,"Linking comple");
  43.  
  44.     if( (fp = fopen(fname, "r")) == NULL)
  45.     {
  46.         printf("open failed on error file %s\n", fname);
  47.         exit(1);
  48.     }
  49.  
  50.     /* skip over "Hello, I am the C compiler" type messages */
  51.  
  52.     switch(phase)
  53.     {
  54.         case c1phase:
  55.         case c2phase:
  56.             c = fseek(fp, 80L, 0);
  57.             break;
  58.         case asphase:
  59.             c = fseek(fp, 114L, 0);
  60.             break;
  61.         case lkphase:
  62.             c = fseek(fp, 100L, 0);
  63.             break;
  64.         default:
  65.             printf("bad error file reference %d\n", fname);
  66.             break;
  67.     }
  68.     if(c == -1) printf("seek failed on error file %s\n", fname);
  69.  
  70.     /* now go through rest of file, cleverly picking out useful info */
  71.  
  72.     if(phase == c1phase)    /* phase 1, done by lc1 */
  73.     {
  74.         do
  75.         {
  76.             pos = ftell(fp);
  77.  
  78.             if((c = fscanf(fp,"%*s %d %s %d:", &linenum,ErrWarn,&EWnum))
  79.                 == 4)
  80.             {
  81.                  if( ErrWarn[0] == 'E'
  82.                 || (ErrWarn[0] == 'W' && lintflag))
  83.                  {
  84.                       numerrs++;
  85.  
  86.                       if(firstline)
  87.                       {
  88.                            firstline = 0;
  89.                            reterr = c1error;
  90.                            printf("%s:\n",srcname);
  91.                       }
  92.                       printf("%7d: (%c%3d) ",
  93.                         linenum,ErrWarn[0],EWnum);
  94.                       do
  95.                       {
  96.                            if((c = fgetc(fp)) == EOF)
  97.                         {
  98.                             putc('\n',stdout);
  99.                             break;
  100.                         }
  101.                            fputc(c,stdout);
  102.                       }
  103.                       while(c != '\n');
  104.                     fflush(stdout);
  105.                  }
  106.                  else if(ErrWarn[0] == 'W')
  107.                     while((c = fgetc(fp)) != '\n' && c != EOF);
  108.                  else printf("lc: unrecognized output from lc1\n");
  109.             }
  110.             else
  111.             {
  112.                  if(c == EOF) break;
  113.  
  114.                  if(pos > 0) fseek(fp, pos, 0);
  115.                  else
  116.                  {
  117.                       DeleteFile(fname);
  118.                       exit();
  119.                  }
  120.  
  121.                  do
  122.                  {
  123.                       if((c = fgetc(fp)) == EOF)
  124.                     {
  125.                         putc('\n',stdout);
  126.                         break;
  127.                     }
  128.                       fputc(c,stdout);
  129.                  }
  130.                  while(c != '\n');
  131.                 fflush(stdout);
  132.             }
  133.         }
  134.         while(c != EOF && numerrs < MAXERRS);
  135.     }
  136.     else if(phase == asphase) /* from assembling */
  137.     {
  138.         do
  139.         {
  140.             while((c = fgetc(fp)) != '\n' && c != EOF);
  141.             if((c = fgetc(fp)) == '*')
  142.             {
  143.                  numerrs++;
  144.  
  145.                  if(firstline)
  146.                  {
  147.                       firstline = 0;
  148.                       reterr = c1error;
  149.                       printf("%s:\n",srcname);
  150.                  }
  151.  
  152.                  i = 0;
  153.                  while(c == '*') c = fgetc(fp);
  154.                  for(i = 0; (s[i] = '\0'), c != '\n'; c = fgetc(fp))
  155.                     s[i++] = c;
  156.  
  157.                  fscanf(fp,"%*s %*s %d: %*s %*s", &linenum);
  158.                  printf("%d:%s\n\t", linenum,s);
  159.                  while((c = fgetc(fp)) != '\n') fputc(c,stdout);
  160.                  fputc('\n',stdout);
  161.             }
  162.         }
  163.         while(c != EOF && numerrs < MAXERRS);
  164.     }
  165.     else    /* from phase 2, done by lc2 */
  166.     {
  167.         if(phase == c2phase) str = c2str;
  168.         else str = linkstr;
  169.  
  170.         while((c = fgetc(fp)) != EOF)
  171.         {
  172.             if(c != str[0])
  173.             {
  174.                  fputc(c,stdout);
  175.                  while((c = fgetc(fp)) != '\n') fputc(c,stdout);
  176.                  fputc('\n',stdout);
  177.                  reterr = othererror;
  178.             }
  179.             else
  180.             {
  181.                  pos = ftell(fp);
  182.                  for(i = 1; i < 14; i++)
  183.                  if(fgetc(fp) != str[i])
  184.                  {
  185.                       fseek(fp,pos,0);
  186.                       fputc(fgetc(fp),stdout);
  187.                       break;
  188.                  }
  189.                  if(i > 10) break; else continue;
  190.             }
  191.         }
  192.     }
  193.  
  194.     if( fclose(fp) == -1) printf("close failed on error file %s\n", fname);
  195.     if( ! DeleteFile(fname)) printf("couldn't delete %s\n",fname);
  196.  
  197.     return(reterr);
  198. }
  199.