Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint2 lint2: in case of parse errors, output t...



details:   https://anonhg.NetBSD.org/src/rev/d3b5d6f92dc2
branches:  trunk
changeset: 1026540:d3b5d6f92dc2
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Nov 28 09:16:46 2021 +0000

description:
lint2: in case of parse errors, output the offending line

This provides more of a clue than a simple '(not alnum or _: )',
especially in the output of build.sh.

While here, change the format of the error message to the standard
'%s:%d'. Since these are internal errors, they are not supposed to occur
often, so no need to change error(1).

diffstat:

 tests/usr.bin/xlint/lint2/t_lint2.sh |  11 +++++++----
 usr.bin/xlint/lint2/read.c           |  11 +++++++----
 2 files changed, 14 insertions(+), 8 deletions(-)

diffs (98 lines):

diff -r 81e4b987bea0 -r d3b5d6f92dc2 tests/usr.bin/xlint/lint2/t_lint2.sh
--- a/tests/usr.bin/xlint/lint2/t_lint2.sh      Sun Nov 28 09:14:21 2021 +0000
+++ b/tests/usr.bin/xlint/lint2/t_lint2.sh      Sun Nov 28 09:16:46 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: t_lint2.sh,v 1.9 2021/11/28 09:10:36 rillig Exp $
+# $NetBSD: t_lint2.sh,v 1.10 2021/11/28 09:16:46 rillig Exp $
 #
 # Copyright (c) 2021 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -76,6 +76,7 @@
        std_emit_body 'emit_lp64'
 }
 
+# usage: test_error input message-regex [input-regex]
 test_error()
 {
        printf '%s\n' \
@@ -86,7 +87,8 @@
            "$1" \
            > 'input.ln'
 
-       atf_check -s 'exit:1' -e "match:input file error: input\\.ln,3 \($2\)\$" \
+       atf_check -s 'exit:1' \
+           -e "match:error: input\\.ln:3: $2 \\(for '${3-$1}'\\)\$" \
            "$lint2" 'input.ln'
 }
 
@@ -141,9 +143,9 @@
        test_error '0c0.0s2"'           'trailing data: '
        test_error '0c0.0s2"%'          'missing closing quote'
        # shellcheck disable=SC1003
-       test_error '0c0.0s2"\'          'missing after \\'
+       test_error '0c0.0s2"\'          'missing after \\'      '0c0\.0s2"\\'
        # shellcheck disable=SC1003
-       test_error '0c0.0s2"%\'         'missing after \\'
+       test_error '0c0.0s2"%\'         'missing after \\'      '0c0\.0s2"%\\'
 
        # declarations and definitions
        test_error '0d0'                'bad line number'
@@ -168,6 +170,7 @@
        test_error '0u0.0'              'bad delim '
        test_error '0u0.0_'             'bad delim _'
        test_error '0u0.0x'             'not a number: '
+
        # trailing garbage is not detected
        test_error_ignored '0u0.0x3var_'
 }
diff -r 81e4b987bea0 -r d3b5d6f92dc2 usr.bin/xlint/lint2/read.c
--- a/usr.bin/xlint/lint2/read.c        Sun Nov 28 09:14:21 2021 +0000
+++ b/usr.bin/xlint/lint2/read.c        Sun Nov 28 09:16:46 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: read.c,v 1.70 2021/11/28 08:21:49 rillig Exp $ */
+/* $NetBSD: read.c,v 1.71 2021/11/28 09:16:46 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: read.c,v 1.70 2021/11/28 08:21:49 rillig Exp $");
+__RCSID("$NetBSD: read.c,v 1.71 2021/11/28 09:16:46 rillig Exp $");
 #endif
 
 #include <ctype.h>
@@ -90,6 +90,7 @@
 /* index of current C source file (as specified at the command line) */
 static int     csrcfile;
 
+static const char *readfile_line;
 
 static void    inperr(const char *, ...)
     __attribute__((format(printf, 1, 2), noreturn));
@@ -228,11 +229,13 @@
                err(1, "cannot open %s", name);
 
        while ((line = fgetln(inp, &len)) != NULL) {
+               readfile_line = line;
                if (len == 0 || line[len - 1] != '\n')
                        inperr("%s", &line[len - 1]);
                line[len - 1] = '\0';
 
                read_ln_line(line, len);
+               readfile_line = NULL;
        }
 
        _destroyhash(renametab);
@@ -254,8 +257,8 @@
        (void)vsnprintf(buf, sizeof(buf), fmt, ap);
        va_end(ap);
 
-       errx(1, "input file error: %s,%zu (%s)",
-           fnames[srcfile], flines[srcfile], buf);
+       errx(1, "error: %s:%zu: %s (for '%s')",
+           fnames[srcfile], flines[srcfile], buf, readfile_line);
 }
 
 /*



Home | Main Index | Thread Index | Old Index