zsh-workers
 help / color / mirror / code / Atom feed
From: Clint Adams <clint@zsh.org>
To: zsh-workers@sunsite.dk
Subject: Re: PATCH: gdbm bindings
Date: Mon, 21 Jul 2008 00:51:52 +0000	[thread overview]
Message-ID: <20080721005152.GA21796@scru.org> (raw)
In-Reply-To: <20080721001634.GA20601@scru.org>

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;
 }


  reply	other threads:[~2008-07-21  0:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-21  0:16 Clint Adams
2008-07-21  0:51 ` Clint Adams [this message]
2008-07-21  1:44   ` PATCH: read-write gdbm elements Clint Adams
2008-07-21  2:21     ` PATCH: unset/delete " 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=20080721005152.GA21796@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).