mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-04 22:51:42 +02:00
34350, 34353: document zsh/db/gdbm module, clean up a few things in the code
Still core dumps at this revision if the tied parameter is forced to be a local and is not untied before end of scope.
This commit is contained in:
parent
f7a2fba534
commit
2fa11b7c54
4 changed files with 63 additions and 20 deletions
|
@ -38,6 +38,13 @@
|
|||
* 34368: Completion/Zsh/Command/_zstyle: _zstyle vcs_info
|
||||
completion: Add missing styles
|
||||
|
||||
2015-01-24 Barton E. Schaefer <schaefer@zsh.org>
|
||||
|
||||
* 34350, 34353: Doc/Makefile.in, Doc/Zsh/mod_db_gdbm.yo,
|
||||
Src/Modules/db_gdbm.c: document zsh/db/gdbm module, clean up a few
|
||||
things in the code. Still core dumps if the tied parameter is
|
||||
forced to be a local and is not untied before end of scope.
|
||||
|
||||
2015-01-23 Jun-ichi Takimoto <takimoto-j@kba.biglobe.ne.jp>
|
||||
|
||||
* 34335: _yum: fix bugs in _yum_all_pkgs
|
||||
|
|
|
@ -60,7 +60,7 @@ MODDOCSRC = \
|
|||
Zsh/mod_attr.yo Zsh/mod_cap.yo Zsh/mod_clone.yo \
|
||||
Zsh/mod_compctl.yo Zsh/mod_complete.yo Zsh/mod_complist.yo \
|
||||
Zsh/mod_computil.yo Zsh/mod_curses.yo \
|
||||
Zsh/mod_datetime.yo Zsh/mod_deltochar.yo \
|
||||
Zsh/mod_datetime.yo Zsh/mod_db_gdbm.yo Zsh/mod_deltochar.yo \
|
||||
Zsh/mod_example.yo Zsh/mod_files.yo Zsh/mod_langinfo.yo \
|
||||
Zsh/mod_mapfile.yo Zsh/mod_mathfunc.yo Zsh/mod_newuser.yo \
|
||||
Zsh/mod_parameter.yo Zsh/mod_pcre.yo Zsh/mod_regex.yo \
|
||||
|
|
27
Doc/Zsh/mod_db_gdbm.yo
Normal file
27
Doc/Zsh/mod_db_gdbm.yo
Normal file
|
@ -0,0 +1,27 @@
|
|||
COMMENT(!MOD!zsh/db/gdbm
|
||||
Builtins for managing associative array parameters tied to GDBM databases.
|
||||
!MOD!)
|
||||
The tt(zsh/db/gdbm) module is used to create "tied" associative arrays
|
||||
that interface to database files. If the GDBM interface is not available,
|
||||
the builtins defined by this module will report an error. This module is
|
||||
also intended as a prototype for creating additional database interfaces,
|
||||
so the tt(ztie) builtin may move to a more generic module in the future.
|
||||
|
||||
The builtins in this module are:
|
||||
|
||||
startitem()
|
||||
findex(ztie)
|
||||
cindex(tied array, creating)
|
||||
item(tt(ztie -d db/gdbm -f) var(filename) var(arrayname))(
|
||||
Open the GDBM database identified by var(filename) and, if successful,
|
||||
create the associative array var(arrayname) linked to the file. Note
|
||||
that var(arrayname) must be unset at the time tt(ztie) is called, and
|
||||
is always created as a global parameter (as if with `tt(typeset -g)').
|
||||
)
|
||||
findex(zuntie)
|
||||
cindex(tied array, destroying)
|
||||
item(tt(zuntie) var(arrayname) ...)(
|
||||
Close the GDBM database associated with each var(arrayname) and then
|
||||
unset the variable.
|
||||
)
|
||||
enditem()
|
|
@ -39,9 +39,7 @@
|
|||
|
||||
#include <gdbm.h>
|
||||
|
||||
#if 0 /* what is this for? */
|
||||
static char *backtype = "db/gdbm";
|
||||
#endif
|
||||
|
||||
static const struct gsu_scalar gdbm_gsu =
|
||||
{ gdbmgetfn, gdbmsetfn, gdbmunsetfn };
|
||||
|
@ -60,33 +58,38 @@ bin_ztie(char *nam, char **args, Options ops, UNUSED(int func))
|
|||
Param tied_param;
|
||||
|
||||
if(!OPT_ISSET(ops,'d')) {
|
||||
zwarnnam(nam, "you must pass `-d db/gdbm' to ztie", NULL);
|
||||
zwarnnam(nam, "you must pass `-d %s'", backtype);
|
||||
return 1;
|
||||
}
|
||||
if(!OPT_ISSET(ops,'f')) {
|
||||
zwarnnam(nam, "you must pass `-f' with a filename to ztie", NULL);
|
||||
zwarnnam(nam, "you must pass `-f' with a filename", NULL);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Here should be a lookup of the backend type against
|
||||
* a registry.
|
||||
*/
|
||||
if (strcmp(OPT_ARG(ops, 'd'), backtype) != 0) {
|
||||
zwarnnam(nam, "unsupported backend type `%s'", OPT_ARG(ops, 'd'));
|
||||
return 1;
|
||||
}
|
||||
|
||||
pmname = ztrdup(*args);
|
||||
|
||||
resource_name = OPT_ARG(ops, 'f');
|
||||
|
||||
if (!(tied_param = createspecialhash(pmname, &getgdbmnode, &scangdbmkeys, 0))) {
|
||||
zwarnnam(nam, "cannot create the requested parameter name", NULL);
|
||||
return 1;
|
||||
}
|
||||
|
||||
dbf = gdbm_open(resource_name, 0, GDBM_WRCREAT | GDBM_SYNC, 0666, 0);
|
||||
if(!dbf) {
|
||||
zwarnnam(nam, "error opening database file %s", resource_name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!(tied_param = createspecialhash(pmname, &getgdbmnode, &scangdbmkeys, 0))) {
|
||||
zwarnnam(nam, "cannot create the requested parameter %s", pmname);
|
||||
gdbm_close(dbf);
|
||||
return 1;
|
||||
}
|
||||
|
||||
tied_param->u.hash->tmpdata = (void *)dbf;
|
||||
|
||||
return 0;
|
||||
|
@ -98,19 +101,25 @@ bin_zuntie(char *nam, char **args, Options ops, UNUSED(int func))
|
|||
{
|
||||
Param pm;
|
||||
GDBM_FILE dbf;
|
||||
char *pmname;
|
||||
int ret = 0;
|
||||
|
||||
pm = (Param) paramtab->getnode(paramtab, args[0]);
|
||||
if(!pm) {
|
||||
zwarnnam(nam, "cannot untie %s", args[0]);
|
||||
return 1;
|
||||
for (pmname = *args; *args++; pmname = *args) {
|
||||
pm = (Param) paramtab->getnode(paramtab, pmname);
|
||||
if(!pm) {
|
||||
zwarnnam(nam, "cannot untie %s", pmname);
|
||||
ret = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
dbf = (GDBM_FILE)(pm->u.hash->tmpdata);
|
||||
gdbm_close(dbf);
|
||||
/* free(pm->u.hash->tmpdata); */
|
||||
pm->u.hash->tmpdata = NULL;
|
||||
paramtab->removenode(paramtab, pm->node.nam);
|
||||
}
|
||||
|
||||
dbf = (GDBM_FILE)(pm->u.hash->tmpdata);
|
||||
gdbm_close(dbf);
|
||||
/* free(pm->u.hash->tmpdata); */
|
||||
paramtab->removenode(paramtab, pm->node.nam);
|
||||
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**/
|
||||
|
|
Loading…
Reference in a new issue