summaryrefslogtreecommitdiff
path: root/Src/hashtable.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2003-09-03 10:15:32 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2003-09-03 10:15:32 +0000
commit3ffb3ad2f2f733fbee58e21dc6aab23827ab8d49 (patch)
tree3ccb2278fd41a91aea8935e4454f91ec4ddd7df0 /Src/hashtable.c
parent716e9253122b962da887fde382c9fd00b40c8a42 (diff)
downloadzsh-3ffb3ad2f2f733fbee58e21dc6aab23827ab8d49.tar.gz
zsh-3ffb3ad2f2f733fbee58e21dc6aab23827ab8d49.zip
19014: add alias -s suf=handler
Diffstat (limited to 'Src/hashtable.c')
-rw-r--r--Src/hashtable.c74
1 files changed, 52 insertions, 22 deletions
diff --git a/Src/hashtable.c b/Src/hashtable.c
index 9fc7a3232..faa858532 100644
--- a/Src/hashtable.c
+++ b/Src/hashtable.c
@@ -1014,30 +1014,51 @@ printreswdnode(HashNode hn, int printflags)
/**/
mod_export HashTable aliastab;
-/* Create new hash table for aliases */
+/* has table containing suffix aliases */
+
+/**/
+mod_export HashTable sufaliastab;
+
+/* Create new hash tables for aliases */
+
+/**/
+void
+createaliastable(HashTable ht)
+{
+ ht->hash = hasher;
+ ht->emptytable = NULL;
+ ht->filltable = NULL;
+ ht->cmpnodes = strcmp;
+ ht->addnode = addhashnode;
+ ht->getnode = gethashnode;
+ ht->getnode2 = gethashnode2;
+ ht->removenode = removehashnode;
+ ht->disablenode = disablehashnode;
+ ht->enablenode = enablehashnode;
+ ht->freenode = freealiasnode;
+ ht->printnode = printaliasnode;
+}
/**/
void
-createaliastable(void)
+createaliastables(void)
{
+ /* Table for regular and global aliases */
+
aliastab = newhashtable(23, "aliastab", NULL);
- aliastab->hash = hasher;
- aliastab->emptytable = NULL;
- aliastab->filltable = NULL;
- aliastab->cmpnodes = strcmp;
- aliastab->addnode = addhashnode;
- aliastab->getnode = gethashnode;
- aliastab->getnode2 = gethashnode2;
- aliastab->removenode = removehashnode;
- aliastab->disablenode = disablehashnode;
- aliastab->enablenode = enablehashnode;
- aliastab->freenode = freealiasnode;
- aliastab->printnode = printaliasnode;
+ createaliastable(aliastab);
/* add the default aliases */
aliastab->addnode(aliastab, ztrdup("run-help"), createaliasnode(ztrdup("man"), 0));
aliastab->addnode(aliastab, ztrdup("which-command"), createaliasnode(ztrdup("whence"), 0));
+
+
+ /* Table for suffix aliases --- make this smaller */
+
+ sufaliastab = newhashtable(11, "sufaliastab", NULL);
+
+ createaliastable(sufaliastab);
}
/* Create a new alias node */
@@ -1093,10 +1114,12 @@ printaliasnode(HashNode hn, int printflags)
if (printflags & PRINT_WHENCE_CSH) {
nicezputs(a->nam, stdout);
- if (a->flags & ALIAS_GLOBAL)
- printf(": globally aliased to ");
- else
- printf(": aliased to ");
+ printf(": ");
+ if (a->flags & ALIAS_SUFFIX)
+ printf("suffix ");
+ else if (a->flags & ALIAS_GLOBAL)
+ printf("globally ");
+ printf (" aliased to ");
nicezputs(a->text, stdout);
putchar('\n');
return;
@@ -1104,10 +1127,14 @@ printaliasnode(HashNode hn, int printflags)
if (printflags & PRINT_WHENCE_VERBOSE) {
nicezputs(a->nam, stdout);
- if (a->flags & ALIAS_GLOBAL)
- printf(" is a global alias for ");
+ printf(" is a");
+ if (a->flags & ALIAS_SUFFIX)
+ printf(" suffix");
+ else if (a->flags & ALIAS_GLOBAL)
+ printf(" global");
else
- printf(" is an alias for ");
+ printf("n");
+ printf(" alias for");
nicezputs(a->text, stdout);
putchar('\n');
return;
@@ -1115,7 +1142,9 @@ printaliasnode(HashNode hn, int printflags)
if (printflags & PRINT_LIST) {
printf("alias ");
- if (a->flags & ALIAS_GLOBAL)
+ if (a->flags & ALIAS_SUFFIX)
+ printf("-s ");
+ else if (a->flags & ALIAS_GLOBAL)
printf("-g ");
/* If an alias begins with `-', then we must output `-- ' *
@@ -1127,6 +1156,7 @@ printaliasnode(HashNode hn, int printflags)
quotedzputs(a->nam, stdout);
putchar('=');
quotedzputs(a->text, stdout);
+
putchar('\n');
}