aboutsummaryrefslogtreecommitdiff
path: root/bin/sh/exec.c
diff options
context:
space:
mode:
Diffstat (limited to 'bin/sh/exec.c')
-rw-r--r--bin/sh/exec.c54
1 files changed, 39 insertions, 15 deletions
diff --git a/bin/sh/exec.c b/bin/sh/exec.c
index 43095a252a35..f7788d0758e3 100644
--- a/bin/sh/exec.c
+++ b/bin/sh/exec.c
@@ -30,14 +30,6 @@
* SUCH DAMAGE.
*/
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)exec.c 8.4 (Berkeley) 6/8/95";
-#endif
-#endif /* not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
@@ -547,6 +539,19 @@ clearcmdentry(void)
}
+static unsigned int
+hashname(const char *p)
+{
+ unsigned int hashval;
+
+ hashval = (unsigned char)*p << 4;
+ while (*p)
+ hashval += *p++;
+
+ return (hashval % CMDTABLESIZE);
+}
+
+
/*
* Locate a command in the command hash table. If "add" is nonzero,
* add the command to the table if it is not already present. The
@@ -561,17 +566,11 @@ static struct tblentry **lastcmdentry;
static struct tblentry *
cmdlookup(const char *name, int add)
{
- unsigned int hashval;
- const char *p;
struct tblentry *cmdp;
struct tblentry **pp;
size_t len;
- p = name;
- hashval = (unsigned char)*p << 4;
- while (*p)
- hashval += *p++;
- pp = &cmdtable[hashval % CMDTABLESIZE];
+ pp = &cmdtable[hashname(name)];
for (cmdp = *pp ; cmdp ; cmdp = cmdp->next) {
if (equal(cmdp->cmdname, name))
break;
@@ -590,6 +589,31 @@ cmdlookup(const char *name, int add)
return cmdp;
}
+const void *
+itercmd(const void *entry, struct cmdentry *result)
+{
+ const struct tblentry *e = entry;
+ size_t i = 0;
+
+ if (e != NULL) {
+ if (e->next != NULL) {
+ e = e->next;
+ goto success;
+ }
+ i = hashname(e->cmdname) + 1;
+ }
+ for (; i < CMDTABLESIZE; i++)
+ if ((e = cmdtable[i]) != NULL)
+ goto success;
+
+ return (NULL);
+success:
+ result->cmdtype = e->cmdtype;
+ result->cmdname = e->cmdname;
+
+ return (e);
+}
+
/*
* Delete the command entry returned on the last lookup.
*/