npfctl/yyerror(): print the right line number if we already parsed the line. trunk
authorrmind <rmind@NetBSD.org>
Tue, 02 Oct 2012 23:38:52 +0000
branchtrunk
changeset 213639 a5bfe221819c
parent 213638 905c734e6444
child 213640 128a24fd6e6f
npfctl/yyerror(): print the right line number if we already parsed the line.
usr.sbin/npf/npfctl/npf_parse.y
--- a/usr.sbin/npf/npfctl/npf_parse.y	Tue Oct 02 23:10:34 2012 +0000
+++ b/usr.sbin/npf/npfctl/npf_parse.y	Tue Oct 02 23:38:52 2012 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: npf_parse.y,v 1.13 2012/09/16 13:47:41 rmind Exp $	*/
+/*	$NetBSD: npf_parse.y,v 1.14 2012/10/02 23:38:52 rmind Exp $	*/
 
 /*-
  * Copyright (c) 2011-2012 The NetBSD Foundation, Inc.
@@ -55,17 +55,23 @@
 	extern char *yytext;
 
 	char *msg, *context = xstrndup(yytext, yyleng);
-	size_t len = strlen(context);
-	char *dst = zalloc(len * 4 + 1);
+	bool eol = (*context == '\n');
 	va_list ap;
 
 	va_start(ap, fmt);
 	vasprintf(&msg, fmt, ap);
 	va_end(ap);
 
-	strvisx(dst, context, len, VIS_WHITE|VIS_CSTYLE);
-	fprintf(stderr, "%s:%d:%d: %s near '%s'\n", yyfilename, yylineno,
-	    yycolumn, msg, dst);
+	fprintf(stderr, "%s:%d:%d: %s", yyfilename,
+	    yylineno - (int)eol, yycolumn, msg);
+	if (!eol) {
+		size_t len = strlen(context);
+		char *dst = zalloc(len * 4 + 1);
+
+		strvisx(dst, context, len, VIS_WHITE|VIS_CSTYLE);
+		fprintf(stderr, " near '%s'", dst);
+	}
+	fprintf(stderr, "\n");
 	exit(EXIT_FAILURE);
 }