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: reduce casts to unsigned char for cha...



details:   https://anonhg.NetBSD.org/src/rev/55d6e2a9e091
branches:  trunk
changeset: 1026345:55d6e2a9e091
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Nov 19 20:23:17 2021 +0000

description:
indent: reduce casts to unsigned char for character classification

No functional change.

diffstat:

 usr.bin/indent/args.c       |  10 ++++------
 usr.bin/indent/indent.c     |   7 +++----
 usr.bin/indent/indent.h     |  27 ++++++++++++++++++++++++++-
 usr.bin/indent/io.c         |   7 +++----
 usr.bin/indent/lexi.c       |  20 +++++++++-----------
 usr.bin/indent/pr_comment.c |   7 +++----
 6 files changed, 48 insertions(+), 30 deletions(-)

diffs (276 lines):

diff -r ad07d4e6cd81 -r 55d6e2a9e091 usr.bin/indent/args.c
--- a/usr.bin/indent/args.c     Fri Nov 19 20:13:05 2021 +0000
+++ b/usr.bin/indent/args.c     Fri Nov 19 20:23:17 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: args.c,v 1.70 2021/11/07 18:09:56 rillig Exp $ */
+/*     $NetBSD: args.c,v 1.71 2021/11/19 20:23:17 rillig Exp $ */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,14 +43,13 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: args.c,v 1.70 2021/11/07 18:09:56 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.71 2021/11/19 20:23:17 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
 #endif
 
 /* Read options from profile files and from the command line. */
 
-#include <ctype.h>
 #include <err.h>
 #include <limits.h>
 #include <stdio.h>
@@ -246,8 +245,7 @@
        errx(1, "%s: argument \"%s\" to option \"-%s\" must be an integer",
            option_source, arg_arg, p->p_name);
 
-    if (!(isdigit((unsigned char)*arg_arg) &&
-           p->i_min <= num && num <= p->i_max))
+    if (!(ch_isdigit(*arg_arg) && p->i_min <= num && num <= p->i_max))
        errx(1,
            "%s: argument \"%s\" to option \"-%s\" must be between %d and %d",
            option_source, arg_arg, p->p_name, p->i_min, p->i_max);
@@ -277,7 +275,7 @@
                comment_ch = '*';
            } else if (comment_ch != -1) {
                comment_ch = ch == '/' && comment_ch == '*' ? -1 : ch;
-           } else if (isspace((unsigned char)ch)) {
+           } else if (ch_isspace((char)ch)) {
                break;
            } else if (n >= array_length(buf) - 5) {
                errx(1, "buffer overflow in %s, starting with '%.10s'",
diff -r ad07d4e6cd81 -r 55d6e2a9e091 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Fri Nov 19 20:13:05 2021 +0000
+++ b/usr.bin/indent/indent.c   Fri Nov 19 20:23:17 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.227 2021/11/19 20:04:02 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.228 2021/11/19 20:23:17 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.227 2021/11/19 20:04:02 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.228 2021/11/19 20:23:17 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -54,7 +54,6 @@
 #include <capsicum_helpers.h>
 #endif
 #include <assert.h>
-#include <ctype.h>
 #include <err.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -266,7 +265,7 @@
         * will be moved into "the else's line", so if there was a newline
         * resulting from the "{" before, it must be scanned now and ignored.
         */
-       while (isspace((unsigned char)inp_peek())) {
+       while (ch_isspace(inp_peek())) {
            inp_skip();
            if (inp_peek() == '\n')
                break;
diff -r ad07d4e6cd81 -r 55d6e2a9e091 usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h   Fri Nov 19 20:13:05 2021 +0000
+++ b/usr.bin/indent/indent.h   Fri Nov 19 20:23:17 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.h,v 1.97 2021/11/19 19:55:15 rillig Exp $       */
+/*     $NetBSD: indent.h,v 1.98 2021/11/19 20:23:17 rillig Exp $       */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -68,6 +68,7 @@
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.h 336333 2018-07-16 05:46:50Z pstef $");
 #endif
 
+#include <ctype.h>
 #include <stdbool.h>
 #include <stdio.h>
 
@@ -407,11 +408,35 @@
 void buf_expand(struct buffer *, size_t);
 
 static inline bool
+ch_isalnum(char ch)
+{
+    return isalnum((unsigned char)ch) != 0;
+}
+
+static inline bool
+ch_isalpha(char ch)
+{
+    return isalpha((unsigned char)ch) != 0;
+}
+
+static inline bool
 ch_isblank(char ch)
 {
     return ch == ' ' || ch == '\t';
 }
 
+static inline bool
+ch_isdigit(char ch)
+{
+    return '0' <= ch && ch <= '9';
+}
+
+static inline bool
+ch_isspace(char ch)
+{
+    return isspace((unsigned char)ch) != 0;
+}
+
 static inline int
 next_tab(int ind)
 {
diff -r ad07d4e6cd81 -r 55d6e2a9e091 usr.bin/indent/io.c
--- a/usr.bin/indent/io.c       Fri Nov 19 20:13:05 2021 +0000
+++ b/usr.bin/indent/io.c       Fri Nov 19 20:23:17 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: io.c,v 1.128 2021/11/19 20:13:05 rillig Exp $  */
+/*     $NetBSD: io.c,v 1.129 2021/11/19 20:23:17 rillig Exp $  */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,13 +43,12 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: io.c,v 1.128 2021/11/19 20:13:05 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.129 2021/11/19 20:23:17 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
 
 #include <assert.h>
-#include <ctype.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -429,7 +428,7 @@
        ps.stats.lines++;
     }
 
-    while (com.e > p && isspace((unsigned char)com.e[-1]))
+    while (com.e > p && ch_isspace(com.e[-1]))
        com.e--;
 
     (void)output_indent(ind, target_ind);
diff -r ad07d4e6cd81 -r 55d6e2a9e091 usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c     Fri Nov 19 20:13:05 2021 +0000
+++ b/usr.bin/indent/lexi.c     Fri Nov 19 20:23:17 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lexi.c,v 1.147 2021/11/19 19:55:15 rillig Exp $        */
+/*     $NetBSD: lexi.c,v 1.148 2021/11/19 20:23:17 rillig Exp $        */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,13 +43,11 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: lexi.c,v 1.147 2021/11/19 19:55:15 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.148 2021/11/19 20:23:17 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
 #endif
 
-#include <assert.h>
-#include <ctype.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -351,13 +349,13 @@
 static bool
 is_identifier_start(char ch)
 {
-    return isalpha((unsigned char)ch) || ch == '_' || ch == '$';
+    return ch_isalpha(ch) || ch == '_' || ch == '$';
 }
 
 static bool
 is_identifier_part(char ch)
 {
-    return isalnum((unsigned char)ch) || ch == '_' || ch == '$';
+    return ch_isalnum(ch) || ch == '_' || ch == '$';
 }
 
 static void
@@ -406,7 +404,7 @@
     if (inp_peek() == '*' && inp_lookahead(1) != '=')
        goto maybe;
     /* XXX: is_identifier_start */
-    if (isalpha((unsigned char)inp_peek()))
+    if (ch_isalpha(inp_peek()))
        goto maybe;
     return false;
 maybe:
@@ -455,8 +453,8 @@
 static lexer_symbol
 lexi_alnum(void)
 {
-    if (isdigit((unsigned char)inp_peek()) ||
-           (inp_peek() == '.' && isdigit((unsigned char)inp_lookahead(1)))) {
+    if (ch_isdigit(inp_peek()) ||
+           (inp_peek() == '.' && ch_isdigit(inp_lookahead(1)))) {
        lex_number();
     } else if (is_identifier_part(inp_peek())) {
        lex_word();
@@ -683,7 +681,7 @@
            break;
        }
 
-       while (inp_peek() == '*' || isspace((unsigned char)inp_peek())) {
+       while (inp_peek() == '*' || ch_isspace(inp_peek())) {
            if (inp_peek() == '*')
                token_add_char('*');
            inp_skip();
@@ -693,7 +691,7 @@
            const char *tp = inp_p(), *e = inp_line_end();
 
            while (tp < e) {
-               if (isspace((unsigned char)*tp))
+               if (ch_isspace(*tp))
                    tp++;
                else if (is_identifier_start(*tp)) {
                    tp++;
diff -r ad07d4e6cd81 -r 55d6e2a9e091 usr.bin/indent/pr_comment.c
--- a/usr.bin/indent/pr_comment.c       Fri Nov 19 20:13:05 2021 +0000
+++ b/usr.bin/indent/pr_comment.c       Fri Nov 19 20:23:17 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pr_comment.c,v 1.120 2021/11/19 18:23:59 rillig Exp $  */
+/*     $NetBSD: pr_comment.c,v 1.121 2021/11/19 20:23:17 rillig Exp $  */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,13 +43,12 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: pr_comment.c,v 1.120 2021/11/19 18:23:59 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.121 2021/11/19 20:23:17 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>
 
@@ -293,7 +292,7 @@
 
            if (now_len <= adj_max_line_length)
                break;
-           if (isspace((unsigned char)com.e[-1]))
+           if (ch_isspace(com.e[-1]))
                break;
 
            if (last_blank == -1) {     /* only a single word in this line */



Home | Main Index | Thread Index | Old Index