1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-01-21 00:01:26 +01:00

25755/25756: Jörg Sommer: improved handling of module arguments

25759: fix dynamic named directory crash, static named directory consistency
This commit is contained in:
Peter Stephenson 2008-09-27 19:57:25 +00:00
parent 4ba03217ca
commit 4a34c96289
5 changed files with 48 additions and 16 deletions

View file

@ -1,3 +1,14 @@
2008-09-27 Peter Stephenson <p.w.stephenson@ntlworld.com>
* Jörg Sommer: 25755, with tweak from 25756:
Completion/Linux/Command/_modutils (args): improved handling
of module arguments.
* 25759: Doc/Zsh/expn.yo, Src/builtin.c, Src/subst.c: fix crash
after failed dynamic named directory expansion; clarify the
fact that static named directories can contain only
alphanumerics, `_', `-' or `.'.
2008-09-26 Clint Adams <clint@zsh.org> 2008-09-26 Clint Adams <clint@zsh.org>
* Mikael Magnusson: 25617: Completion/Unix/Command/_vim: * Mikael Magnusson: 25617: Completion/Unix/Command/_vim:

View file

@ -36,7 +36,7 @@ case "$service" in
'(-C --config)'{-C,--config}'[specify config file]:config file:_files' \ '(-C --config)'{-C,--config}'[specify config file]:config file:_files' \
"(-r --remove -l --list -t --type -a --all $ign)"{-r,--remove}'[remove module (stacks)]' \ "(-r --remove -l --list -t --type -a --all $ign)"{-r,--remove}'[remove module (stacks)]' \
"(* -l --list -r --remove $ign)"{-l,--list}'[list matching modules]' \ "(* -l --list -r --remove $ign)"{-l,--list}'[list matching modules]' \
"(-c $ign)1:modules:->all_modules" \ "(-c $ign)1:modules:->loadable_modules" \
"(-c -l --list -t --type $ign)*:params:->params" && ret=0 "(-c -l --list -t --type $ign)*:params:->params" && ret=0
[[ -n $state ]] && (( $+opt_args[-r] )) && state=loaded_modules [[ -n $state ]] && (( $+opt_args[-r] )) && state=loaded_modules
@ -60,23 +60,31 @@ case "$service" in
esac esac
case "$state" in case "$state" in
loaded_modules) loaded_modules|loadable_modules)
if [[ -r /proc/modules ]]; then if [[ -r /proc/modules ]]; then
modules=(${${(f)"$(</proc/modules)"}%% *}) loaded_modules=(${${(f)"$(</proc/modules)"}%% *})
elif [[ -x /sbin/lsmod ]]; then elif [[ -x /sbin/lsmod ]]; then
modules=(${${(f)"$(/sbin/lsmod)"}[2,-1]%% *}) loaded_modules=(${${(f)"$(/sbin/lsmod)"}[2,-1]%% *})
else else
return 1 return 1
fi fi
_wanted modules expl 'loaded module' compadd -a modules && return if [[ $state = loaded_modules ]]; then
;; _wanted modules expl 'loaded module' compadd -a loaded_modules && return
return ret
fi
;&
all_modules) all_modules)
modules=( ${${${${(f)"$(_call_program modules ${(M)words[1]##*/}modprobe -l 2>/dev/null)"}:#}##*/}%%.*} ) modules=( ${${${${(f)"$(_call_program modules ${(M)words[1]##*/}modprobe -l 2>/dev/null)"}:#}##*/}%%.*} )
if [[ $state = loadable_modules ]]; then
modules=( ${modules:#(${(j:|:)~${=loaded_modules//_/-}})} )
fi
_tags files modules _tags files modules
while _tags; do while _tags; do
_requested files expl "module file" _files && ret=0 _requested files expl "module file" _files -g '*.ko' && ret=0
_requested modules expl module compadd -a modules && ret=0 _requested modules expl module compadd -a modules && ret=0
done done
;; ;;

View file

@ -1375,13 +1375,16 @@ subsect(Static named directories)
cindex(directories, named, static) cindex(directories, named, static)
cindex(named directories, static) cindex(named directories, static)
cindex(static named directories) cindex(static named directories)
A `tt(~)' followed by anything not already covered is looked up as a A `tt(~)' followed by anything not already covered consisting
of any number of alphanumeric characters or underscore (`tt(_)'),
hyphen (`tt(-)'), or dot (`tt(.)') is looked up as a
named directory, and replaced by the value of that named directory if found. named directory, and replaced by the value of that named directory if found.
Named directories are typically home directories for users on the system. Named directories are typically home directories for users on the system.
They may also be defined if the text after the `tt(~)' is the name They may also be defined if the text after the `tt(~)' is the name
of a string shell parameter whose value begins with a `tt(/)'. of a string shell parameter whose value begins with a `tt(/)'.
Note that trailing slashes will be removed from the path to the directory Note that trailing slashes will be removed from the path to the directory
(though the original parameter is not modified). (though the original parameter is not modified).
It is also possible to define directory names using the tt(-d) option to the It is also possible to define directory names using the tt(-d) option to the
tt(hash) builtin. tt(hash) builtin.

View file

@ -3262,9 +3262,19 @@ bin_hash(char *name, char **argv, Options ops, UNUSED(int func))
/* The argument is of the form foo=bar, * /* The argument is of the form foo=bar, *
* so define an entry for the table. */ * so define an entry for the table. */
if(OPT_ISSET(ops,'d')) { if(OPT_ISSET(ops,'d')) {
Nameddir nd = hn = zshcalloc(sizeof *nd); /* shouldn't return NULL if asg->name is not NULL */
nd->node.flags = 0; if (*itype_end(asg->name, IUSER, 0)) {
nd->dir = ztrdup(asg->value); zwarnnam(name,
"invalid character in directory name: %s",
asg->name);
returnval = 1;
argv++;
continue;
} else {
Nameddir nd = hn = zshcalloc(sizeof *nd);
nd->node.flags = 0;
nd->dir = ztrdup(asg->value);
}
} else { } else {
Cmdnam cn = hn = zshcalloc(sizeof *cn); Cmdnam cn = hn = zshcalloc(sizeof *cn);
cn->node.flags = HASHED; cn->node.flags = HASHED;

View file

@ -529,7 +529,7 @@ filesubstr(char **namptr, int assign)
if (*str == Tilde && str[1] != '=' && str[1] != Equals) { if (*str == Tilde && str[1] != '=' && str[1] != Equals) {
Shfunc dirfunc; Shfunc dirfunc;
char *ptr, *tmp, *res; char *ptr, *tmp, *res, *ptr2;
int val; int val;
val = zstrtol(str + 1, &ptr, 10); val = zstrtol(str + 1, &ptr, 10);
@ -544,14 +544,14 @@ filesubstr(char **namptr, int assign)
return 1; return 1;
} else if (str[1] == Inbrack && } else if (str[1] == Inbrack &&
(dirfunc = getshfunc("zsh_directory_name")) && (dirfunc = getshfunc("zsh_directory_name")) &&
(ptr = strchr(str+2, Outbrack))) { (ptr2 = strchr(str+2, Outbrack))) {
char **arr; char **arr;
untokenize(tmp = dupstrpfx(str+2, ptr - (str+2))); untokenize(tmp = dupstrpfx(str+2, ptr2 - (str+2)));
remnulargs(tmp); remnulargs(tmp);
arr = subst_string_by_func(dirfunc, "n", tmp); arr = subst_string_by_func(dirfunc, "n", tmp);
res = arr ? *arr : NULL; res = arr ? *arr : NULL;
if (res) { if (res) {
*namptr = dyncat(res, ptr+1); *namptr = dyncat(res, ptr2+1);
return 1; return 1;
} }
if (isset(NOMATCH)) if (isset(NOMATCH))