improved (plumb(1)'able) error messages from lex(1). Reference: /n/sources/patch/applied/lex-err-msgs Date: Wed Dec 17 17:32:52 CET 2008 Signed-off-by: steve@quintile.net --- /sys/src/cmd/lex/lmain.c Wed Dec 17 17:31:34 2008 +++ /sys/src/cmd/lex/lmain.c Wed Dec 17 17:31:31 2008 @@ -32,6 +32,7 @@ char **sargv; uchar buf[520]; int yyline; /* line number of file */ +char *yyfile; /* filename for error messages */ int eof; int lgatflg; int divflg; @@ -119,13 +120,15 @@ sargc = argc; sargv = argv; if (argc > 0){ - fin = Bopen(argv[fptr++], OREAD); + yyfile = argv[fptr++]; + fin = Bopen(yyfile, OREAD); if(fin == 0) - error ("Can't read input file %s",argv[0]); + error ("%s - can't open file", yyfile); sargc--; sargv++; } else { + yyfile = "stdin"; fin = myalloc(sizeof(Biobuf), 1); if(fin == 0) exits("core"); @@ -289,5 +292,5 @@ void yyerror(char *s) { - fprint(2, "line %d: %s\n", yyline, s); + fprint(2, "%s:%d %s\n", yyfile, yyline, s); } --- /sys/src/cmd/lex/ldefs.h Wed Dec 17 17:31:41 2008 +++ /sys/src/cmd/lex/ldefs.h Wed Dec 17 17:31:37 2008 @@ -68,6 +68,7 @@ extern char **sargv; extern uchar buf[520]; extern int yyline; /* line number of file */ +extern char *yyfile; /* file name of file */ extern int sect; extern int eof; extern int lgatflg; --- /sys/src/cmd/lex/sub1.c Wed Dec 17 17:31:48 2008 +++ /sys/src/cmd/lex/sub1.c Wed Dec 17 17:31:44 2008 @@ -21,7 +21,7 @@ { char buf[1024]; - if(!eof)fprint(errorf,"%d: ",yyline); + if(!eof)fprint(errorf,"%s:%d ", yyfile, yyline); fprint(errorf,"(%s) ", type); vseprint(buf, buf+sizeof(buf), fmt, argl); fprint(errorf, "%s\n", buf); @@ -174,10 +174,12 @@ { /* copy C action to the next ; or closing } */ int brac, c, mth; int savline, sw; + char *savfile; brac = 0; sw = TRUE; savline = 0; + savfile = "?"; while(!eof){ c = gch(); @@ -201,6 +203,7 @@ case '{': brac++; savline=yyline; + savfile=yyfile; break; case '}': @@ -221,6 +224,7 @@ Bputc(&fout, c); savline=yyline; + savfile=yyfile; while( c=gch() ){ if( c=='*' ){ Bputc(&fout, c); @@ -229,6 +233,7 @@ Bputc(&fout, c); } yyline=savline; + yyfile=savfile; error( "EOF inside comment" ); case '\'': /* character constant */ @@ -257,6 +262,7 @@ case '\0': yyline = savline; + yyfile = savfile; error("Action does not terminate"); default: break; /* usual character */ @@ -277,9 +283,10 @@ peek = pushptr > pushc ? *--pushptr : Bgetc(fin); if(peek == Beof && sargc > 1){ Bterm(fin); - fin = Bopen(sargv[fptr++],OREAD); + yyfile = sargv[fptr++]; + fin = Bopen(yyfile,OREAD); if(fin == 0) - error("Cannot open file %s",sargv[fptr-1]); + error("%s - cannot open file",yyfile); peek = Bgetc(fin); sargc--; sargv++;