Module Name: src Committed By: rillig Date: Sun Oct 24 17:19:49 UTC 2021
Modified Files: src/tests/usr.bin/indent: t_errors.sh t_misc.sh token_lparen.c src/usr.bin/indent: indent.c io.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/indent/t_errors.sh cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/indent/t_misc.sh cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/indent/token_lparen.c cvs rdiff -u -r1.147 -r1.148 src/usr.bin/indent/indent.c cvs rdiff -u -r1.101 -r1.102 src/usr.bin/indent/io.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/usr.bin/indent/t_errors.sh diff -u src/tests/usr.bin/indent/t_errors.sh:1.4 src/tests/usr.bin/indent/t_errors.sh:1.5 --- src/tests/usr.bin/indent/t_errors.sh:1.4 Sun Oct 17 18:13:00 2021 +++ src/tests/usr.bin/indent/t_errors.sh Sun Oct 24 17:19:49 2021 @@ -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 @@ option_buffer_overflow_body() # 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 @@ unterminated_comment_body() 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 @@ unexpected_end_of_file_body() 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 @@ unexpected_closing_brace_top_level_body( 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 @@ unexpected_closing_brace_decl_body() 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 @@ preprocessing_overflow_body() #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 @@ preprocessing_unrecognized_body() #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' \ Index: src/tests/usr.bin/indent/t_misc.sh diff -u src/tests/usr.bin/indent/t_misc.sh:1.7 src/tests/usr.bin/indent/t_misc.sh:1.8 --- src/tests/usr.bin/indent/t_misc.sh:1.7 Sun Oct 24 16:51:44 2021 +++ src/tests/usr.bin/indent/t_misc.sh Sun Oct 24 17:19:49 2021 @@ -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 @@ nested_struct_declarations_body() }; 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 @@ line_no_counting_body() EOF cat <<-\EOF > code.err - /**INDENT** Warning@3: Extra ) */ + warning: code.c:3: Extra ) EOF atf_check -o 'ignore' -e 'file:code.err' \ Index: src/tests/usr.bin/indent/token_lparen.c diff -u src/tests/usr.bin/indent/token_lparen.c:1.3 src/tests/usr.bin/indent/token_lparen.c:1.4 --- src/tests/usr.bin/indent/token_lparen.c:1.3 Sun Oct 24 16:38:00 2021 +++ src/tests/usr.bin/indent/token_lparen.c Sun Oct 24 17:19:49 2021 @@ -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 @@ function(void) /* 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 Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.147 src/usr.bin/indent/indent.c:1.148 --- src/usr.bin/indent/indent.c:1.147 Sun Oct 24 16:51:44 2021 +++ src/usr.bin/indent/indent.c Sun Oct 24 17:19:48 2021 @@ -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 @@ static char sccsid[] = "@(#)indent.c 5.1 #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 @@ init_capsicum(void) } #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) { Index: src/usr.bin/indent/io.c diff -u src/usr.bin/indent/io.c:1.101 src/usr.bin/indent/io.c:1.102 --- src/usr.bin/indent/io.c:1.101 Sun Oct 24 11:17:05 2021 +++ src/usr.bin/indent/io.c Sun Oct 24 17:19:48 2021 @@ -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 @@ static char sccsid[] = "@(#)io.c 8.1 (Be #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 @@ indentation_after(int ind, const char *s { 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); -}