/** this file is butt-stupid.  you want to know why it's here?  because
 ** for some reason, i can't get ndbm to work right from C++ ... if i
 ** #include <ndbm.h>, then it incorrectly prototypes the function names,
 ** even if i try to fix that with the  extern "C" ... redeclarations
 ** below.  If i don't do that, it doesn't link right.  So... this works
 ** here, but if anyone can make it work with the built-in ndbm.h, let
 ** me know.   */


#define PBLKSIZ 1024
#define DBLKSIZ 4096

typedef struct {
        char    *dptr;
        int     dsize;
} datum;

typedef struct {
        int     dbm_dirf;               /* open directory file */
        int     dbm_pagf;               /* open page file */
        int     dbm_flags;              /* flags, see below */
        long    dbm_maxbno;             /* last ``bit'' in dir file */
        long    dbm_bitno;              /* current bit number */
        long    dbm_hmask;              /* hash mask */
        long    dbm_blkptr;             /* current block for dbm_nextkey */
        int     dbm_keyptr;             /* current key for dbm_nextkey */
        long    dbm_blkno;              /* current page to read/write */
        long    dbm_pagbno;             /* current page in pagbuf */
        char    dbm_pagbuf[PBLKSIZ];    /* page file block buffer */
        long    dbm_dirbno;             /* current block in dirbuf */
        char    dbm_dirbuf[DBLKSIZ];    /* directory file block buffer */
} DBM;

extern "C" struct DBM*  dbm_open    (char*, int, int);
extern "C" void  dbm_close   (DBM*);
extern "C" datum dbm_fetch   (DBM* db, datum key);
extern "C" int   dbm_store   (DBM* db, datum key, datum content, int flags);
extern "C" int   dbm_delete  (DBM* db, datum key);
extern "C" datum dbm_firstkey(DBM* db);
extern "C" datum dbm_nextkey (DBM* db);

#define DBM_INSERT      0
#define DBM_REPLACE     1