From: Clint Adams <clint@zsh.org>
To: zsh-workers@sunsite.dk
Subject: PATCH: read-write gdbm elements
Date: Mon, 21 Jul 2008 01:44:12 +0000 [thread overview]
Message-ID: <20080721014412.GA23562@scru.org> (raw)
In-Reply-To: <20080721005152.GA21796@scru.org>
ztie -d db/gdbm -f /tmp/newfile.db hokeypokey
hokeypokey[horse]=buggy
hokeypokey[apple]=pie
print -l -- ${hokeypokey}
print ${hokeypokey[horse]}
print ${hokeypokey[apple]}
diff --git a/Src/Modules/db_gdbm.c b/Src/Modules/db_gdbm.c
index f0915e0..d8f6724 100644
--- a/Src/Modules/db_gdbm.c
+++ b/Src/Modules/db_gdbm.c
@@ -39,7 +39,7 @@
#include <gdbm.h>
-static const struct gsu_hash gdbm_gsu =
+static const struct gsu_scalar gdbm_gsu =
{ gdbmgetfn, gdbmsetfn, gdbmunsetfn };
static struct builtin bintab[] = {
@@ -105,26 +105,47 @@ bin_zuntie(char *nam, char **args, Options ops, UNUSED(int func))
return 0;
}
-
/**/
static char *
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
-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
gdbmunsetfn(Param pm, int um)
{
-return;
+
}
/**/
@@ -143,17 +164,8 @@ getgdbmnode(UNUSED(HashTable ht), const char *name)
pm = (Param) hcalloc(sizeof(struct param));
pm->node.nam = nameu;
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;
}
next prev parent reply other threads:[~2008-07-21 1:44 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-21 0:16 PATCH: gdbm bindings Clint Adams
2008-07-21 0:51 ` Clint Adams
2008-07-21 1:44 ` Clint Adams [this message]
2008-07-21 2:21 ` PATCH: unset/delete gdbm elements Clint Adams
2008-07-21 2:33 ` PATCH: make ${(k)gdbmhash} work Clint Adams
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080721014412.GA23562@scru.org \
--to=clint@zsh.org \
--cc=zsh-workers@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).