Module Name: src Committed By: rillig Date: Fri Nov 19 20:23:17 UTC 2021
Modified Files: src/usr.bin/indent: args.c indent.c indent.h io.c lexi.c pr_comment.c Log Message: indent: reduce casts to unsigned char for character classification No functional change. To generate a diff of this commit: cvs rdiff -u -r1.70 -r1.71 src/usr.bin/indent/args.c cvs rdiff -u -r1.227 -r1.228 src/usr.bin/indent/indent.c cvs rdiff -u -r1.97 -r1.98 src/usr.bin/indent/indent.h cvs rdiff -u -r1.128 -r1.129 src/usr.bin/indent/io.c cvs rdiff -u -r1.147 -r1.148 src/usr.bin/indent/lexi.c cvs rdiff -u -r1.120 -r1.121 src/usr.bin/indent/pr_comment.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/indent/args.c diff -u src/usr.bin/indent/args.c:1.70 src/usr.bin/indent/args.c:1.71 --- src/usr.bin/indent/args.c:1.70 Sun Nov 7 18:09:56 2021 +++ src/usr.bin/indent/args.c Fri Nov 19 20:23:17 2021 @@ -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 @@ static char sccsid[] = "@(#)args.c 8.1 ( #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 @@ found: 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 @@ load_profile(const char *fname, bool mus 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'", Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.227 src/usr.bin/indent/indent.c:1.228 --- src/usr.bin/indent/indent.c:1.227 Fri Nov 19 20:04:02 2021 +++ src/usr.bin/indent/indent.c Fri Nov 19 20:23:17 2021 @@ -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 @@ static char sccsid[] = "@(#)indent.c 5.1 #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 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/ #include <capsicum_helpers.h> #endif #include <assert.h> -#include <ctype.h> #include <err.h> #include <errno.h> #include <fcntl.h> @@ -266,7 +265,7 @@ search_stmt_lbrace(void) * 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; Index: src/usr.bin/indent/indent.h diff -u src/usr.bin/indent/indent.h:1.97 src/usr.bin/indent/indent.h:1.98 --- src/usr.bin/indent/indent.h:1.97 Fri Nov 19 19:55:15 2021 +++ src/usr.bin/indent/indent.h Fri Nov 19 20:23:17 2021 @@ -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 @@ char *xstrdup(const char *); 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) { Index: src/usr.bin/indent/io.c diff -u src/usr.bin/indent/io.c:1.128 src/usr.bin/indent/io.c:1.129 --- src/usr.bin/indent/io.c:1.128 Fri Nov 19 20:13:05 2021 +++ src/usr.bin/indent/io.c Fri Nov 19 20:23:17 2021 @@ -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 @@ static char sccsid[] = "@(#)io.c 8.1 (Be #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 @@ dump_line_comment(int ind) 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); Index: src/usr.bin/indent/lexi.c diff -u src/usr.bin/indent/lexi.c:1.147 src/usr.bin/indent/lexi.c:1.148 --- src/usr.bin/indent/lexi.c:1.147 Fri Nov 19 19:55:15 2021 +++ src/usr.bin/indent/lexi.c Fri Nov 19 20:23:17 2021 @@ -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 @@ static char sccsid[] = "@(#)lexi.c 8.1 ( #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 @@ lex_number(void) 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 @@ probably_typename(void) 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 @@ cmp_keyword_by_name(const void *key, con 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 @@ lexi(void) 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 @@ lexi(void) 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++; Index: src/usr.bin/indent/pr_comment.c diff -u src/usr.bin/indent/pr_comment.c:1.120 src/usr.bin/indent/pr_comment.c:1.121 --- src/usr.bin/indent/pr_comment.c:1.120 Fri Nov 19 18:23:59 2021 +++ src/usr.bin/indent/pr_comment.c Fri Nov 19 20:23:17 2021 @@ -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 @@ static char sccsid[] = "@(#)pr_comment.c #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 @@ copy_comment_wrap(int adj_max_line_lengt 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 */