Mercurial > hg > xemacs-beta
annotate src/database.c @ 5866:5ea790936de9
Automated merge with file:///Sources/xemacs-21.5-checked-out
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Mon, 16 Mar 2015 00:11:30 +0000 |
parents | 5d5aeb79edb4 |
children |
rev | line source |
---|---|
428 | 1 /* Database access routines |
2 Copyright (C) 1996, William M. Perry | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5125
diff
changeset
|
3 Copyright (C) 2001, 2002, 2005, 2010 Ben Wing. |
428 | 4 |
5 This file is part of XEmacs. | |
6 | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5146
diff
changeset
|
7 XEmacs is free software: you can redistribute it and/or modify it |
428 | 8 under the terms of the GNU General Public License as published by the |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5146
diff
changeset
|
9 Free Software Foundation, either version 3 of the License, or (at your |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5146
diff
changeset
|
10 option) any later version. |
428 | 11 |
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5146
diff
changeset
|
18 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */ |
428 | 19 |
20 /* Synched up with: Not in FSF. */ | |
21 | |
22 /* Written by Bill Perry */ | |
23 /* Substantially rewritten by Martin Buchholz */ | |
24 /* db 2.x support added by Andreas Jaeger */ | |
771 | 25 /* Mule-ized 6-22-00 Ben Wing */ |
428 | 26 |
27 #include <config.h> | |
28 #include "lisp.h" | |
771 | 29 |
428 | 30 #include "sysfile.h" |
31 #include "buffer.h" | |
4351
bc3b9f61018e
Respect the CODESYS argument in #'open-database; don't autodetect EOL.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4124
diff
changeset
|
32 #include "file-coding.h" |
428 | 33 |
34 #ifndef HAVE_DATABASE | |
35 #error HAVE_DATABASE not defined!! | |
36 #endif | |
37 | |
38 #include "database.h" /* Our include file */ | |
39 | |
40 #ifdef HAVE_BERKELEY_DB | |
41 /* Work around Berkeley DB's use of int types which are defined | |
42 slightly differently in the not quite yet standard <inttypes.h>. | |
43 See db.h for details of why we're resorting to this... */ | |
44 /* glibc 2.1 doesn't have this problem with DB 2.x */ | |
45 #if !(defined __GLIBC__ && __GLIBC_MINOR__ >= 1) | |
46 #ifdef HAVE_INTTYPES_H | |
3739 | 47 #ifndef __BIT_TYPES_DEFINED__ |
428 | 48 #define __BIT_TYPES_DEFINED__ |
3739 | 49 #endif |
428 | 50 #include <inttypes.h> |
3739 | 51 #if !HAVE_U_INT8_T |
428 | 52 typedef uint8_t u_int8_t; |
3739 | 53 #endif |
54 #if !HAVE_U_INT16_T | |
428 | 55 typedef uint16_t u_int16_t; |
3739 | 56 #endif |
57 #if !HAVE_U_INT32_T | |
428 | 58 typedef uint32_t u_int32_t; |
3739 | 59 #endif |
428 | 60 #ifdef WE_DONT_NEED_QUADS |
3739 | 61 #if !HAVE_U_INT64_T |
428 | 62 typedef uint64_t u_int64_t; |
3739 | 63 #endif |
428 | 64 #endif /* WE_DONT_NEED_QUADS */ |
65 #endif /* HAVE_INTTYPES_H */ | |
66 #endif /* !(defined __GLIBC__ && __GLIBC_MINOR__ >= 1) */ | |
1460 | 67 /* Berkeley DB wants __STDC__ to be defined; else if does `#define const' */ |
68 #if ! defined (__STDC__) && ! defined(__cplusplus) | |
69 #define __STDC__ 0 | |
70 #endif | |
442 | 71 #include DB_H_FILE /* Berkeley db's header file */ |
428 | 72 #ifndef DB_VERSION_MAJOR |
73 # define DB_VERSION_MAJOR 1 | |
74 #endif /* DB_VERSION_MAJOR */ | |
1141 | 75 #ifndef DB_VERSION_MINOR |
76 # define DB_VERSION_MINOR 0 | |
77 #endif /* DB_VERSION_MINOR */ | |
428 | 78 Lisp_Object Qberkeley_db; |
79 Lisp_Object Qhash, Qbtree, Qrecno, Qunknown; | |
448 | 80 #if DB_VERSION_MAJOR > 2 |
81 Lisp_Object Qqueue; | |
82 #endif | |
428 | 83 #endif /* HAVE_BERKELEY_DB */ |
84 | |
85 #ifdef HAVE_DBM | |
5825 | 86 BEGIN_C_DECLS |
4991
97c45e3ad810
implement configure test for whether ndbm.h prototypes are broken
Ben Wing <ben@xemacs.org>
parents:
4981
diff
changeset
|
87 # ifdef TRUST_NDBM_H_PROTOTYPES |
97c45e3ad810
implement configure test for whether ndbm.h prototypes are broken
Ben Wing <ben@xemacs.org>
parents:
4981
diff
changeset
|
88 # include NDBM_H_FILE |
97c45e3ad810
implement configure test for whether ndbm.h prototypes are broken
Ben Wing <ben@xemacs.org>
parents:
4981
diff
changeset
|
89 # else /* not TRUST_NDBM_H_PROTOTYPES */ |
97c45e3ad810
implement configure test for whether ndbm.h prototypes are broken
Ben Wing <ben@xemacs.org>
parents:
4981
diff
changeset
|
90 |
97c45e3ad810
implement configure test for whether ndbm.h prototypes are broken
Ben Wing <ben@xemacs.org>
parents:
4981
diff
changeset
|
91 /* The prototypes in gdbm/ndbm.h currently are broken when compiling |
97c45e3ad810
implement configure test for whether ndbm.h prototypes are broken
Ben Wing <ben@xemacs.org>
parents:
4981
diff
changeset
|
92 using C++, since they are of the form `datum dbm_firstkey()', without any |
97c45e3ad810
implement configure test for whether ndbm.h prototypes are broken
Ben Wing <ben@xemacs.org>
parents:
4981
diff
changeset
|
93 args given. */ |
4824
c12b646d84ee
changes to get things to compile under latest cygwin
Ben Wing <ben@xemacs.org>
parents:
4699
diff
changeset
|
94 |
c12b646d84ee
changes to get things to compile under latest cygwin
Ben Wing <ben@xemacs.org>
parents:
4699
diff
changeset
|
95 /* Parameters to dbm_store for simple insertion or replacement. */ |
c12b646d84ee
changes to get things to compile under latest cygwin
Ben Wing <ben@xemacs.org>
parents:
4699
diff
changeset
|
96 #define DBM_INSERT 0 |
c12b646d84ee
changes to get things to compile under latest cygwin
Ben Wing <ben@xemacs.org>
parents:
4699
diff
changeset
|
97 #define DBM_REPLACE 1 |
c12b646d84ee
changes to get things to compile under latest cygwin
Ben Wing <ben@xemacs.org>
parents:
4699
diff
changeset
|
98 |
c12b646d84ee
changes to get things to compile under latest cygwin
Ben Wing <ben@xemacs.org>
parents:
4699
diff
changeset
|
99 /* The data and key structure. This structure is defined for compatibility. */ |
4991
97c45e3ad810
implement configure test for whether ndbm.h prototypes are broken
Ben Wing <ben@xemacs.org>
parents:
4981
diff
changeset
|
100 typedef struct |
97c45e3ad810
implement configure test for whether ndbm.h prototypes are broken
Ben Wing <ben@xemacs.org>
parents:
4981
diff
changeset
|
101 { |
97c45e3ad810
implement configure test for whether ndbm.h prototypes are broken
Ben Wing <ben@xemacs.org>
parents:
4981
diff
changeset
|
102 char *dptr; |
97c45e3ad810
implement configure test for whether ndbm.h prototypes are broken
Ben Wing <ben@xemacs.org>
parents:
4981
diff
changeset
|
103 int dsize; |
97c45e3ad810
implement configure test for whether ndbm.h prototypes are broken
Ben Wing <ben@xemacs.org>
parents:
4981
diff
changeset
|
104 } datum; |
4824
c12b646d84ee
changes to get things to compile under latest cygwin
Ben Wing <ben@xemacs.org>
parents:
4699
diff
changeset
|
105 |
c12b646d84ee
changes to get things to compile under latest cygwin
Ben Wing <ben@xemacs.org>
parents:
4699
diff
changeset
|
106 /* The file information header. This is good enough for most applications. */ |
c12b646d84ee
changes to get things to compile under latest cygwin
Ben Wing <ben@xemacs.org>
parents:
4699
diff
changeset
|
107 typedef struct {int dummy[10];} DBM; |
c12b646d84ee
changes to get things to compile under latest cygwin
Ben Wing <ben@xemacs.org>
parents:
4699
diff
changeset
|
108 |
c12b646d84ee
changes to get things to compile under latest cygwin
Ben Wing <ben@xemacs.org>
parents:
4699
diff
changeset
|
109 int dbm_clearerr(DBM *); |
c12b646d84ee
changes to get things to compile under latest cygwin
Ben Wing <ben@xemacs.org>
parents:
4699
diff
changeset
|
110 void dbm_close(DBM *); |
c12b646d84ee
changes to get things to compile under latest cygwin
Ben Wing <ben@xemacs.org>
parents:
4699
diff
changeset
|
111 int dbm_delete(DBM *, datum); |
c12b646d84ee
changes to get things to compile under latest cygwin
Ben Wing <ben@xemacs.org>
parents:
4699
diff
changeset
|
112 int dbm_error(DBM *); |
c12b646d84ee
changes to get things to compile under latest cygwin
Ben Wing <ben@xemacs.org>
parents:
4699
diff
changeset
|
113 datum dbm_fetch(DBM *, datum); |
c12b646d84ee
changes to get things to compile under latest cygwin
Ben Wing <ben@xemacs.org>
parents:
4699
diff
changeset
|
114 datum dbm_firstkey(DBM *); |
c12b646d84ee
changes to get things to compile under latest cygwin
Ben Wing <ben@xemacs.org>
parents:
4699
diff
changeset
|
115 datum dbm_nextkey(DBM *); |
c12b646d84ee
changes to get things to compile under latest cygwin
Ben Wing <ben@xemacs.org>
parents:
4699
diff
changeset
|
116 DBM *dbm_open(const char *, int, mode_t); |
c12b646d84ee
changes to get things to compile under latest cygwin
Ben Wing <ben@xemacs.org>
parents:
4699
diff
changeset
|
117 int dbm_store(DBM *, datum, datum, int); |
c12b646d84ee
changes to get things to compile under latest cygwin
Ben Wing <ben@xemacs.org>
parents:
4699
diff
changeset
|
118 |
5825 | 119 # endif /* (not) TRUST_NDBM_H_PROTOTYPES */ |
120 END_C_DECLS | |
4824
c12b646d84ee
changes to get things to compile under latest cygwin
Ben Wing <ben@xemacs.org>
parents:
4699
diff
changeset
|
121 |
428 | 122 Lisp_Object Qdbm; |
123 #endif /* HAVE_DBM */ | |
124 | |
125 Lisp_Object Vdatabase_coding_system; | |
126 | |
127 Lisp_Object Qdatabasep; | |
128 | |
129 typedef struct | |
130 { | |
131 Lisp_Object (*get_subtype) (Lisp_Database *); | |
132 Lisp_Object (*get_type) (Lisp_Database *); | |
133 Lisp_Object (*get) (Lisp_Database *, Lisp_Object); | |
134 int (*put) (Lisp_Database *, Lisp_Object, Lisp_Object, Lisp_Object); | |
135 int (*rem) (Lisp_Database *, Lisp_Object); | |
136 void (*map) (Lisp_Database *, Lisp_Object); | |
137 void (*close) (Lisp_Database *); | |
138 Lisp_Object (*last_error) (Lisp_Database *); | |
139 } DB_FUNCS; | |
140 | |
141 struct Lisp_Database | |
142 { | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5125
diff
changeset
|
143 NORMAL_LISP_OBJECT_HEADER header; |
428 | 144 Lisp_Object fname; |
145 int mode; | |
146 int access_; | |
147 int dberrno; | |
148 int live_p; | |
149 #ifdef HAVE_DBM | |
150 DBM *dbm_handle; | |
151 #endif | |
152 #ifdef HAVE_BERKELEY_DB | |
153 DB *db_handle; | |
154 #endif | |
155 DB_FUNCS *funcs; | |
156 Lisp_Object coding_system; | |
157 }; | |
158 | |
159 #define XDATABASE(x) XRECORD (x, database, Lisp_Database) | |
617 | 160 #define wrap_database(p) wrap_record (p, database) |
428 | 161 #define DATABASEP(x) RECORDP (x, database) |
162 #define CHECK_DATABASE(x) CHECK_RECORD (x, database) | |
163 #define CONCHECK_DATABASE(x) CONCHECK_RECORD (x, database) | |
164 #define DATABASE_LIVE_P(x) (x->live_p) | |
165 | |
166 #define CHECK_LIVE_DATABASE(db) do { \ | |
167 CHECK_DATABASE (db); \ | |
168 if (!DATABASE_LIVE_P (XDATABASE(db))) \ | |
563 | 169 invalid_operation ("Attempting to access closed database", db); \ |
428 | 170 } while (0) |
171 | |
172 | |
173 static Lisp_Database * | |
174 allocate_database (void) | |
175 { | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5125
diff
changeset
|
176 Lisp_Object obj = ALLOC_NORMAL_LISP_OBJECT (database); |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3072
diff
changeset
|
177 Lisp_Database *db = XDATABASE (obj); |
428 | 178 |
179 db->fname = Qnil; | |
180 db->live_p = 0; | |
181 #ifdef HAVE_BERKELEY_DB | |
182 db->db_handle = NULL; | |
183 #endif | |
184 #ifdef HAVE_DBM | |
185 db->dbm_handle = NULL; | |
186 #endif | |
187 db->access_ = 0; | |
188 db->mode = 0; | |
189 db->dberrno = 0; | |
771 | 190 db->coding_system = Qnil; |
428 | 191 return db; |
192 } | |
193 | |
1204 | 194 static const struct memory_description database_description[] = { |
934 | 195 { XD_LISP_OBJECT, offsetof (struct Lisp_Database, fname) }, |
196 { XD_END} | |
197 }; | |
198 | |
428 | 199 static Lisp_Object |
444 | 200 mark_database (Lisp_Object object) |
428 | 201 { |
444 | 202 Lisp_Database *db = XDATABASE (object); |
428 | 203 return db->fname; |
204 } | |
205 | |
206 static void | |
2286 | 207 print_database (Lisp_Object obj, Lisp_Object printcharfun, |
208 int UNUSED (escapeflag)) | |
428 | 209 { |
210 Lisp_Database *db = XDATABASE (obj); | |
211 | |
212 if (print_readably) | |
5142
f965e31a35f0
reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
213 printing_unreadable_lisp_object (obj, 0); |
428 | 214 |
793 | 215 write_fmt_string_lisp (printcharfun, "#<database \"%s\" (%s/%s/", |
216 3, db->fname, db->funcs->get_type (db), | |
217 db->funcs->get_subtype (db)); | |
218 | |
4351
bc3b9f61018e
Respect the CODESYS argument in #'open-database; don't autodetect EOL.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4124
diff
changeset
|
219 write_fmt_string (printcharfun, "%s) ", |
793 | 220 (!DATABASE_LIVE_P (db) ? "closed" : |
221 (db->access_ & O_WRONLY) ? "writeonly" : | |
4351
bc3b9f61018e
Respect the CODESYS argument in #'open-database; don't autodetect EOL.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4124
diff
changeset
|
222 (db->access_ & O_RDWR) ? "readwrite" : "readonly")); |
bc3b9f61018e
Respect the CODESYS argument in #'open-database; don't autodetect EOL.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4124
diff
changeset
|
223 |
bc3b9f61018e
Respect the CODESYS argument in #'open-database; don't autodetect EOL.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4124
diff
changeset
|
224 write_fmt_string_lisp (printcharfun, "coding: %s ", 1, |
bc3b9f61018e
Respect the CODESYS argument in #'open-database; don't autodetect EOL.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4124
diff
changeset
|
225 XSYMBOL_NAME (XCODING_SYSTEM_NAME |
bc3b9f61018e
Respect the CODESYS argument in #'open-database; don't autodetect EOL.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4124
diff
changeset
|
226 (db->coding_system))); |
bc3b9f61018e
Respect the CODESYS argument in #'open-database; don't autodetect EOL.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4124
diff
changeset
|
227 |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
228 write_fmt_string (printcharfun, "0x%x>", LISP_OBJECT_UID (obj)); |
428 | 229 } |
230 | |
231 static void | |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5125
diff
changeset
|
232 finalize_database (Lisp_Object obj) |
428 | 233 { |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5125
diff
changeset
|
234 Lisp_Database *db = XDATABASE (obj); |
428 | 235 |
236 db->funcs->close (db); | |
237 } | |
238 | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
239 DEFINE_NODUMP_LISP_OBJECT ("database", database, |
5124
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
240 mark_database, print_database, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
241 finalize_database, 0, 0, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
242 database_description, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
243 Lisp_Database); |
428 | 244 |
245 DEFUN ("close-database", Fclose_database, 1, 1, 0, /* | |
246 Close database DATABASE. | |
247 */ | |
248 (database)) | |
249 { | |
250 Lisp_Database *db; | |
251 CHECK_LIVE_DATABASE (database); | |
252 db = XDATABASE (database); | |
253 db->funcs->close (db); | |
254 db->live_p = 0; | |
255 return Qnil; | |
256 } | |
257 | |
258 DEFUN ("database-type", Fdatabase_type, 1, 1, 0, /* | |
259 Return the type of database DATABASE. | |
260 */ | |
261 (database)) | |
262 { | |
263 CHECK_DATABASE (database); | |
264 | |
265 return XDATABASE (database)->funcs->get_type (XDATABASE (database)); | |
266 } | |
267 | |
268 DEFUN ("database-subtype", Fdatabase_subtype, 1, 1, 0, /* | |
269 Return the subtype of database DATABASE, if any. | |
270 */ | |
271 (database)) | |
272 { | |
273 CHECK_DATABASE (database); | |
274 | |
275 return XDATABASE (database)->funcs->get_subtype (XDATABASE (database)); | |
276 } | |
277 | |
278 DEFUN ("database-live-p", Fdatabase_live_p, 1, 1, 0, /* | |
444 | 279 Return t if OBJECT is an active database. |
428 | 280 */ |
444 | 281 (object)) |
428 | 282 { |
444 | 283 return DATABASEP (object) && DATABASE_LIVE_P (XDATABASE (object)) ? |
284 Qt : Qnil; | |
428 | 285 } |
286 | |
287 DEFUN ("database-file-name", Fdatabase_file_name, 1, 1, 0, /* | |
288 Return the filename associated with the database DATABASE. | |
289 */ | |
290 (database)) | |
291 { | |
292 CHECK_DATABASE (database); | |
293 | |
294 return XDATABASE (database)->fname; | |
295 } | |
296 | |
297 DEFUN ("databasep", Fdatabasep, 1, 1, 0, /* | |
444 | 298 Return t if OBJECT is a database. |
428 | 299 */ |
444 | 300 (object)) |
428 | 301 { |
444 | 302 return DATABASEP (object) ? Qt : Qnil; |
428 | 303 } |
304 | |
305 #ifdef HAVE_DBM | |
306 static void | |
307 dbm_map (Lisp_Database *db, Lisp_Object func) | |
308 { | |
309 datum keydatum, valdatum; | |
310 Lisp_Object key, val; | |
311 | |
312 for (keydatum = dbm_firstkey (db->dbm_handle); | |
313 keydatum.dptr != NULL; | |
314 keydatum = dbm_nextkey (db->dbm_handle)) | |
315 { | |
316 valdatum = dbm_fetch (db->dbm_handle, keydatum); | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
317 key = make_extstring ((Extbyte *) keydatum.dptr, keydatum.dsize, |
771 | 318 db->coding_system); |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
319 val = make_extstring ((Extbyte *) valdatum.dptr, valdatum.dsize, |
771 | 320 db->coding_system); |
428 | 321 call2 (func, key, val); |
322 } | |
323 } | |
324 | |
325 static Lisp_Object | |
326 dbm_get (Lisp_Database *db, Lisp_Object key) | |
327 { | |
328 datum keydatum, valdatum; | |
329 | |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
330 LISP_STRING_TO_SIZED_EXTERNAL (key, keydatum.dptr, keydatum.dsize, |
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
331 db->coding_system); |
428 | 332 valdatum = dbm_fetch (db->dbm_handle, keydatum); |
333 | |
334 return (valdatum.dptr | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
335 ? make_extstring ((Extbyte *) valdatum.dptr, valdatum.dsize, |
771 | 336 db->coding_system) |
428 | 337 : Qnil); |
338 } | |
339 | |
340 static int | |
341 dbm_put (Lisp_Database *db, | |
342 Lisp_Object key, Lisp_Object val, Lisp_Object replace) | |
343 { | |
344 datum keydatum, valdatum; | |
345 | |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
346 LISP_STRING_TO_SIZED_EXTERNAL (val, valdatum.dptr, valdatum.dsize, |
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
347 db->coding_system); |
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
348 LISP_STRING_TO_SIZED_EXTERNAL (key, keydatum.dptr, keydatum.dsize, |
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
349 db->coding_system); |
428 | 350 |
351 return !dbm_store (db->dbm_handle, keydatum, valdatum, | |
352 NILP (replace) ? DBM_INSERT : DBM_REPLACE); | |
353 } | |
354 | |
355 static int | |
356 dbm_remove (Lisp_Database *db, Lisp_Object key) | |
357 { | |
358 datum keydatum; | |
359 | |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
360 LISP_STRING_TO_SIZED_EXTERNAL (key, keydatum.dptr, keydatum.dsize, |
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
361 db->coding_system); |
428 | 362 |
363 return dbm_delete (db->dbm_handle, keydatum); | |
364 } | |
365 | |
366 static Lisp_Object | |
2494 | 367 dbm_type (Lisp_Database *UNUSED (db)) |
428 | 368 { |
369 return Qdbm; | |
370 } | |
371 | |
372 static Lisp_Object | |
2494 | 373 dbm_subtype (Lisp_Database *UNUSED (db)) |
428 | 374 { |
375 return Qnil; | |
376 } | |
377 | |
378 static Lisp_Object | |
379 dbm_lasterr (Lisp_Database *db) | |
380 { | |
381 return lisp_strerror (db->dberrno); | |
382 } | |
383 | |
384 static void | |
385 dbm_closeit (Lisp_Database *db) | |
386 { | |
387 if (db->dbm_handle) | |
388 { | |
389 dbm_close (db->dbm_handle); | |
390 db->dbm_handle = NULL; | |
391 } | |
392 } | |
393 | |
394 static DB_FUNCS ndbm_func_block = | |
395 { | |
396 dbm_subtype, | |
397 dbm_type, | |
398 dbm_get, | |
399 dbm_put, | |
400 dbm_remove, | |
401 dbm_map, | |
402 dbm_closeit, | |
403 dbm_lasterr | |
404 }; | |
405 #endif /* HAVE_DBM */ | |
406 | |
407 #ifdef HAVE_BERKELEY_DB | |
408 static Lisp_Object | |
2286 | 409 berkdb_type (Lisp_Database *UNUSED (db)) |
428 | 410 { |
411 return Qberkeley_db; | |
412 } | |
413 | |
414 static Lisp_Object | |
415 berkdb_subtype (Lisp_Database *db) | |
416 { | |
417 if (!db->db_handle) | |
418 return Qnil; | |
419 | |
420 switch (db->db_handle->type) | |
421 { | |
422 case DB_BTREE: return Qbtree; | |
423 case DB_HASH: return Qhash; | |
424 case DB_RECNO: return Qrecno; | |
448 | 425 #if DB_VERSION_MAJOR > 2 |
426 case DB_QUEUE: return Qqueue; | |
427 #endif | |
428 | 428 default: return Qunknown; |
429 } | |
430 } | |
431 | |
432 static Lisp_Object | |
433 berkdb_lasterr (Lisp_Database *db) | |
434 { | |
435 return lisp_strerror (db->dberrno); | |
436 } | |
437 | |
438 static Lisp_Object | |
439 berkdb_get (Lisp_Database *db, Lisp_Object key) | |
440 { | |
441 DBT keydatum, valdatum; | |
442 int status = 0; | |
443 | |
444 /* DB Version 2 requires DBT's to be zeroed before use. */ | |
445 xzero (keydatum); | |
446 xzero (valdatum); | |
447 | |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
448 LISP_STRING_TO_SIZED_EXTERNAL (key, keydatum.data, keydatum.size, |
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
449 db->coding_system); |
428 | 450 |
451 #if DB_VERSION_MAJOR == 1 | |
452 status = db->db_handle->get (db->db_handle, &keydatum, &valdatum, 0); | |
453 #else | |
454 status = db->db_handle->get (db->db_handle, NULL, &keydatum, &valdatum, 0); | |
455 #endif /* DB_VERSION_MAJOR */ | |
456 | |
457 if (!status) | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
458 return make_extstring ((const Extbyte *) valdatum.data, valdatum.size, |
771 | 459 db->coding_system); |
428 | 460 |
461 #if DB_VERSION_MAJOR == 1 | |
462 db->dberrno = (status == 1) ? -1 : errno; | |
463 #else | |
464 db->dberrno = (status < 0) ? -1 : errno; | |
465 #endif /* DB_VERSION_MAJOR */ | |
466 | |
467 return Qnil; | |
468 } | |
469 | |
470 static int | |
471 berkdb_put (Lisp_Database *db, | |
472 Lisp_Object key, | |
473 Lisp_Object val, | |
474 Lisp_Object replace) | |
475 { | |
476 DBT keydatum, valdatum; | |
477 int status = 0; | |
478 | |
479 /* DB Version 2 requires DBT's to be zeroed before use. */ | |
480 xzero (keydatum); | |
481 xzero (valdatum); | |
482 | |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
483 LISP_STRING_TO_SIZED_EXTERNAL (key, keydatum.data, keydatum.size, |
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
484 db->coding_system); |
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
485 LISP_STRING_TO_SIZED_EXTERNAL (val, valdatum.data, valdatum.size, |
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
486 db->coding_system); |
428 | 487 #if DB_VERSION_MAJOR == 1 |
488 status = db->db_handle->put (db->db_handle, &keydatum, &valdatum, | |
489 NILP (replace) ? R_NOOVERWRITE : 0); | |
490 db->dberrno = (status == 1) ? -1 : errno; | |
491 #else | |
492 status = db->db_handle->put (db->db_handle, NULL, &keydatum, &valdatum, | |
493 NILP (replace) ? DB_NOOVERWRITE : 0); | |
494 db->dberrno = (status < 0) ? -1 : errno; | |
495 #endif/* DV_VERSION_MAJOR = 2 */ | |
496 | |
497 return status; | |
498 } | |
499 | |
500 static int | |
501 berkdb_remove (Lisp_Database *db, Lisp_Object key) | |
502 { | |
503 DBT keydatum; | |
504 int status; | |
505 | |
506 /* DB Version 2 requires DBT's to be zeroed before use. */ | |
507 xzero (keydatum); | |
508 | |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
509 LISP_STRING_TO_SIZED_EXTERNAL (key, keydatum.data, keydatum.size, |
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
510 db->coding_system); |
428 | 511 |
512 #if DB_VERSION_MAJOR == 1 | |
513 status = db->db_handle->del (db->db_handle, &keydatum, 0); | |
514 #else | |
515 status = db->db_handle->del (db->db_handle, NULL, &keydatum, 0); | |
516 #endif /* DB_VERSION_MAJOR */ | |
517 | |
518 if (!status) | |
519 return 0; | |
520 | |
521 #if DB_VERSION_MAJOR == 1 | |
522 db->dberrno = (status == 1) ? -1 : errno; | |
523 #else | |
524 db->dberrno = (status < 0) ? -1 : errno; | |
525 #endif /* DB_VERSION_MAJOR */ | |
526 | |
527 return 1; | |
528 } | |
529 | |
530 static void | |
531 berkdb_map (Lisp_Database *db, Lisp_Object func) | |
532 { | |
533 DBT keydatum, valdatum; | |
534 Lisp_Object key, val; | |
535 DB *dbp = db->db_handle; | |
536 int status; | |
537 | |
538 xzero (keydatum); | |
539 xzero (valdatum); | |
540 | |
541 #if DB_VERSION_MAJOR == 1 | |
542 for (status = dbp->seq (dbp, &keydatum, &valdatum, R_FIRST); | |
543 status == 0; | |
544 status = dbp->seq (dbp, &keydatum, &valdatum, R_NEXT)) | |
545 { | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
546 key = make_extstring ((const Extbyte *) keydatum.data, keydatum.size, |
771 | 547 db->coding_system); |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
548 val = make_extstring ((const Extbyte *) valdatum.data, valdatum.size, |
771 | 549 db->coding_system); |
428 | 550 call2 (func, key, val); |
551 } | |
552 #else | |
553 { | |
554 DBC *dbcp; | |
555 | |
556 #if DB_VERSION_MAJOR > 2 || DB_VERSION_MINOR >=6 | |
557 status = dbp->cursor (dbp, NULL, &dbcp, 0); | |
558 #else | |
559 status = dbp->cursor (dbp, NULL, &dbcp); | |
440 | 560 #endif |
428 | 561 for (status = dbcp->c_get (dbcp, &keydatum, &valdatum, DB_FIRST); |
562 status == 0; | |
563 status = dbcp->c_get (dbcp, &keydatum, &valdatum, DB_NEXT)) | |
564 { | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
565 key = make_extstring ((const Extbyte *) keydatum.data, keydatum.size, |
771 | 566 db->coding_system); |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
567 val = make_extstring ((const Extbyte *) valdatum.data, valdatum.size, |
771 | 568 db->coding_system); |
428 | 569 call2 (func, key, val); |
570 } | |
571 dbcp->c_close (dbcp); | |
572 } | |
573 #endif /* DB_VERSION_MAJOR */ | |
574 } | |
575 | |
576 static void | |
577 berkdb_close (Lisp_Database *db) | |
578 { | |
579 if (db->db_handle) | |
580 { | |
581 #if DB_VERSION_MAJOR == 1 | |
582 db->db_handle->sync (db->db_handle, 0); | |
583 db->db_handle->close (db->db_handle); | |
584 #else | |
585 db->db_handle->sync (db->db_handle, 0); | |
586 db->db_handle->close (db->db_handle, 0); | |
587 #endif /* DB_VERSION_MAJOR */ | |
588 db->db_handle = NULL; | |
589 } | |
590 } | |
591 | |
592 static DB_FUNCS berk_func_block = | |
593 { | |
594 berkdb_subtype, | |
595 berkdb_type, | |
596 berkdb_get, | |
597 berkdb_put, | |
598 berkdb_remove, | |
599 berkdb_map, | |
600 berkdb_close, | |
601 berkdb_lasterr | |
602 }; | |
603 #endif /* HAVE_BERKELEY_DB */ | |
604 | |
605 DEFUN ("database-last-error", Fdatabase_last_error, 0, 1, 0, /* | |
606 Return the last error associated with DATABASE. | |
607 */ | |
608 (database)) | |
609 { | |
610 if (NILP (database)) | |
611 return lisp_strerror (errno); | |
612 | |
613 CHECK_DATABASE (database); | |
614 | |
615 return XDATABASE (database)->funcs->last_error (XDATABASE (database)); | |
616 } | |
617 | |
771 | 618 DEFUN ("open-database", Fopen_database, 1, 6, 0, /* |
428 | 619 Return a new database object opened on FILE. |
620 Optional arguments TYPE and SUBTYPE specify the database type. | |
621 Optional argument ACCESS specifies the access rights, which may be any | |
622 combination of 'r' 'w' and '+', for read, write, and creation flags. | |
623 Optional argument MODE gives the permissions to use when opening FILE, | |
624 and defaults to 0755. | |
771 | 625 Optional argument CODESYS specifies the coding system used to encode/decode |
626 data passed to/from the database, and defaults to the value of the | |
627 variable `database-coding-system'. | |
428 | 628 */ |
771 | 629 (file, type, subtype, access_, mode, codesys)) |
428 | 630 { |
631 /* This function can GC */ | |
632 int modemask; | |
633 int accessmask = 0; | |
634 Lisp_Database *db = NULL; | |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
635 Extbyte *filename; |
428 | 636 struct gcpro gcpro1, gcpro2; |
637 | |
638 CHECK_STRING (file); | |
639 GCPRO2 (file, access_); | |
640 file = Fexpand_file_name (file, Qnil); | |
641 UNGCPRO; | |
642 | |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
643 LISP_PATHNAME_CONVERT_OUT (file, filename); |
428 | 644 |
645 if (NILP (access_)) | |
646 { | |
647 accessmask = O_RDWR | O_CREAT; | |
648 } | |
649 else | |
650 { | |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
651 Ibyte *acc; |
428 | 652 CHECK_STRING (access_); |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
653 acc = XSTRING_DATA (access_); |
428 | 654 |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
655 if (qxestrchr (acc, '+')) |
428 | 656 accessmask |= O_CREAT; |
657 | |
658 { | |
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
659 int rp = !!qxestrchr (acc, 'r'); |
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
660 int wp = !!qxestrchr (acc, 'w'); |
428 | 661 if (rp && wp) accessmask |= O_RDWR; |
662 else if (wp) accessmask |= O_WRONLY; | |
663 else accessmask |= O_RDONLY; | |
664 } | |
665 } | |
666 | |
667 if (NILP (mode)) | |
668 { | |
669 modemask = 0755; /* rwxr-xr-x */ | |
670 } | |
671 else | |
672 { | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
673 CHECK_FIXNUM (mode); |
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
674 modemask = XFIXNUM (mode); |
428 | 675 } |
676 | |
771 | 677 if (NILP (codesys)) |
678 codesys = Vdatabase_coding_system; | |
679 | |
4351
bc3b9f61018e
Respect the CODESYS argument in #'open-database; don't autodetect EOL.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4124
diff
changeset
|
680 codesys = get_coding_system_for_text_file (codesys, 0); |
771 | 681 |
428 | 682 #ifdef HAVE_DBM |
683 if (NILP (type) || EQ (type, Qdbm)) | |
684 { | |
685 DBM *dbase = dbm_open (filename, accessmask, modemask); | |
686 if (!dbase) | |
687 return Qnil; | |
688 | |
689 db = allocate_database (); | |
690 db->dbm_handle = dbase; | |
691 db->funcs = &ndbm_func_block; | |
771 | 692 db->coding_system = codesys; |
428 | 693 goto db_done; |
694 } | |
695 #endif /* HAVE_DBM */ | |
696 | |
697 #ifdef HAVE_BERKELEY_DB | |
698 if (NILP (type) || EQ (type, Qberkeley_db)) | |
699 { | |
700 DBTYPE real_subtype; | |
701 DB *dbase; | |
702 #if DB_VERSION_MAJOR != 1 | |
703 int status; | |
704 #endif | |
705 | |
706 if (EQ (subtype, Qhash) || NILP (subtype)) | |
707 real_subtype = DB_HASH; | |
708 else if (EQ (subtype, Qbtree)) | |
709 real_subtype = DB_BTREE; | |
710 else if (EQ (subtype, Qrecno)) | |
711 real_subtype = DB_RECNO; | |
448 | 712 #if DB_VERSION_MAJOR > 2 |
713 else if (EQ (subtype, Qqueue)) | |
714 real_subtype = DB_QUEUE; | |
715 #endif | |
428 | 716 else |
563 | 717 invalid_constant ("Unsupported subtype", subtype); |
428 | 718 |
719 #if DB_VERSION_MAJOR == 1 | |
720 dbase = dbopen (filename, accessmask, modemask, real_subtype, NULL); | |
721 if (!dbase) | |
722 return Qnil; | |
723 #else | |
724 /* Berkeley DB Version 2 has only the accessmask DB_CREATE and DB_RDONLY, | |
725 other flags shouldn't be set */ | |
726 if (NILP (access_)) | |
727 accessmask = DB_CREATE; | |
728 else | |
729 { | |
730 char *acc; | |
731 CHECK_STRING (access_); | |
732 acc = (char *) XSTRING_DATA (access_); | |
733 accessmask = 0; | |
734 | |
735 if (strchr (acc, '+')) | |
736 accessmask |= DB_CREATE; | |
737 | |
738 if (strchr (acc, 'r') && !strchr (acc, 'w')) | |
739 accessmask |= DB_RDONLY; | |
740 } | |
448 | 741 #if DB_VERSION_MAJOR == 2 |
428 | 742 status = db_open (filename, real_subtype, accessmask, |
743 modemask, NULL , NULL, &dbase); | |
744 if (status) | |
745 return Qnil; | |
448 | 746 #else |
747 status = db_create (&dbase, NULL, 0); | |
748 if (status) | |
749 return Qnil; | |
1141 | 750 #if DB_VERSION_MAJOR < 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR < 1) |
448 | 751 status = dbase->open (dbase, filename, NULL, |
752 real_subtype, accessmask, modemask); | |
1141 | 753 #else /* DB_VERSION >= 4.1 */ |
1377 | 754 /* You can't use DB_AUTO_COMMIT unless you have a txn environment. */ |
1141 | 755 status = dbase->open (dbase, NULL, filename, NULL, real_subtype, |
1377 | 756 accessmask, modemask); |
1141 | 757 #endif /* DB_VERSION < 4.1 */ |
448 | 758 if (status) |
759 { | |
760 dbase->close (dbase, 0); | |
761 return Qnil; | |
762 } | |
763 #endif /* DB_VERSION_MAJOR > 2 */ | |
764 /* Normalize into system specific file modes. Only for printing */ | |
765 accessmask = accessmask & DB_RDONLY ? O_RDONLY : O_RDWR; | |
428 | 766 #endif /* DB_VERSION_MAJOR */ |
767 | |
768 db = allocate_database (); | |
769 db->db_handle = dbase; | |
770 db->funcs = &berk_func_block; | |
771 | 771 db->coding_system = codesys; |
428 | 772 goto db_done; |
773 } | |
774 #endif /* HAVE_BERKELEY_DB */ | |
775 | |
563 | 776 invalid_constant ("Unsupported database type", type); |
428 | 777 return Qnil; |
778 | |
779 db_done: | |
780 db->live_p = 1; | |
781 db->fname = file; | |
782 db->mode = modemask; | |
783 db->access_ = accessmask; | |
784 | |
793 | 785 return wrap_database (db); |
428 | 786 } |
787 | |
788 DEFUN ("put-database", Fput_database, 3, 4, 0, /* | |
789 Store KEY and VALUE in DATABASE. | |
790 If optional fourth arg REPLACE is non-nil, | |
791 replace any existing entry in the database. | |
792 */ | |
793 (key, value, database, replace)) | |
794 { | |
795 CHECK_LIVE_DATABASE (database); | |
796 CHECK_STRING (key); | |
797 CHECK_STRING (value); | |
798 { | |
799 Lisp_Database *db = XDATABASE (database); | |
800 int status = db->funcs->put (db, key, value, replace); | |
801 return status ? Qt : Qnil; | |
802 } | |
803 } | |
804 | |
805 DEFUN ("remove-database", Fremove_database, 2, 2, 0, /* | |
806 Remove KEY from DATABASE. | |
807 */ | |
808 (key, database)) | |
809 { | |
810 CHECK_LIVE_DATABASE (database); | |
811 CHECK_STRING (key); | |
812 { | |
813 Lisp_Database *db = XDATABASE (database); | |
814 int status = db->funcs->rem (db, key); | |
815 return status ? Qt : Qnil; | |
816 } | |
817 } | |
818 | |
819 DEFUN ("get-database", Fget_database, 2, 3, 0, /* | |
820 Return value for KEY in DATABASE. | |
821 If there is no corresponding value, return DEFAULT (defaults to nil). | |
822 */ | |
823 (key, database, default_)) | |
824 { | |
825 CHECK_LIVE_DATABASE (database); | |
826 CHECK_STRING (key); | |
827 { | |
828 Lisp_Database *db = XDATABASE (database); | |
829 Lisp_Object retval = db->funcs->get (db, key); | |
830 return NILP (retval) ? default_ : retval; | |
831 } | |
832 } | |
833 | |
834 DEFUN ("map-database", Fmapdatabase, 2, 2, 0, /* | |
835 Map FUNCTION over entries in DATABASE, calling it with two args, | |
836 each key and value in the database. | |
837 */ | |
838 (function, database)) | |
839 { | |
840 CHECK_LIVE_DATABASE (database); | |
841 | |
842 XDATABASE (database)->funcs->map (XDATABASE (database), function); | |
843 | |
844 return Qnil; | |
845 } | |
846 | |
847 void | |
848 syms_of_database (void) | |
849 { | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3072
diff
changeset
|
850 INIT_LISP_OBJECT (database); |
442 | 851 |
563 | 852 DEFSYMBOL (Qdatabasep); |
428 | 853 #ifdef HAVE_DBM |
563 | 854 DEFSYMBOL (Qdbm); |
428 | 855 #endif |
856 #ifdef HAVE_BERKELEY_DB | |
563 | 857 DEFSYMBOL (Qberkeley_db); |
858 DEFSYMBOL (Qhash); | |
859 DEFSYMBOL (Qbtree); | |
860 DEFSYMBOL (Qrecno); | |
448 | 861 #if DB_VERSION_MAJOR > 2 |
563 | 862 DEFSYMBOL (Qqueue); |
448 | 863 #endif |
563 | 864 DEFSYMBOL (Qunknown); |
428 | 865 #endif |
866 | |
867 DEFSUBR (Fopen_database); | |
868 DEFSUBR (Fdatabasep); | |
869 DEFSUBR (Fmapdatabase); | |
870 DEFSUBR (Fput_database); | |
871 DEFSUBR (Fget_database); | |
872 DEFSUBR (Fremove_database); | |
873 DEFSUBR (Fdatabase_type); | |
874 DEFSUBR (Fdatabase_subtype); | |
875 DEFSUBR (Fdatabase_last_error); | |
876 DEFSUBR (Fdatabase_live_p); | |
877 DEFSUBR (Fdatabase_file_name); | |
878 DEFSUBR (Fclose_database); | |
879 } | |
880 | |
881 void | |
882 vars_of_database (void) | |
883 { | |
884 #ifdef HAVE_DBM | |
885 Fprovide (Qdbm); | |
886 #endif | |
887 #ifdef HAVE_BERKELEY_DB | |
888 Fprovide (Qberkeley_db); | |
889 #endif | |
890 | |
891 DEFVAR_LISP ("database-coding-system", &Vdatabase_coding_system /* | |
771 | 892 Default coding system used to convert data in database files. |
428 | 893 */ ); |
771 | 894 Vdatabase_coding_system = Qnative; |
428 | 895 } |