;; ;; bsddb.stub - BSD DB interface ;; ;; Copyright(C) 2001 by Shiro Kawai (shiro@acm.org) ;; ;; Permission to use, copy, modify, distribute this software and ;; accompanying documentation for any purpose is hereby granted, ;; provided that existing copyright notices are retained in all ;; copies and that this notice is included verbatim in all ;; distributions. ;; This software is provided as is, without express or implied ;; warranty. In no circumstances the author(s) shall be liable ;; for any damages arising out of the use of this software. ;; ;; $Id: bsddb.stub,v 1.4 2002/12/31 09:36:51 shirok Exp $ ;; " #include \"bsddb.h\" #define TO_DBT(dbt_, scm_) \\ do { \\ dbt_.data = SCM_STRING_START(scm_); \\ dbt_.size = SCM_STRING_SIZE(scm_); \\ } while (0) #define FROM_DBT(scm_, dbt_) \\ do { \\ if (dbt_.data) { \\ scm_ = Scm_MakeString(dbt_.data, dbt_.size, -1, SCM_MAKSTR_COPYING); \\ } else { \\ scm_ = SCM_FALSE; \\ } \\ } while (0) #define CHECK_DB(b) if (!b->db) Scm_Error(\"bsd db already closed: %S\", b) " (define-type "ScmBsdDb*") (define-cproc bsd-db-open (file rwflags:: mode:: type:: &keyword (flags:: 0) (cache-size:: 0) (max-key-page:: 0) (min-key-page:: 0) (page-size:: 0) (compare:: #f) (prefix:: #f) (byte-order:: #f) (bucket-size:: 0) (ffactor:: 0) (num-elements:: 0) (hash:: #f) (record-length:: 0) (bval:: #f) (btree-file-name:: 0)) "void *info = NULL; const char *filename = NULL; DB *db; ScmBsdDb *sdb; ScmClass *klass = NULL; switch (type) { case DB_BTREE: case DB_HASH: case DB_RECNO: case DB_UNKNOWN: default: } if (SCM_STRINGP(file)) filename = Scm_GetStringConst(SCM_STRING(file)); else if (!SCM_FALSEP(file)) Scm_Error(\"string or #f is required for filename, but got %S\", file); db = dbopen(filename, flags, mode, type, info); if (db == NULL) Scm_SysError(\"opening db file %S\", file); switch (db->type) { case DB_BTREE: klass = SCM_CLASS_BSD_BTREE; break; case DB_HASH: klass = SCM_CLASS_BSD_HASH; break; case DB_RECNO: klass = SCM_CLASS_BSD_RECNO; break; default: Scm_Error(\"opened unsupported BSD DB type: %d\", db->type); } sdb = SCM_ALLOCATE(ScmBsdDb*, klass); SCM_SET_CLASS(sdb, klass); sdb->db = db; SCM_RETURN(SCM_OBJ(sdb)); ") (define-cproc bsd-db-close (d::) "CHECK_DB(d); /*if (d->db->close(d->db) == -1) Scm_SysError(\"closing %S\", d);*/ SCM_RETURN(SCM_UNDEFINED);") (define-cproc bsd-db-delete! (d:: key:: &optional (flags:: 0)) "DBT dkey; CHECK_DB(d); TO_DBT(dkey, key); /*if (d->db->del(d->db, &dkey, flags) == -1) Scm_SysError(\"deleteing key %S from %S\", key, d);*/ SCM_RETURN(SCM_UNDEFINED);") (define-cproc bsd-db-fd (d::) "CHECK_DB(d); /*SCM_RETURN(SCM_MAKE_INT(d->db->fd(d->db)));*/") (define-cproc bsd-db-get (d:: key:: &optional (flags:: 0)) "DBT dkey, ddata; ScmObj data; CHECK_DB(d); TO_DBT(dkey, key); /*if (d->db->get(d->db, &dkey, &ddata, flags) == -1) Scm_SysError(\"getting key %S from %S\", key, d);*/ FROM_DBT(data, ddata); SCM_RETURN(data);") ;; Local variables: ;; mode: scheme ;; end: