home *** CD-ROM | disk | FTP | other *** search
- /* Z editor options
- :ma=1
- :ts=6
- :bk=0
- :wm=0
- */
-
- /*
- This program, both executable and sources, are
- Copyright 1986, Jay Ts, Box 890 West Oneonta NY 13861.
- You may copy, distribute, alter, and use them, but absolutely no
- permission is granted to remove copyright notices from them or
- distribute them, in whole or in part, as, or as part of, a
- commercial product.
- */
-
- #include "lc.h"
- #define MAXERRS 20 /* stop after this many errors were found */
-
- /*
- Reformat Lattice's error messages from the
- different phases of compilation
- */
-
- int geterrs(fname,srcname,phase,lintflag)
- char *fname;
- char *srcname;
- int phase;
- int lintflag;
- {
- FILE *fp;
- int c;
- int reterr = 0, numerrs = 0;
- int i, firstline = 1, linenum, EWnum;
- char ErrWarn[16];
- long pos;
- char *str;
- char c2str[16], linkstr[16];
- char s[256];
-
- strcpy(c2str,"Module size P=");
- strcpy(linkstr,"Linking comple");
-
- if( (fp = fopen(fname, "r")) == NULL)
- {
- printf("open failed on error file %s\n", fname);
- exit(1);
- }
-
- /* skip over "Hello, I am the C compiler" type messages */
-
- switch(phase)
- {
- case c1phase:
- case c2phase:
- c = fseek(fp, 80L, 0);
- break;
- case asphase:
- c = fseek(fp, 114L, 0);
- break;
- case lkphase:
- c = fseek(fp, 100L, 0);
- break;
- default:
- printf("bad error file reference %d\n", fname);
- break;
- }
- if(c == -1) printf("seek failed on error file %s\n", fname);
-
- /* now go through rest of file, cleverly picking out useful info */
-
- if(phase == c1phase) /* phase 1, done by lc1 */
- {
- do
- {
- pos = ftell(fp);
-
- if((c = fscanf(fp,"%*s %d %s %d:", &linenum,ErrWarn,&EWnum))
- == 4)
- {
- if( ErrWarn[0] == 'E'
- || (ErrWarn[0] == 'W' && lintflag))
- {
- numerrs++;
-
- if(firstline)
- {
- firstline = 0;
- reterr = c1error;
- printf("%s:\n",srcname);
- }
- printf("%7d: (%c%3d) ",
- linenum,ErrWarn[0],EWnum);
- do
- {
- if((c = fgetc(fp)) == EOF)
- {
- putc('\n',stdout);
- break;
- }
- fputc(c,stdout);
- }
- while(c != '\n');
- fflush(stdout);
- }
- else if(ErrWarn[0] == 'W')
- while((c = fgetc(fp)) != '\n' && c != EOF);
- else printf("lc: unrecognized output from lc1\n");
- }
- else
- {
- if(c == EOF) break;
-
- if(pos > 0) fseek(fp, pos, 0);
- else
- {
- DeleteFile(fname);
- exit();
- }
-
- do
- {
- if((c = fgetc(fp)) == EOF)
- {
- putc('\n',stdout);
- break;
- }
- fputc(c,stdout);
- }
- while(c != '\n');
- fflush(stdout);
- }
- }
- while(c != EOF && numerrs < MAXERRS);
- }
- else if(phase == asphase) /* from assembling */
- {
- do
- {
- while((c = fgetc(fp)) != '\n' && c != EOF);
- if((c = fgetc(fp)) == '*')
- {
- numerrs++;
-
- if(firstline)
- {
- firstline = 0;
- reterr = c1error;
- printf("%s:\n",srcname);
- }
-
- i = 0;
- while(c == '*') c = fgetc(fp);
- for(i = 0; (s[i] = '\0'), c != '\n'; c = fgetc(fp))
- s[i++] = c;
-
- fscanf(fp,"%*s %*s %d: %*s %*s", &linenum);
- printf("%d:%s\n\t", linenum,s);
- while((c = fgetc(fp)) != '\n') fputc(c,stdout);
- fputc('\n',stdout);
- }
- }
- while(c != EOF && numerrs < MAXERRS);
- }
- else /* from phase 2, done by lc2 */
- {
- if(phase == c2phase) str = c2str;
- else str = linkstr;
-
- while((c = fgetc(fp)) != EOF)
- {
- if(c != str[0])
- {
- fputc(c,stdout);
- while((c = fgetc(fp)) != '\n') fputc(c,stdout);
- fputc('\n',stdout);
- reterr = othererror;
- }
- else
- {
- pos = ftell(fp);
- for(i = 1; i < 14; i++)
- if(fgetc(fp) != str[i])
- {
- fseek(fp,pos,0);
- fputc(fgetc(fp),stdout);
- break;
- }
- if(i > 10) break; else continue;
- }
- }
- }
-
- if( fclose(fp) == -1) printf("close failed on error file %s\n", fname);
- if( ! DeleteFile(fname)) printf("couldn't delete %s\n",fname);
-
- return(reterr);
- }
-