mirror of
git://git.code.sf.net/p/zsh/code
synced 2024-10-01 00:12:08 +02:00
22483: add $sysparams to zsh/system
This commit is contained in:
parent
38ad28d8ac
commit
8346a5e8d2
@ -1,3 +1,8 @@
|
|||||||
|
2006-06-05 Peter Stephenson <pws@csr.com>
|
||||||
|
|
||||||
|
* 22483: Src/params.c, Src/Modules/system.c,
|
||||||
|
Doc/Zsh/mod_system.yo: add $sysparams to zsh/system.
|
||||||
|
|
||||||
2006-06-02 Clint Adams <clint@zsh.org>
|
2006-06-02 Clint Adams <clint@zsh.org>
|
||||||
|
|
||||||
* 22481: Oliver Kiddle: Completion/Unix/Command/_subversion:
|
* 22481: Oliver Kiddle: Completion/Unix/Command/_subversion:
|
||||||
|
@ -2,7 +2,7 @@ COMMENT(!MOD!zsh/system
|
|||||||
A builtin interface to various low-level system features.
|
A builtin interface to various low-level system features.
|
||||||
!MOD!)
|
!MOD!)
|
||||||
The tt(zsh/system) module makes available three builtin commands and
|
The tt(zsh/system) module makes available three builtin commands and
|
||||||
a parameter.
|
two parameters.
|
||||||
|
|
||||||
sect(Builtins)
|
sect(Builtins)
|
||||||
|
|
||||||
@ -114,6 +114,7 @@ enditem()
|
|||||||
sect(Parameters)
|
sect(Parameters)
|
||||||
|
|
||||||
startitem()
|
startitem()
|
||||||
|
vindex(errnos)
|
||||||
item(tt(errnos))(
|
item(tt(errnos))(
|
||||||
A readonly array of the names of errors defined on the system. These
|
A readonly array of the names of errors defined on the system. These
|
||||||
are typically macros defined in C by including the system header file
|
are typically macros defined in C by including the system header file
|
||||||
@ -125,4 +126,19 @@ tt(E)var(num) in the array.
|
|||||||
Note that aliases for errors are not handled; only the canonical name is
|
Note that aliases for errors are not handled; only the canonical name is
|
||||||
used.
|
used.
|
||||||
)
|
)
|
||||||
|
vindex(sysparams)
|
||||||
|
item(tt(sysparams))(
|
||||||
|
A readonly associative array. The keys are:
|
||||||
|
startitem()
|
||||||
|
item(tt(pid))(
|
||||||
|
Returns the process ID of the current process, even in subshells. Compare
|
||||||
|
tt($$), which returns the process ID of the main shell process.
|
||||||
|
)
|
||||||
|
item(tt(ppid))(
|
||||||
|
Returns the process ID of the parent of the current process, even in
|
||||||
|
subshells. Compare tt($PPID), which returns the process ID of the parent
|
||||||
|
of the main shell process.
|
||||||
|
)
|
||||||
|
enditem()
|
||||||
|
)
|
||||||
enditem()
|
enditem()
|
||||||
|
@ -340,6 +340,12 @@ bin_syserror(char *nam, char **args, Options ops, UNUSED(int func))
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct builtin bintab[] = {
|
||||||
|
BUILTIN("syserror", 0, bin_syserror, 0, 1, 0, "e:p:", NULL),
|
||||||
|
BUILTIN("sysread", 0, bin_sysread, 0, 1, 0, "c:i:o:s:t:", NULL),
|
||||||
|
BUILTIN("syswrite", 0, bin_syswrite, 1, 1, 0, "c:o:", NULL),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/* Functions for the errnos special parameter. */
|
/* Functions for the errnos special parameter. */
|
||||||
|
|
||||||
@ -351,16 +357,54 @@ errnosgetfn(UNUSED(Param pm))
|
|||||||
return arrdup((char **)sys_errnames);
|
return arrdup((char **)sys_errnames);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static struct builtin bintab[] = {
|
|
||||||
BUILTIN("syserror", 0, bin_syserror, 0, 1, 0, "e:p:", NULL),
|
|
||||||
BUILTIN("sysread", 0, bin_sysread, 0, 1, 0, "c:i:o:s:t:", NULL),
|
|
||||||
BUILTIN("syswrite", 0, bin_syswrite, 1, 1, 0, "c:o:", NULL),
|
|
||||||
};
|
|
||||||
|
|
||||||
static const struct gsu_array errnos_gsu =
|
static const struct gsu_array errnos_gsu =
|
||||||
{ errnosgetfn, arrsetfn, stdunsetfn };
|
{ errnosgetfn, arrsetfn, stdunsetfn };
|
||||||
|
|
||||||
|
|
||||||
|
/* Functions for the sysparams special parameter. */
|
||||||
|
|
||||||
|
/**/
|
||||||
|
static char *
|
||||||
|
sysparamgetfn(Param pm)
|
||||||
|
{
|
||||||
|
char buf[DIGBUFSIZE];
|
||||||
|
int num;
|
||||||
|
|
||||||
|
if (!strcmp(pm->node.nam, "pid")) {
|
||||||
|
num = (int)getpid();
|
||||||
|
} else if (!strcmp(pm->node.nam, "ppid")) {
|
||||||
|
num = (int)getppid();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
#ifdef DEBUG
|
||||||
|
dputs("Bad sysparam parameter");
|
||||||
|
#endif
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
sprintf(buf, "%d", num);
|
||||||
|
return dupstring(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct gsu_scalar sysparam_gsu =
|
||||||
|
{ sysparamgetfn, strsetfn, stdunsetfn };
|
||||||
|
|
||||||
|
static void
|
||||||
|
fixsysparams(HashNode hn, int flags)
|
||||||
|
{
|
||||||
|
Param pm = (Param)hn;
|
||||||
|
|
||||||
|
if (flags) {
|
||||||
|
/* prepare to free */
|
||||||
|
pm->node.flags &= ~PM_READONLY;
|
||||||
|
} else {
|
||||||
|
/* assign */
|
||||||
|
pm->gsu.s = &sysparam_gsu;
|
||||||
|
pm->node.flags |= PM_READONLY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* The load/unload routines required by the zsh library interface */
|
/* The load/unload routines required by the zsh library interface */
|
||||||
|
|
||||||
/**/
|
/**/
|
||||||
@ -385,7 +429,12 @@ tidyparam(Param pm)
|
|||||||
int
|
int
|
||||||
boot_(Module m)
|
boot_(Module m)
|
||||||
{
|
{
|
||||||
Param pm_nos;
|
Param pm_nos, pm_params;
|
||||||
|
HashTable ht;
|
||||||
|
const char *sysparams_args[] = {
|
||||||
|
"pid", "ppid", NULL
|
||||||
|
}, **srcptr;
|
||||||
|
char **arglist, **dstptr;
|
||||||
|
|
||||||
/* this takes care of an autoload on errnos */
|
/* this takes care of an autoload on errnos */
|
||||||
unsetparam("errnos");
|
unsetparam("errnos");
|
||||||
@ -394,8 +443,31 @@ boot_(Module m)
|
|||||||
return 1;
|
return 1;
|
||||||
pm_nos->gsu.a = &errnos_gsu;
|
pm_nos->gsu.a = &errnos_gsu;
|
||||||
|
|
||||||
|
if (!(pm_params = createparam("sysparams", PM_HASHED|PM_SPECIAL|
|
||||||
|
PM_HIDE|PM_HIDEVAL|PM_REMOVABLE))) {
|
||||||
|
tidyparam(pm_nos);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
pm_params->level = pm_params->old ? locallevel : 0;
|
||||||
|
pm_params->gsu.h = &stdhash_gsu;
|
||||||
|
pm_params->u.hash = ht = newparamtable(0, "sysparams");
|
||||||
|
|
||||||
|
arglist = (char **)zshcalloc((2*arrlen((char **)sysparams_args) + 1) *
|
||||||
|
sizeof(char *));
|
||||||
|
for (srcptr = sysparams_args, dstptr = arglist; *srcptr; ) {
|
||||||
|
*dstptr++ = ztrdup(*srcptr++);
|
||||||
|
*dstptr++ = ztrdup("");
|
||||||
|
}
|
||||||
|
*dstptr = NULL;
|
||||||
|
/* make sure we don't overwrite the hash table: use the "augment" arg */
|
||||||
|
arrhashsetfn(pm_params, arglist, 1);
|
||||||
|
scanhashtable(ht, 0, 0, 0, fixsysparams, 0);
|
||||||
|
|
||||||
|
pm_params->node.flags |= PM_READONLY;
|
||||||
|
|
||||||
if (!addbuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab))) {
|
if (!addbuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab))) {
|
||||||
tidyparam(pm_nos);
|
tidyparam(pm_nos);
|
||||||
|
tidyparam(pm_params);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -406,7 +478,14 @@ boot_(Module m)
|
|||||||
int
|
int
|
||||||
cleanup_(Module m)
|
cleanup_(Module m)
|
||||||
{
|
{
|
||||||
tidyparam((Param)paramtab->getnode(paramtab, "errnos"));
|
Param pm;
|
||||||
|
if ((pm = (Param)paramtab->getnode(paramtab, "errnos")))
|
||||||
|
tidyparam(pm);
|
||||||
|
if ((pm = (Param)paramtab->getnode(paramtab, "sysparams")))
|
||||||
|
{
|
||||||
|
scanhashtable(pm->u.hash, 0, 0, 0, fixsysparams, 1);
|
||||||
|
tidyparam(pm);
|
||||||
|
}
|
||||||
|
|
||||||
deletebuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab));
|
deletebuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab));
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -2516,7 +2516,7 @@ strgetfn(Param pm)
|
|||||||
/* Function to set value of a scalar (string) parameter */
|
/* Function to set value of a scalar (string) parameter */
|
||||||
|
|
||||||
/**/
|
/**/
|
||||||
static void
|
mod_export void
|
||||||
strsetfn(Param pm, char *x)
|
strsetfn(Param pm, char *x)
|
||||||
{
|
{
|
||||||
zsfree(pm->u.str);
|
zsfree(pm->u.str);
|
||||||
@ -2587,7 +2587,7 @@ nullsethashfn(UNUSED(Param pm), HashTable x)
|
|||||||
/* Function to set value of an association parameter using key/value pairs */
|
/* Function to set value of an association parameter using key/value pairs */
|
||||||
|
|
||||||
/**/
|
/**/
|
||||||
static void
|
mod_export void
|
||||||
arrhashsetfn(Param pm, char **val, int augment)
|
arrhashsetfn(Param pm, char **val, int augment)
|
||||||
{
|
{
|
||||||
/* Best not to shortcut this by using the existing hash table, *
|
/* Best not to shortcut this by using the existing hash table, *
|
||||||
|
Loading…
Reference in New Issue
Block a user