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-w32-80b8b39899a09c7516920cda5fd343b3086d4824.tar.gz
busybox-w32-80b8b39899a09c7516920cda5fd343b3086d4824.tar.bz2
busybox-w32-80b8b39899a09c7516920cda5fd343b3086d4824.zip
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[] = {
101#define optletters(n) optletters_optnames[(n)][0] 101#define optletters(n) optletters_optnames[(n)][0]
102#define optnames(n) (&optletters_optnames[(n)][1]) 102#define optnames(n) (&optletters_optnames[(n)][1])
103 103
104#define NOPTS (sizeof(optletters_optnames)/sizeof(optletters_optnames[0])) 104enum { NOPTS = ARRAY_SIZE(optletters_optnames) };
105 105
106static char optlist[NOPTS]; 106static char optlist[NOPTS];
107 107
@@ -1837,7 +1837,7 @@ initvar(void)
1837 vps1.text = "PS1=# "; 1837 vps1.text = "PS1=# ";
1838#endif 1838#endif
1839 vp = varinit; 1839 vp = varinit;
1840 end = vp + sizeof(varinit) / sizeof(varinit[0]); 1840 end = vp + ARRAY_SIZE(varinit);
1841 do { 1841 do {
1842 vpp = hashvar(vp->text); 1842 vpp = hashvar(vp->text);
1843 vp->next = *vpp; 1843 vp->next = *vpp;
@@ -6876,8 +6876,8 @@ static const char *const *
6876findkwd(const char *s) 6876findkwd(const char *s)
6877{ 6877{
6878 return bsearch(s, tokname_array + KWDOFFSET, 6878 return bsearch(s, tokname_array + KWDOFFSET,
6879 (sizeof(tokname_array) / sizeof(char *)) - KWDOFFSET, 6879 ARRAY_SIZE(tokname_array) - KWDOFFSET,
6880 sizeof(char *), pstrcmp); 6880 sizeof(tokname_array[0]), pstrcmp);
6881} 6881}
6882 6882
6883/* 6883/*
@@ -8094,7 +8094,6 @@ static const struct builtincmd builtintab[] = {
8094 { BUILTIN_REGULAR "wait", waitcmd }, 8094 { BUILTIN_REGULAR "wait", waitcmd },
8095}; 8095};
8096 8096
8097#define NUMBUILTINS (sizeof(builtintab) / sizeof(builtintab[0]))
8098 8097
8099#define COMMANDCMD (builtintab + 5 + \ 8098#define COMMANDCMD (builtintab + 5 + \
8100 2 * ENABLE_ASH_BUILTIN_TEST + \ 8099 2 * ENABLE_ASH_BUILTIN_TEST + \
@@ -8116,7 +8115,7 @@ find_builtin(const char *name)
8116 struct builtincmd *bp; 8115 struct builtincmd *bp;
8117 8116
8118 bp = bsearch( 8117 bp = bsearch(
8119 name, builtintab, NUMBUILTINS, sizeof(builtintab[0]), 8118 name, builtintab, ARRAY_SIZE(builtintab), sizeof(builtintab[0]),
8120 pstrcmp 8119 pstrcmp
8121 ); 8120 );
8122 return bp; 8121 return bp;
@@ -11255,7 +11254,7 @@ helpcmd(int argc, char **argv)
11255 int col, i; 11254 int col, i;
11256 11255
11257 out1fmt("\nBuilt-in commands:\n-------------------\n"); 11256 out1fmt("\nBuilt-in commands:\n-------------------\n");
11258 for (col = 0, i = 0; i < NUMBUILTINS; i++) { 11257 for (col = 0, i = 0; i < ARRAY_SIZE(builtintab) ; i++) {
11259 col += out1fmt("%c%s", ((col == 0) ? '\t' : ' '), 11258 col += out1fmt("%c%s", ((col == 0) ? '\t' : ' '),
11260 builtintab[i].name + 1); 11259 builtintab[i].name + 1);
11261 if (col > 60) { 11260 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)
2889 { "done", RES_DONE, FLAG_END } 2889 { "done", RES_DONE, FLAG_END }
2890#endif 2890#endif
2891 }; 2891 };
2892 enum { NRES = sizeof(reserved_list)/sizeof(reserved_list[0]) }; 2892
2893 const struct reserved_combo *r; 2893 const struct reserved_combo *r;
2894 2894
2895 for (r = reserved_list; r < reserved_list + NRES; r++) { 2895 for (r = reserved_list; r < reserved_list + ARRAY_SIZE(reserved_list); r++) {
2896 if (strcmp(dest->data, r->literal) != 0) 2896 if (strcmp(dest->data, r->literal) != 0)
2897 continue; 2897 continue;
2898 debug_printf("found reserved word %s, code %d\n", r->literal, r->code); 2898 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[] = {
146 /* to do: add ulimit */ 146 /* to do: add ulimit */
147}; 147};
148 148
149#define VEC_SIZE(v) (sizeof(v)/sizeof(v[0])) 149
150#define VEC_LAST(v) v[VEC_SIZE(v)-1] 150#define VEC_LAST(v) v[ARRAY_SIZE(v)-1]
151 151
152 152
153static int shell_context; /* Type prompt trigger (PS1 or PS2) */ 153static 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[] = {
596 "Terminated", 596 "Terminated",
597}; 597};
598 598
599#define NSIGNAL (sizeof(signame)/sizeof(signame[0])) 599
600 600
601struct res { 601struct res {
602 const char *r_name; 602 const char *r_name;
@@ -2997,7 +2997,7 @@ static int waitfor(int lastpid, int canintr)
2997 } else { 2997 } else {
2998 rv = WAITSIG(s); 2998 rv = WAITSIG(s);
2999 if (rv != 0) { 2999 if (rv != 0) {
3000 if (rv < NSIGNAL) { 3000 if (rv < ARRAY_SIZE(signame)) {
3001 if (signame[rv] != NULL) { 3001 if (signame[rv] != NULL) {
3002 if (pid != lastpid) { 3002 if (pid != lastpid) {
3003 prn(pid); 3003 prn(pid);
@@ -3016,7 +3016,7 @@ static int waitfor(int lastpid, int canintr)
3016 } 3016 }
3017 if (WAITCORE(s)) 3017 if (WAITCORE(s))
3018 prs(" - core dumped"); 3018 prs(" - core dumped");
3019 if (rv >= NSIGNAL || signame[rv]) 3019 if (rv >= ARRAY_SIZE(signame) || signame[rv])
3020 prs("\n"); 3020 prs("\n");
3021 rv = -1; 3021 rv = -1;
3022 } else 3022 } else