Module Name:    src
Committed By:   rillig
Date:           Sun Oct 24 11:19:25 UTC 2021

Modified Files:
        src/usr.bin/indent: args.c indent.c indent.h lexi.c

Log Message:
indent: rename nitems to array_length


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/usr.bin/indent/args.c
cvs rdiff -u -r1.145 -r1.146 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.44 -r1.45 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.93 -r1.94 src/usr.bin/indent/lexi.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.57 src/usr.bin/indent/args.c:1.58
--- src/usr.bin/indent/args.c:1.57	Sun Oct 24 10:54:12 2021
+++ src/usr.bin/indent/args.c	Sun Oct 24 11:19:25 2021
@@ -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 @@ static char sccsid[] = "@(#)args.c	8.1 (
 
 #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 @@ load_profile(const char *fname, bool mus
 		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 @@ set_option(const char *arg, const char *
     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;

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.145 src/usr.bin/indent/indent.c:1.146
--- src/usr.bin/indent/indent.c:1.145	Sun Oct 24 11:17:05 2021
+++ src/usr.bin/indent/indent.c	Sun Oct 24 11:19:25 2021
@@ -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 @@ static char sccsid[] = "@(#)indent.c	5.1
 
 #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 @@ want_blank_before_lparen(void)
 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 @@ process_preprocessing(void)
     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 @@ main_loop(void)
 
 	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:

Index: src/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.44 src/usr.bin/indent/indent.h:1.45
--- src/usr.bin/indent/indent.h:1.44	Sun Oct 24 11:17:05 2021
+++ src/usr.bin/indent/indent.h	Sun Oct 24 11:19:25 2021
@@ -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 @@ extern struct parser_state {
 }            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);

Index: src/usr.bin/indent/lexi.c
diff -u src/usr.bin/indent/lexi.c:1.93 src/usr.bin/indent/lexi.c:1.94
--- src/usr.bin/indent/lexi.c:1.93	Sun Oct 24 10:54:12 2021
+++ src/usr.bin/indent/lexi.c	Sun Oct 24 11:19:25 2021
@@ -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 @@ static char sccsid[] = "@(#)lexi.c	8.1 (
 
 #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 @@ token_type_name(token_type ttype)
 	"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 @@ lex_number(void)
 {
     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 @@ lexi_alnum(struct parser_state *state)
     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;

Reply via email to