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 wrapping for comments in otherwis...



details:   https://anonhg.NetBSD.org/src/rev/82f347382d09
branches:  trunk
changeset: 1024215:82f347382d09
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Oct 12 18:22:01 2021 +0000

description:
indent: fix wrapping for comments in otherwise empty lines

The comment above the code was wrong. The leading 3 characters were
indeed ignored, but the first of them was '/', not ' '. Of the trailing
3 characters, 2 were not ignored. The start and end of the comment would
not cancel out, they would rather sum up.

diffstat:

 tests/usr.bin/indent/elsecomment.0.stdout   |   6 ++++--
 tests/usr.bin/indent/token-comment.0.stdout |  10 +++++++---
 usr.bin/indent/pr_comment.c                 |  25 ++++++++++---------------
 3 files changed, 21 insertions(+), 20 deletions(-)

diffs (90 lines):

diff -r eae7794f145b -r 82f347382d09 tests/usr.bin/indent/elsecomment.0.stdout
--- a/tests/usr.bin/indent/elsecomment.0.stdout Tue Oct 12 17:27:26 2021 +0000
+++ b/tests/usr.bin/indent/elsecomment.0.stdout Tue Oct 12 18:22:01 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: elsecomment.0.stdout,v 1.1 2019/04/04 15:27:35 kamil Exp $     */
+/*     $NetBSD: elsecomment.0.stdout,v 1.2 2021/10/12 18:22:01 rillig Exp $    */
 /* $FreeBSD: head/usr.bin/indent/tests/elsecomment.0.stdout 334559 2018-06-03 14:03:20Z pstef $ */
 /* See r303484 and r309342 */
 void
@@ -23,7 +23,9 @@
 
 
 
-       /* Old indent would remove the 3 blank lines above, awaiting "else". */
+       /*
+        * Old indent would remove the 3 blank lines above, awaiting "else".
+        */
 
        if (1)
        {
diff -r eae7794f145b -r 82f347382d09 tests/usr.bin/indent/token-comment.0.stdout
--- a/tests/usr.bin/indent/token-comment.0.stdout       Tue Oct 12 17:27:26 2021 +0000
+++ b/tests/usr.bin/indent/token-comment.0.stdout       Tue Oct 12 18:22:01 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: token-comment.0.stdout,v 1.8 2021/10/08 23:53:37 rillig Exp $ */
+/* $NetBSD: token-comment.0.stdout,v 1.9 2021/10/12 18:22:01 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -10,8 +10,12 @@
  */
 
 /* 456789 123456789 123456789 123456789 123456789 123456789 123456789 12345 */
-/* 456789 123456789 123456789 123456789 123456789 123456789 123456789 123456 */
-/* 456789 123456789 123456789 123456789 123456789 123456789 123456789 1234567 */
+/*
+ * 456789 123456789 123456789 123456789 123456789 123456789 123456789 123456
+ */
+/*
+ * 456789 123456789 123456789 123456789 123456789 123456789 123456789 1234567
+ */
 /*
  * 456789 123456789 123456789 123456789 123456789 123456789 123456789 12345678
  */
diff -r eae7794f145b -r 82f347382d09 usr.bin/indent/pr_comment.c
--- a/usr.bin/indent/pr_comment.c       Tue Oct 12 17:27:26 2021 +0000
+++ b/usr.bin/indent/pr_comment.c       Tue Oct 12 18:22:01 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pr_comment.c,v 1.69 2021/10/09 11:00:27 rillig Exp $   */
+/*     $NetBSD: pr_comment.c,v 1.70 2021/10/12 18:22:01 rillig Exp $   */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: pr_comment.c,v 1.69 2021/10/09 11:00:27 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.70 2021/10/12 18:22:01 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -172,19 +172,14 @@
     if (break_delim) {
        for (const char *p = inp.s; *p != '\n'; p++) {
            assert(*p != '\0');
-           assert(p < inp.e);
-           if (p[0] == '*' && p[1] == '/') {
-               /*
-                * XXX: This computation ignores the leading " * ", as well as
-                * the trailing ' ' '*' '/'.  In simple cases, these cancel
-                * out since they are equally long.
-                */
-               int right_margin = indentation_after_range(ps.com_ind,
-                   inp.s, p + 2);
-               if (right_margin < adj_max_line_length)
-                   break_delim = false;
-               break;
-           }
+           assert(inp.e - p >= 2);
+           if (!(p[0] == '*' && p[1] == '/'))
+               continue;
+
+           int len = 3 + indentation_after_range(ps.com_ind, inp.s, p + 2);
+           if (len <= adj_max_line_length)
+               break_delim = false;
+           break;
        }
     }
 



Home | Main Index | Thread Index | Old Index