aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-06-25 10:55:35 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-06-25 10:55:35 +0000
commit80b8b39899a09c7516920cda5fd343b3086d4824 (patch)
treeaa9903fd6b64d19c5f640fa302272d85c92b204e /shell
parent1399282b47bb218132a554cbe5b2b0ce4dcc055f (diff)
downloadbusybox-80b8b39899a09c7516920cda5fd343b3086d4824.tar.gz
Consolidate ARRAY_SIZE macro; remove one unneeded global var (walter harms <wharms@bfs.de>)
Diffstat (limited to 'shell')
-rw-r--r--shell/ash.c13
-rw-r--r--shell/hush.c4
-rw-r--r--shell/lash.c4
-rw-r--r--shell/msh.c6
4 files changed, 13 insertions, 14 deletions
diff --git a/shell/ash.c b/shell/ash.c
index b54f66609..d9fe64121 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -101,7 +101,7 @@ static const char *const optletters_optnames[] = {
#define optletters(n) optletters_optnames[(n)][0]
#define optnames(n) (&optletters_optnames[(n)][1])
-#define NOPTS (sizeof(optletters_optnames)/sizeof(optletters_optnames[0]))
+enum { NOPTS = ARRAY_SIZE(optletters_optnames) };
static char optlist[NOPTS];
@@ -1837,7 +1837,7 @@ initvar(void)
vps1.text = "PS1=# ";
#endif
vp = varinit;
- end = vp + sizeof(varinit) / sizeof(varinit[0]);
+ end = vp + ARRAY_SIZE(varinit);
do {
vpp = hashvar(vp->text);
vp->next = *vpp;
@@ -6876,8 +6876,8 @@ static const char *const *
findkwd(const char *s)
{
return bsearch(s, tokname_array + KWDOFFSET,
- (sizeof(tokname_array) / sizeof(char *)) - KWDOFFSET,
- sizeof(char *), pstrcmp);
+ ARRAY_SIZE(tokname_array) - KWDOFFSET,
+ sizeof(tokname_array[0]), pstrcmp);
}
/*
@@ -8094,7 +8094,6 @@ static const struct builtincmd builtintab[] = {
{ BUILTIN_REGULAR "wait", waitcmd },
};
-#define NUMBUILTINS (sizeof(builtintab) / sizeof(builtintab[0]))
#define COMMANDCMD (builtintab + 5 + \
2 * ENABLE_ASH_BUILTIN_TEST + \
@@ -8116,7 +8115,7 @@ find_builtin(const char *name)
struct builtincmd *bp;
bp = bsearch(
- name, builtintab, NUMBUILTINS, sizeof(builtintab[0]),
+ name, builtintab, ARRAY_SIZE(builtintab), sizeof(builtintab[0]),
pstrcmp
);
return bp;
@@ -11255,7 +11254,7 @@ helpcmd(int argc, char **argv)
int col, i;
out1fmt("\nBuilt-in commands:\n-------------------\n");
- for (col = 0, i = 0; i < NUMBUILTINS; i++) {
+ for (col = 0, i = 0; i < ARRAY_SIZE(builtintab) ; i++) {
col += out1fmt("%c%s", ((col == 0) ? '\t' : ' '),
builtintab[i].name + 1);
if (col > 60) {
diff --git a/shell/hush.c b/shell/hush.c
index a446bbeb2..275b69ef3 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -2889,10 +2889,10 @@ static int reserved_word(o_string *dest, struct p_context *ctx)
{ "done", RES_DONE, FLAG_END }
#endif
};
- enum { NRES = sizeof(reserved_list)/sizeof(reserved_list[0]) };
+
const struct reserved_combo *r;
- for (r = reserved_list; r < reserved_list + NRES; r++) {
+ for (r = reserved_list; r < reserved_list + ARRAY_SIZE(reserved_list); r++) {
if (strcmp(dest->data, r->literal) != 0)
continue;
debug_printf("found reserved word %s, code %d\n", r->literal, r->code);
diff --git a/shell/lash.c b/shell/lash.c
index 4e8b23776..e5c7ef670 100644
--- a/shell/lash.c
+++ b/shell/lash.c
@@ -146,8 +146,8 @@ static const struct built_in_command bltins[] = {
/* to do: add ulimit */
};
-#define VEC_SIZE(v) (sizeof(v)/sizeof(v[0]))
-#define VEC_LAST(v) v[VEC_SIZE(v)-1]
+
+#define VEC_LAST(v) v[ARRAY_SIZE(v)-1]
static int shell_context; /* Type prompt trigger (PS1 or PS2) */
diff --git a/shell/msh.c b/shell/msh.c
index 2328e0734..effdc0107 100644
--- a/shell/msh.c
+++ b/shell/msh.c
@@ -596,7 +596,7 @@ static const char * const signame[] = {
"Terminated",
};
-#define NSIGNAL (sizeof(signame)/sizeof(signame[0]))
+
struct res {
const char *r_name;
@@ -2997,7 +2997,7 @@ static int waitfor(int lastpid, int canintr)
} else {
rv = WAITSIG(s);
if (rv != 0) {
- if (rv < NSIGNAL) {
+ if (rv < ARRAY_SIZE(signame)) {
if (signame[rv] != NULL) {
if (pid != lastpid) {
prn(pid);
@@ -3016,7 +3016,7 @@ static int waitfor(int lastpid, int canintr)
}
if (WAITCORE(s))
prs(" - core dumped");
- if (rv >= NSIGNAL || signame[rv])
+ if (rv >= ARRAY_SIZE(signame) || signame[rv])
prs("\n");
rv = -1;
} else