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: make copy_comment_nowrap simpler



details:   https://anonhg.NetBSD.org/src/rev/ec80423cdd10
branches:  trunk
changeset: 991085:ec80423cdd10
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Nov 07 10:13:26 2021 +0000

description:
indent: make copy_comment_nowrap simpler

Since a nowrap comment is copied unmodified, it need not depend on any
maximum line length.

No functional change.

diffstat:

 tests/usr.bin/indent/token_comment.c |  26 +++++++++++++++++++++++++-
 usr.bin/indent/pr_comment.c          |  30 +++++++-----------------------
 2 files changed, 32 insertions(+), 24 deletions(-)

diffs (115 lines):

diff -r 9331108b84c1 -r ec80423cdd10 tests/usr.bin/indent/token_comment.c
--- a/tests/usr.bin/indent/token_comment.c      Sun Nov 07 09:48:08 2021 +0000
+++ b/tests/usr.bin/indent/token_comment.c      Sun Nov 07 10:13:26 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: token_comment.c,v 1.19 2021/11/07 07:45:00 rillig Exp $ */
+/* $NetBSD: token_comment.c,v 1.20 2021/11/07 10:13:26 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -962,3 +962,27 @@
 #indent end
 
 #indent run-equals-input
+
+
+/*
+ * Tests for comments that are not wrapped.
+ */
+#indent input
+/*-    tab space       tab space */
+/*-    very-long-word-that-cannot-be-broken very-long-word-that-cannot-be-broken */
+/*-    very-long-word-that-cannot-be-broken very-long-word-that-cannot-be-broken */
+#indent end
+
+#indent run-equals-input -l5
+#indent run-equals-input -l32
+
+
+/*
+ * Test for form feeds in nowrap comments.
+ */
+#indent input
+/*-*/
+/*-<>*/
+#indent end
+
+#indent run-equals-input
diff -r 9331108b84c1 -r ec80423cdd10 usr.bin/indent/pr_comment.c
--- a/usr.bin/indent/pr_comment.c       Sun Nov 07 09:48:08 2021 +0000
+++ b/usr.bin/indent/pr_comment.c       Sun Nov 07 10:13:26 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pr_comment.c,v 1.102 2021/11/07 08:41:13 rillig Exp $  */
+/*     $NetBSD: pr_comment.c,v 1.103 2021/11/07 10:13:26 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.102 2021/11/07 08:41:13 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.103 2021/11/07 10:13:26 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -330,10 +330,8 @@
 }
 
 static void
-copy_comment_nowrap(int adj_max_line_length)
+copy_comment_nowrap(void)
 {
-    ssize_t last_blank = -1;   /* index of the last blank in com.buf */
-
     for (;;) {
        switch (*inp.s) {
        case '\f':
@@ -351,7 +349,6 @@
                return;
            }
 
-           last_blank = -1;
            if (com.s == com.e)
                com_add_char(' ');      /* force output of an empty line */
            dump_line();
@@ -370,28 +367,15 @@
                    com_add_char('/');
                }
                com_terminate();
+               ps.next_col_1 = false;
                return;
 
            } else              /* handle isolated '*' */
                com_add_char('*');
            break;
 
-       default:                /* we have a random char */
-           ;
-           int now_len = ind_add(ps.com_ind, com.s, com.e);
-           for (;;) {
-               char ch = inp_next();
-               if (ch_isblank(ch))
-                   last_blank = com.e - com.buf;
-               com_add_char(ch);
-               now_len++;
-               if (memchr("*\n\r\b\t", *inp.s, 6) != NULL)
-                   break;
-               if (now_len >= adj_max_line_length && last_blank != -1)
-                   break;
-           }
-
-           ps.next_col_1 = false;
+       default:
+           com_add_char(inp_next());
            break;
        }
     }
@@ -432,6 +416,6 @@
     if (may_wrap)
        copy_comment_wrap(adj_max_line_length, break_delim);
     else
-       copy_comment_nowrap(adj_max_line_length);
+       copy_comment_nowrap();
     ps.just_saw_decl = l_just_saw_decl;
 }



Home | Main Index | Thread Index | Old Index