From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18111 invoked from network); 21 Jul 2008 00:52:05 -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=AWL,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 00:52:05 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 48051 invoked from network); 21 Jul 2008 00:52:01 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 21 Jul 2008 00:52:01 -0000 Received: (qmail 20882 invoked by alias); 21 Jul 2008 00:51:59 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 25319 Received: (qmail 20869 invoked from network); 21 Jul 2008 00:51:58 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 21 Jul 2008 00:51:58 -0000 Received: from cork.scru.org (cork.scru.org [209.20.67.2]) by bifrost.dotsrc.org (Postfix) with ESMTPS id E7FB480561C3 for ; Mon, 21 Jul 2008 02:51:55 +0200 (CEST) Received: by cork.scru.org (Postfix, from userid 1000) id EF70310402E; Mon, 21 Jul 2008 00:51:52 +0000 (UTC) Date: Mon, 21 Jul 2008 00:51:52 +0000 From: Clint Adams To: zsh-workers@sunsite.dk Subject: Re: PATCH: gdbm bindings Message-ID: <20080721005152.GA21796@scru.org> Mail-Followup-To: zsh-workers@sunsite.dk References: <20080721001634.GA20601@scru.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20080721001634.GA20601@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/data.base hokeypokey print -l -- ${hokeypokey} Those option letters could probably be changed to something more sensible too. diff --git a/Src/Modules/db_gdbm.c b/Src/Modules/db_gdbm.c index 33a4712..f0915e0 100644 --- a/Src/Modules/db_gdbm.c +++ b/Src/Modules/db_gdbm.c @@ -43,11 +43,10 @@ static const struct gsu_hash gdbm_gsu = { gdbmgetfn, gdbmsetfn, gdbmunsetfn }; static struct builtin bintab[] = { - BUILTIN("ztie", 0, bin_ztie, 1, -1, 0, "d:", NULL), + BUILTIN("ztie", 0, bin_ztie, 1, -1, 0, "d:f:", NULL), BUILTIN("zuntie", 0, bin_zuntie, 1, -1, 0, NULL, NULL), }; -static char resource_name[] = "/tmp/db_test"; GDBM_FILE dbf = NULL; Param tied_param; @@ -55,25 +54,29 @@ Param tied_param; static int bin_ztie(char *nam, char **args, Options ops, UNUSED(int func)) { + char *resource_name, *pmname; + if(!OPT_ISSET(ops,'d')) { zwarnnam(nam, "you must pass `-d db/gdbm' to ztie", NULL); return 1; } + if(!OPT_ISSET(ops,'f')) { + zwarnnam(nam, "you must pass `-f' with a filename to ztie", NULL); + return 1; + } /* Here should be a lookup of the backend type against * a registry. */ - /* Here should be an assignment of a resource name - * for the backend. - */ - if(dbf) { zwarnnam(nam, "something is already ztied and this implementation is flawed", NULL); return 1; } - char *pmname = ztrdup(*args); + pmname = ztrdup(*args); + + resource_name = OPT_ARG(ops, 'f'); if (!(tied_param = createspecialhash(pmname, &getgdbmnode, &scangdbmkeys, PM_SPECIAL | PM_HASHED))) { zwarnnam(nam, "cannot create the requested parameter name", NULL); @@ -82,7 +85,7 @@ bin_ztie(char *nam, char **args, Options ops, UNUSED(int func)) dbf = gdbm_open(resource_name, 0, GDBM_WRCREAT | GDBM_SYNC, 0666, 0); if(!dbf) { - zwarnnam(nam, "error opening database file", NULL); + zwarnnam(nam, "error opening database file %s", resource_name); return 1; } @@ -93,10 +96,11 @@ bin_ztie(char *nam, char **args, Options ops, UNUSED(int func)) static int bin_zuntie(char *nam, char **args, Options ops, UNUSED(int func)) { - /* should untie the argument */ - paramtab->removenode(paramtab, tied_param->node.nam); + free(tied_param); + tied_param = NULL; gdbm_close(dbf); + dbf = NULL; return 0; }