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: clean up process_comment



details:   https://anonhg.NetBSD.org/src/rev/333c4a606bda
branches:  trunk
changeset: 990422:333c4a606bda
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Oct 26 21:37:27 2021 +0000

description:
indent: clean up process_comment

There is no undefined behavior since the compared characters are always
from the basic execution character set. All other cases are covered by
the condition above for now_len.

Fix debug logging for non-ASCII characters, previously a character was
output as \xffffffc3.

diffstat:

 tests/usr.bin/indent/token_comment.c |  14 +++++++++++++-
 usr.bin/indent/indent.c              |   6 +++---
 usr.bin/indent/pr_comment.c          |   8 ++++----
 3 files changed, 20 insertions(+), 8 deletions(-)

diffs (86 lines):

diff -r c1c89109bb0b -r 333c4a606bda tests/usr.bin/indent/token_comment.c
--- a/tests/usr.bin/indent/token_comment.c      Tue Oct 26 21:23:52 2021 +0000
+++ b/tests/usr.bin/indent/token_comment.c      Tue Oct 26 21:37:27 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: token_comment.c,v 1.7 2021/10/24 21:55:07 rillig Exp $ */
+/* $NetBSD: token_comment.c,v 1.8 2021/10/26 21:37:27 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -729,3 +729,15 @@
 #indent end
 
 #indent run-equals-input -nfc1
+
+
+#indent input
+/* comment comment comment comment Ümläute */
+#indent end
+
+#indent run -l40
+/*
+ * comment comment comment comment
+ * Ümläute
+ */
+#indent end
diff -r c1c89109bb0b -r 333c4a606bda usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Tue Oct 26 21:23:52 2021 +0000
+++ b/usr.bin/indent/indent.c   Tue Oct 26 21:37:27 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.161 2021/10/26 20:43:35 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.162 2021/10/26 21:37:27 rillig Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.161 2021/10/26 20:43:35 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.162 2021/10/26 21:37:27 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -1562,7 +1562,7 @@
        else if (*p == '\t')
            debug_printf("\\t");
        else
-           debug_printf("\\x%02x", *p);
+           debug_printf("\\x%02x", (unsigned char)*p);
     }
     debug_printf("%s", suffix);
 }
diff -r c1c89109bb0b -r 333c4a606bda usr.bin/indent/pr_comment.c
--- a/usr.bin/indent/pr_comment.c       Tue Oct 26 21:23:52 2021 +0000
+++ b/usr.bin/indent/pr_comment.c       Tue Oct 26 21:37:27 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pr_comment.c,v 1.86 2021/10/26 21:23:52 rillig Exp $   */
+/*     $NetBSD: pr_comment.c,v 1.87 2021/10/26 21:37:27 rillig Exp $   */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,12 +43,13 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: pr_comment.c,v 1.86 2021/10/26 21:23:52 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.87 2021/10/26 21:37:27 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
 
 #include <assert.h>
+#include <ctype.h>
 #include <stdio.h>
 #include <string.h>
 
@@ -333,8 +334,7 @@
 
            if (now_len <= adj_max_line_length || !may_wrap)
                break;
-           /* XXX: signed character comparison '>' does not work for UTF-8 */
-           if (com.e[-1] <= ' ')
+           if (isspace((unsigned char)com.e[-1]))
                break;
 
            if (last_blank == -1) {     /* only a single word in this line */



Home | Main Index | Thread Index | Old Index