aboutsummaryrefslogtreecommitdiff
path: root/bin/sh/alias.c
diff options
context:
space:
mode:
Diffstat (limited to 'bin/sh/alias.c')
-rw-r--r--bin/sh/alias.c42
1 files changed, 28 insertions, 14 deletions
diff --git a/bin/sh/alias.c b/bin/sh/alias.c
index bbcf5fbe17e3..681e82b3e19e 100644
--- a/bin/sh/alias.c
+++ b/bin/sh/alias.c
@@ -30,14 +30,6 @@
* SUCH DAMAGE.
*/
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)alias.c 8.3 (Berkeley) 5/4/95";
-#endif
-#endif /* not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <stdlib.h>
#include "shell.h"
#include "output.h"
@@ -55,7 +47,7 @@ static int aliases;
static void setalias(const char *, const char *);
static int unalias(const char *);
-static struct alias **hashalias(const char *);
+static size_t hashalias(const char *);
static
void
@@ -64,7 +56,7 @@ setalias(const char *name, const char *val)
struct alias *ap, **app;
unalias(name);
- app = hashalias(name);
+ app = &atab[hashalias(name)];
INTOFF;
ap = ckmalloc(sizeof (struct alias));
ap->name = savestr(name);
@@ -89,7 +81,7 @@ unalias(const char *name)
{
struct alias *ap, **app;
- app = hashalias(name);
+ app = &atab[hashalias(name)];
for (ap = *app; ap; app = &(ap->next), ap = ap->next) {
if (equal(name, ap->name)) {
@@ -147,7 +139,7 @@ lookupalias(const char *name, int check)
if (aliases == 0)
return (NULL);
- for (ap = *hashalias(name); ap; ap = ap->next) {
+ for (ap = atab[hashalias(name)]; ap; ap = ap->next) {
if (equal(name, ap->name)) {
if (check && (ap->flag & ALIASINUSE))
return (NULL);
@@ -212,6 +204,11 @@ aliascmd(int argc __unused, char **argv __unused)
return (0);
}
while ((n = *argptr++) != NULL) {
+ if (n[0] == '\0') {
+ warning("'': not found");
+ ret = 1;
+ continue;
+ }
if ((v = strchr(n+1, '=')) == NULL) /* n+1: funny ksh stuff */
if ((ap = lookupalias(n, 0)) == NULL) {
warning("%s: not found", n);
@@ -244,7 +241,7 @@ unaliascmd(int argc __unused, char **argv __unused)
return (i);
}
-static struct alias **
+static size_t
hashalias(const char *p)
{
unsigned int hashval;
@@ -252,5 +249,22 @@ hashalias(const char *p)
hashval = (unsigned char)*p << 4;
while (*p)
hashval+= *p++;
- return &atab[hashval % ATABSIZE];
+ return (hashval % ATABSIZE);
+}
+
+const struct alias *
+iteralias(const struct alias *index)
+{
+ size_t i = 0;
+
+ if (index != NULL) {
+ if (index->next != NULL)
+ return (index->next);
+ i = hashalias(index->name) + 1;
+ }
+ for (; i < ATABSIZE; i++)
+ if (atab[i] != NULL)
+ return (atab[i]);
+
+ return (NULL);
}