mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-10-24 04:50:27 +02:00
25320: fix read and write of elements by key.
This commit is contained in:
parent
9f42d3211e
commit
fdf4449338
2 changed files with 31 additions and 16 deletions
|
|
@ -1,5 +1,8 @@
|
||||||
2008-07-21 Clint Adams <clint@zsh.org>
|
2008-07-21 Clint Adams <clint@zsh.org>
|
||||||
|
|
||||||
|
* 25320: Src/Modules/db_gdbm.c: fix read and write of elements
|
||||||
|
by key.
|
||||||
|
|
||||||
* 25319: Src/Modules/db_gdbm.c: fix zuntie, add -f option
|
* 25319: Src/Modules/db_gdbm.c: fix zuntie, add -f option
|
||||||
to ztie.
|
to ztie.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@
|
||||||
|
|
||||||
#include <gdbm.h>
|
#include <gdbm.h>
|
||||||
|
|
||||||
static const struct gsu_hash gdbm_gsu =
|
static const struct gsu_scalar gdbm_gsu =
|
||||||
{ gdbmgetfn, gdbmsetfn, gdbmunsetfn };
|
{ gdbmgetfn, gdbmsetfn, gdbmunsetfn };
|
||||||
|
|
||||||
static struct builtin bintab[] = {
|
static struct builtin bintab[] = {
|
||||||
|
|
@ -105,26 +105,47 @@ bin_zuntie(char *nam, char **args, Options ops, UNUSED(int func))
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**/
|
/**/
|
||||||
static char *
|
static char *
|
||||||
gdbmgetfn(Param pm)
|
gdbmgetfn(Param pm)
|
||||||
{
|
{
|
||||||
return;
|
datum key, content;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
key.dptr = pm->node.nam;
|
||||||
|
key.dsize = strlen(key.dptr) + 1;
|
||||||
|
|
||||||
|
ret = gdbm_exists(dbf, key);
|
||||||
|
if(ret) {
|
||||||
|
content = gdbm_fetch(dbf, key);
|
||||||
|
} else {
|
||||||
|
content.dptr = dupstring("");
|
||||||
|
}
|
||||||
|
|
||||||
|
return content.dptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**/
|
/**/
|
||||||
static void
|
static void
|
||||||
gdbmsetfn(Param pm, char **key)
|
gdbmsetfn(Param pm, char **val)
|
||||||
{
|
{
|
||||||
return;
|
datum key, content;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
|
||||||
|
key.dptr = pm->node.nam;
|
||||||
|
key.dsize = strlen(key.dptr) + 1;
|
||||||
|
content.dptr = val;
|
||||||
|
content.dsize = strlen(content.dptr) + 1;
|
||||||
|
|
||||||
|
ret = gdbm_store(dbf, key, content, GDBM_REPLACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**/
|
/**/
|
||||||
static void
|
static void
|
||||||
gdbmunsetfn(Param pm, int um)
|
gdbmunsetfn(Param pm, int um)
|
||||||
{
|
{
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**/
|
/**/
|
||||||
|
|
@ -143,17 +164,8 @@ getgdbmnode(UNUSED(HashTable ht), const char *name)
|
||||||
pm = (Param) hcalloc(sizeof(struct param));
|
pm = (Param) hcalloc(sizeof(struct param));
|
||||||
pm->node.nam = nameu;
|
pm->node.nam = nameu;
|
||||||
pm->node.flags = PM_SCALAR;
|
pm->node.flags = PM_SCALAR;
|
||||||
|
pm->gsu.s = &gdbm_gsu;
|
||||||
|
|
||||||
ret = gdbm_exists(dbf, key);
|
|
||||||
if(!ret) {
|
|
||||||
pm->u.str = dupstring("");
|
|
||||||
pm->node.flags |= PM_UNSET;
|
|
||||||
} else {
|
|
||||||
content = gdbm_fetch(dbf, key);
|
|
||||||
|
|
||||||
pm->u.str = content.dptr;
|
|
||||||
pm->gsu.s = &nullsetscalar_gsu;
|
|
||||||
}
|
|
||||||
return &pm->node;
|
return &pm->node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue