Loading...
Searching...
No Matches
sing_dbm.cc File Reference
`#include "kernel/mod2.h"`
`#include <fcntl.h>`
`#include "Singular/tok.h"`
`#include "Singular/ipid.h"`
`#include "Singular/links/silink.h"`
`#include "Singular/links/sing_dbm.h"`
`#include "ndbm.h"`

Go to the source code of this file.

## Data Structures

struct | DBM_info

## Functions

LINKAGE BOOLEAN | dbOpen (si_link l, short flag, leftv)
LINKAGE BOOLEAN | dbClose (si_link l)
LINKAGE leftv | dbRead2 (si_link l, leftv key)
LINKAGE leftv | dbRead1 (si_link l)
LINKAGE BOOLEAN | dbWrite (si_link l, leftv key)

## Variables

STATIC_VAR datum | d_value

## Data Structure Documentation

## DBM_info

struct DBM_info

Definition at line 277 of file sing_dbm.cc.

Data Fields
DBM * | db |
int | first |

## Function Documentation

## dbClose()

LINKAGE BOOLEAN dbClose | ( | si_link | l | ) |

Definition at line 320 of file sing_dbm.cc.

{
DBM_info *db = (DBM_info *)l->data;
dbm_close(db->db);
omFreeSize((ADDRESS)db,(sizeof *db));
l->data=NULL;
SI_LINK_SET_CLOSE_P(l);
return FALSE;
}
FALSE
#define FALSE
Definition auxiliary.h:97
ADDRESS
void * ADDRESS
Definition auxiliary.h:120
l
int l
Definition cfEzgcd.cc:100
dbm_close
void dbm_close(DBM *db)
Definition ndbm.cc:97
omFreeSize
#define omFreeSize(addr, size)
Definition omAllocDecl.h:260
NULL
#define NULL
Definition omList.c:12
SI_LINK_SET_CLOSE_P
#define SI_LINK_SET_CLOSE_P(l)
Definition silink.h:76
DBM_info
Definition sing_dbm.cc:277

## dbOpen()

LINKAGE BOOLEAN dbOpen | ( | si_link | l,
|  | short | flag,
|  | leftv | u )

Definition at line 283 of file sing_dbm.cc.

{
const char *mode = "r";
DBM_info *db;
int dbm_flags = O_RDONLY | O_CREAT; // open database readonly as default
if((l->mode!=NULL)
&& ((l->mode[0]=='w')||(l->mode[1]=='w')))
{
dbm_flags = O_RDWR | O_CREAT;
mode = "rw";
flag|=SI_LINK_WRITE|SI_LINK_READ;
}
else if(flag & SI_LINK_WRITE)
{
// request w- open, but mode is not "w" nor "rw" => fail
return TRUE;
}
//if (((db = (DBM_info *)omAlloc(sizeof *db)) != NULL)
//&&((db->db = dbm_open(l->name, dbm_flags, 0664 )) != NULL ))
db = (DBM_info *)omAlloc(sizeof *db);
if((db->db = dbm_open(l->name, dbm_flags, 0664 )) != NULL )
{
db->first=1;
if(flag & SI_LINK_WRITE)
SI_LINK_SET_RW_OPEN_P(l);
else
SI_LINK_SET_R_OPEN_P(l);
l->data=(void *)(db);
omFreeBinAddr(l->mode);
l->mode=omStrDup(mode);
return FALSE;
}
return TRUE;
}
TRUE
#define TRUE
Definition auxiliary.h:101
dbm_open
DBM * dbm_open(char *file, int flags, int mode)
Definition ndbm.cc:59
omStrDup
#define omStrDup(s)
Definition omAllocDecl.h:263
omAlloc
#define omAlloc(size)
Definition omAllocDecl.h:210
omFreeBinAddr
#define omFreeBinAddr(addr)
Definition omAllocDecl.h:258
SI_LINK_WRITE
#define SI_LINK_WRITE
Definition silink.h:67
SI_LINK_SET_R_OPEN_P
#define SI_LINK_SET_R_OPEN_P(l)
Definition silink.h:79
SI_LINK_SET_RW_OPEN_P
#define SI_LINK_SET_RW_OPEN_P(l)
Definition silink.h:80
SI_LINK_READ
#define SI_LINK_READ
Definition silink.h:66
DBM_info::first
int first
Definition sing_dbm.cc:279
DBM_info::db
DBM * db
Definition sing_dbm.cc:278

## dbRead1()

LINKAGE leftv dbRead1 | ( | si_link | l | ) |

Definition at line 379 of file sing_dbm.cc.

{
return dbRead2(l,NULL);
}
dbRead2
LINKAGE leftv dbRead2(si_link l, leftv key)
Definition sing_dbm.cc:333

## dbRead2()

LINKAGE leftv dbRead2 | ( | si_link | l,
|  | leftv | key )

Definition at line 333 of file sing_dbm.cc.

{
DBM_info *db = (DBM_info *)l->data;
leftv v=NULL;
datum d_key;
if(key!=NULL)
{
if (key->Typ()==STRING_CMD)
{
d_key.dptr = (char*)key->Data();
d_key.dsize = strlen(d_key.dptr)+1;
d_value = dbm_fetch(db->db, d_key);
v=(leftv)omAlloc0Bin(sleftv_bin);
if (d_value.dptr!=NULL) v->data=omStrDup(d_value.dptr);
else v->data=omStrDup("");
v->rtyp=STRING_CMD;
}
else
{
WerrorS("read(`DBM link`,`string`) expected");
}
}
else
{
if(db->first)
d_value = dbm_firstkey((DBM *)db->db);
else
d_value = dbm_nextkey((DBM *)db->db);
v=(leftv)omAlloc0Bin(sleftv_bin);
v->rtyp=STRING_CMD;
if (d_value.dptr!=NULL)
{
v->data=omStrDup(d_value.dptr);
db->first = 0;
}
else
{
v->data=omStrDup("");
db->first = 1;
}
}
return v;
}
sleftv::Typ
int Typ()
Definition subexpr.cc:1048
sleftv::Data
void * Data()
Definition subexpr.cc:1192
v
const Variable & v
< [in] a sqrfree bivariate poly
Definition facBivar.h:39
WerrorS
void WerrorS(const char *s)
Definition feFopen.cc:24
sleftv_bin
EXTERN_VAR omBin sleftv_bin
Definition ipid.h:145
dbm_fetch
datum dbm_fetch(DBM *db, datum key)
Definition ndbm.cc:119
dbm_nextkey
datum dbm_nextkey(DBM *db)
Definition ndbm.cc:260
dbm_firstkey
datum dbm_firstkey(DBM *db)
Definition ndbm.cc:252
datum::dptr
char * dptr
Definition ndbm.h:84
datum::dsize
int dsize
Definition ndbm.h:85
DBM
Definition ndbm.h:54
datum
Definition ndbm.h:83
omAlloc0Bin
#define omAlloc0Bin(bin)
Definition omAllocDecl.h:206
d_value
STATIC_VAR datum d_value
Definition sing_dbm.cc:332
leftv
sleftv * leftv
Definition structs.h:53
STRING_CMD
@ STRING_CMD
Definition tok.h:187

## dbWrite()

LINKAGE BOOLEAN dbWrite | ( | si_link | l,
|  | leftv | key )

Definition at line 384 of file sing_dbm.cc.

{
DBM_info *db = (DBM_info *)l->data;
BOOLEAN b=TRUE;
int ret;
// database is opened
if((key!=NULL) && (key->Typ()==STRING_CMD) )
{
if (key->next!=NULL) // have a second parameter ?
{
if(key->next->Typ()==STRING_CMD) // replace (key,value)
{
datum d_key, d_value;
d_key.dptr = (char *)key->Data();
d_key.dsize = strlen(d_key.dptr)+1;
d_value.dptr = (char *)key->next->Data();
d_value.dsize = strlen(d_value.dptr)+1;
ret = dbm_store(db->db, d_key, d_value, DBM_REPLACE);
if(!ret )
b=FALSE;
else
{
if(dbm_error(db->db))
{
Werror("DBM link I/O error. Is '%s' readonly?", l->name);
dbm_clearerr(db->db);
}
}
}
}
else
{ // delete (key)
datum d_key;
d_key.dptr = (char *)key->Data();
d_key.dsize = strlen(d_key.dptr)+1;
dbm_delete(db->db, d_key);
b=FALSE;
}
}
else
{
WerrorS("write(`DBM link`,`key string` [,`data string`]) expected");
}
return b;
}
BOOLEAN
int BOOLEAN
Definition auxiliary.h:88
b
CanonicalForm b
Definition cfModGcd.cc:4111
sleftv::next
leftv next
Definition subexpr.h:86
dbm_store
int dbm_store(DBM *db, datum key, datum dat, int replace)
Definition ndbm.cc:167
dbm_delete
int dbm_delete(DBM *db, datum key)
Definition ndbm.cc:139
dbm_clearerr
#define dbm_clearerr(db)
Definition ndbm.h:77
dbm_error
#define dbm_error(db)
Definition ndbm.h:75
DBM_REPLACE
#define DBM_REPLACE
Definition ndbm.h:92
Werror
void Werror(const char *fmt,...)
Definition reporter.cc:189

## Variable Documentation

## d_value

STATIC_VAR datum d_value

Definition at line 332 of file sing_dbm.cc.