9front - general discussion about 9front
 help / color / mirror / Atom feed
From: ori@eigenstate.org
To: 9front@9front.org
Subject: [PATCH] Fix yacc error messages.
Date: Wed, 11 Dec 2019 14:30:12 -0800	[thread overview]
Message-ID: <963C9871BB6B58DED6E4A93B48B07C0D@eigenstate.org> (raw)

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



                 reply	other threads:[~2019-12-11 22:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=963C9871BB6B58DED6E4A93B48B07C0D@eigenstate.org \
    --to=ori@eigenstate.org \
    --cc=9front@9front.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).