mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-26 18:01:03 +02:00
25490: make zties dynamic so there can be more than one gdbm handle in use at a time.
This commit is contained in:
parent
cdd9f7751c
commit
0d07bf44e7
3 changed files with 37 additions and 17 deletions
|
@ -1,5 +1,8 @@
|
||||||
2008-08-19 Clint Adams <clint@zsh.org>
|
2008-08-19 Clint Adams <clint@zsh.org>
|
||||||
|
|
||||||
|
* 25490: Src/zsh.h, Src/Modules/db_gdbm.c: make zties dynamic so
|
||||||
|
there can be more than one gdbm handle in use at a time.
|
||||||
|
|
||||||
* 25489: Completion/Unix/Command/_git: remove cruft for "git
|
* 25489: Completion/Unix/Command/_git: remove cruft for "git
|
||||||
octopus/octupus".
|
octopus/octupus".
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,8 @@
|
||||||
|
|
||||||
#include <gdbm.h>
|
#include <gdbm.h>
|
||||||
|
|
||||||
|
static char *backtype = "db/gdbm";
|
||||||
|
|
||||||
static const struct gsu_scalar gdbm_gsu =
|
static const struct gsu_scalar gdbm_gsu =
|
||||||
{ gdbmgetfn, gdbmsetfn, gdbmunsetfn };
|
{ gdbmgetfn, gdbmsetfn, gdbmunsetfn };
|
||||||
|
|
||||||
|
@ -47,14 +49,13 @@ static struct builtin bintab[] = {
|
||||||
BUILTIN("zuntie", 0, bin_zuntie, 1, -1, 0, NULL, NULL),
|
BUILTIN("zuntie", 0, bin_zuntie, 1, -1, 0, NULL, NULL),
|
||||||
};
|
};
|
||||||
|
|
||||||
GDBM_FILE dbf = NULL;
|
|
||||||
Param tied_param;
|
|
||||||
|
|
||||||
/**/
|
/**/
|
||||||
static int
|
static int
|
||||||
bin_ztie(char *nam, char **args, Options ops, UNUSED(int func))
|
bin_ztie(char *nam, char **args, Options ops, UNUSED(int func))
|
||||||
{
|
{
|
||||||
char *resource_name, *pmname;
|
char *resource_name, *pmname;
|
||||||
|
GDBM_FILE dbf = NULL;
|
||||||
|
Param tied_param;
|
||||||
|
|
||||||
if(!OPT_ISSET(ops,'d')) {
|
if(!OPT_ISSET(ops,'d')) {
|
||||||
zwarnnam(nam, "you must pass `-d db/gdbm' to ztie", NULL);
|
zwarnnam(nam, "you must pass `-d db/gdbm' to ztie", NULL);
|
||||||
|
@ -69,16 +70,11 @@ bin_ztie(char *nam, char **args, Options ops, UNUSED(int func))
|
||||||
* a registry.
|
* a registry.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if(dbf) {
|
|
||||||
zwarnnam(nam, "something is already ztied and this implementation is flawed", NULL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
pmname = ztrdup(*args);
|
pmname = ztrdup(*args);
|
||||||
|
|
||||||
resource_name = OPT_ARG(ops, 'f');
|
resource_name = OPT_ARG(ops, 'f');
|
||||||
|
|
||||||
if (!(tied_param = createspecialhash(pmname, &getgdbmnode, &scangdbmkeys, PM_SPECIAL | PM_HASHED))) {
|
if (!(tied_param = createspecialhash(pmname, &getgdbmnode, &scangdbmkeys, 0))) {
|
||||||
zwarnnam(nam, "cannot create the requested parameter name", NULL);
|
zwarnnam(nam, "cannot create the requested parameter name", NULL);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -89,6 +85,8 @@ bin_ztie(char *nam, char **args, Options ops, UNUSED(int func))
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tied_param->u.hash->tmpdata = (void *)dbf;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,11 +94,19 @@ bin_ztie(char *nam, char **args, Options ops, UNUSED(int func))
|
||||||
static int
|
static int
|
||||||
bin_zuntie(char *nam, char **args, Options ops, UNUSED(int func))
|
bin_zuntie(char *nam, char **args, Options ops, UNUSED(int func))
|
||||||
{
|
{
|
||||||
paramtab->removenode(paramtab, tied_param->node.nam);
|
Param pm;
|
||||||
free(tied_param);
|
GDBM_FILE dbf;
|
||||||
tied_param = NULL;
|
|
||||||
|
pm = (Param) paramtab->getnode(paramtab, args[0]);
|
||||||
|
if(!pm) {
|
||||||
|
zwarnnam(nam, "cannot untie %s", args[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
dbf = (GDBM_FILE)(pm->u.hash->tmpdata);
|
||||||
gdbm_close(dbf);
|
gdbm_close(dbf);
|
||||||
dbf = NULL;
|
/* free(pm->u.hash->tmpdata); */
|
||||||
|
paramtab->removenode(paramtab, pm->node.nam);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -111,10 +117,12 @@ gdbmgetfn(Param pm)
|
||||||
{
|
{
|
||||||
datum key, content;
|
datum key, content;
|
||||||
int ret;
|
int ret;
|
||||||
|
GDBM_FILE dbf;
|
||||||
|
|
||||||
key.dptr = pm->node.nam;
|
key.dptr = pm->node.nam;
|
||||||
key.dsize = strlen(key.dptr) + 1;
|
key.dsize = strlen(key.dptr) + 1;
|
||||||
|
|
||||||
|
dbf = (GDBM_FILE)(pm->u.hash->tmpdata);
|
||||||
ret = gdbm_exists(dbf, key);
|
ret = gdbm_exists(dbf, key);
|
||||||
if(ret) {
|
if(ret) {
|
||||||
content = gdbm_fetch(dbf, key);
|
content = gdbm_fetch(dbf, key);
|
||||||
|
@ -131,12 +139,14 @@ gdbmsetfn(Param pm, char **val)
|
||||||
{
|
{
|
||||||
datum key, content;
|
datum key, content;
|
||||||
int ret;
|
int ret;
|
||||||
|
GDBM_FILE dbf;
|
||||||
|
|
||||||
key.dptr = pm->node.nam;
|
key.dptr = pm->node.nam;
|
||||||
key.dsize = strlen(key.dptr) + 1;
|
key.dsize = strlen(key.dptr) + 1;
|
||||||
content.dptr = val;
|
content.dptr = val;
|
||||||
content.dsize = strlen(content.dptr) + 1;
|
content.dsize = strlen(content.dptr) + 1;
|
||||||
|
|
||||||
|
dbf = (GDBM_FILE)(pm->u.hash->tmpdata);
|
||||||
ret = gdbm_store(dbf, key, content, GDBM_REPLACE);
|
ret = gdbm_store(dbf, key, content, GDBM_REPLACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,20 +156,22 @@ gdbmunsetfn(Param pm, int um)
|
||||||
{
|
{
|
||||||
datum key;
|
datum key;
|
||||||
int ret;
|
int ret;
|
||||||
|
GDBM_FILE dbf;
|
||||||
|
|
||||||
key.dptr = pm->node.nam;
|
key.dptr = pm->node.nam;
|
||||||
key.dsize = strlen(key.dptr) + 1;
|
key.dsize = strlen(key.dptr) + 1;
|
||||||
|
|
||||||
|
dbf = (GDBM_FILE)(pm->u.hash->tmpdata);
|
||||||
ret = gdbm_delete(dbf, key);
|
ret = gdbm_delete(dbf, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**/
|
/**/
|
||||||
static HashNode
|
static HashNode
|
||||||
getgdbmnode(UNUSED(HashTable ht), const char *name)
|
getgdbmnode(HashTable ht, const char *name)
|
||||||
{
|
{
|
||||||
int len, ret;
|
int len;
|
||||||
char *nameu;
|
char *nameu;
|
||||||
datum content, key;
|
datum key;
|
||||||
Param pm = NULL;
|
Param pm = NULL;
|
||||||
|
|
||||||
nameu = dupstring(name);
|
nameu = dupstring(name);
|
||||||
|
@ -170,16 +182,20 @@ getgdbmnode(UNUSED(HashTable ht), const char *name)
|
||||||
pm->node.nam = nameu;
|
pm->node.nam = nameu;
|
||||||
pm->node.flags = PM_SCALAR;
|
pm->node.flags = PM_SCALAR;
|
||||||
pm->gsu.s = &gdbm_gsu;
|
pm->gsu.s = &gdbm_gsu;
|
||||||
|
pm->u.hash = ht;
|
||||||
|
|
||||||
return &pm->node;
|
return &pm->node;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**/
|
/**/
|
||||||
static void
|
static void
|
||||||
scangdbmkeys(UNUSED(HashTable ht), ScanFunc func, int flags)
|
scangdbmkeys(HashTable ht, ScanFunc func, int flags)
|
||||||
{
|
{
|
||||||
Param pm = NULL;
|
Param pm = NULL;
|
||||||
datum key, content;
|
datum key, content;
|
||||||
|
GDBM_FILE dbf;
|
||||||
|
|
||||||
|
dbf = (GDBM_FILE)(ht->tmpdata);
|
||||||
|
|
||||||
pm = (Param) hcalloc(sizeof(struct param));
|
pm = (Param) hcalloc(sizeof(struct param));
|
||||||
|
|
||||||
|
|
|
@ -979,6 +979,7 @@ struct hashtable {
|
||||||
int hsize; /* size of nodes[] (number of hash values) */
|
int hsize; /* size of nodes[] (number of hash values) */
|
||||||
int ct; /* number of elements */
|
int ct; /* number of elements */
|
||||||
HashNode *nodes; /* array of size hsize */
|
HashNode *nodes; /* array of size hsize */
|
||||||
|
void *tmpdata;
|
||||||
|
|
||||||
/* HASHTABLE METHODS */
|
/* HASHTABLE METHODS */
|
||||||
HashFunc hash; /* pointer to hash function for this table */
|
HashFunc hash; /* pointer to hash function for this table */
|
||||||
|
|
Loading…
Reference in a new issue