My Project
Loading...
Searching...
No Matches
Data Structures | Functions | Variables
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 276 of file sing_dbm.cc.

Data Fields
DBM * db
int first

Function Documentation

◆ dbClose()

LINKAGE BOOLEAN dbClose ( si_link  l)

Definition at line 319 of file sing_dbm.cc.

320{
321 DBM_info *db = (DBM_info *)l->data;
322
323 dbm_close(db->db);
324 omFreeSize((ADDRESS)db,(sizeof *db));
325 l->data=NULL;
327 return FALSE;
328}
#define FALSE
Definition: auxiliary.h:96
void * ADDRESS
Definition: auxiliary.h:119
int l
Definition: cfEzgcd.cc:100
void dbm_close(DBM *db)
Definition: ndbm.cc:97
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define NULL
Definition: omList.c:12
DBM * db
Definition: sing_dbm.cc:277

◆ dbOpen()

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

Definition at line 282 of file sing_dbm.cc.

283{
284 const char *mode = "r";
285 DBM_info *db;
286 int dbm_flags = O_RDONLY | O_CREAT; // open database readonly as default
287
288 if((l->mode!=NULL)
289 && ((l->mode[0]=='w')||(l->mode[1]=='w')))
290 {
291 dbm_flags = O_RDWR | O_CREAT;
292 mode = "rw";
294 }
295 else if(flag & SI_LINK_WRITE)
296 {
297 // request w- open, but mode is not "w" nor "rw" => fail
298 return TRUE;
299 }
300 //if (((db = (DBM_info *)omAlloc(sizeof *db)) != NULL)
301 //&&((db->db = dbm_open(l->name, dbm_flags, 0664 )) != NULL ))
302 db = (DBM_info *)omAlloc(sizeof *db);
303 if((db->db = dbm_open(l->name, dbm_flags, 0664 )) != NULL )
304 {
305 db->first=1;
306 if(flag & SI_LINK_WRITE)
308 else
310 l->data=(void *)(db);
311 omFreeBinAddr(l->mode);
312 l->mode=omStrDup(mode);
313 return FALSE;
314 }
315 return TRUE;
316}
#define TRUE
Definition: auxiliary.h:100
DBM * dbm_open(char *file, int flags, int mode)
Definition: ndbm.cc:59
#define omStrDup(s)
Definition: omAllocDecl.h:263
#define omAlloc(size)
Definition: omAllocDecl.h:210
#define omFreeBinAddr(addr)
Definition: omAllocDecl.h:258
int first
Definition: sing_dbm.cc:278

◆ dbRead1()

LINKAGE leftv dbRead1 ( si_link  l)

Definition at line 378 of file sing_dbm.cc.

379{
380 return dbRead2(l,NULL);
381}
LINKAGE leftv dbRead2(si_link l, leftv key)
Definition: sing_dbm.cc:332

◆ dbRead2()

LINKAGE leftv dbRead2 ( si_link  l,
leftv  key 
)

Definition at line 332 of file sing_dbm.cc.

333{
334 DBM_info *db = (DBM_info *)l->data;
335 leftv v=NULL;
336 datum d_key;
337
338 if(key!=NULL)
339 {
340 if (key->Typ()==STRING_CMD)
341 {
342 d_key.dptr = (char*)key->Data();
343 d_key.dsize = strlen(d_key.dptr)+1;
344 d_value = dbm_fetch(db->db, d_key);
346 if (d_value.dptr!=NULL) v->data=omStrDup(d_value.dptr);
347 else v->data=omStrDup("");
348 v->rtyp=STRING_CMD;
349 }
350 else
351 {
352 WerrorS("read(`DBM link`,`string`) expected");
353 }
354 }
355 else
356 {
357 if(db->first)
358 d_value = dbm_firstkey((DBM *)db->db);
359 else
360 d_value = dbm_nextkey((DBM *)db->db);
361
363 v->rtyp=STRING_CMD;
364 if (d_value.dptr!=NULL)
365 {
366 v->data=omStrDup(d_value.dptr);
367 db->first = 0;
368 }
369 else
370 {
371 v->data=omStrDup("");
372 db->first = 1;
373 }
374
375 }
376 return v;
377}
Class used for (list of) interpreter objects.
Definition: subexpr.h:83
int Typ()
Definition: subexpr.cc:1019
void * Data()
Definition: subexpr.cc:1162
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:39
void WerrorS(const char *s)
Definition: feFopen.cc:24
EXTERN_VAR omBin sleftv_bin
Definition: ipid.h:145
datum dbm_fetch(DBM *db, datum key)
Definition: ndbm.cc:119
datum dbm_nextkey(DBM *db)
Definition: ndbm.cc:260
datum dbm_firstkey(DBM *db)
Definition: ndbm.cc:252
char * dptr
Definition: ndbm.h:84
Definition: ndbm.h:54
Definition: ndbm.h:83
#define omAlloc0Bin(bin)
Definition: omAllocDecl.h:206
STATIC_VAR datum d_value
Definition: sing_dbm.cc:331
sleftv * leftv
Definition: structs.h:57
@ STRING_CMD
Definition: tok.h:185

◆ dbWrite()

LINKAGE BOOLEAN dbWrite ( si_link  l,
leftv  key 
)

Definition at line 383 of file sing_dbm.cc.

384{
385 DBM_info *db = (DBM_info *)l->data;
386 BOOLEAN b=TRUE;
387 int ret;
388
389 // database is opened
390 if((key!=NULL) && (key->Typ()==STRING_CMD) )
391 {
392 if (key->next!=NULL) // have a second parameter ?
393 {
394 if(key->next->Typ()==STRING_CMD) // replace (key,value)
395 {
396 datum d_key, d_value;
397
398 d_key.dptr = (char *)key->Data();
399 d_key.dsize = strlen(d_key.dptr)+1;
400 d_value.dptr = (char *)key->next->Data();
401 d_value.dsize = strlen(d_value.dptr)+1;
402 ret = dbm_store(db->db, d_key, d_value, DBM_REPLACE);
403 if(!ret )
404 b=FALSE;
405 else
406 {
407 if(dbm_error(db->db))
408 {
409 Werror("DBM link I/O error. Is '%s' readonly?", l->name);
410 dbm_clearerr(db->db);
411 }
412 }
413 }
414 }
415 else
416 { // delete (key)
417 datum d_key;
418
419 d_key.dptr = (char *)key->Data();
420 d_key.dsize = strlen(d_key.dptr)+1;
421 dbm_delete(db->db, d_key);
422 b=FALSE;
423 }
424 }
425 else
426 {
427 WerrorS("write(`DBM link`,`key string` [,`data string`]) expected");
428 }
429 return b;
430}
int BOOLEAN
Definition: auxiliary.h:87
CanonicalForm b
Definition: cfModGcd.cc:4103
leftv next
Definition: subexpr.h:86
int dbm_store(DBM *db, datum key, datum dat, int replace)
Definition: ndbm.cc:167
int dbm_delete(DBM *db, datum key)
Definition: ndbm.cc:139
#define dbm_clearerr(db)
Definition: ndbm.h:77
#define dbm_error(db)
Definition: ndbm.h:75
#define DBM_REPLACE
Definition: ndbm.h:92
int dsize
Definition: ndbm.h:85
void Werror(const char *fmt,...)
Definition: reporter.cc:189

Variable Documentation

◆ d_value

STATIC_VAR datum d_value

Definition at line 331 of file sing_dbm.cc.