1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-10-18 00:51:07 +02:00

23665: autoloading of module features and related tweaks

This commit is contained in:
Peter Stephenson 2007-07-06 21:52:38 +00:00
parent 018c9a2708
commit 1b52f47cf2
46 changed files with 1354 additions and 780 deletions

View file

@ -1,3 +1,28 @@
2007-07-06 Peter Stephenson <p.w.stephenson@ntlworld.com>
* 23665: Doc/Zsh/builtins.yo,
Etc/zsh-development-guide,Src/builtin.c, Src/cond.c, Src/exec.c,
Src/hashtable.c, Src/init.c, Src/jobs.c, Src/mkbltnmlst.sh,
Src/module.c, Src/params.c, Src/string.c, Src/zsh.h,
Src/Builtins/rlimits.c, Src/Builtins/sched.c, Src/Modules/cap.c,
Src/Modules/clone.c, Src/Modules/datetime.c,
Src/Modules/example.c, Src/Modules/files.c,
Src/Modules/langinfo.c, Src/Modules/mapfile.c,
Src/Modules/mathfunc.c, Src/Modules/parameter.c,
Src/Modules/pcre.c, Src/Modules/regex.c, Src/Modules/socket.c,
Src/Modules/stat.c, Src/Modules/system.c, Src/Modules/tcp.c,
Src/Modules/termcap.c, Src/Modules/terminfo.c,
Src/Modules/zftp.c, Src/Modules/zprof.c, Src/Modules/zpty.c,
Src/Modules/zselect.c, Src/Modules/zutil.c, Src/Zle/compctl.c,
Src/Zle/complete.c, Src/Zle/complist.c, Src/Zle/computil.c,
Src/Zle/deltochar.c, Src/Zle/zle_main.c, Src/Zle/zleparameter.c,
Test/V01zmodload.ztst: Finish autoloading of modules;
make autoloads persistent. Put modules in hash table.
Rationalise error handling and error messages. Improve
module listing. Abort at top level of list execution when
errflag is set instead of relying on called functions returning
early.
2007-07-06 Clint Adams <clint@zsh.org>
* 23664: Completion/Debian/Command/_bts: handle bts cache

View file

@ -1932,11 +1932,16 @@ the option tt(-P) var(param) then the parameter tt(param) is set to an
array of features, either features together with their state or (if
tt(-L) alone is given) enabled features.
A set of features may be provided together with tt(-l) or tt(-L); in
that case only the state of features provided is considered. Each
feature may be preceded by tt(PLUS()) or tt(-) but the character
has no effect. If no set of features is provided, all features
are considered.
With the option tt(-L) the module name may be omitted; then a list
of all enabled features for all modules providing features is printed
in the form of tt(zmodload -F) commands. If tt(-l) is also given,
the state of both enabled and disabled features is output in that form.
A set of features may be provided together with tt(-l) or tt(-L) and a
module name; in that case only the state of those features is
considered. Each feature may be preceded by tt(PLUS()) or tt(-) but the
character has no effect. If no set of features is provided, all
features are considered.
With tt(-e), the command first tests that the module is loaded;
if it is not, status 1 is returned. If the module is loaded,
@ -1947,11 +1952,31 @@ see if is provided and in the given state. If the tests on all features
in the list succeed, status 0 is returned, else status 1.
With tt(-a), the given list of features is marked for autoload from
the specified module, which may not be loaded. An optional tt(PLUS())
the specified module, which may not yet be loaded. An optional tt(PLUS())
may appear before the feature name. If the feature is prefixed with
tt(-), the existing autoload is deleted. Note that only standard
features as described above can be autoloaded; other features require
the module to be loaded.
tt(-), any existing autoload is removed. The options tt(-l) and tt(-L)
may be used to list autoloads. Autoloading is specific to individual
features; when the module is loaded only the requested feature is
enabled. Autoload requests are preserved if the module is
subsequently unloaded until an explicit `tt(zmodload -Fa) var(module)
tt(-)var(feature)' is issued. It is not an error to request an autoload
for a feature of a module that is already loaded.
When the module is loaded each autoload is checked against the features
actually provided by the module; if the feature is not provided the
autoload request is deleted. A warning message is output; if the
module is being loaded to provide a different feature, and that autoload
is successful, there is no effect on the status of the current command.
If the module is already loaded at the time when tt(zmodload -Fa) is
run, an error message is printed and status 1 returned.
tt(zmodload -Fa) can be used with the tt(-l), tt(-L), tt(-e) and
tt(-P) options for listing and testing the existence of autoloadable
features. In this case tt(-l) is ignored if tt(-L) is specified.
tt(zmodload -FaL) with no module name lists autoloads for all modules.
Note that only standard features as described above can be autoloaded;
other features require the module to be loaded before enabling.
)
xitem(tt(zmodload) tt(-d) [ tt(-L) ] [ var(name) ])
xitem(tt(zmodload) tt(-d) var(name) var(dep) ...)
@ -1973,10 +1998,12 @@ xitem(tt(zmodload) tt(-ab) [ tt(-i) ] var(name) [ var(builtin) ... ])
item(tt(zmodload) tt(-ub) [ tt(-i) ] var(builtin) ...)(
The tt(-ab) option defines autoloaded builtins. It defines the specified
var(builtin)s. When any of those builtins is called, the module specified
in the first argument is loaded. If only the var(name) is given, one
builtin is defined, with the same name as the module. tt(-i) suppresses
the error if the builtin is already defined or autoloaded, regardless of
which module it came from.
in the first argument is loaded and all its features are enabled (for
selective control of features use `tt(zmodload -F -a)' as described
above). If only the var(name) is given, one builtin is defined, with
the same name as the module. tt(-i) suppresses the error if the builtin
is already defined or autoloaded, but not if another builtin of the
same name is already defined.
With tt(-ab) and no arguments, all autoloaded builtins are listed, with the
module name (if different) shown in parentheses after the builtin name.
@ -1987,6 +2014,9 @@ If tt(-b) is used together with the tt(-u) option, it removes builtins
previously defined with tt(-ab). This is only possible if the builtin is
not yet loaded. tt(-i) suppresses the error if the builtin is already
removed (or never existed).
Autoload requests are retained if the module is subsequently unloaded
until an explicit `tt(zmodload -ub) var(builtin)' is issued.
)
xitem(tt(zmodload) tt(-ac) [ tt(-IL) ])
xitem(tt(zmodload) tt(-ac) [ tt(-iI) ] var(name) [ var(cond) ... ])
@ -2021,12 +2051,12 @@ Equivalent to tt(-ab) and tt(-ub).
item(tt(zmodload -e) [ tt(-A) ] [ var(string) ... ])(
The tt(-e) option without arguments lists all loaded modules; if the tt(-A)
option is also given, module aliases corresponding to loaded modules are
also shown. With arguments only the return status is set to zero
if all var(string)s given as arguments are names of loaded modules
and to one if at least on var(string) is not the name of a
loaded module. This can be used to test for the availability
of things implemented by modules. In this case, any aliases are
automatically resolved and the tt(-A) flag is not used.
also shown. If arguments are provided, nothing is printed;
the return status is set to zero if all var(string)s given as arguments
are names of loaded modules and to one if at least on var(string) is not
the name of a loaded module. This can be used to test for the
availability of things implemented by modules. In this case, any
aliases are automatically resolved and the tt(-A) flag is not used.
)
item(tt(zmodload) tt(-A) [ tt(-L) ] [ var(modalias)[tt(=)var(module)] ... ])(
For each argument, if both var(modalias) and var(module) are given,

View file

@ -218,7 +218,7 @@ by the zsh core. The first one, named `setup_', should set up any data
needed in the module, at least any data other modules may be interested
in.
The next pair are features_ and enables_ and deal with enabling module
The next pair are `features_' and `enables_' and deal with enabling module
features. Ensure you are familiar with the description of features under
`zmodload -F'. The function features_ takes an argument `char
***featuresp'; *featuresp is to be set to a NULL-terminated array
@ -235,8 +235,7 @@ initialised so setting them is mandatory any time there are any present.
A structure "struct features" should
be used to contain all standard features as well as the number of
abstract features (those only understood by the module itself).
It contains pointers to all builtins, conditions, parameters and
conditions controlled by the module.
See below.
enables_ takes an argument `int **enablesp'. If *enablesp is NULL, it
should be set to an array of the same length as *featuresp without the
@ -248,31 +247,44 @@ function handlefeatures() conveniently handles all standard features
present in the module's features structure; abstract features must be
handled by the module (as with the features array, the area of the enables
array for abstract features is not even initialised by the main shell). As
with features_, any handling of the array by the module itself should take
with `features_', any handling of the array by the module itself should take
into account that the array will not be freed and any allocation should
therefore be from heap memory.
The functions features_ and enables_ can be called at any point
after setup_ has been called and before cleanup_ is called. In
particular they can be called before or after boot_.
The functions `features_' and `enables_' can be called at any point
after `setup_' has been called and before `cleanup_' is called. In
particular they can be called before or after `boot_'.
The function named `boot_' should register function wrappers, hooks and
anything that will be visible to the user that is not handled by features_
and enables_ (so features should not be turned on here). It will be called
after the `setup_'-function, and also after the intial set of features
have been set by calls to features_ and enables_.
have been set by calls to `features_' and `enables_'.
The function named `cleanup_', is called when the user tries to unload
a module and should de-register all features and hooks. A call
to setfeatures with the final argument NULL will remove all standard
features present in the module's features structure.
features present in the module's features structure. Note that
`cleanup_' is called whenever `setup_' succeeded, so that `cleanup_'
must be prepared to handle any state resulting from a failed `boot_'
or initial call to `features_'. Note also that a return code of 1
from `cleanup_' will result in the module not being unloaded, so
usually `cleanup_' will return 0 even if it has to handle an unclean
state; if it does return 1, it must be prepared to be called again
in a future attempt to unload.
The last function, `finish_' is called when the module is actually unloaded
and should finalize all the data initialized in the `setup_'-function.
However, `finish_' is called even if `setup_' failed, so it should
not rely on the module successfully being set up.
The state from `finish_' module is currently ignored; it is called
too late to prevent the module from being unloaded.
In short, the `cleanup_'-function should undo what the `boot_'-function did
(together with handling any residual effects of enables_), and the
`finish_'-function should undo what the `setup_'-function did.
(together with handling any residual effects of `enables_'), but should
not rely on `boot_' having been successful, and the
`finish_'-function should undo what the `setup_'-function did, but
should not rely on `setup_' having been successful.
All of these functions should return zero if they succeeded and
non-zero otherwise.
@ -302,6 +314,10 @@ as discussed below:
0, /* number of abstract features */
}
Within each individual table ("bintab", etc.), features should be listed
in ASCII order as no further sorting is performed by the shell when
features are listed.
Abstract features are handled by the module; the number present
in `struct features' is there to ensure the main shell allocated
space in the features and enables array in the standard

View file

@ -908,7 +908,7 @@ setup_(UNUSED(Module m))
int
features_(Module m, char ***features)
{
*features = featuresarray(m->nam, &module_features);
*features = featuresarray(m, &module_features);
return 0;
}
@ -916,7 +916,7 @@ features_(Module m, char ***features)
int
enables_(Module m, int **enables)
{
return handlefeatures(m->nam, &module_features, enables);
return handlefeatures(m, &module_features, enables);
}
/**/
@ -930,7 +930,7 @@ boot_(Module m)
int
cleanup_(Module m)
{
return setfeatureenables(m->nam, &module_features, NULL);
return setfeatureenables(m, &module_features, NULL);
return 0;
}

View file

@ -381,8 +381,8 @@ static struct paramdef partab[] = {
static struct features module_features = {
bintab, sizeof(bintab)/sizeof(*bintab),
NULL, 0,
partab, sizeof(partab)/sizeof(*partab),
NULL, 0,
partab, sizeof(partab)/sizeof(*partab),
0
};
@ -397,7 +397,7 @@ setup_(UNUSED(Module m))
int
features_(Module m, char ***features)
{
*features = featuresarray(m->nam, &module_features);
*features = featuresarray(m, &module_features);
return 0;
}
@ -405,7 +405,7 @@ features_(Module m, char ***features)
int
enables_(Module m, int **enables)
{
return handlefeatures(m->nam, &module_features, enables);
return handlefeatures(m, &module_features, enables);
}
/**/
@ -430,7 +430,7 @@ cleanup_(Module m)
zfree(sch, sizeof(*sch));
}
delprepromptfn(&checksched);
return setfeatureenables(m->nam, &module_features, NULL);
return setfeatureenables(m, &module_features, NULL);
}
/**/

View file

@ -141,7 +141,7 @@ setup_(UNUSED(Module m))
int
features_(Module m, char ***features)
{
*features = featuresarray(m->nam, &module_features);
*features = featuresarray(m, &module_features);
return 0;
}
@ -149,7 +149,7 @@ features_(Module m, char ***features)
int
enables_(Module m, int **enables)
{
return handlefeatures(m->nam, &module_features, enables);
return handlefeatures(m, &module_features, enables);
}
/**/
@ -163,7 +163,7 @@ boot_(UNUSED(Module m))
int
cleanup_(Module m)
{
return setfeatureenables(m->nam, &module_features, NULL);
return setfeatureenables(m, &module_features, NULL);
}
/**/

View file

@ -128,7 +128,7 @@ setup_(UNUSED(Module m))
int
features_(Module m, char ***features)
{
*features = featuresarray(m->nam, &module_features);
*features = featuresarray(m, &module_features);
return 0;
}
@ -136,7 +136,7 @@ features_(Module m, char ***features)
int
enables_(Module m, int **enables)
{
return handlefeatures(m->nam, &module_features, enables);
return handlefeatures(m, &module_features, enables);
}
/**/
@ -150,7 +150,7 @@ boot_(UNUSED(Module m))
int
cleanup_(Module m)
{
return setfeatureenables(m->nam, &module_features, NULL);
return setfeatureenables(m, &module_features, NULL);
}
/**/

View file

@ -161,8 +161,8 @@ static struct paramdef patab[] = {
static struct features module_features = {
bintab, sizeof(bintab)/sizeof(*bintab),
NULL, 0,
patab, sizeof(patab)/sizeof(*patab),
NULL, 0,
patab, sizeof(patab)/sizeof(*patab),
0
};
@ -177,7 +177,7 @@ setup_(UNUSED(Module m))
int
features_(Module m, char ***features)
{
*features = featuresarray(m->nam, &module_features);
*features = featuresarray(m, &module_features);
return 0;
}
@ -185,7 +185,7 @@ features_(Module m, char ***features)
int
enables_(Module m, int **enables)
{
return handlefeatures(m->nam, &module_features, enables);
return handlefeatures(m, &module_features, enables);
}
/**/
@ -199,7 +199,7 @@ boot_(Module m)
int
cleanup_(Module m)
{
return setfeatureenables(m->nam, &module_features, NULL);
return setfeatureenables(m, &module_features, NULL);
}
/**/

View file

@ -165,19 +165,19 @@ static struct builtin bintab[] = {
};
static struct conddef cotab[] = {
CONDDEF("len", 0, cond_p_len, 1, 2, 0),
CONDDEF("ex", CONDF_INFIX, cond_i_ex, 0, 0, 0),
CONDDEF("len", 0, cond_p_len, 1, 2, 0),
};
static struct paramdef patab[] = {
ARRPARAMDEF("exarr", &arrparam),
INTPARAMDEF("exint", &intparam),
STRPARAMDEF("exstr", &strparam),
ARRPARAMDEF("exarr", &arrparam),
};
static struct mathfunc mftab[] = {
NUMMATHFUNC("sum", math_sum, 1, -1, 0),
STRMATHFUNC("length", math_length, 0),
NUMMATHFUNC("sum", math_sum, 1, -1, 0),
};
static struct funcwrap wrapper[] = {
@ -187,8 +187,8 @@ static struct funcwrap wrapper[] = {
static struct features module_features = {
bintab, sizeof(bintab)/sizeof(*bintab),
cotab, sizeof(cotab)/sizeof(*cotab),
patab, sizeof(patab)/sizeof(*patab),
mftab, sizeof(mftab)/sizeof(*mftab),
patab, sizeof(patab)/sizeof(*patab),
0
};
@ -205,7 +205,7 @@ setup_(UNUSED(Module m))
int
features_(Module m, char ***features)
{
*features = featuresarray(m->nam, &module_features);
*features = featuresarray(m, &module_features);
return 0;
}
@ -213,7 +213,7 @@ features_(Module m, char ***features)
int
enables_(Module m, int **enables)
{
return handlefeatures(m->nam, &module_features, enables);
return handlefeatures(m, &module_features, enables);
}
/**/
@ -234,7 +234,7 @@ int
cleanup_(Module m)
{
deletewrapper(m, wrapper);
return setfeatureenables(m->nam, &module_features, NULL);
return setfeatureenables(m, &module_features, NULL);
}
/**/

View file

@ -725,7 +725,7 @@ setup_(UNUSED(Module m))
int
features_(Module m, char ***features)
{
*features = featuresarray(m->nam, &module_features);
*features = featuresarray(m, &module_features);
return 0;
}
@ -733,7 +733,7 @@ features_(Module m, char ***features)
int
enables_(Module m, int **enables)
{
return handlefeatures(m->nam, &module_features, enables);
return handlefeatures(m, &module_features, enables);
}
/**/
@ -747,7 +747,7 @@ boot_(Module m)
int
cleanup_(Module m)
{
return setfeatureenables(m->nam, &module_features, NULL);
return setfeatureenables(m, &module_features, NULL);
}
/**/

View file

@ -376,7 +376,7 @@ static nl_item nl_vals[] = {
};
static nl_item *
liitem(char *name)
liitem(const char *name)
{
char **element;
nl_item *nlcode;
@ -393,16 +393,17 @@ liitem(char *name)
/**/
static HashNode
getlanginfo(UNUSED(HashTable ht), char *name)
getlanginfo(UNUSED(HashTable ht), const char *name)
{
int len, *elem;
char *listr;
char *listr, *nameu;
Param pm = NULL;
unmetafy(name, &len);
nameu = dupstring(name);
unmetafy(nameu, &len);
pm = (Param) hcalloc(sizeof(struct param));
pm->node.nam = dupstring(name);
pm->node.nam = nameu;
pm->node.flags = PM_READONLY | PM_SCALAR;
pm->gsu.s = &nullsetscalar_gsu;
@ -456,12 +457,12 @@ static struct paramdef partab[] = {
static struct features module_features = {
NULL, 0,
NULL, 0,
NULL, 0,
#ifdef HAVE_NL_LANGINFO
partab, sizeof(partab)/sizeof(*partab),
#else
NULL, 0,
#endif
NULL, 0,
0
};
@ -476,7 +477,7 @@ setup_(UNUSED(Module m))
int
features_(Module m, char ***features)
{
*features = featuresarray(m->nam, &module_features);
*features = featuresarray(m, &module_features);
return 0;
}
@ -484,7 +485,7 @@ features_(Module m, char ***features)
int
enables_(Module m, int **enables)
{
return handlefeatures(m->nam, &module_features, enables);
return handlefeatures(m, &module_features, enables);
}
/**/
@ -498,7 +499,7 @@ boot_(UNUSED(Module m))
int
cleanup_(UNUSED(Module m))
{
return setfeatureenables(m->nam, &module_features, NULL);
return setfeatureenables(m, &module_features, NULL);
}
/**/

View file

@ -213,7 +213,7 @@ static struct paramdef partab[] = {
/**/
static HashNode
getpmmapfile(UNUSED(HashTable ht), char *name)
getpmmapfile(UNUSED(HashTable ht), const char *name)
{
char *contents;
Param pm = NULL;
@ -268,8 +268,8 @@ scanpmmapfile(UNUSED(HashTable ht), ScanFunc func, int flags)
static struct features module_features = {
NULL, 0,
NULL, 0,
partab, sizeof(partab)/sizeof(*partab),
NULL, 0,
partab, sizeof(partab)/sizeof(*partab),
0
};
@ -284,7 +284,7 @@ setup_(UNUSED(Module m))
int
features_(Module m, char ***features)
{
*features = featuresarray(m->nam, &module_features);
*features = featuresarray(m, &module_features);
return 0;
}
@ -292,7 +292,7 @@ features_(Module m, char ***features)
int
enables_(Module m, int **enables)
{
return handlefeatures(m->nam, &module_features, enables);
return handlefeatures(m, &module_features, enables);
}
/**/
@ -306,7 +306,7 @@ boot_(UNUSED(Module m))
int
cleanup_(UNUSED(Module m))
{
return setfeatureenables(m->nam, &module_features, NULL);
return setfeatureenables(m, &module_features, NULL);
}
/**/

View file

@ -125,12 +125,6 @@ enum {
static struct mathfunc mftab[] = {
/* Functions taking string arguments */
#ifdef HAVE_ERAND48
/* here to avoid comma hassle */
STRMATHFUNC("rand48", math_string, MS_RAND48),
#endif
NUMMATHFUNC("abs", math_func, 1, 1, MF_ABS | BFLAG(BF_FRAC) |
TFLAG(TF_NOCONV|TF_NOASS)),
NUMMATHFUNC("acos", math_func, 1, 1, MF_ACOS | BFLAG(BF_FRAC)),
@ -167,6 +161,9 @@ static struct mathfunc mftab[] = {
NUMMATHFUNC("log1p", math_func, 1, 1, MF_LOG1P | BFLAG(BF_GTRM1)),
NUMMATHFUNC("logb", math_func, 1, 1, MF_LOGB | BFLAG(BF_NONZ)),
NUMMATHFUNC("nextafter", math_func, 2, 2, MF_NEXTAFTER),
#ifdef HAVE_ERAND48
STRMATHFUNC("rand48", math_string, MS_RAND48),
#endif
NUMMATHFUNC("rint", math_func, 1, 1, MF_RINT),
NUMMATHFUNC("scalb", math_func, 2, 2, MF_SCALB | TFLAG(TF_INT2)),
#ifdef HAVE_SIGNGAM
@ -562,10 +559,10 @@ math_string(UNUSED(char *name), char *arg, int id)
static struct features module_features = {
NULL, 0,
NULL, 0,
NULL, 0,
mftab, sizeof(mftab)/sizeof(*mftab),
NULL, 0,
0
};
@ -580,7 +577,7 @@ setup_(UNUSED(Module m))
int
features_(Module m, char ***features)
{
*features = featuresarray(m->nam, &module_features);
*features = featuresarray(m, &module_features);
return 0;
}
@ -588,7 +585,7 @@ features_(Module m, char ***features)
int
enables_(Module m, int **enables)
{
return handlefeatures(m->nam, &module_features, enables);
return handlefeatures(m, &module_features, enables);
}
/**/
@ -602,7 +599,7 @@ boot_(Module m)
int
cleanup_(Module m)
{
return setfeatureenables(m->nam, &module_features, NULL);
return setfeatureenables(m, &module_features, NULL);
}
/**/

View file

@ -93,7 +93,7 @@ paramtypestr(Param pm)
/**/
static HashNode
getpmparameter(UNUSED(HashTable ht), char *name)
getpmparameter(UNUSED(HashTable ht), const char *name)
{
Param rpm, pm = NULL;
@ -199,7 +199,7 @@ static const struct gsu_scalar pmcommand_gsu =
/**/
static HashNode
getpmcommand(UNUSED(HashTable ht), char *name)
getpmcommand(UNUSED(HashTable ht), const char *name)
{
Cmdnam cmd;
Param pm = NULL;
@ -372,7 +372,7 @@ static const struct gsu_scalar pmdisfunction_gsu =
/**/
static HashNode
getfunction(UNUSED(HashTable ht), char *name, int dis)
getfunction(UNUSED(HashTable ht), const char *name, int dis)
{
Shfunc shf;
Param pm = NULL;
@ -416,14 +416,14 @@ getfunction(UNUSED(HashTable ht), char *name, int dis)
/**/
static HashNode
getpmfunction(HashTable ht, char *name)
getpmfunction(HashTable ht, const char *name)
{
return getfunction(ht, name, 0);
}
/**/
static HashNode
getpmdisfunction(HashTable ht, char *name)
getpmdisfunction(HashTable ht, const char *name)
{
return getfunction(ht, name, DISABLED);
}
@ -542,7 +542,7 @@ functracegetfn(UNUSED(Param pm))
/**/
static HashNode
getbuiltin(UNUSED(HashTable ht), char *name, int dis)
getbuiltin(UNUSED(HashTable ht), const char *name, int dis)
{
Param pm = NULL;
Builtin bn;
@ -566,14 +566,14 @@ getbuiltin(UNUSED(HashTable ht), char *name, int dis)
/**/
static HashNode
getpmbuiltin(HashTable ht, char *name)
getpmbuiltin(HashTable ht, const char *name)
{
return getbuiltin(ht, name, 0);
}
/**/
static HashNode
getpmdisbuiltin(HashTable ht, char *name)
getpmdisbuiltin(HashTable ht, const char *name)
{
return getbuiltin(ht, name, DISABLED);
}
@ -721,7 +721,7 @@ static const struct gsu_scalar pmoption_gsu =
/**/
static HashNode
getpmoption(UNUSED(HashTable ht), char *name)
getpmoption(UNUSED(HashTable ht), const char *name)
{
Param pm = NULL;
int n;
@ -771,69 +771,29 @@ scanpmoptions(UNUSED(HashTable ht), ScanFunc func, int flags)
/* Functions for the modules special parameter. */
static char *modpmname;
static int modpmfound;
/**/
static void
modpmbuiltinscan(HashNode hn, UNUSED(int dummy))
{
if (!(((Builtin) hn)->node.flags & BINF_ADDED) &&
!strcmp(((Builtin) hn)->optstr, modpmname))
modpmfound = 1;
}
/**/
static void
modpmparamscan(HashNode hn, UNUSED(int dummy))
{
if ((((Param) hn)->node.flags & PM_AUTOLOAD) &&
!strcmp(((Param) hn)->u.str, modpmname))
modpmfound = 1;
}
/**/
static HashNode
getpmmodule(UNUSED(HashTable ht), char *name)
getpmmodule(UNUSED(HashTable ht), const char *name)
{
Param pm = NULL;
char *type = NULL;
LinkNode node;
Module m;
pm = (Param) hcalloc(sizeof(struct param));
pm->node.nam = dupstring(name);
pm->node.flags = PM_SCALAR | PM_READONLY;
pm->gsu.s = &nullsetscalar_gsu;
if (!type) {
Module m;
m = (Module)modulestab->getnode2(modulestab, name);
for (node = firstnode(modules); node; incnode(node)) {
m = (Module) getdata(node);
if (m->u.handle && !(m->flags & MOD_UNLOAD) &&
!strcmp(name, m->nam)) {
type = ((m->flags & MOD_ALIAS) ?
dyncat("alias:", m->u.alias) : "loaded");
break;
}
}
if (!m)
return NULL;
if (m->u.handle && !(m->node.flags & MOD_UNLOAD)) {
type = ((m->node.flags & MOD_ALIAS) ?
dyncat("alias:", m->u.alias) : "loaded");
}
modpmname = name;
modpmfound = 0;
if (!type) {
scanhashtable(builtintab, 0, 0, 0, modpmbuiltinscan, 0);
if (!modpmfound) {
Conddef p;
for (p = condtab; p; p = p->next)
if (p->module && !strcmp(name, p->module)) {
modpmfound = 1;
break;
}
if (!modpmfound)
scanhashtable(realparamtab, 0, 0, 0, modpmparamscan, 0);
}
if (modpmfound)
if (m->autoloads && firstnode(m->autoloads))
type = "autoloaded";
}
if (type)
@ -853,7 +813,6 @@ scanpmmodules(UNUSED(HashTable ht), ScanFunc func, int flags)
int i;
HashNode hn;
LinkList done = newlinklist();
LinkNode node;
Module m;
Conddef p;
char *loaded = dupstring("loaded");
@ -862,14 +821,16 @@ scanpmmodules(UNUSED(HashTable ht), ScanFunc func, int flags)
pm.node.flags = PM_SCALAR | PM_READONLY;
pm.gsu.s = &nullsetscalar_gsu;
for (node = firstnode(modules); node; incnode(node)) {
m = (Module) getdata(node);
if (m->u.handle && !(m->flags & MOD_UNLOAD)) {
pm.node.nam = m->nam;
pm.u.str = ((m->flags & MOD_ALIAS) ?
dyncat("alias:", m->u.alias) : loaded);
addlinknode(done, pm.node.nam);
func(&pm.node, flags);
for (i = 0; i < modulestab->hsize; i++) {
for (hn = modulestab->nodes[i]; hn; hn = hn->next) {
m = (Module) hn;
if (m->u.handle && !(m->node.flags & MOD_UNLOAD)) {
pm.node.nam = m->node.nam;
pm.u.str = ((m->node.flags & MOD_ALIAS) ?
dyncat("alias:", m->u.alias) : loaded);
addlinknode(done, pm.node.nam);
func(&pm.node, flags);
}
}
}
pm.u.str = dupstring("autoloaded");
@ -928,11 +889,11 @@ dirsgetfn(UNUSED(Param pm))
/**/
static HashNode
getpmhistory(UNUSED(HashTable ht), char *name)
getpmhistory(UNUSED(HashTable ht), const char *name)
{
Param pm = NULL;
Histent he;
char *p;
const char *p;
int ok = 1;
pm = (Param) hcalloc(sizeof(struct param));
@ -1042,7 +1003,7 @@ pmjobtext(int job)
/**/
static HashNode
getpmjobtext(UNUSED(HashTable ht), char *name)
getpmjobtext(UNUSED(HashTable ht), const char *name)
{
Param pm = NULL;
int job;
@ -1139,7 +1100,7 @@ pmjobstate(int job)
/**/
static HashNode
getpmjobstate(UNUSED(HashTable ht), char *name)
getpmjobstate(UNUSED(HashTable ht), const char *name)
{
Param pm = NULL;
int job;
@ -1201,7 +1162,7 @@ pmjobdir(int job)
/**/
static HashNode
getpmjobdir(UNUSED(HashTable ht), char *name)
getpmjobdir(UNUSED(HashTable ht), const char *name)
{
Param pm = NULL;
int job;
@ -1329,7 +1290,7 @@ static const struct gsu_scalar pmnamedir_gsu =
/**/
static HashNode
getpmnameddir(UNUSED(HashTable ht), char *name)
getpmnameddir(UNUSED(HashTable ht), const char *name)
{
Param pm = NULL;
Nameddir nd;
@ -1378,7 +1339,7 @@ scanpmnameddirs(UNUSED(HashTable ht), ScanFunc func, int flags)
/**/
static HashNode
getpmuserdir(UNUSED(HashTable ht), char *name)
getpmuserdir(UNUSED(HashTable ht), const char *name)
{
Param pm = NULL;
Nameddir nd;
@ -1631,7 +1592,7 @@ assignaliasdefs(Param pm, int flags)
/**/
static HashNode
getalias(HashTable alht, UNUSED(HashTable ht), char *name, int flags)
getalias(HashTable alht, UNUSED(HashTable ht), const char *name, int flags)
{
Param pm = NULL;
Alias al;
@ -1653,45 +1614,45 @@ getalias(HashTable alht, UNUSED(HashTable ht), char *name, int flags)
/**/
static HashNode
getpmralias(HashTable ht, char *name)
getpmralias(HashTable ht, const char *name)
{
return getalias(aliastab, ht, name, 0);
}
/**/
static HashNode
getpmdisralias(HashTable ht, char *name)
getpmdisralias(HashTable ht, const char *name)
{
return getalias(aliastab, ht, name, DISABLED);
}
/**/
static HashNode
getpmgalias(HashTable ht, char *name)
getpmgalias(HashTable ht, const char *name)
{
return getalias(aliastab, ht, name, ALIAS_GLOBAL);
}
/**/
static HashNode
getpmdisgalias(HashTable ht, char *name)
getpmdisgalias(HashTable ht, const char *name)
{
return getalias(aliastab, ht, name, ALIAS_GLOBAL|DISABLED);
}
/**/
static HashNode
getpmsalias(HashTable ht, char *name)
getpmsalias(HashTable ht, const char *name)
{
return getalias(sufaliastab, ht, name, ALIAS_SUFFIX);
}
/**/
static HashNode
getpmdissalias(HashTable ht, char *name)
getpmdissalias(HashTable ht, const char *name)
{
return getalias(sufaliastab, ht, name, ALIAS_SUFFIX|DISABLED);
}
}
/**/
static void
@ -1809,63 +1770,63 @@ static const struct gsu_array historywords_gsu =
{ histwgetfn, arrsetfn, stdunsetfn };
static struct paramdef partab[] = {
SPECIALPMDEF("parameters", PM_READONLY,
NULL, getpmparameter, scanpmparameters),
SPECIALPMDEF("commands", 0, &pmcommands_gsu, getpmcommand, scanpmcommands),
SPECIALPMDEF("functions", 0, &pmfunctions_gsu, getpmfunction,
scanpmfunctions),
SPECIALPMDEF("dis_functions", 0,
&pmdisfunctions_gsu, getpmdisfunction, scanpmdisfunctions),
SPECIALPMDEF("funcstack", PM_ARRAY|PM_READONLY,
&funcstack_gsu, NULL, NULL),
SPECIALPMDEF("functrace", PM_ARRAY|PM_READONLY,
&functrace_gsu, NULL, NULL),
SPECIALPMDEF("aliases", 0,
&pmraliases_gsu, getpmralias, scanpmraliases),
SPECIALPMDEF("builtins", PM_READONLY, NULL, getpmbuiltin, scanpmbuiltins),
SPECIALPMDEF("dis_builtins", PM_READONLY,
NULL, getpmdisbuiltin, scanpmdisbuiltins),
SPECIALPMDEF("reswords", PM_ARRAY|PM_READONLY,
&reswords_gsu, NULL, NULL),
SPECIALPMDEF("dis_reswords", PM_ARRAY|PM_READONLY,
&disreswords_gsu, NULL, NULL),
SPECIALPMDEF("options", 0,
&pmoptions_gsu, getpmoption, scanpmoptions),
SPECIALPMDEF("modules", PM_READONLY,
NULL, getpmmodule, scanpmmodules),
SPECIALPMDEF("commands", 0, &pmcommands_gsu, getpmcommand, scanpmcommands),
SPECIALPMDEF("dirstack", PM_ARRAY,
&dirs_gsu, NULL, NULL),
SPECIALPMDEF("dis_aliases", 0,
&pmdisraliases_gsu, getpmdisralias, scanpmdisraliases),
SPECIALPMDEF("dis_builtins", PM_READONLY,
NULL, getpmdisbuiltin, scanpmdisbuiltins),
SPECIALPMDEF("dis_functions", 0,
&pmdisfunctions_gsu, getpmdisfunction, scanpmdisfunctions),
SPECIALPMDEF("dis_galiases", 0,
&pmdisgaliases_gsu, getpmdisgalias, scanpmdisgaliases),
SPECIALPMDEF("dis_reswords", PM_ARRAY|PM_READONLY,
&disreswords_gsu, NULL, NULL),
SPECIALPMDEF("dis_saliases", 0,
&pmdissaliases_gsu, getpmdissalias, scanpmdissaliases),
SPECIALPMDEF("funcstack", PM_ARRAY|PM_READONLY,
&funcstack_gsu, NULL, NULL),
SPECIALPMDEF("functions", 0, &pmfunctions_gsu, getpmfunction,
scanpmfunctions),
SPECIALPMDEF("functrace", PM_ARRAY|PM_READONLY,
&functrace_gsu, NULL, NULL),
SPECIALPMDEF("galiases", 0,
&pmgaliases_gsu, getpmgalias, scanpmgaliases),
SPECIALPMDEF("history", PM_READONLY,
NULL, getpmhistory, scanpmhistory),
SPECIALPMDEF("historywords", PM_ARRAY|PM_READONLY,
&historywords_gsu, NULL, NULL),
SPECIALPMDEF("jobtexts", PM_READONLY,
NULL, getpmjobtext, scanpmjobtexts),
SPECIALPMDEF("jobstates", PM_READONLY,
NULL, getpmjobstate, scanpmjobstates),
SPECIALPMDEF("jobdirs", PM_READONLY,
NULL, getpmjobdir, scanpmjobdirs),
SPECIALPMDEF("jobstates", PM_READONLY,
NULL, getpmjobstate, scanpmjobstates),
SPECIALPMDEF("jobtexts", PM_READONLY,
NULL, getpmjobtext, scanpmjobtexts),
SPECIALPMDEF("modules", PM_READONLY,
NULL, getpmmodule, scanpmmodules),
SPECIALPMDEF("nameddirs", 0,
&pmnameddirs_gsu, getpmnameddir, scanpmnameddirs),
SPECIALPMDEF("userdirs", PM_READONLY,
NULL, getpmuserdir, scanpmuserdirs),
SPECIALPMDEF("aliases", 0,
&pmraliases_gsu, getpmralias, scanpmraliases),
SPECIALPMDEF("galiases", 0,
&pmgaliases_gsu, getpmgalias, scanpmgaliases),
SPECIALPMDEF("options", 0,
&pmoptions_gsu, getpmoption, scanpmoptions),
SPECIALPMDEF("parameters", PM_READONLY,
NULL, getpmparameter, scanpmparameters),
SPECIALPMDEF("reswords", PM_ARRAY|PM_READONLY,
&reswords_gsu, NULL, NULL),
SPECIALPMDEF("saliases", 0,
&pmsaliases_gsu, getpmsalias, scanpmsaliases),
SPECIALPMDEF("dis_aliases", 0,
&pmdisraliases_gsu, getpmdisralias, scanpmdisraliases),
SPECIALPMDEF("dis_galiases", 0,
&pmdisgaliases_gsu, getpmdisgalias, scanpmdisgaliases),
SPECIALPMDEF("dis_saliases", 0,
&pmdissaliases_gsu, getpmdissalias, scanpmdissaliases)
SPECIALPMDEF("userdirs", PM_READONLY,
NULL, getpmuserdir, scanpmuserdirs)
};
static struct features module_features = {
NULL, 0,
NULL, 0,
partab, sizeof(partab)/sizeof(*partab),
NULL, 0,
partab, sizeof(partab)/sizeof(*partab),
0
};
@ -1880,7 +1841,7 @@ setup_(UNUSED(Module m))
int
features_(Module m, char ***features)
{
*features = featuresarray(m->nam, &module_features);
*features = featuresarray(m, &module_features);
return 0;
}
@ -1894,7 +1855,7 @@ enables_(Module m, int **enables)
* on the main shell, so set the flag to indicate.
*/
incleanup = 1;
ret = handlefeatures(m->nam, &module_features, enables);
ret = handlefeatures(m, &module_features, enables);
incleanup = 0;
return ret;
}
@ -1912,7 +1873,7 @@ cleanup_(Module m)
{
int ret;
incleanup = 1;
ret = setfeatureenables(m->nam, &module_features, NULL);
ret = setfeatureenables(m, &module_features, NULL);
incleanup = 0;
return ret;
}

View file

@ -290,8 +290,8 @@ static struct conddef cotab[] = {
static struct builtin bintab[] = {
BUILTIN("pcre_compile", 0, bin_pcre_compile, 1, 1, 0, "aimx", NULL),
BUILTIN("pcre_study", 0, bin_pcre_study, 0, 0, 0, NULL, NULL),
BUILTIN("pcre_match", 0, bin_pcre_match, 1, 1, 0, "a:v:", NULL)
BUILTIN("pcre_match", 0, bin_pcre_match, 1, 1, 0, "a:v:", NULL),
BUILTIN("pcre_study", 0, bin_pcre_study, 0, 0, 0, NULL, NULL)
};
@ -319,7 +319,7 @@ setup_(UNUSED(Module m))
int
features_(Module m, char ***features)
{
*features = featuresarray(m->nam, &module_features);
*features = featuresarray(m, &module_features);
return 0;
}
@ -327,7 +327,7 @@ features_(Module m, char ***features)
int
enables_(Module m, int **enables)
{
return handlefeatures(m->nam, &module_features, enables);
return handlefeatures(m, &module_features, enables);
}
/**/
@ -341,7 +341,7 @@ boot_(Module m)
int
cleanup_(Module m)
{
return setfeatureenables(m->nam, &module_features, NULL);
return setfeatureenables(m, &module_features, NULL);
}
/**/

View file

@ -152,7 +152,7 @@ setup_(UNUSED(Module m))
int
features_(Module m, char ***features)
{
*features = featuresarray(m->nam, &module_features);
*features = featuresarray(m, &module_features);
return 0;
}
@ -160,7 +160,7 @@ features_(Module m, char ***features)
int
enables_(Module m, int **enables)
{
return handlefeatures(m->nam, &module_features, enables);
return handlefeatures(m, &module_features, enables);
}
/**/
@ -174,7 +174,7 @@ boot_(Module m)
int
cleanup_(Module m)
{
return setfeatureenables(m->nam, &module_features, NULL);
return setfeatureenables(m, &module_features, NULL);
}
/**/

View file

@ -276,7 +276,7 @@ setup_(UNUSED(Module m))
int
features_(Module m, char ***features)
{
*features = featuresarray(m->nam, &module_features);
*features = featuresarray(m, &module_features);
return 0;
}
@ -284,7 +284,7 @@ features_(Module m, char ***features)
int
enables_(Module m, int **enables)
{
return handlefeatures(m->nam, &module_features, enables);
return handlefeatures(m, &module_features, enables);
}
/**/
@ -298,7 +298,7 @@ boot_(Module m)
int
cleanup_(Module m)
{
return setfeatureenables(m->nam, &module_features, NULL);
return setfeatureenables(m, &module_features, NULL);
}
/**/

View file

@ -643,7 +643,7 @@ setup_(UNUSED(Module m))
int
features_(Module m, char ***features)
{
*features = featuresarray(m->nam, &module_features);
*features = featuresarray(m, &module_features);
return 0;
}
@ -651,7 +651,7 @@ features_(Module m, char ***features)
int
enables_(Module m, int **enables)
{
return handlefeatures(m->nam, &module_features, enables);
return handlefeatures(m, &module_features, enables);
}
/**/
@ -665,7 +665,7 @@ boot_(Module m)
int
cleanup_(Module m)
{
return setfeatureenables(m->nam, &module_features, NULL);
return setfeatureenables(m, &module_features, NULL);
}
/**/

View file

@ -365,7 +365,7 @@ static const struct gsu_array errnos_gsu =
/**/
static void
fillpmsysparams(Param pm, char *name)
fillpmsysparams(Param pm, const char *name)
{
char buf[DIGBUFSIZE];
int num;
@ -390,7 +390,7 @@ fillpmsysparams(Param pm, char *name)
/**/
static HashNode
getpmsysparams(UNUSED(HashTable ht), char *name)
getpmsysparams(UNUSED(HashTable ht), const char *name)
{
Param pm;
@ -423,8 +423,8 @@ static struct paramdef partab[] = {
static struct features module_features = {
bintab, sizeof(bintab)/sizeof(*bintab),
NULL, 0,
partab, sizeof(partab)/sizeof(*partab),
NULL, 0,
partab, sizeof(partab)/sizeof(*partab),
0
};
@ -441,7 +441,7 @@ setup_(UNUSED(Module m))
int
features_(Module m, char ***features)
{
*features = featuresarray(m->nam, &module_features);
*features = featuresarray(m, &module_features);
return 0;
}
@ -449,7 +449,7 @@ features_(Module m, char ***features)
int
enables_(Module m, int **enables)
{
return handlefeatures(m->nam, &module_features, enables);
return handlefeatures(m, &module_features, enables);
}
/**/
@ -464,7 +464,7 @@ boot_(Module m)
int
cleanup_(Module m)
{
return setfeatureenables(m->nam, &module_features, NULL);
return setfeatureenables(m, &module_features, NULL);
}
/**/

View file

@ -696,7 +696,7 @@ setup_(UNUSED(Module m))
int
features_(Module m, char ***features)
{
*features = featuresarray(m->nam, &module_features);
*features = featuresarray(m, &module_features);
return 0;
}
@ -704,7 +704,7 @@ features_(Module m, char ***features)
int
enables_(Module m, int **enables)
{
return handlefeatures(m->nam, &module_features, enables);
return handlefeatures(m, &module_features, enables);
}
/**/
@ -722,7 +722,7 @@ cleanup_(Module m)
{
tcp_cleanup();
freelinklist(ztcp_sessions, (FreeFunc) ztcp_free_session);
return setfeatureenables(m->nam, &module_features, NULL);
return setfeatureenables(m, &module_features, NULL);
}
/**/

View file

@ -164,10 +164,10 @@ static struct builtin bintab[] = {
/**/
static HashNode
gettermcap(UNUSED(HashTable ht), char *name)
gettermcap(UNUSED(HashTable ht), const char *name)
{
int len, num;
char *tcstr, buf[2048], *u;
char *tcstr, buf[2048], *u, *nameu;
Param pm = NULL;
/* This depends on the termcap stuff in init.c */
@ -176,16 +176,18 @@ gettermcap(UNUSED(HashTable ht), char *name)
if ((termflags & TERM_UNKNOWN) && (isset(INTERACTIVE) || !init_term()))
return NULL;
unmetafy(name, &len);
nameu = dupstring(name);
unmetafy(nameu, &len);
pm = (Param) hcalloc(sizeof(struct param));
pm->node.nam = dupstring(name);
pm->node.nam = nameu;
pm->node.flags = PM_READONLY;
u = buf;
/* logic in the following cascade copied from echotc, above */
if ((num = tgetnum(name)) != -1) {
if ((num = tgetnum(nameu)) != -1) {
pm->gsu.i = &nullsetinteger_gsu;
pm->u.val = num;
pm->node.flags |= PM_INTEGER;
@ -193,7 +195,7 @@ gettermcap(UNUSED(HashTable ht), char *name)
}
pm->gsu.s = &nullsetscalar_gsu;
switch (ztgetflag(name)) {
switch (ztgetflag(nameu)) {
case -1:
break;
case 0:
@ -205,7 +207,7 @@ gettermcap(UNUSED(HashTable ht), char *name)
pm->node.flags |= PM_SCALAR;
return &pm->node;
}
if ((tcstr = tgetstr(name, &u)) != NULL && tcstr != (char *)-1) {
if ((tcstr = tgetstr(nameu, &u)) != NULL && tcstr != (char *)-1) {
pm->u.str = dupstring(tcstr);
pm->node.flags |= PM_SCALAR;
} else {
@ -324,12 +326,12 @@ static struct features module_features = {
NULL, 0,
#endif
NULL, 0,
NULL, 0,
#ifdef HAVE_TGETENT
partab, sizeof(partab)/sizeof(*partab),
#else
NULL, 0,
#endif
NULL, 0,
0
};
@ -344,7 +346,7 @@ setup_(UNUSED(Module m))
int
features_(Module m, char ***features)
{
*features = featuresarray(m->nam, &module_features);
*features = featuresarray(m, &module_features);
return 0;
}
@ -352,7 +354,7 @@ features_(Module m, char ***features)
int
enables_(Module m, int **enables)
{
return handlefeatures(m->nam, &module_features, enables);
return handlefeatures(m, &module_features, enables);
}
/**/
@ -371,7 +373,7 @@ boot_(Module m)
int
cleanup_(Module m)
{
return setfeatureenables(m->nam, &module_features, NULL);
return setfeatureenables(m, &module_features, NULL);
}
/**/

View file

@ -129,10 +129,10 @@ static struct builtin bintab[] = {
/**/
static HashNode
getterminfo(UNUSED(HashTable ht), char *name)
getterminfo(UNUSED(HashTable ht), const char *name)
{
int len, num;
char *tistr;
char *tistr, *nameu;
Param pm = NULL;
/* This depends on the termcap stuff in init.c */
@ -141,21 +141,22 @@ getterminfo(UNUSED(HashTable ht), char *name)
if ((termflags & TERM_UNKNOWN) && (isset(INTERACTIVE) || !init_term()))
return NULL;
unmetafy(name, &len);
nameu = dupstring(name);
unmetafy(nameu, &len);
pm = (Param) hcalloc(sizeof(struct param));
pm->node.nam = dupstring(name);
pm->node.nam = nameu;
pm->node.flags = PM_READONLY;
if (((num = tigetnum(name)) != -1) && (num != -2)) {
if (((num = tigetnum(nameu)) != -1) && (num != -2)) {
pm->u.val = num;
pm->node.flags |= PM_INTEGER;
pm->gsu.i = &nullsetinteger_gsu;
} else if ((num = tigetflag(name)) != -1) {
} else if ((num = tigetflag(nameu)) != -1) {
pm->u.str = num ? dupstring("yes") : dupstring("no");
pm->node.flags |= PM_SCALAR;
pm->gsu.s = &nullsetscalar_gsu;
} else if ((tistr = (char *)tigetstr(name)) != NULL && tistr != (char *)-1) {
} else if ((tistr = (char *)tigetstr(nameu)) != NULL && tistr != (char *)-1) {
pm->u.str = dupstring(tistr);
pm->node.flags |= PM_SCALAR;
pm->gsu.s = &nullsetscalar_gsu;
@ -298,12 +299,12 @@ static struct features module_features = {
NULL, 0,
#endif
NULL, 0,
NULL, 0,
#ifdef USE_TERMINFO_MODULE
partab, sizeof(partab)/sizeof(*partab),
#else
NULL, 0,
#endif
NULL, 0,
0
};
@ -318,7 +319,7 @@ setup_(UNUSED(Module m))
int
features_(Module m, char ***features)
{
*features = featuresarray(m->nam, &module_features);
*features = featuresarray(m, &module_features);
return 0;
}
@ -326,7 +327,7 @@ features_(Module m, char ***features)
int
enables_(Module m, int **enables)
{
return handlefeatures(m->nam, &module_features, enables);
return handlefeatures(m, &module_features, enables);
}
/**/
@ -349,7 +350,7 @@ boot_(Module m)
int
cleanup_(Module m)
{
return setfeatureenables(m->nam, &module_features, NULL);
return setfeatureenables(m, &module_features, NULL);
}
/**/

View file

@ -3181,7 +3181,7 @@ setup_(UNUSED(Module m))
int
features_(Module m, char ***features)
{
*features = featuresarray(m->nam, &module_features);
*features = featuresarray(m, &module_features);
return 0;
}
@ -3189,7 +3189,7 @@ features_(Module m, char ***features)
int
enables_(Module m, int **enables)
{
return handlefeatures(m->nam, &module_features, enables);
return handlefeatures(m, &module_features, enables);
}
/**/
@ -3221,7 +3221,7 @@ cleanup_(Module m)
{
deletehookfunc("exit", zftpexithook);
zftp_cleanup();
return setfeatureenables(m->nam, &module_features, NULL);
return setfeatureenables(m, &module_features, NULL);
}
/**/

View file

@ -225,7 +225,7 @@ zprof_wrapper(Eprog prog, FuncWrap w, char *name)
struct timezone dummy;
double prev = 0, now;
if (zprof_module && !(zprof_module->flags & MOD_UNLOAD)) {
if (zprof_module && !(zprof_module->node.flags & MOD_UNLOAD)) {
active = 1;
if (!(f = findpfunc(name))) {
f = (Pfunc) zalloc(sizeof(*f));
@ -260,7 +260,7 @@ zprof_wrapper(Eprog prog, FuncWrap w, char *name)
}
runshfunc(prog, w, name);
if (active) {
if (zprof_module && !(zprof_module->flags & MOD_UNLOAD)) {
if (zprof_module && !(zprof_module->node.flags & MOD_UNLOAD)) {
tv.tv_sec = tv.tv_usec = 0;
gettimeofday(&tv, &dummy);
@ -315,7 +315,7 @@ setup_(Module m)
int
features_(Module m, char ***features)
{
*features = featuresarray(m->nam, &module_features);
*features = featuresarray(m, &module_features);
return 0;
}
@ -323,7 +323,7 @@ features_(Module m, char ***features)
int
enables_(Module m, int **enables)
{
return handlefeatures(m->nam, &module_features, enables);
return handlefeatures(m, &module_features, enables);
}
/**/
@ -345,7 +345,7 @@ cleanup_(Module m)
freepfuncs(calls);
freeparcs(arcs);
deletewrapper(m, wrapper);
return setfeatureenables(m->nam, &module_features, NULL);
return setfeatureenables(m, &module_features, NULL);
}
/**/

View file

@ -750,7 +750,7 @@ setup_(UNUSED(Module m))
int
features_(Module m, char ***features)
{
*features = featuresarray(m->nam, &module_features);
*features = featuresarray(m, &module_features);
return 0;
}
@ -758,7 +758,7 @@ features_(Module m, char ***features)
int
enables_(Module m, int **enables)
{
return handlefeatures(m->nam, &module_features, enables);
return handlefeatures(m, &module_features, enables);
}
/**/
@ -777,7 +777,7 @@ cleanup_(Module m)
{
deletehookfunc("exit", ptyhook);
deleteallptycmds();
return setfeatureenables(m->nam, &module_features, NULL);
return setfeatureenables(m, &module_features, NULL);
}
/**/

View file

@ -294,7 +294,7 @@ setup_(UNUSED(Module m))
int
features_(Module m, char ***features)
{
*features = featuresarray(m->nam, &module_features);
*features = featuresarray(m, &module_features);
return 0;
}
@ -302,7 +302,7 @@ features_(Module m, char ***features)
int
enables_(Module m, int **enables)
{
return handlefeatures(m->nam, &module_features, enables);
return handlefeatures(m, &module_features, enables);
}
/**/
@ -317,7 +317,7 @@ boot_(Module m)
int
cleanup_(Module m)
{
return setfeatureenables(m->nam, &module_features, NULL);
return setfeatureenables(m, &module_features, NULL);
}
/**/

View file

@ -1801,10 +1801,10 @@ bin_zparseopts(char *nam, char **args, UNUSED(Options ops), UNUSED(int func))
}
static struct builtin bintab[] = {
BUILTIN("zstyle", 0, bin_zstyle, 0, -1, 0, NULL, NULL),
BUILTIN("zformat", 0, bin_zformat, 3, -1, 0, NULL, NULL),
BUILTIN("zregexparse", 0, bin_zregexparse, 3, -1, 0, "c", NULL),
BUILTIN("zparseopts", 0, bin_zparseopts, 1, -1, 0, NULL, NULL),
BUILTIN("zregexparse", 0, bin_zregexparse, 3, -1, 0, "c", NULL),
BUILTIN("zstyle", 0, bin_zstyle, 0, -1, 0, NULL, NULL),
};
static struct features module_features = {
@ -1828,7 +1828,7 @@ setup_(UNUSED(Module m))
int
features_(Module m, char ***features)
{
*features = featuresarray(m->nam, &module_features);
*features = featuresarray(m, &module_features);
return 0;
}
@ -1836,7 +1836,7 @@ features_(Module m, char ***features)
int
enables_(Module m, int **enables)
{
return handlefeatures(m->nam, &module_features, enables);
return handlefeatures(m, &module_features, enables);
}
/**/
@ -1850,7 +1850,7 @@ boot_(Module m)
int
cleanup_(Module m)
{
return setfeatureenables(m->nam, &module_features, NULL);
return setfeatureenables(m, &module_features, NULL);
}
/**/

View file

@ -3938,8 +3938,8 @@ makecomplistflags(Compctl cc, char *s, int incmd, int compadd)
static struct builtin bintab[] = {
BUILTIN("compctl", 0, bin_compctl, 0, -1, 0, NULL, NULL),
BUILTIN("compcall", 0, bin_compcall, 0, 0, 0, "TD", NULL),
BUILTIN("compctl", 0, bin_compctl, 0, -1, 0, NULL, NULL),
};
static struct features module_features = {
@ -3974,7 +3974,7 @@ setup_(UNUSED(Module m))
int
features_(Module m, char ***features)
{
*features = featuresarray(m->nam, &module_features);
*features = featuresarray(m, &module_features);
return 0;
}
@ -3982,7 +3982,7 @@ features_(Module m, char ***features)
int
enables_(Module m, int **enables)
{
return handlefeatures(m->nam, &module_features, enables);
return handlefeatures(m, &module_features, enables);
}
/**/
@ -4000,7 +4000,7 @@ cleanup_(Module m)
{
deletehookfunc("compctl_make", (Hookfn) ccmakehookfn);
deletehookfunc("compctl_cleanup", (Hookfn) cccleanuphookfn);
return setfeatureenables(m->nam, &module_features, NULL);
return setfeatureenables(m, &module_features, NULL);
}
/**/

View file

@ -1445,10 +1445,10 @@ static struct builtin bintab[] = {
};
static struct conddef cotab[] = {
CONDDEF("after", 0, cond_range, 1, 1, 0),
CONDDEF("between", 0, cond_range, 2, 2, 1),
CONDDEF("prefix", 0, cond_psfix, 1, 2, CVT_PREPAT),
CONDDEF("suffix", 0, cond_psfix, 1, 2, CVT_SUFPAT),
CONDDEF("between", 0, cond_range, 2, 2, 1),
CONDDEF("after", 0, cond_range, 1, 1, 0),
};
static struct funcwrap wrapper[] = {
@ -1502,7 +1502,7 @@ setup_(UNUSED(Module m))
int
features_(Module m, char ***features)
{
*features = featuresarray(m->nam, &module_features);
*features = featuresarray(m, &module_features);
return 0;
}
@ -1510,7 +1510,7 @@ features_(Module m, char ***features)
int
enables_(Module m, int **enables)
{
return handlefeatures(m->nam, &module_features, enables);
return handlefeatures(m, &module_features, enables);
}
/**/
@ -1524,7 +1524,7 @@ boot_(Module m)
addhookfunc("reverse_menu", (Hookfn) reverse_menu);
addhookfunc("list_matches", (Hookfn) list_matches);
addhookfunc("invalidate_list", (Hookfn) invalidate_list);
(void)addhookdefs(m->nam, comphooks, sizeof(comphooks)/sizeof(*comphooks));
(void)addhookdefs(m, comphooks, sizeof(comphooks)/sizeof(*comphooks));
return addwrapper(m, wrapper);
}
@ -1539,10 +1539,10 @@ cleanup_(Module m)
deletehookfunc("reverse_menu", (Hookfn) reverse_menu);
deletehookfunc("list_matches", (Hookfn) list_matches);
deletehookfunc("invalidate_list", (Hookfn) invalidate_list);
(void)deletehookdefs(m->nam, comphooks,
(void)deletehookdefs(m, comphooks,
sizeof(comphooks)/sizeof(*comphooks));
deletewrapper(m, wrapper);
return setfeatureenables(m->nam, &module_features, NULL);
return setfeatureenables(m, &module_features, NULL);
}
/**/

View file

@ -3238,7 +3238,7 @@ setup_(UNUSED(Module m))
int
features_(Module m, char ***features)
{
*features = featuresarray(m->nam, &module_features);
*features = featuresarray(m, &module_features);
return 0;
}
@ -3246,7 +3246,7 @@ features_(Module m, char ***features)
int
enables_(Module m, int **enables)
{
return handlefeatures(m->nam, &module_features, enables);
return handlefeatures(m, &module_features, enables);
}
/**/
@ -3261,7 +3261,8 @@ boot_(Module m)
w_menuselect = addzlefunction("menu-select", menuselect,
ZLE_MENUCMP|ZLE_KEEPSUFFIX|ZLE_ISCOMP);
if (!w_menuselect) {
zwarnnam(m->nam, "name clash when adding ZLE function `menu-select'");
zwarnnam(m->node.nam,
"name clash when adding ZLE function `menu-select'");
return -1;
}
addhookfunc("comp_list_matches", (Hookfn) complistmatches);
@ -3302,7 +3303,7 @@ cleanup_(Module m)
deletehookfunc("menu_start", (Hookfn) domenuselect);
unlinkkeymap("menuselect", 1);
unlinkkeymap("listscroll", 1);
return setfeatureenables(m->nam, &module_features, NULL);
return setfeatureenables(m, &module_features, NULL);
}
/**/

View file

@ -4544,14 +4544,14 @@ bin_compgroups(char *nam, char **args, UNUSED(Options ops), UNUSED(int func))
}
static struct builtin bintab[] = {
BUILTIN("compdescribe", 0, bin_compdescribe, 3, -1, 0, NULL, NULL),
BUILTIN("comparguments", 0, bin_comparguments, 1, -1, 0, NULL, NULL),
BUILTIN("compvalues", 0, bin_compvalues, 1, -1, 0, NULL, NULL),
BUILTIN("compdescribe", 0, bin_compdescribe, 3, -1, 0, NULL, NULL),
BUILTIN("compfiles", 0, bin_compfiles, 1, -1, 0, NULL, NULL),
BUILTIN("compgroups", 0, bin_compgroups, 1, -1, 0, NULL, NULL),
BUILTIN("compquote", 0, bin_compquote, 1, -1, 0, "p", NULL),
BUILTIN("comptags", 0, bin_comptags, 1, -1, 0, NULL, NULL),
BUILTIN("comptry", 0, bin_comptry, 0, -1, 0, NULL, NULL),
BUILTIN("compfiles", 0, bin_compfiles, 1, -1, 0, NULL, NULL),
BUILTIN("compgroups", 0, bin_compgroups, 1, -1, 0, NULL, NULL),
BUILTIN("compvalues", 0, bin_compvalues, 1, -1, 0, NULL, NULL)
};
static struct features module_features = {
@ -4581,7 +4581,7 @@ setup_(UNUSED(Module m))
int
features_(Module m, char ***features)
{
*features = featuresarray(m->nam, &module_features);
*features = featuresarray(m, &module_features);
return 0;
}
@ -4589,7 +4589,7 @@ features_(Module m, char ***features)
int
enables_(Module m, int **enables)
{
return handlefeatures(m->nam, &module_features, enables);
return handlefeatures(m, &module_features, enables);
}
/**/
@ -4603,7 +4603,7 @@ boot_(Module m)
int
cleanup_(Module m)
{
return setfeatureenables(m->nam, &module_features, NULL);
return setfeatureenables(m, &module_features, NULL);
}
/**/

View file

@ -95,7 +95,7 @@ setup_(UNUSED(Module m))
int
features_(Module m, char ***features)
{
*features = featuresarray(m->nam, &module_features);
*features = featuresarray(m, &module_features);
return 0;
}
@ -103,7 +103,7 @@ features_(Module m, char ***features)
int
enables_(Module m, int **enables)
{
return handlefeatures(m->nam, &module_features, enables);
return handlefeatures(m, &module_features, enables);
}
/**/
@ -119,7 +119,7 @@ boot_(Module m)
return 0;
deletezlefunction(w_deletetochar);
}
zwarnnam(m->nam, "deltochar: name clash when adding ZLE functions");
zwarnnam(m->node.nam, "deltochar: name clash when adding ZLE functions");
return -1;
}
@ -129,7 +129,7 @@ cleanup_(Module m)
{
deletezlefunction(w_deletetochar);
deletezlefunction(w_zaptochar);
return setfeatureenables(m->nam, &module_features, NULL);
return setfeatureenables(m, &module_features, NULL);
}
/**/

View file

@ -1827,7 +1827,7 @@ setup_(UNUSED(Module m))
int
features_(Module m, char ***features)
{
*features = featuresarray(m->nam, &module_features);
*features = featuresarray(m, &module_features);
return 0;
}
@ -1835,7 +1835,7 @@ features_(Module m, char ***features)
int
enables_(Module m, int **enables)
{
return handlefeatures(m->nam, &module_features, enables);
return handlefeatures(m, &module_features, enables);
}
/**/
@ -1844,7 +1844,7 @@ boot_(Module m)
{
addhookfunc("before_trap", (Hookfn) zlebeforetrap);
addhookfunc("after_trap", (Hookfn) zleaftertrap);
(void)addhookdefs(m->nam, zlehooks, sizeof(zlehooks)/sizeof(*zlehooks));
(void)addhookdefs(m, zlehooks, sizeof(zlehooks)/sizeof(*zlehooks));
return 0;
}
@ -1853,13 +1853,14 @@ int
cleanup_(Module m)
{
if(zleactive) {
zerrnam(m->nam, "can't unload the zle module while zle is active");
zerrnam(m->node.nam,
"can't unload the zle module while zle is active");
return 1;
}
deletehookfunc("before_trap", (Hookfn) zlebeforetrap);
deletehookfunc("after_trap", (Hookfn) zleaftertrap);
(void)deletehookdefs(m->nam, zlehooks, sizeof(zlehooks)/sizeof(*zlehooks));
return setfeatureenables(m->nam, &module_features, NULL);
(void)deletehookdefs(m, zlehooks, sizeof(zlehooks)/sizeof(*zlehooks));
return setfeatureenables(m, &module_features, NULL);
}
/**/

View file

@ -56,7 +56,7 @@ widgetstr(Widget w)
/**/
static HashNode
getpmwidgets(UNUSED(HashTable ht), char *name)
getpmwidgets(UNUSED(HashTable ht), const char *name)
{
Param pm = NULL;
Thingy th;
@ -129,16 +129,16 @@ static const struct gsu_array keymaps_gsu =
{ keymapsgetfn, arrsetfn, stdunsetfn };
static struct paramdef partab[] = {
SPECIALPMDEF("widgets", PM_READONLY,
&zlestdhash_gsu, getpmwidgets, scanpmwidgets),
SPECIALPMDEF("keymaps", PM_ARRAY|PM_READONLY, &keymaps_gsu, NULL, NULL),
SPECIALPMDEF("widgets", PM_READONLY,
&zlestdhash_gsu, getpmwidgets, scanpmwidgets)
};
static struct features module_features = {
NULL, 0,
NULL, 0,
partab, sizeof(partab)/sizeof(*partab),
NULL, 0,
partab, sizeof(partab)/sizeof(*partab),
0
};
@ -153,7 +153,7 @@ setup_(UNUSED(Module m))
int
features_(Module m, char ***features)
{
*features = featuresarray(m->nam, &module_features);
*features = featuresarray(m, &module_features);
return 0;
}
@ -161,7 +161,7 @@ features_(Module m, char ***features)
int
enables_(Module m, int **enables)
{
return handlefeatures(m->nam, &module_features, enables);
return handlefeatures(m, &module_features, enables);
}
/**/
@ -175,7 +175,7 @@ boot_(UNUSED(Module m))
int
cleanup_(Module m)
{
return setfeatureenables(m->nam, &module_features, NULL);
return setfeatureenables(m, &module_features, NULL);
}
/**/

View file

@ -250,7 +250,7 @@ execbuiltin(LinkList args, Builtin bn)
name = (char *) ugetnode(args);
if (!bn->handlerfunc) {
zwarnnam(name, "autoload failed");
DPUTS(1, "Missing builtin detected too late");
deletebuiltin(bn->node.nam);
return 1;
}

View file

@ -96,11 +96,7 @@ evalcond(Estate state, char *fromtest)
{
char *modname = isset(REMATCHPCRE) ? "zsh/pcre" : "zsh/regex";
sprintf(overridename = overridebuf, "-%s-match", modname+4);
if (ensurefeature(modname, "c:", overridename+1)) {
zwarnnam(fromtest, "%s not available for regex",
modname);
return 2;
}
(void)ensurefeature(modname, "c:", overridename+1);
ctype = COND_MODI;
}
/*FALLTHROUGH*/
@ -129,7 +125,7 @@ evalcond(Estate state, char *fromtest)
if ((cd = getconddef((ctype == COND_MODI), name + 1, 1))) {
if (ctype == COND_MOD &&
(l < cd->min || (cd->max >= 0 && l > cd->max))) {
zwarnnam(fromtest, "unrecognized condition: `%s'", name);
zwarnnam(fromtest, "unknown condition: -%s", name);
return 2;
}
if (tracingcond)
@ -139,13 +135,23 @@ evalcond(Estate state, char *fromtest)
else {
char *s = strs[0];
if (overridename) {
/*
* Standard regex function not available: this
* is a hard error.
*/
zerrnam(fromtest, "%s not available for regex",
overridename);
return 2;
}
strs[0] = dupstring(name);
name = s;
if (name && name[0] == '-' &&
(cd = getconddef(0, name + 1, 1))) {
if (l < cd->min || (cd->max >= 0 && l > cd->max)) {
zwarnnam(fromtest, "unrecognized condition: `%s'",
zwarnnam(fromtest, "unknown condition: -%s",
name);
return 2;
}
@ -154,7 +160,7 @@ evalcond(Estate state, char *fromtest)
return !cd->handler(strs, cd->condid);
} else {
zwarnnam(fromtest,
"unrecognized condition: `%s'",
"unknown condition: -%s",
name ? name : "<null>");
}
}

View file

@ -871,7 +871,7 @@ execlist(Estate state, int dont_change_job, int exiting)
/* Loop over all sets of comands separated by newline, *
* semi-colon or ampersand (`sublists'). */
code = *state->pc++;
while (wc_code(code) == WC_LIST && !breaks && !retflag) {
while (wc_code(code) == WC_LIST && !breaks && !retflag && !errflag) {
int donedebug;
ltype = WC_LIST_TYPE(code);
@ -1915,6 +1915,34 @@ execsubst(LinkList strs)
}
}
/*
* Check if a builtin requires an autoload and if so
* deal with it. This may return NULL.
*/
/**/
static HashNode
resolvebuiltin(const char *cmdarg, HashNode hn)
{
if (!((Builtin) hn)->handlerfunc) {
/*
* Ensure the module is loaded and the
* feature corresponding to the builtin
* is enabled.
*/
(void)ensurefeature(((Builtin) hn)->optstr, "b:",
(hn->flags & BINF_AUTOALL) ? NULL :
hn->nam);
hn = builtintab->getnode(builtintab, cmdarg);
if (!hn) {
lastval = 1;
zerr("unknown builtin: %s");
return NULL;
}
}
return hn;
}
/**/
static void
execcmd(Estate state, int input, int output, int how, int last1)
@ -2011,16 +2039,9 @@ execcmd(Estate state, int input, int output, int how, int last1)
is_builtin = 1;
/* autoload the builtin if necessary */
if (!((Builtin) hn)->handlerfunc) {
/*
* Ensure the module is loaded and the
* feature corresponding to the builtin
* is enabled.
*/
(void)ensurefeature(((Builtin) hn)->optstr, "b:", hn->nam);
hn = builtintab->getnode(builtintab, cmdarg);
}
assign = (hn && (hn->flags & BINF_MAGICEQUALS));
if (!(hn = resolvebuiltin(cmdarg, hn)))
return;
assign = (hn->flags & BINF_MAGICEQUALS);
break;
}
cflags &= ~BINF_BUILTIN & ~BINF_COMMAND;
@ -2233,10 +2254,8 @@ execcmd(Estate state, int input, int output, int how, int last1)
is_builtin = 1;
/* autoload the builtin if necessary */
if (!((Builtin) hn)->handlerfunc) {
(void)ensurefeature(((Builtin) hn)->optstr, "b:", cmdarg);
hn = builtintab->getnode(builtintab, cmdarg);
}
if (!(hn = resolvebuiltin(cmdarg, hn)))
return;
break;
}
cflags &= ~BINF_BUILTIN & ~BINF_COMMAND;
@ -4104,8 +4123,8 @@ runshfunc(Eprog prog, FuncWrap wrap, char *name)
wrap->module->wrapper--;
if (!wrap->module->wrapper &&
(wrap->module->flags & MOD_UNLOAD))
unload_module(wrap->module, NULL);
(wrap->module->node.flags & MOD_UNLOAD))
unload_module(wrap->module);
if (!cont)
return;

View file

@ -78,7 +78,7 @@ static HashTable firstht, lastht;
/**/
mod_export unsigned
hasher(char *str)
hasher(const char *str)
{
unsigned hashval = 0, c;
@ -223,7 +223,7 @@ addhashnode2(HashTable ht, char *nam, void *nodeptr)
/**/
mod_export HashNode
gethashnode(HashTable ht, char *nam)
gethashnode(HashTable ht, const char *nam)
{
unsigned hashval;
HashNode hp;
@ -247,7 +247,7 @@ gethashnode(HashTable ht, char *nam)
/**/
mod_export HashNode
gethashnode2(HashTable ht, char *nam)
gethashnode2(HashTable ht, const char *nam)
{
unsigned hashval;
HashNode hp;
@ -267,7 +267,7 @@ gethashnode2(HashTable ht, char *nam)
/**/
mod_export HashNode
removehashnode(HashTable ht, char *nam)
removehashnode(HashTable ht, const char *nam)
{
unsigned hashval;
HashNode hp, hq;
@ -795,7 +795,7 @@ createshfunctable(void)
/**/
static HashNode
removeshfuncnode(UNUSED(HashTable ht), char *nam)
removeshfuncnode(UNUSED(HashTable ht), const char *nam)
{
HashNode hn;
int signum;
@ -1378,7 +1378,7 @@ addnameddirnode(HashTable ht, char *nam, void *nodeptr)
/**/
static HashNode
removenameddirnode(HashTable ht, char *nam)
removenameddirnode(HashTable ht, const char *nam)
{
HashNode hn = removehashnode(ht, nam);
@ -1453,7 +1453,7 @@ createhisttable(void)
/**/
unsigned
histhasher(char *str)
histhasher(const char *str)
{
unsigned hashval = 0;

View file

@ -701,7 +701,7 @@ setupvals(void)
close(tmppipe[1]);
}
(void)addhookdefs(argzero, zshhooks, sizeof(zshhooks)/sizeof(*zshhooks));
(void)addhookdefs(NULL, zshhooks, sizeof(zshhooks)/sizeof(*zshhooks));
init_eprog();
@ -769,7 +769,7 @@ setupvals(void)
watch = mkarray(NULL);
psvar = mkarray(NULL);
module_path = mkarray(ztrdup(MODULE_DIR));
modules = znewlinklist();
modulestab = newmoduletable(17, "modules");
linkedmodules = znewlinklist();
/* Set default prompts */

View file

@ -2147,7 +2147,7 @@ bin_kill(char *nam, char **argv, UNUSED(Options ops), UNUSED(int func))
/**/
mod_export int
getsignum(char *s)
getsignum(const char *s)
{
int x, i;
@ -2205,7 +2205,7 @@ gettrapnode(int sig, int ignoredisable)
{
char fname[20];
HashNode hn;
HashNode (*getptr)(HashTable ht, char *name);
HashNode (*getptr)(HashTable ht, const char *name);
int i;
if (ignoredisable)
getptr = shfunctab->getnode2;

View file

@ -37,8 +37,7 @@ for x_mod in $x_mods; do
echo "/* non-linked-in known module \`$x_mod' */"
linked=no
esac
unset moddeps autobins autoinfixconds autoprefixconds autoparams
unset automathfuncs
unset moddeps autofeatures
. $srcdir/../$modfile
if test "x$autofeatures" != x; then
echo " if (emulation == EMULATE_ZSH) {"

File diff suppressed because it is too large Load diff

View file

@ -411,7 +411,7 @@ newparamtable(int size, char const *name)
/**/
static HashNode
getparamnode(HashTable ht, char *nam)
getparamnode(HashTable ht, const char *nam)
{
HashNode hn = gethashnode2(ht, nam);
Param pm = (Param) hn;
@ -419,12 +419,16 @@ getparamnode(HashTable ht, char *nam)
if (pm && pm->u.str && (pm->node.flags & PM_AUTOLOAD)) {
char *mn = dupstring(pm->u.str);
if (ensurefeature(mn, "p:", nam))
return NULL;
(void)ensurefeature(mn, "p:", (pm->node.flags & PM_AUTOALL) ? NULL :
nam);
hn = gethashnode2(ht, nam);
if (((Param) hn) == pm && (pm->node.flags & PM_AUTOLOAD)) {
pm->node.flags &= ~PM_AUTOLOAD;
zwarnnam(nam, "autoload failed");
if (!hn) {
/*
* This used to be a warning, but surely if we allow
* stuff to go ahead with the autoload stub with
* no error status we're in for all sorts of mayhem?
*/
zerr("unknown parameter: %s", nam);
}
}
return hn;

View file

@ -109,7 +109,7 @@ zhtricat(char const *s1, char const *s2, char const *s3)
/**/
mod_export char *
dyncat(char *s1, char *s2)
dyncat(const char *s1, const char *s2)
{
/* This version always uses space from the current heap. */
char *ptr;

View file

@ -92,6 +92,8 @@ struct mathfunc {
#define MFF_ADDED 2
/* Math function is implemented by a shell function */
#define MFF_USERFUNC 4
/* When autoloading, enable all features in module */
#define MFF_AUTOALL 8
#define NUMMATHFUNC(name, func, min, max, id) \
@ -538,8 +540,12 @@ struct conddef {
char *module; /* module to autoload */
};
#define CONDF_INFIX 1
#define CONDF_ADDED 2
/* Condition is an infix */
#define CONDF_INFIX 1
/* Condition has been loaded from library */
#define CONDF_ADDED 2
/* When autoloading, enable all features in library */
#define CONDF_AUTOALL 4
#define CONDDEF(name, flags, handler, min, max, condid) \
{ NULL, name, flags, handler, min, max, condid, NULL }
@ -928,11 +934,16 @@ struct dirsav {
typedef void *(*VFunc) _((void *));
typedef void (*FreeFunc) _((void *));
typedef unsigned (*HashFunc) _((char *));
typedef unsigned (*HashFunc) _((const char *));
typedef void (*TableFunc) _((HashTable));
/*
* Note that this is deliberately "char *", not "const char *",
* since the AddNodeFunc is passed a pointer to a string that
* will be stored and later freed.
*/
typedef void (*AddNodeFunc) _((HashTable, char *, void *));
typedef HashNode (*GetNodeFunc) _((HashTable, char *));
typedef HashNode (*RemoveNodeFunc) _((HashTable, char *));
typedef HashNode (*GetNodeFunc) _((HashTable, const char *));
typedef HashNode (*RemoveNodeFunc) _((HashTable, const char *));
typedef void (*FreeNodeFunc) _((HashNode));
typedef int (*CompareFunc) _((const char *, const char *));
@ -1152,25 +1163,37 @@ struct builtin {
#define BINF_SKIPDASH (1<<14) /* Treat `-' as argument (maybe `+') */
#define BINF_DASHDASHVALID (1<<15) /* Handle `--' even if SKIPINVALD */
#define BINF_CLEARENV (1<<16) /* new process started with cleared env */
#define BINF_AUTOALL (1<<17) /* autoload all features at once */
struct module {
char *nam;
int flags;
struct hashnode node;
union {
void *handle;
Linkedmod linked;
char *alias;
} u;
LinkList autoloads;
LinkList deps;
int wrapper;
};
/* We are in the process of loading the module */
#define MOD_BUSY (1<<0)
/*
* We are in the process of unloading the module.
* Note this is not needed to indicate a module is actually
* unloaded: for that, the handle (or linked pointer) is set to NULL.
*/
#define MOD_UNLOAD (1<<1)
/* We are in the process of setting up the module */
#define MOD_SETUP (1<<2)
/* Module is statically linked into the main binary */
#define MOD_LINKED (1<<3)
/* Module setup has been carried out (and module has not been finished) */
#define MOD_INIT_S (1<<4)
/* Module boot has been carried out (and module has not been finished) */
#define MOD_INIT_B (1<<5)
/* Module record is an alias */
#define MOD_ALIAS (1<<6)
typedef int (*Module_generic_func) _((void));
@ -1199,12 +1222,12 @@ struct features {
/* List of conditions provided by the module and the size thereof */
Conddef cd_list;
int cd_size;
/* List of parameters provided by the module and the size thereof */
Paramdef pd_list;
int pd_size;
/* List of math functions provided by the module and the size thereof */
MathFunc mf_list;
int mf_size;
/* List of parameters provided by the module and the size thereof */
Paramdef pd_list;
int pd_size;
/* Number of abstract features */
int n_abstract;
};
@ -1408,6 +1431,10 @@ struct tieddata {
#define PM_REMOVABLE (1<<26) /* special can be removed from paramtab */
#define PM_AUTOLOAD (1<<27) /* autoloaded from module */
#define PM_NORESTORE (1<<28) /* do not restore value of local special */
#define PM_AUTOALL (1<<28) /* autoload all features in module
* when loading: valid only if PM_AUTOLOAD
* is also present.
*/
#define PM_HASHELEM (1<<29) /* is a hash-element */
#define PM_NAMEDDIR (1<<30) /* has a corresponding nameddirtab entry */

View file

@ -39,6 +39,9 @@
fi
}
mkdir zmodload.tmp
cd zmodload.tmp
%test
# This first test depends on knowing that zsh is run with +Z from the
@ -118,10 +121,85 @@
zmodload -ab zsh/example example
builtin example
zmodload -e zsh/example
else print -u8 Warning: zsh/example not linked: not checking autoloading
else print -u$ZTST_fd Warning: zsh/example not linked: not checking autoloading
fi
0d:Autoload a module via a builtin
zmodload -u zsh/example
builtin example
0d:Autoloads are persistent
(zmodload -u zsh/parameter
zmodload -aF zsh/parameter b:fail
fail
print "Shouldn't get here.")
1:Failed builtin autoload
?(eval):3: module `zsh/parameter' has no such feature: `b:fail': autoload cancelled
?(eval):3: unknown builtin: fail
(zmodload -u zsh/parameter
zmodload -aF zsh/parameter p:fail
print $fail
print "Shouldn't get here.")
1:Failed parameter autoload
?(eval):3: module `zsh/parameter' has no such feature: `p:fail': autoload cancelled
?(eval):3: unknown parameter: fail
(zmodload -u zsh/parameter
zmodload -aF zsh/parameter c:fail
[[ -fail foo ]]
print "Shouldn't get here.")
2:Failed condition autoload
?(eval):3: module `zsh/parameter' has no such feature: `c:fail': autoload cancelled
?(eval):3: unknown condition: -foo
(zmodload -u zsh/parameter
zmodload -aF zsh/parameter f:fail
(( fail() )) )
2:Failed math function autoload
?(eval):3: module `zsh/parameter' has no such feature: `f:fail': autoload cancelled
?(eval):3: unknown function: fail
zmodload -aF zsh/parameter f:fail2
1:Immediate autoload failure on non-existent feature when module loaded
?(eval):zmodload:1: module `zsh/parameter' has no such feature: `f:fail2'
(zmodload -u zsh/parameter
zmodload -aF zsh/parameter p:fail
print $(( ${#modules} > 1 )) )
0:Autoloads checked on loading but don't necessarily effect current command
>1
?(eval):3: module `zsh/parameter' has no such feature: `p:fail': autoload cancelled
zmodload -laF zsh/parameter
0:List default autoloads
>p:aliases
>p:builtins
>p:commands
>p:dirstack
>p:dis_aliases
>p:dis_builtins
>p:dis_functions
>p:dis_galiases
>p:dis_reswords
>p:dis_saliases
>p:funcstack
>p:functions
>p:functrace
>p:galiases
>p:history
>p:historywords
>p:jobdirs
>p:jobstates
>p:jobtexts
>p:modules
>p:nameddirs
>p:options
>p:parameters
>p:reswords
>p:saliases
>p:userdirs
if [[ $mods[(r)zsh/example] == zsh/example ]]; then
zmodload -u zsh/example
zmodload -ac -I zsh/example ex
@ -169,6 +247,11 @@
zmodload -e example
1:Delete the module alias again
zmodload >zmodload_list
print -l ${(o)mods} >mods_list
diff zmodload_list mods_list
0:Listing with zmodload should give all our modules.
# Don't unload the main module.
# Do unload zsh/parameter, but reload it as it is needed.