From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eigenstate.org ([206.124.132.107]) by ewsd; Wed Dec 11 17:30:16 EST 2019 Received: from eigenstate.org (localhost [127.0.0.1]) by eigenstate.org (OpenSMTPD) with ESMTP id 4e72aa0b for <9front@9front.org>; Wed, 11 Dec 2019 14:30:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=eigenstate.org; h= message-id:to:subject:date:from:mime-version:content-type :content-transfer-encoding; s=mail; bh=WlfFAugvhDXRp1hiEhwlf1HW5 uk=; b=FKP8h1U1QX89rmgG9czP86HsYPIu0y6cvsn1puzw3dWctDAEv9dQWYb/e YbImuut78iiHt7rXmeWlcX44y8E5mJm+F8SdSDWJ53HHG3xLNdPRjQlsmEZWZRPp A+VZZ4WmnemWmUkMvlPz8ywxJHC0IpsW1mDN6KOSbStWGP+f/I= DomainKey-Signature: a=rsa-sha1; c=nofws; d=eigenstate.org; h=message-id :to:subject:date:from:mime-version:content-type :content-transfer-encoding; q=dns; s=mail; b=EcY63NkIlK4W1ESCvK4 Ru1TRKoM5lnRy5gasPJpzCTGNNJEwMFYXeUyLG/Xb6798US46JgV3uylCvS+Njny JEm3QsjJGcS0Kd/oVneRnraLV3AIZuX4hG8Az/Y/u+uD/mlDGUE3usDway2esSuY IFtTodqYB8FqZuGF8l+/gwI8= Received: from stockyard.guest.pikopiko.org (mail.gunshopcomputers.com [209.180.212.191]) by eigenstate.org (OpenSMTPD) with ESMTPSA id 7dd51322 (TLSv1.2:ECDHE-RSA-AES256-SHA:256:NO) for <9front@9front.org>; Wed, 11 Dec 2019 14:30:13 -0800 (PST) Message-ID: <963C9871BB6B58DED6E4A93B48B07C0D@eigenstate.org> To: 9front@9front.org Subject: [PATCH] Fix yacc error messages. Date: Wed, 11 Dec 2019 14:30:12 -0800 From: ori@eigenstate.org MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: abstract generic interface information locator 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