* [PATCH] Fix yacc error messages.
@ 2019-12-11 22:30 ori
0 siblings, 0 replies; only message in thread
From: ori @ 2019-12-11 22:30 UTC (permalink / raw)
To: 9front
Was playing with rc changes, and ran into a bug in yacc
error messages. Here's the fix. Two changes:
- Close the Biobuf on error. This prevents spurious Blethal
errors.
- Clean up the formatting of the error messages. Remove stray
newlines, and bring them in line with cc.
Before:
yacc syn.y
fatal error:must specify type for comwords, /sys/src/cmd/rc/syn.y:73
yacc: write error: phase error -- directory entry not allocated
After:
syn.y:73: fatal error:must specify type for comwords
diff -r f1523de908ce sys/src/cmd/yacc.c
--- a/sys/src/cmd/yacc.c Tue Dec 10 23:13:25 2019 -0800
+++ b/sys/src/cmd/yacc.c Wed Dec 11 14:29:16 2019 -0800
@@ -125,7 +125,10 @@
/* command to clobber tempfiles after use */
-#define ZAPFILE(x) if(x) remove(x)
+#define ZAPFILE(bfd, x) {\
+ if(bfd) Bterm(bfd); \
+ if(x) remove(x); \
+ }
/* I/O descriptors */
@@ -140,6 +143,7 @@
/* communication variables between various I/O routines */
char* infile; /* input file name */
+char* inpath; /* input full path */
int numbval; /* value of an input number */
char tokname[NAMESIZE+UTFmax+1]; /* input token name, slop for runes and 0 */
@@ -486,8 +490,7 @@
Blethal(faction, nil);
while((c=Bgetrune(faction)) != Beof)
Bputrune(ftable, c);
- Bterm(faction);
- ZAPFILE(actname);
+ ZAPFILE(faction, actname);
c = Bgetrune(finput);
}
}
@@ -617,11 +620,14 @@
void
error(char *s, ...)
{
+ va_list ap;
nerrors++;
- fprint(2, "\n fatal error:");
- fprint(2, s, (&s)[1]);
- fprint(2, ", %s:%d\n", infile, lineno);
+ va_start(ap, s);
+ fprint(2, "%s:%d: fatal error: ", infile, lineno);
+ vfprint(2, s, ap);
+ fprint(2, "\n");
+ va_end(ap);
if(!fatfl)
return;
summary();
@@ -1155,8 +1161,8 @@
void
cleantmp(void)
{
- ZAPFILE(actname);
- ZAPFILE(tempname);
+ ZAPFILE(faction, actname);
+ ZAPFILE(ftemp, tempname);
}
void
@@ -1231,10 +1237,10 @@
if(s != nil){
snprint(s, i, "%s/%s", dirbuf, infile);
cleanname(s);
- infile = s;
+ inpath = s;
}
}
- finput = Bopen(infile, OREAD);
+ finput = Bopen(inpath, OREAD);
if(finput == 0)
error("cannot open '%s'", argv[0]);
Blethal(finput, nil);
@@ -1509,7 +1515,7 @@
finact();
if(t == MARK) {
- Bprint(ftable, "\n#line\t%d\t\"%s\"\n", lineno, infile);
+ Bprint(ftable, "\n#line\t%d\t\"%s\"\n", lineno, inpath);
while((c=Bgetrune(finput)) != Beof)
Bputrune(ftable, c);
}
@@ -1845,7 +1851,7 @@
long c;
int level;
- Bprint(ftable, "\n#line\t%d\t\"%s\"\n", lineno, infile);
+ Bprint(ftable, "\n#line\t%d\t\"%s\"\n", lineno, inpath);
Bprint(ftable, "typedef union ");
if(fdefine != 0)
Bprint(fdefine, "\ntypedef union ");
@@ -1892,7 +1898,7 @@
c = Bgetrune(finput);
lineno++;
}
- Bprint(ftable, "\n#line\t%d\t\"%s\"\n", lineno, infile);
+ Bprint(ftable, "\n#line\t%d\t\"%s\"\n", lineno, inpath);
while(c != Beof) {
if(c == '\\') {
if((c=Bgetrune(finput)) == '}')
@@ -1953,7 +1959,7 @@
long c;
int brac, match, j, s, fnd, tok;
- Bprint(faction, "\n#line\t%d\t\"%s\"\n", lineno, infile);
+ Bprint(faction, "\n#line\t%d\t\"%s\"\n", lineno, inpath);
brac = 0;
loop:
@@ -2735,7 +2741,7 @@
/* write out the output appropriate to the language */
aoutput();
osummary();
- ZAPFILE(tempname);
+ ZAPFILE(ftemp, tempname);
}
void
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2019-12-11 22:30 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-11 22:30 [PATCH] Fix yacc error messages ori
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).