Module Name: src Committed By: rillig Date: Tue May 16 08:22:11 UTC 2023
Modified Files: src/tests/usr.bin/indent: fmt_decl.c src/usr.bin/indent: indent.c Log Message: indent: remove blank between comment and parentheses or brackets Finally, indent formats its own source code without messing up the layout. To generate a diff of this commit: cvs rdiff -u -r1.42 -r1.43 src/tests/usr.bin/indent/fmt_decl.c cvs rdiff -u -r1.287 -r1.288 src/usr.bin/indent/indent.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/fmt_decl.c diff -u src/tests/usr.bin/indent/fmt_decl.c:1.42 src/tests/usr.bin/indent/fmt_decl.c:1.43 --- src/tests/usr.bin/indent/fmt_decl.c:1.42 Mon May 15 21:51:46 2023 +++ src/tests/usr.bin/indent/fmt_decl.c Tue May 16 08:22:11 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: fmt_decl.c,v 1.42 2023/05/15 21:51:46 rillig Exp $ */ +/* $NetBSD: fmt_decl.c,v 1.43 2023/05/16 08:22:11 rillig Exp $ */ /* * Tests for declarations of global variables, external functions, and local @@ -128,7 +128,7 @@ void t2 (char *x, int y) ,n ,o ; - int chars[ /* push the comma beyond column 74 .... */ ], x; + int chars[ /* push the comma beyond column 74 ...... */ ], x; } //indent end @@ -145,7 +145,7 @@ t2(char *x, int y) ,n ,o ; - int chars[ /* push the comma beyond column 74 .... */ ], + int chars[/* push the comma beyond column 74 ...... */], x; } //indent end Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.287 src/usr.bin/indent/indent.c:1.288 --- src/usr.bin/indent/indent.c:1.287 Tue May 16 08:04:03 2023 +++ src/usr.bin/indent/indent.c Tue May 16 08:22:11 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.287 2023/05/16 08:04:03 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.288 2023/05/16 08:22:11 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -38,7 +38,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: indent.c,v 1.287 2023/05/16 08:04:03 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.288 2023/05/16 08:22:11 rillig Exp $"); #include <sys/param.h> #include <err.h> @@ -357,13 +357,24 @@ maybe_break_line(lexer_symbol lsym) ps.force_nl = false; } +static bool +want_blank_before_comment(void) +{ + if (code.len > 0) { + char ch = code.mem[code.len - 1]; + return ch != '[' && ch != '('; + } + return lab.len > 0; +} + static void -move_com_to_code(void) +move_com_to_code(lexer_symbol lsym) { - if (lab.len > 0 || code.len > 0) + if (want_blank_before_comment()) buf_add_char(&code, ' '); buf_add_buf(&code, &com); - buf_add_char(&code, ' '); + if (lsym != lsym_rparen_or_rbracket) + buf_add_char(&code, ' '); com.len = 0; ps.want_blank = false; } @@ -1022,7 +1033,7 @@ main_loop(void) ps.in_stmt_or_decl = true; /* add an extra level of indentation; * turned off again by a ';' or '}' */ if (com.len > 0) - move_com_to_code(); + move_com_to_code(lsym); } switch (lsym) {