1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-11-01 18:30:55 +01:00

Add -L option to the hash builtin

This commit is contained in:
Oliver Kiddle 2000-05-15 00:31:20 +00:00
parent 26cc1ad1df
commit 6ff206e057
6 changed files with 32 additions and 6 deletions

View file

@ -1,3 +1,8 @@
2000-05-15 Oliver Kiddle <opk@zsh.org>
* 11xxx: Src/builtin.c, Src/hashtable.c, Completion/Builtins/_hash,
Doc/Zsh/builtins.yo, Completion/Builtins/_vars_eq: add -L opt to hash
2000-05-14 Peter Stephenson <pws@pwstephenson.fsnet.co.uk>
* Src/builtin.c: make integer builtin understand `-i base'.

View file

@ -13,6 +13,7 @@ case ${words[1]} in
'(-f -m -v)-r[empty hash table]' \
'(-f -r)-m[treat arguments as patterns]' \
'(-f -r -m)-v[list entires as they are added]' \
'(-f -r -v)-L[list in the form of calls to hash]' \
"${common_args[@]}" \
'(-d -f -r -m -v)*:hash:->hashval' && return 0
;;

View file

@ -39,7 +39,7 @@ case ${words[1]} in
use="Umtu"
func=f
;;
integer) use="ghlrtux" ;;
integer) use="ghilrtux" ;;
readonly) use="${use/r/}" ;;
local) use="${use/f/}" ;&
export) use="${${use/g/}/x/}" ;;

View file

@ -452,7 +452,7 @@ an error message when an option is invalid. The exit status is
nonzero when there are no more options.
)
findex(hash)
item(tt(hash) [ tt(-dfmrv) ] [ var(name)[tt(=)var(value)] ] ...)(
item(tt(hash) [ tt(-Ldfmrv) ] [ var(name)[tt(=)var(value)] ] ...)(
tt(hash) can be used to directly modify the contents of the command
hash table, and the named directory hash table. Normally one would
modify these tables by modifying one's tt(PATH)
@ -494,6 +494,9 @@ the hash table will be unchanged.
The tt(-v) option causes hash table entries to be listed as they are
added by explicit specification. If has no effect if used with tt(-f).
If the tt(-L) flag is present, then each hash table entry is printed in
the form of a call to hash.
)
alias(history)(fc -l)
findex(integer)

View file

@ -68,7 +68,7 @@ static struct builtin builtins[] =
BUILTIN("functions", BINF_TYPEOPTS, bin_functions, 0, -1, 0, "mtuU", NULL),
BUILTIN("getln", 0, bin_read, 0, -1, 0, "ecnAlE", "zr"),
BUILTIN("getopts", 0, bin_getopts, 2, -1, 0, NULL, NULL),
BUILTIN("hash", BINF_MAGICEQUALS, bin_hash, 0, -1, 0, "dfmrv", NULL),
BUILTIN("hash", BINF_MAGICEQUALS, bin_hash, 0, -1, 0, "Ldfmrv", NULL),
#ifdef ZSH_HASH_DEBUG
BUILTIN("hashinfo", 0, bin_hashinfo, 0, 0, 0, NULL, NULL),
@ -99,7 +99,7 @@ static struct builtin builtins[] =
BUILTIN("r", BINF_R, bin_fc, 0, -1, BIN_FC, "nrl", NULL),
BUILTIN("read", 0, bin_read, 0, -1, 0, "rzu0123456789pkqecnAlE", NULL),
BUILTIN("readonly", BINF_TYPEOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL, bin_typeset, 0, -1, 0, "AEFLRTUZafghiltux", "r"),
BUILTIN("rehash", 0, bin_hash, 0, 0, 0, "dfv", "r"),
BUILTIN("rehash", 0, bin_hash, 0, 0, 0, "df", "r"),
BUILTIN("return", BINF_PSPECIAL, bin_break, 0, 1, BIN_RETURN, NULL, NULL),
BUILTIN("set", BINF_PSPECIAL, bin_set, 0, -1, 0, NULL, NULL),
BUILTIN("setopt", 0, bin_setopt, 0, -1, BIN_SETOPT, NULL, NULL),
@ -2461,6 +2461,7 @@ bin_hash(char *name, char **argv, char *ops, int func)
Patprog pprog;
Asgment asg;
int returnval = 0;
int printflags = 0;
if (ops['d'])
ht = nameddirtab;
@ -2485,9 +2486,11 @@ bin_hash(char *name, char **argv, char *ops, int func)
return 0;
}
if (ops['L']) printflags |= PRINT_LIST;
/* Given no arguments, display current hash table. */
if (!*argv) {
scanhashtable(ht, 1, 0, 0, ht->printnode, 0);
scanhashtable(ht, 1, 0, 0, ht->printnode, printflags);
return 0;
}
@ -2498,7 +2501,7 @@ bin_hash(char *name, char **argv, char *ops, int func)
tokenize(*argv); /* expand */
if ((pprog = patcompile(*argv, PAT_STATIC, NULL))) {
/* display matching hash table elements */
scanmatchtable(ht, pprog, 0, 0, ht->printnode, 0);
scanmatchtable(ht, pprog, 0, 0, ht->printnode, printflags);
} else {
untokenize(*argv);
zwarnnam(name, "bad pattern : %s", *argv, 0);

View file

@ -734,6 +734,13 @@ printcmdnamnode(HashNode hn, int printflags)
return;
}
if (printflags & PRINT_LIST) {
printf("hash ");
if(cn->nam[0] == '-')
printf("-- ");
}
if (cn->flags & HASHED) {
quotedzputs(cn->nam, stdout);
putchar('=');
@ -1371,6 +1378,13 @@ printnameddirnode(HashNode hn, int printflags)
putchar('\n');
return;
}
if (printflags & PRINT_LIST) {
printf("hash -d ");
if(nd->nam[0] == '-')
printf("-- ");
}
quotedzputs(nd->nam, stdout);
putchar('=');