From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22399 invoked from network); 21 Jul 2008 01:44:28 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00 autolearn=ham version=3.2.5 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 21 Jul 2008 01:44:28 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 69255 invoked from network); 21 Jul 2008 01:44:23 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 21 Jul 2008 01:44:23 -0000 Received: (qmail 15965 invoked by alias); 21 Jul 2008 01:44:20 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 25320 Received: (qmail 15953 invoked from network); 21 Jul 2008 01:44:20 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 21 Jul 2008 01:44:20 -0000 Received: from cork.scru.org (cork.scru.org [209.20.67.2]) by bifrost.dotsrc.org (Postfix) with ESMTPS id A835080561C3 for ; Mon, 21 Jul 2008 03:44:14 +0200 (CEST) Received: by cork.scru.org (Postfix, from userid 1000) id BE16B10402D; Mon, 21 Jul 2008 01:44:12 +0000 (UTC) Date: Mon, 21 Jul 2008 01:44:12 +0000 From: Clint Adams To: zsh-workers@sunsite.dk Subject: PATCH: read-write gdbm elements Message-ID: <20080721014412.GA23562@scru.org> Mail-Followup-To: zsh-workers@sunsite.dk References: <20080721001634.GA20601@scru.org> <20080721005152.GA21796@scru.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20080721005152.GA21796@scru.org> User-Agent: Mutt/1.5.18 (2008-05-17) X-Virus-Scanned: ClamAV 0.92.1/7764/Sun Jul 20 18:42:45 2008 on bifrost X-Virus-Status: Clean 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 -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; }