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: fix token duplication after C99 comment



details:   https://anonhg.NetBSD.org/src/rev/753dd868126f
branches:  trunk
changeset: 1023724:753dd868126f
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Sep 24 16:29:31 2021 +0000

description:
indent: fix token duplication after C99 comment

The code that keeps blank lines after C99 comments still looks wrong,
but at least it's better than before.

diffstat:

 tests/usr.bin/indent/comment-line-end.0        |  3 +--
 tests/usr.bin/indent/comment-line-end.0.stdout |  5 ++---
 usr.bin/indent/io.c                            |  7 ++++---
 3 files changed, 7 insertions(+), 8 deletions(-)

diffs (68 lines):

diff -r 177ee106a216 -r 753dd868126f tests/usr.bin/indent/comment-line-end.0
--- a/tests/usr.bin/indent/comment-line-end.0   Fri Sep 24 15:48:35 2021 +0000
+++ b/tests/usr.bin/indent/comment-line-end.0   Fri Sep 24 16:29:31 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: comment-line-end.0,v 1.6 2021/09/24 06:30:02 rillig Exp $ */
+/* $NetBSD: comment-line-end.0,v 1.7 2021/09/24 16:29:31 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -27,7 +27,6 @@
 {
 }
 
-/* FIXME: in the formatted output, the word 'bar' is repeated. */
 void c99_comment(void)
 {
 foo(); // C++ comment
diff -r 177ee106a216 -r 753dd868126f tests/usr.bin/indent/comment-line-end.0.stdout
--- a/tests/usr.bin/indent/comment-line-end.0.stdout    Fri Sep 24 15:48:35 2021 +0000
+++ b/tests/usr.bin/indent/comment-line-end.0.stdout    Fri Sep 24 16:29:31 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: comment-line-end.0.stdout,v 1.6 2021/09/24 06:30:02 rillig Exp $ */
+/* $NetBSD: comment-line-end.0.stdout,v 1.7 2021/09/24 16:29:31 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -30,12 +30,11 @@
 {
 }
 
-/* FIXME: in the formatted output, the word 'bar' is repeated. */
 void
 c99_comment(void)
 {
        foo();                  // C++ comment
-bar    bar();
+       bar();
 }
 
 // end-of-line comment at the end of the file
diff -r 177ee106a216 -r 753dd868126f usr.bin/indent/io.c
--- a/usr.bin/indent/io.c       Fri Sep 24 15:48:35 2021 +0000
+++ b/usr.bin/indent/io.c       Fri Sep 24 16:29:31 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: io.c,v 1.49 2021/03/14 01:44:37 rillig Exp $   */
+/*     $NetBSD: io.c,v 1.50 2021/09/24 16:29:31 rillig Exp $   */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@
 #include <sys/cdefs.h>
 #ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: io.c,v 1.49 2021/03/14 01:44:37 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.50 2021/09/24 16:29:31 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -260,7 +260,8 @@
     }
 
     /* keep blank lines after '//' comments */
-    if (e_com - s_com > 1 && s_com[1] == '/')
+    if (e_com - s_com > 1 && s_com[1] == '/'
+       && s_token < e_token && isspace((unsigned char)s_token[0]))
        output_range(s_token, e_token);
 
     ps.decl_on_line = ps.in_decl; /* if we are in the middle of a declaration,



Home | Main Index | Thread Index | Old Index