Hello all.
This diff removes NELEM() definitions in favour of nitems(). Not sure
about bin/ksh/ part, but sys/i386/i386/est.c is obviously a leftover.
There are more NELEM() items in tree, but they belong to foreign stuff
and therefore should not be touched, as far as I understand.
--
Best wishes,
Vadim Zhukov
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?
Index: sys/arch/i386/i386/est.c
===================================================================
RCS file: /cvs/src/sys/arch/i386/i386/est.c,v
retrieving revision 1.36
diff -u -p -r1.36 est.c
--- sys/arch/i386/i386/est.c 5 Jul 2010 22:47:41 -0000 1.36
+++ sys/arch/i386/i386/est.c 12 May 2011 23:03:48 -0000
@@ -862,10 +862,8 @@ struct fqlist {
struct est_op *table;
};
-#define NELEM(x) (sizeof(x) / sizeof((x)[0]))
-
#define ENTRY(ven, bus_clk, tab) \
- { CPUVENDOR_##ven, bus_clk == BUS133 ? 1 : 0, NELEM(tab), tab }
+ { CPUVENDOR_##ven, bus_clk == BUS133 ? 1 : 0, nitems(tab), tab }
#define BUS_CLK(fqp) ((fqp)->bus_clk ? BUS133 : BUS100)
@@ -1082,7 +1080,7 @@ est_init(const char *cpu_device, int ven
/*
* Find an entry which matches (vendor, bus_clock, idhi, idlo)
*/
- for (i = 0; i < NELEM(est_cpus); i++) {
+ for (i = 0; i < nitems(est_cpus); i++) {
fql = &est_cpus[i];
if (vendor == fql->vendor && bus_clock == BUS_CLK(fql)
&& idhi == fql->table[0].ctrl
Index: bin/ksh/c_ulimit.c
===================================================================
RCS file: /cvs/src/bin/ksh/c_ulimit.c,v
retrieving revision 1.17
diff -u -p -r1.17 c_ulimit.c
--- bin/ksh/c_ulimit.c 21 Mar 2008 12:51:19 -0000 1.17
+++ bin/ksh/c_ulimit.c 12 May 2011 23:03:48 -0000
@@ -53,7 +53,7 @@ c_ulimit(char **wp)
#endif /* RLIMIT_VMEM */
{ (char *) 0 }
};
- static char options[4 + NELEM(limits) * 2];
+ static char options[4 + nitems(limits) * 2];
int how = SOFT | HARD;
const struct limits *l;
int optc, all = 0;
Index: bin/ksh/edit.c
===================================================================
RCS file: /cvs/src/bin/ksh/edit.c,v
retrieving revision 1.34
diff -u -p -r1.34 edit.c
--- bin/ksh/edit.c 20 May 2010 01:13:07 -0000 1.34
+++ bin/ksh/edit.c 12 May 2011 23:03:48 -0000
@@ -223,7 +223,7 @@ set_editmode(const char *ed)
if ((rcp = strrchr(ed, '/')))
ed = ++rcp;
- for (i = 0; i < NELEM(edit_flags); i++)
+ for (i = 0; i < nitems(edit_flags); i++)
if (strstr(ed, options[(int) edit_flags[i]].name)) {
change_flag(edit_flags[i], OF_SPECIAL, 1);
return;
Index: bin/ksh/emacs.c
===================================================================
RCS file: /cvs/src/bin/ksh/emacs.c,v
retrieving revision 1.43
diff -u -p -r1.43 emacs.c
--- bin/ksh/emacs.c 14 Mar 2011 21:20:01 -0000 1.43
+++ bin/ksh/emacs.c 12 May 2011 23:03:49 -0000
@@ -1312,7 +1312,7 @@ x_bind( const char *a1, const char *a2,
/* List function names */
if (list) {
- for (f = 0; f < NELEM(x_ftab); f++)
+ for (f = 0; f < nitems(x_ftab); f++)
if (x_ftab[f].xf_name &&
!(x_ftab[f].xf_flags & XF_NOBIND))
shprintf("%s\n", x_ftab[f].xf_name);
@@ -1352,11 +1352,11 @@ x_bind( const char *a1, const char *a2,
if (*a2 == 0)
f = XFUNC_insert;
else if (!macro) {
- for (f = 0; f < NELEM(x_ftab); f++)
+ for (f = 0; f < nitems(x_ftab); f++)
if (x_ftab[f].xf_name &&
strcmp(x_ftab[f].xf_name, a2) == 0)
break;
- if (f == NELEM(x_ftab) || x_ftab[f].xf_flags & XF_NOBIND) {
+ if (f == nitems(x_ftab) || x_ftab[f].xf_flags & XF_NOBIND) {
bi_errorf("%s: no such function", a2);
return 1;
}
@@ -1402,7 +1402,7 @@ x_init_emacs(void)
for (i = 1; i < X_NTABS; i++)
for (j = 0; j < X_TABSZ; j++)
x_tab[i][j] = XFUNC_error;
- for (i = 0; i < NELEM(x_defbindings); i++)
+ for (i = 0; i < nitems(x_defbindings); i++)
x_tab[(unsigned char)x_defbindings[i].xdb_tab]
[x_defbindings[i].xdb_char]
= x_defbindings[i].xdb_func;
Index: bin/ksh/jobs.c
===================================================================
RCS file: /cvs/src/bin/ksh/jobs.c,v
retrieving revision 1.39
diff -u -p -r1.39 jobs.c
--- bin/ksh/jobs.c 13 Dec 2009 04:36:48 -0000 1.39
+++ bin/ksh/jobs.c 12 May 2011 23:03:49 -0000
@@ -169,7 +169,7 @@ j_init(int mflagset)
/* the TF_SHELL_USES test is a kludge that lets us know if
* if the signals have been changed by the shell.
*/
- for (i = NELEM(tt_sigs); --i >= 0; ) {
+ for (i = nitems(tt_sigs); --i >= 0; ) {
sigtraps[tt_sigs[i]].flags |= TF_SHELL_USES;
/* j_change() sets this to SS_RESTORE_DFL if FMONITOR */
setsig(&sigtraps[tt_sigs[i]], SIG_IGN,
@@ -282,7 +282,7 @@ j_change(void)
kill(0, SIGTTIN);
}
}
- for (i = NELEM(tt_sigs); --i >= 0; )
+ for (i = nitems(tt_sigs); --i >= 0; )
setsig(&sigtraps[tt_sigs[i]], SIG_IGN,
SS_RESTORE_DFL|SS_FORCE);
if (ttypgrp_ok && our_pgrp != kshpid) {
@@ -311,11 +311,11 @@ j_change(void)
} else {
ttypgrp_ok = 0;
if (Flag(FTALKING))
- for (i = NELEM(tt_sigs); --i >= 0; )
+ for (i = nitems(tt_sigs); --i >= 0; )
setsig(&sigtraps[tt_sigs[i]], SIG_IGN,
SS_RESTORE_IGN|SS_FORCE);
else
- for (i = NELEM(tt_sigs); --i >= 0; ) {
+ for (i = nitems(tt_sigs); --i >= 0; ) {
if (sigtraps[tt_sigs[i]].flags &
(TF_ORIG_IGN | TF_ORIG_DFL))
setsig(&sigtraps[tt_sigs[i]],
@@ -449,7 +449,7 @@ exchild(struct op *t, int flags, volatil
* their inherited values.
*/
if (Flag(FMONITOR) && !(flags & XXCOM)) {
- for (i = NELEM(tt_sigs); --i >= 0; )
+ for (i = nitems(tt_sigs); --i >= 0; )
setsig(&sigtraps[tt_sigs[i]], SIG_DFL,
SS_RESTORE_DFL|SS_FORCE);
}
Index: bin/ksh/misc.c
===================================================================
RCS file: /cvs/src/bin/ksh/misc.c,v
retrieving revision 1.37
diff -u -p -r1.37 misc.c
--- bin/ksh/misc.c 19 Apr 2009 20:34:05 -0000 1.37
+++ bin/ksh/misc.c 12 May 2011 23:03:49 -0000
@@ -179,7 +179,7 @@ option(const char *n)
{
int i;
- for (i = 0; i < NELEM(options); i++)
+ for (i = 0; i < nitems(options); i++)
if (options[i].name && strcmp(options[i].name, n) == 0)
return i;
@@ -191,7 +191,7 @@ struct options_info {
struct {
const char *name;
int flag;
- } opts[NELEM(options)];
+ } opts[nitems(options)];
};
static char *options_fmt_entry(void *arg, int i, char *buf, int buflen);
@@ -221,7 +221,7 @@ printoptions(int verbose)
/* verbose version */
shprintf("Current option settings\n");
- for (i = n = oi.opt_width = 0; i < NELEM(options); i++)
+ for (i = n = oi.opt_width = 0; i < nitems(options); i++)
if (options[i].name) {
len = strlen(options[i].name);
oi.opts[n].name = options[i].name;
@@ -234,7 +234,7 @@ printoptions(int verbose)
} else {
/* short version ala ksh93 */
shprintf("set");
- for (i = 0; i < NELEM(options); i++)
+ for (i = 0; i < nitems(options); i++)
if (Flag(i) && options[i].name)
shprintf(" -o %s", options[i].name);
shprintf(newline);
@@ -248,7 +248,7 @@ getoptions(void)
char m[(int) FNFLAGS + 1];
char *cp = m;
- for (i = 0; i < NELEM(options); i++)
+ for (i = 0; i < nitems(options); i++)
if (options[i].c && Flag(i))
*cp++ = options[i].c;
*cp = 0;
@@ -320,8 +320,8 @@ parse_args(char **argv,
int what, /* OF_CMDLINE or OF_SET */
int *setargsp)
{
- static char cmd_opts[NELEM(options) + 3]; /* o:\0 */
- static char set_opts[NELEM(options) + 5]; /* Ao;s\0 */
+ static char cmd_opts[nitems(options) + 3]; /* o:\0 */
+ static char set_opts[nitems(options) + 5]; /* Ao;s\0 */
char *opts;
char *array = (char *) 0;
Getopt go;
@@ -337,7 +337,7 @@ parse_args(char **argv,
/* see set_opts[] declaration */
strlcpy(set_opts, "A:o;s", sizeof set_opts);
q = set_opts + strlen(set_opts);
- for (i = 0; i < NELEM(options); i++) {
+ for (i = 0; i < nitems(options); i++) {
if (options[i].c) {
if (options[i].flags & OF_CMDLINE)
*p++ = options[i].c;
@@ -404,14 +404,14 @@ parse_args(char **argv,
sortargs = 1;
break;
}
- for (i = 0; i < NELEM(options); i++)
+ for (i = 0; i < nitems(options); i++)
if (optc == options[i].c &&
(what & options[i].flags)) {
change_flag((enum sh_flag) i, what,
set);
break;
}
- if (i == NELEM(options)) {
+ if (i == nitems(options)) {
internal_errorf(1, "parse_args: `%c'", optc);
return -1; /* not reached */
}
Index: bin/ksh/sh.h
===================================================================
RCS file: /cvs/src/bin/ksh/sh.h,v
retrieving revision 1.30
diff -u -p -r1.30 sh.h
--- bin/ksh/sh.h 4 Jan 2010 18:07:11 -0000 1.30
+++ bin/ksh/sh.h 12 May 2011 23:03:49 -0000
@@ -12,6 +12,7 @@
#include <stdio.h>
#include <sys/types.h>
+#include <sys/param.h>
#include <setjmp.h>
#include <stdbool.h>
#include <stddef.h>
@@ -48,7 +49,6 @@
#define EXECSHELL _PATH_BSHELL
#define EXECSHELL_STR "EXECSHELL"
-#define NELEM(a) (sizeof(a) / sizeof((a)[0]))
#define sizeofN(type, n) (sizeof(type) * (n))
#define BIT(i) (1<<(i)) /* define bit in flag */