Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/indent indent: clean up format of warnings and errors



details:   https://anonhg.NetBSD.org/src/rev/913e3f5b59ab
branches:  trunk
changeset: 990037:913e3f5b59ab
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Oct 24 17:19:48 2021 +0000

description:
indent: clean up format of warnings and errors

Previously, warnings and errors had the form of C block comments. Before
NetBSD io.c 1.20 from 2019-10-19, this format made sense because the
diagnostics could end up in the same output stream as the formatted
output.

Since NetBSD io.c 1.20 from 2019-10-19, all diagnostics are redirected
to stderr. This change was not mentioned in the commit message back
then, it makes sense nevertheless. Since stdout and stderr now are
properly separated, there is no need anymore to keep the weird format
for warnings and errors. Switch to the standard 'error: file:line'
format.

Move the function 'diag' to indent.c to have access to the name of the
current input file.

diffstat:

 tests/usr.bin/indent/t_errors.sh    |  26 +++++++++++++-------------
 tests/usr.bin/indent/t_misc.sh      |  14 +++++++-------
 tests/usr.bin/indent/token_lparen.c |   4 ++--
 usr.bin/indent/indent.c             |  20 ++++++++++++++++++--
 usr.bin/indent/io.c                 |  27 ++-------------------------
 5 files changed, 42 insertions(+), 49 deletions(-)

diffs (223 lines):

diff -r 3e45fa05beeb -r 913e3f5b59ab tests/usr.bin/indent/t_errors.sh
--- a/tests/usr.bin/indent/t_errors.sh  Sun Oct 24 16:51:44 2021 +0000
+++ b/tests/usr.bin/indent/t_errors.sh  Sun Oct 24 17:19:48 2021 +0000
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $NetBSD: t_errors.sh,v 1.4 2021/10/17 18:13:00 rillig Exp $
+# $NetBSD: t_errors.sh,v 1.5 2021/10/24 17:19:49 rillig Exp $
 #
 # Copyright (c) 2021 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -146,7 +146,7 @@
 
        # TODO: The call to 'diag' should be replaced with 'errx'.
        expect_error \
-           'Error@1: buffer overflow in indent.pro, starting with '\''-123456781'\''' \
+           'error: Standard Input:1: buffer overflow in indent.pro, starting with '\''-123456781'\''' \
            -Pindent.pro
 }
 
@@ -174,7 +174,7 @@
 
        atf_check -s 'exit:1' \
            -o 'inline:/*'"$nl"' *'"$nl" \
-           -e 'inline:/**INDENT** Error@2: Unterminated comment */'"$nl" \
+           -e 'inline:error: Standard Input:2: Unterminated comment'"$nl" \
            "$indent" -st < comment.c
 }
 
@@ -254,7 +254,7 @@
        echo 'struct{' > code.c
 
        expect_error \
-           'Error@1: Stuff missing from end of file' \
+           'error: code.c:1: Stuff missing from end of file' \
            code.c
 
        atf_check \
@@ -268,7 +268,7 @@
        echo '}' > code.c
 
        expect_error \
-           'Error@1: Statement nesting error' \
+           'error: code.c:1: Statement nesting error' \
            code.c
        atf_check \
            -o 'inline:}'"$nl" \
@@ -281,7 +281,7 @@
        echo 'int i = 3};' > code.c
 
        expect_error \
-           'Error@1: Statement nesting error' \
+           'error: code.c:1: Statement nesting error' \
            code.c
        # Despite the error message, the original file got overwritten with a
        # best-effort rewrite of the code.
@@ -309,9 +309,9 @@
                #endif too much
        EOF
        cat <<-\EOF > stderr.exp
-               Error@6: #if stack overflow
-               Error@12: Unmatched #endif
-               Error@13: Unmatched #endif
+               error: code.c:6: #if stack overflow
+               error: code.c:12: Unmatched #endif
+               error: code.c:13: Unmatched #endif
        EOF
 
        atf_check -s 'exit:1' \
@@ -329,10 +329,10 @@
                #else
        EOF
        cat <<-\EOF > stderr.exp
-               Error@1: Unrecognized cpp directive
-               Error@2: Unrecognized cpp directive
-               Error@3: Unmatched #elif
-               Error@4: Unmatched #else
+               error: code.c:1: Unrecognized cpp directive
+               error: code.c:2: Unrecognized cpp directive
+               error: code.c:3: Unmatched #elif
+               error: code.c:4: Unmatched #else
        EOF
 
        atf_check -s 'exit:1' \
diff -r 3e45fa05beeb -r 913e3f5b59ab tests/usr.bin/indent/t_misc.sh
--- a/tests/usr.bin/indent/t_misc.sh    Sun Oct 24 16:51:44 2021 +0000
+++ b/tests/usr.bin/indent/t_misc.sh    Sun Oct 24 17:19:48 2021 +0000
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $NetBSD: t_misc.sh,v 1.7 2021/10/24 16:51:44 rillig Exp $
+# $NetBSD: t_misc.sh,v 1.8 2021/10/24 17:19:49 rillig Exp $
 #
 # Copyright (c) 2021 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -161,11 +161,11 @@
                };
        EOF
        cat <<-\EOF > expected.err
-               /**INDENT** Warning@5: Reached internal limit of 20 struct levels */
-               /**INDENT** Warning@6: Reached internal limit of 20 struct levels */
-               /**INDENT** Warning@6: Reached internal limit of 20 struct levels */
-               /**INDENT** Warning@6: Reached internal limit of 20 struct levels */
-               /**INDENT** Warning@6: Reached internal limit of 20 struct levels */
+               warning: Standard Input:5: Reached internal limit of 20 struct levels
+               warning: Standard Input:6: Reached internal limit of 20 struct levels
+               warning: Standard Input:6: Reached internal limit of 20 struct levels
+               warning: Standard Input:6: Reached internal limit of 20 struct levels
+               warning: Standard Input:6: Reached internal limit of 20 struct levels
        EOF
 
        atf_check -o 'file:expected.out' -e 'file:expected.err' \
@@ -320,7 +320,7 @@
        EOF
 
        cat <<-\EOF > code.err
-               /**INDENT** Warning@3: Extra ) */
+               warning: code.c:3: Extra )
        EOF
 
        atf_check -o 'ignore' -e 'file:code.err' \
diff -r 3e45fa05beeb -r 913e3f5b59ab tests/usr.bin/indent/token_lparen.c
--- a/tests/usr.bin/indent/token_lparen.c       Sun Oct 24 16:51:44 2021 +0000
+++ b/tests/usr.bin/indent/token_lparen.c       Sun Oct 24 17:19:48 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: token_lparen.c,v 1.3 2021/10/24 16:38:00 rillig Exp $ */
+/* $NetBSD: token_lparen.c,v 1.4 2021/10/24 17:19:49 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -52,7 +52,7 @@
 
     /* GCC statement expression */
     /* expr = ({if(expr)debug();expr;}); */
-/* $ XXX: Generates wrong 'Error@36: Unbalanced parens'. */
+/* $ XXX: Generates wrong 'error: Standard Input:36: Unbalanced parens'. */
 }
 #indent end
 
diff -r 3e45fa05beeb -r 913e3f5b59ab usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Sun Oct 24 16:51:44 2021 +0000
+++ b/usr.bin/indent/indent.c   Sun Oct 24 17:19:48 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.147 2021/10/24 16:51:44 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.148 2021/10/24 17:19:48 rillig Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.147 2021/10/24 16:51:44 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.148 2021/10/24 17:19:48 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -140,6 +140,22 @@
 }
 #endif
 
+void
+diag(int level, const char *msg, ...)
+{
+    va_list ap;
+
+    if (level != 0)
+       found_err = true;
+
+    va_start(ap, msg);
+    fprintf(stderr, "%s: %s:%d: ",
+       level == 0 ? "warning" : "error", in_name, line_no);
+    vfprintf(stderr, msg, ap);
+    fprintf(stderr, "\n");
+    va_end(ap);
+}
+
 static void
 search_brace_newline(bool *force_nl)
 {
diff -r 3e45fa05beeb -r 913e3f5b59ab usr.bin/indent/io.c
--- a/usr.bin/indent/io.c       Sun Oct 24 16:51:44 2021 +0000
+++ b/usr.bin/indent/io.c       Sun Oct 24 17:19:48 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: io.c,v 1.101 2021/10/24 11:17:05 rillig Exp $  */
+/*     $NetBSD: io.c,v 1.102 2021/10/24 17:19:48 rillig Exp $  */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: io.c,v 1.101 2021/10/24 11:17:05 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.102 2021/10/24 17:19:48 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -483,26 +483,3 @@
 {
     return indentation_after_range(ind, s, NULL);
 }
-
-void
-diag(int level, const char *msg, ...)
-{
-    va_list ap;
-    const char *s, *e;
-
-    if (level != 0)
-       found_err = true;
-
-    if (output == stdout) {
-       s = "/**INDENT** ";
-       e = " */";
-    } else {
-       s = e = "";
-    }
-
-    va_start(ap, msg);
-    fprintf(stderr, "%s%s@%d: ", s, level == 0 ? "Warning" : "Error", line_no);
-    vfprintf(stderr, msg, ap);
-    fprintf(stderr, "%s\n", e);
-    va_end(ap);
-}



Home | Main Index | Thread Index | Old Index