aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--shell/ash.c54
-rw-r--r--shell/hush.c26
2 files changed, 45 insertions, 35 deletions
diff --git a/shell/ash.c b/shell/ash.c
index c77ee8620..9bb8fd805 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -10286,44 +10286,56 @@ find_builtin(const char *name)
10286static const char * FAST_FUNC 10286static const char * FAST_FUNC
10287ash_command_name(struct exe_state *e) 10287ash_command_name(struct exe_state *e)
10288{ 10288{
10289 if (e->e_type == 0) { 10289 int index;
10290 if (/*e->e_index >= 0 &&*/ e->e_index < ARRAY_SIZE(builtintab)) { 10290 struct tblentry *cmdp;
10291# if ENABLE_ASH_ALIAS
10292 struct alias *ap;
10293# endif
10294
10295 index = e->e_index;
10296 switch (e->e_type) {
10297 case 0:
10298 if (index < ARRAY_SIZE(builtintab))
10291 return builtintab[e->e_index++].name + 1; 10299 return builtintab[e->e_index++].name + 1;
10292 }
10293 e->e_type++; 10300 e->e_type++;
10294 e->e_index = 0; 10301 index = 0;
10295 e->e_ptr = cmdtable[0]; 10302 /* e->e_ptr = NULL; */
10296 } 10303 /* fall through */
10297 if (e->e_type == 1) { 10304 case 1:
10298 struct tblentry *cmdp = (struct tblentry *)e->e_ptr; 10305 cmdp = (struct tblentry *)e->e_ptr;
10299 while (e->e_index < CMDTABLESIZE) { 10306 for (;;) {
10300 while (cmdp) { 10307 while (cmdp) {
10301 if (cmdp->cmdtype == CMDFUNCTION) { 10308 if (cmdp->cmdtype == CMDFUNCTION) {
10309 e->e_index = index;
10302 e->e_ptr = cmdp->next; 10310 e->e_ptr = cmdp->next;
10303 return cmdp->cmdname; 10311 return cmdp->cmdname;
10304 } 10312 }
10305 cmdp = cmdp->next; 10313 cmdp = cmdp->next;
10306 } 10314 }
10307 cmdp = cmdtable[++e->e_index]; 10315 if (++index == CMDTABLESIZE)
10316 break;
10317 cmdp = cmdtable[index];
10308 } 10318 }
10309# if ENABLE_ASH_ALIAS 10319# if ENABLE_ASH_ALIAS
10310 e->e_type++; 10320 e->e_type++;
10311 e->e_index = 0; 10321 index = 0;
10312 e->e_ptr = atab[0]; 10322 e->e_ptr = NULL;
10313# endif 10323 /* fall through */
10314 } 10324 case 2:
10315# if ENABLE_ASH_ALIAS 10325 ap = (struct alias *)e->e_ptr;
10316 if (e->e_type == 2) { 10326 for (;;) {
10317 struct alias *ap = (struct alias *)e->e_ptr; 10327 if (ap) {
10318 while (e->e_index < ATABSIZE) { 10328 e->e_index = index;
10319 while (ap) {
10320 e->e_ptr = ap->next; 10329 e->e_ptr = ap->next;
10321 return ap->name; 10330 return ap->name;
10322 } 10331 }
10323 ap = atab[++e->e_index]; 10332 if (++index == ATABSIZE)
10333 break;
10334 ap = atab[index];
10324 } 10335 }
10325 }
10326# endif 10336# endif
10337 break;
10338 }
10327 return NULL; 10339 return NULL;
10328} 10340}
10329#endif 10341#endif
diff --git a/shell/hush.c b/shell/hush.c
index 443bdeccf..04633ab2d 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -8222,33 +8222,31 @@ static const struct built_in_command *find_builtin(const char *name)
8222#if ENABLE_HUSH_JOB && ENABLE_FEATURE_TAB_COMPLETION 8222#if ENABLE_HUSH_JOB && ENABLE_FEATURE_TAB_COMPLETION
8223static const char * FAST_FUNC hush_command_name(exe_state *e) 8223static const char * FAST_FUNC hush_command_name(exe_state *e)
8224{ 8224{
8225 if (e->e_type == 0) { 8225 switch (e->e_type) {
8226 if (/*e->e_index >= 0 && */ e->e_index < ARRAY_SIZE(bltins1)) { 8226 case 0:
8227 if (e->e_index < ARRAY_SIZE(bltins1))
8227 return bltins1[e->e_index++].b_cmd; 8228 return bltins1[e->e_index++].b_cmd;
8228 }
8229 e->e_type++; 8229 e->e_type++;
8230 e->e_index = 0; 8230 e->e_index = 0;
8231 /* e->e_ptr = NULL; */ 8231 /* e->e_ptr = NULL; */
8232 } 8232 /* fall through */
8233 if (e->e_type == 1) { 8233 case 1:
8234 if (e->e_index < ARRAY_SIZE(bltins2)) { 8234 if (e->e_index < ARRAY_SIZE(bltins2))
8235 return bltins2[e->e_index++].b_cmd; 8235 return bltins2[e->e_index++].b_cmd;
8236 }
8237# if ENABLE_HUSH_FUNCTIONS 8236# if ENABLE_HUSH_FUNCTIONS
8238 e->e_type++; 8237 e->e_type++;
8239 /* e->e_index = 0; */ 8238 /* e->e_index = 0; */
8240 e->e_ptr = G.top_func; 8239 e->e_ptr = G.top_func;
8241# endif 8240 /* fall through */
8242 } 8241 case 2:
8243# if ENABLE_HUSH_FUNCTIONS 8242 if (e->e_ptr) {
8244 if (e->e_type == 2) { 8243 struct function *funcp = (struct function *)e->e_ptr;
8245 struct function *funcp = (struct function *)e->e_ptr;
8246 while (funcp) {
8247 e->e_ptr = funcp->next; 8244 e->e_ptr = funcp->next;
8248 return funcp->name; 8245 return funcp->name;
8249 } 8246 }
8250 }
8251# endif 8247# endif
8248 break;
8249 }
8252 return NULL; 8250 return NULL;
8253} 8251}
8254#endif 8252#endif