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: rename nitems to array_length
details: https://anonhg.NetBSD.org/src/rev/9994c9809f0f
branches: trunk
changeset: 1024445:9994c9809f0f
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Oct 24 11:19:25 2021 +0000
description:
indent: rename nitems to array_length
diffstat:
usr.bin/indent/args.c | 8 ++++----
usr.bin/indent/indent.c | 12 ++++++------
usr.bin/indent/indent.h | 6 ++----
usr.bin/indent/lexi.c | 10 +++++-----
4 files changed, 17 insertions(+), 19 deletions(-)
diffs (149 lines):
diff -r 477b59cac713 -r 9994c9809f0f usr.bin/indent/args.c
--- a/usr.bin/indent/args.c Sun Oct 24 11:17:05 2021 +0000
+++ b/usr.bin/indent/args.c Sun Oct 24 11:19:25 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: args.c,v 1.57 2021/10/24 10:54:12 rillig Exp $ */
+/* $NetBSD: args.c,v 1.58 2021/10/24 11:19:25 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
#include <sys/cdefs.h>
#if defined(__NetBSD__)
-__RCSID("$NetBSD: args.c,v 1.57 2021/10/24 10:54:12 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.58 2021/10/24 11:19:25 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
#endif
@@ -160,7 +160,7 @@
comment_ch = ch == '/' && comment_ch == '*' ? -1 : ch;
} else if (isspace((unsigned char)ch)) {
break;
- } else if (n >= nitems(buf) - 5) {
+ } else if (n >= array_length(buf) - 5) {
diag(1, "buffer overflow in %s, starting with '%.10s'",
fname, buf);
exit(1);
@@ -286,7 +286,7 @@
if (set_special_option(arg, option_source))
return;
- for (p = pro + nitems(pro); p-- != pro;) {
+ for (p = pro + array_length(pro); p-- != pro;) {
param_start = skip_over(arg, p->p_may_negate, p->p_name);
if (param_start != NULL)
goto found;
diff -r 477b59cac713 -r 9994c9809f0f usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c Sun Oct 24 11:17:05 2021 +0000
+++ b/usr.bin/indent/indent.c Sun Oct 24 11:19:25 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.c,v 1.145 2021/10/24 11:17:05 rillig Exp $ */
+/* $NetBSD: indent.c,v 1.146 2021/10/24 11:19:25 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.145 2021/10/24 11:17:05 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.146 2021/10/24 11:19:25 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
#endif
@@ -700,9 +700,9 @@
static void
process_lparen_or_lbracket(int decl_ind, bool tabs_to_var, bool sp_sw)
{
- if (++ps.p_l_follow == nitems(ps.paren_indents)) {
+ if (++ps.p_l_follow == array_length(ps.paren_indents)) {
diag(0, "Reached internal limit of %zu unclosed parens",
- nitems(ps.paren_indents));
+ array_length(ps.paren_indents));
ps.p_l_follow--;
}
@@ -1266,7 +1266,7 @@
ps.is_case_label = false;
if (strncmp(lab.s, "#if", 3) == 0) { /* also ifdef, ifndef */
- if ((size_t)ifdef_level < nitems(state_stack))
+ if ((size_t)ifdef_level < array_length(state_stack))
state_stack[ifdef_level++] = ps;
else
diag(1, "#if stack overflow");
@@ -1411,7 +1411,7 @@
case lbrace:
process_lbrace(&force_nl, &sp_sw, hd_type, di_stack,
- (int)nitems(di_stack), &decl_ind);
+ (int)array_length(di_stack), &decl_ind);
break;
case rbrace:
diff -r 477b59cac713 -r 9994c9809f0f usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h Sun Oct 24 11:17:05 2021 +0000
+++ b/usr.bin/indent/indent.h Sun Oct 24 11:19:25 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.h,v 1.44 2021/10/24 11:17:05 rillig Exp $ */
+/* $NetBSD: indent.h,v 1.45 2021/10/24 11:19:25 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -325,9 +325,7 @@
} ps;
-#ifndef nitems
-#define nitems(array) (sizeof (array) / sizeof (array[0]))
-#endif
+#define array_length(array) (sizeof (array) / sizeof (array[0]))
void add_typename(const char *);
int compute_code_indent(void);
diff -r 477b59cac713 -r 9994c9809f0f usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c Sun Oct 24 11:17:05 2021 +0000
+++ b/usr.bin/indent/lexi.c Sun Oct 24 11:19:25 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lexi.c,v 1.93 2021/10/24 10:54:12 rillig Exp $ */
+/* $NetBSD: lexi.c,v 1.94 2021/10/24 11:19:25 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
#include <sys/cdefs.h>
#if defined(__NetBSD__)
-__RCSID("$NetBSD: lexi.c,v 1.93 2021/10/24 10:54:12 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.94 2021/10/24 11:19:25 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
#endif
@@ -234,7 +234,7 @@
"storage_class", "funcname", "type_def", "keyword_struct_union_enum"
};
- assert(0 <= ttype && ttype < nitems(name));
+ assert(0 <= ttype && ttype < array_length(name));
return name[ttype];
}
@@ -270,7 +270,7 @@
{
for (uint8_t s = 'A'; s != 'f' && s != 'i' && s != 'u';) {
uint8_t ch = (uint8_t)*inp.s;
- if (ch >= nitems(lex_number_row) || lex_number_row[ch] == 0)
+ if (ch >= array_length(lex_number_row) || lex_number_row[ch] == 0)
break;
uint8_t row = lex_number_row[ch];
@@ -412,7 +412,7 @@
state->next_unary = state->last_token == keyword_struct_union_enum;
const struct keyword *kw = bsearch(token.s, keywords,
- nitems(keywords), sizeof(keywords[0]), cmp_keyword_by_name);
+ array_length(keywords), sizeof(keywords[0]), cmp_keyword_by_name);
if (kw == NULL) {
if (is_typename()) {
state->keyword = kw_type;
Home |
Main Index |
Thread Index |
Old Index