annotate src/database.c @ 209:41ff10fd062f r20-4b3

Import from CVS: tag r20-4b3
author cvs
date Mon, 13 Aug 2007 10:04:58 +0200
parents e45d5e7c476e
children 78478c60bfcd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* Database access routines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Copyright (C) 1996, William M. Perry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 /* Synched up with: Not in FSF. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 /* Written by Bill Perry */
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
24 /* Substantially rewritten by Martin Buchholz */
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
25 /* db 2.x support added by Andreas Jaeger */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 #include "lisp.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 #include <errno.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 94
diff changeset
31 #ifndef HAVE_DATABASE
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 94
diff changeset
32 #error database.c being compiled, but HAVE_DATABASE not defined!
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 94
diff changeset
33 #endif /* HAVE_DATABASE */
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 94
diff changeset
34
157
6b37e6ddd302 Import from CVS: tag r20-3b5
cvs
parents: 151
diff changeset
35 #include "database.h" /* Our include file */
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 94
diff changeset
36
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 #ifdef HAVE_BERKELEY_DB
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 94
diff changeset
38 /* Work around Berkeley DB's use of int types which are defined
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 94
diff changeset
39 slightly differently in the not quite yet standard <inttypes.h>.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 94
diff changeset
40 See db.h for details of why we're resorting to this... */
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
41 /* glibc 2.1 doesn't have this problem with DB 2.x */
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
42 #if !(defined __GLIBC__ && __GLIBC_MINOR__ >= 1)
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 94
diff changeset
43 #ifdef HAVE_INTTYPES_H
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 94
diff changeset
44 #define __BIT_TYPES_DEFINED__
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 94
diff changeset
45 #include <inttypes.h>
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 94
diff changeset
46 typedef uint8_t u_int8_t;
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 94
diff changeset
47 typedef uint16_t u_int16_t;
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 94
diff changeset
48 typedef uint32_t u_int32_t;
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 94
diff changeset
49 #ifdef WE_DONT_NEED_QUADS
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 94
diff changeset
50 typedef uint64_t u_int64_t;
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 94
diff changeset
51 #endif /* WE_DONT_NEED_QUADS */
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 94
diff changeset
52 #endif /* HAVE_INTTYPES_H */
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
53 #endif /* !(defined __GLIBC__ && __GLIBC_MINOR__ >= 1) */
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 94
diff changeset
54 #include DB_H_PATH /* Berkeley db's header file */
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
55 #ifndef DB_VERSION_MAJOR
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
56 # define DB_VERSION_MAJOR 1
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
57 #endif /* DB_VERSION_MAJOR */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 Lisp_Object Qberkeley_db;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 Lisp_Object Qhash;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 Lisp_Object Qbtree;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 Lisp_Object Qrecno;
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 94
diff changeset
62 #endif /* HAVE_BERKELEY_DB */
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 94
diff changeset
63
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 94
diff changeset
64 #ifdef HAVE_DBM
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 94
diff changeset
65 #include <ndbm.h>
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 94
diff changeset
66 Lisp_Object Qdbm;
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 94
diff changeset
67 #endif /* HAVE_DBM */
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 94
diff changeset
68
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 94
diff changeset
69 Lisp_Object Qdatabasep;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
71 typedef enum { DB_DBM, DB_BERKELEY, DB_IS_UNKNOWN } XEMACS_DB_TYPE;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
73 struct database;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
74 typedef struct database database;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 94
diff changeset
76 typedef struct
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
78 CONST char * (*get_subtype) (struct database *);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
79 CONST char * (*get_type) (struct database *);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
80 Lisp_Object (*get) (struct database *, Lisp_Object);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
81 int (*put) (struct database *, Lisp_Object, Lisp_Object, Lisp_Object);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
82 int (*rem) (struct database *, Lisp_Object);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
83 void (*map) (struct database *, Lisp_Object);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
84 Lisp_Object (*get_lisp_type) (struct database *);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
85 void (*close) (struct database *);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
86 Lisp_Object (*last_error) (struct database *);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 } DB_FUNCS;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
89 struct database
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 struct lcrecord_header header;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 Lisp_Object fname;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 XEMACS_DB_TYPE type;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 int mode;
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 157
diff changeset
95 int access_;
94
1040fe1366ac Import from CVS: tag xemacs-20-0f2
cvs
parents: 70
diff changeset
96 int dberrno;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
97 int live_p;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
98 #ifdef HAVE_DBM
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
99 DBM *dbm_handle;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
100 #endif
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
101 #ifdef HAVE_BERKELEY_DB
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
102 DB *db_handle;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
103 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 DB_FUNCS *funcs;
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 94
diff changeset
105 #ifdef MULE
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 94
diff changeset
106 Lisp_Object coding_system;
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 94
diff changeset
107 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
110 #define XDATABASE(x) XRECORD (x, database, struct database)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 #define XSETDATABASE(x, p) XSETRECORD (x, p, database)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 #define DATABASEP(x) RECORDP (x, database)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 #define GC_DATABASEP(x) GC_RECORDP (x, database)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 #define CHECK_DATABASE(x) CHECK_RECORD (x, database)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
115 #define CONCHECK_DATABASE(x) CONCHECK_RECORD (x, database)
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
116 #define DATABASE_LIVE_P(x) (x->live_p)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 static Lisp_Object mark_database (Lisp_Object, void (*) (Lisp_Object));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 static void print_database (Lisp_Object, Lisp_Object, int);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 static void finalize_database (void *, int);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 DEFINE_LRECORD_IMPLEMENTATION ("database", database,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 mark_database, print_database,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 finalize_database, 0, 0,
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
123 struct database);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
125 #define CHECK_LIVE_DATABASE(db) do { \
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
126 CHECK_DATABASE(db); \
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
127 if (!DATABASE_LIVE_P (XDATABASE(db))) \
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
128 signal_simple_error ("Attempting to access closed database", db); \
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
129 } while (0)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
130
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
131
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
132 static struct database *
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
133 allocate_database (void)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
135 struct database *dbase =
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
136 alloc_lcrecord_type (struct database, lrecord_database);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 dbase->fname = Qnil;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
139 dbase->live_p = 0;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
140 #ifdef HAVE_BERKELEY_DB
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 dbase->db_handle = NULL;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
142 #endif
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
143 #ifdef HAVE_DBM
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
144 dbase->dbm_handle = NULL;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
145 #endif
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 157
diff changeset
146 dbase->access_ = 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 dbase->mode = 0;
94
1040fe1366ac Import from CVS: tag xemacs-20-0f2
cvs
parents: 70
diff changeset
148 dbase->dberrno = 0;
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
149 dbase->type = DB_IS_UNKNOWN;
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 94
diff changeset
150 #ifdef MULE
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 94
diff changeset
151 dbase->coding_system = Fget_coding_system (Qbinary);
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 94
diff changeset
152 #endif
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 157
diff changeset
153 return dbase;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 mark_database (Lisp_Object obj, void (*markobj) (Lisp_Object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
159 struct database *dbase = XDATABASE (obj);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 ((markobj) (dbase->fname));
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 157
diff changeset
162 return Qnil;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 print_database (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 {
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
168 char buf[64];
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
169 struct database *dbase = XDATABASE (obj);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 if (print_readably)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
172 error ("printing unreadable object #<database 0x%x>", dbase->header.uid);
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
173
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
174 write_c_string ("#<database \"", printcharfun);
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
175 print_internal (dbase->fname, printcharfun, 0);
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
176 sprintf (buf, "\" (%s/%s/%s) 0x%x>",
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
177 dbase->funcs->get_type (dbase),
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
178 dbase->funcs->get_subtype (dbase),
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
179 (!DATABASE_LIVE_P (dbase) ? "closed" :
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
180 (dbase->access_ & O_WRONLY) ? "writeonly" :
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
181 (dbase->access_ & O_RDWR) ? "readwrite" : "readonly"),
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
182 dbase->header.uid);
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
183 write_c_string (buf, printcharfun);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 finalize_database (void *header, int for_disksave)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
189 struct database *db = (struct database *) header;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 if (for_disksave)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
193 Lisp_Object obj;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
194 XSETOBJ (obj, Lisp_Type_Record, (void *) db);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
195
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 signal_simple_error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 ("Can't dump an emacs containing window system objects", obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 db->funcs->close (db);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
202 DEFUN ("close-database", Fclose_database, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 Close database OBJ.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
204 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
205 (obj))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
207 CHECK_LIVE_DATABASE (obj);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
208 XDATABASE (obj)->funcs->close (XDATABASE (obj));
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
209 XDATABASE (obj)->live_p = 0;
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 157
diff changeset
210 return Qnil;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
213 DEFUN ("database-type", Fdatabase_type, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 Return the type of database OBJ.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
215 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
216 (obj))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 CHECK_DATABASE (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
220 return XDATABASE (obj)->funcs->get_lisp_type (XDATABASE (obj));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
223 DEFUN ("database-subtype", Fdatabase_subtype, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 Return the subtype of database OBJ, if any.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
225 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
226 (obj))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 CHECK_DATABASE (obj);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
229
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
230 return intern (XDATABASE (obj)->funcs->get_subtype (XDATABASE (obj)));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
233 DEFUN ("database-live-p", Fdatabase_live_p, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 Return t iff OBJ is an active database, else nil.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
235 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
236 (obj))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 CHECK_DATABASE (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
240 return DATABASE_LIVE_P (XDATABASE (obj)) ? Qt : Qnil;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
243 DEFUN ("database-file-name", Fdatabase_file_name, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 Return the filename associated with the database OBJ.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
245 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
246 (obj))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 CHECK_DATABASE (obj);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
249
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
250 return XDATABASE (obj)->fname;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
253 DEFUN ("databasep", Fdatabasep, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 Return t iff OBJ is a database, else nil.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
255 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
256 (obj))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 {
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 157
diff changeset
258 return DATABASEP (obj) ? Qt : Qnil;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 #ifdef HAVE_DBM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 static void
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
263 dbm_map (struct database *db, Lisp_Object func)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 datum keydatum, valdatum;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 Lisp_Object key, val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
268 for (keydatum = dbm_firstkey (db->dbm_handle);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 keydatum.dptr != NULL;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
270 keydatum = dbm_nextkey (db->dbm_handle))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
272 valdatum = dbm_fetch (db->dbm_handle, keydatum);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 key = make_string ((unsigned char *) keydatum.dptr, keydatum.dsize);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 val = make_string ((unsigned char *) valdatum.dptr, valdatum.dsize);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 call2 (func, key, val);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 static Lisp_Object
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
280 dbm_get (struct database *db, Lisp_Object key)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 datum keydatum, valdatum;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
283
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
284 keydatum.dptr = (char *) XSTRING_DATA (key);
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
285 keydatum.dsize = XSTRING_LENGTH (key);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
286 valdatum = dbm_fetch (db->dbm_handle, keydatum);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 return (valdatum.dptr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 ? make_string ((unsigned char *) valdatum.dptr, valdatum.dsize)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 : Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 static int
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
294 dbm_put (struct database *db,
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
295 Lisp_Object key, Lisp_Object val, Lisp_Object replace)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 datum keydatum, valdatum;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
298
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
299 valdatum.dptr = (char *) XSTRING_DATA (val);
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
300 valdatum.dsize = XSTRING_LENGTH (val);
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
301 keydatum.dptr = (char *) XSTRING_DATA (key);
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
302 keydatum.dsize = XSTRING_LENGTH (key);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
304 return !dbm_store (db->dbm_handle, keydatum, valdatum,
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
305 NILP (replace) ? DBM_INSERT : DBM_REPLACE);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 static int
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
309 dbm_remove (struct database *db, Lisp_Object key)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 datum keydatum;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
312
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
313 keydatum.dptr = (char *) XSTRING_DATA (key);
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
314 keydatum.dsize = XSTRING_LENGTH (key);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
315
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
316 return dbm_delete (db->dbm_handle, keydatum);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 static Lisp_Object
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
320 dbm_lisp_type (struct database *db)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 {
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 157
diff changeset
322 return Qdbm;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 static CONST char *
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
326 dbm_type (struct database *db)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 {
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 157
diff changeset
328 return "dbm";
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 static CONST char *
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
332 dbm_subtype (struct database *db)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 {
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 157
diff changeset
334 return "nil";
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 static Lisp_Object
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
338 dbm_lasterr (struct database *dbp)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 {
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
340 return lisp_strerror (dbp->dberrno);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 static void
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
344 dbm_closeit (struct database *db)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
346 if (db->dbm_handle)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
347 {
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
348 dbm_close (db->dbm_handle);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
349 db->dbm_handle = NULL;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
350 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 static DB_FUNCS ndbm_func_block =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 dbm_subtype,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 dbm_type,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 dbm_get,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 dbm_put,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 dbm_remove,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 dbm_map,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 dbm_lisp_type,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 dbm_closeit,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 dbm_lasterr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 };
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
365 #endif /* HAVE_DBM */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 #ifdef HAVE_BERKELEY_DB
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 static Lisp_Object
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
369 berkdb_lisp_type (struct database *db)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 {
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 157
diff changeset
371 return Qberkeley_db;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 static CONST char *
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
375 berkdb_type (struct database *db)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 {
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 157
diff changeset
377 return "berkeley";
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 static CONST char *
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
381 berkdb_subtype (struct database *db)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
383 if (!db->db_handle)
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 157
diff changeset
384 return "nil";
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
386 switch (db->db_handle->type)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
387 {
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
388 case DB_BTREE: return "btree";
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
389 case DB_HASH: return "hash";
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
390 case DB_RECNO: return "recno";
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
391 default: return "unknown";
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
392 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 static Lisp_Object
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
396 berkdb_lasterr (struct database *dbp)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 {
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
398 return lisp_strerror (dbp->dberrno);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 static Lisp_Object
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
402 berkdb_get (struct database *db, Lisp_Object key)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
404 /* #### Needs mule-izing */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 DBT keydatum, valdatum;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 int status = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
408 #if DB_VERSION_MAJOR == 2
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
409 /* Always initialize keydatum, valdatum. */
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
410 memset(&keydatum, 0, sizeof(keydatum));
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
411 memset(&valdatum, 0, sizeof(valdatum));
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
412 #endif /* DV_VERSION_MAJOR = 2 */
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
413
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
414 keydatum.data = XSTRING_DATA (key);
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
415 keydatum.size = XSTRING_LENGTH (key);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
416
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
417 #if DB_VERSION_MAJOR == 1
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
418 status = db->db_handle->get (db->db_handle, &keydatum, &valdatum, 0);
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
419 #else
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
420 status = db->db_handle->get (db->db_handle, NULL, &keydatum, &valdatum, 0);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
421 #endif /* DB_VERSION_MAJOR */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 if (!status)
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
424 return make_string ((Bufbyte *) valdatum.data, valdatum.size);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
426 #if DB_VERSION_MAJOR == 1
94
1040fe1366ac Import from CVS: tag xemacs-20-0f2
cvs
parents: 70
diff changeset
427 db->dberrno = (status == 1) ? -1 : errno;
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
428 #else
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
429 db->dberrno = (status < 0) ? -1 : errno;
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
430 #endif /* DB_VERSION_MAJOR */
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
431
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 157
diff changeset
432 return Qnil;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 static int
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
436 berkdb_put (struct database *db,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 Lisp_Object key,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 Lisp_Object val,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 Lisp_Object replace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 DBT keydatum, valdatum;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 int status = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
444 #if DB_VERSION_MAJOR == 2
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
445 /* Always initalize keydatum, valdatum. */
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
446 memset(&keydatum, 0, sizeof(keydatum));
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
447 memset(&valdatum, 0, sizeof(valdatum));
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
448 #endif /* DV_VERSION_MAJOR = 2 */
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
449
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
450 keydatum.data = XSTRING_DATA (key);
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
451 keydatum.size = XSTRING_LENGTH (key);
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
452 valdatum.data = XSTRING_DATA (val);
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
453 valdatum.size = XSTRING_LENGTH (val);
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
454 #if DB_VERSION_MAJOR == 1
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
455 status = db->db_handle->put (db->db_handle, &keydatum, &valdatum,
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
456 NILP (replace) ? R_NOOVERWRITE : 0);
94
1040fe1366ac Import from CVS: tag xemacs-20-0f2
cvs
parents: 70
diff changeset
457 db->dberrno = (status == 1) ? -1 : errno;
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
458 #else
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
459 status = db->db_handle->put (db->db_handle, NULL, &keydatum, &valdatum,
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
460 NILP (replace) ? DB_NOOVERWRITE : 0);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
461 db->dberrno = (status < 0) ? -1 : errno;
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
462 #endif/* DV_VERSION_MAJOR = 2 */
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
463
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 return status;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 static int
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
468 berkdb_remove (struct database *db, Lisp_Object key)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 DBT keydatum;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 int status;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
473 #if DB_VERSION_MAJOR == 2
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
474 /* Always initialize keydatum. */
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
475 memset(&keydatum, 0, sizeof(keydatum));
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
476 #endif /* DV_VERSION_MAJOR = 2 */
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
477
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
478 keydatum.data = XSTRING_DATA (key);
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
479 keydatum.size = XSTRING_LENGTH (key);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
480
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
481 #if DB_VERSION_MAJOR == 1
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
482 status = db->db_handle->del (db->db_handle, &keydatum, 0);
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
483 #else
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
484 status = db->db_handle->del (db->db_handle, NULL, &keydatum, 0);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
485 #endif /* DB_VERSION_MAJOR */
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
486
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 if (!status)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 return 0;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
489
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
490 #if DB_VERSION_MAJOR == 1
94
1040fe1366ac Import from CVS: tag xemacs-20-0f2
cvs
parents: 70
diff changeset
491 db->dberrno = (status == 1) ? -1 : errno;
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
492 #else
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
493 db->dberrno = (status < 0) ? -1 : errno;
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
494 #endif /* DB_VERSION_MAJOR */
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
495
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 static void
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
500 berkdb_map (struct database *db, Lisp_Object func)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 DBT keydatum, valdatum;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 Lisp_Object key, val;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
504 DB *dbp = db->db_handle;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 int status;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
507 #if DB_VERSION_MAJOR == 1
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 for (status = dbp->seq (dbp, &keydatum, &valdatum, R_FIRST);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 status == 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 status = dbp->seq (dbp, &keydatum, &valdatum, R_NEXT))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
512 /* ### Needs mule-izing */
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
513 key = make_string ((Bufbyte *) keydatum.data, keydatum.size);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
514 val = make_string ((Bufbyte *) valdatum.data, valdatum.size);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 call2 (func, key, val);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 }
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
517 #else
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
518 DBC *dbcp;
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
519 /* Initialize the key/data pair so the flags aren't set. */
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
520 memset(&keydatum, 0, sizeof(keydatum));
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
521 memset(&valdatum, 0, sizeof(valdatum));
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
522
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
523 status = dbp->cursor (dbp, NULL, &dbcp);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
524 for (status = dbcp->c_get (dbcp, &keydatum, &valdatum, DB_FIRST);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
525 status == 0;
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
526 status = dbcp->c_get (dbcp, &keydatum, &valdatum, DB_NEXT))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
527 {
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
528 /* ### Needs mule-izing */
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
529 key = make_string ((Bufbyte *) keydatum.data, keydatum.size);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
530 val = make_string ((Bufbyte *) valdatum.data, valdatum.size);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
531 call2 (func, key, val);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
532 }
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
533 dbcp->c_close (dbcp);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
534 #endif /* DB_VERSION_MAJOR */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 static void
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
538 berkdb_close (struct database *db)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
540 if (db->db_handle)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 {
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
542 #if DB_VERSION_MAJOR == 1
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
543 db->db_handle->sync (db->db_handle, 0);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
544 db->db_handle->close (db->db_handle);
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
545 #else
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
546 db->db_handle->sync (db->db_handle, 0);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
547 db->db_handle->close (db->db_handle, 0);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
548 #endif /* DB_VERSION_MAJOR */
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
549 db->db_handle = NULL;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 static DB_FUNCS berk_func_block =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 berkdb_subtype,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 berkdb_type,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 berkdb_get,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 berkdb_put,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 berkdb_remove,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 berkdb_map,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 berkdb_lisp_type,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 berkdb_close,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 berkdb_lasterr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 };
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
565 #endif /* HAVE_BERKELEY_DB */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
567 DEFUN ("database-last-error", Fdatabase_last_error, 0, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 Return the last error associated with database OBJ.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
569 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
570 (obj))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 if (NILP (obj))
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 149
diff changeset
573 return lisp_strerror (errno);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
574
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 CHECK_DATABASE (obj);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
576
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
577 return XDATABASE (obj)->funcs->last_error (XDATABASE (obj));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
580 DEFUN ("open-database", Fopen_database, 1, 5, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 Open database FILE, using database method TYPE and SUBTYPE, with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 access rights ACCESS and permissions MODE. ACCESS can be any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 combination of 'r' 'w' and '+', for read, write, and creation flags.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
584 */
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 157
diff changeset
585 (file, type, subtype, access_, mode))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 {
187
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
587 /* This function can GC */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 Lisp_Object retval = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 int modemask;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 int accessmask = 0;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
591 struct database *dbase = NULL;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
592 char *filename;
187
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
593 struct gcpro gcpro1, gcpro2;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
595 CHECK_STRING (file);
187
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
596 GCPRO2 (file, access_);
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
597 file = Fexpand_file_name (file, Qnil);
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
598 UNGCPRO;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
599 filename = (char *) XSTRING_DATA (file);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 157
diff changeset
601 if (NILP (access_))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 accessmask = O_RDWR | O_CREAT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 char *acc;
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 157
diff changeset
608 CHECK_STRING (access_);
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 157
diff changeset
609 acc = (char *) XSTRING_DATA (access_);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
610
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 if (strchr (acc, '+'))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 accessmask |= O_CREAT;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
613
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 if (strchr (acc, 'r') && strchr (acc, 'w'))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 accessmask |= O_RDWR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 else if (strchr (acc, 'w'))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 accessmask |= O_WRONLY;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 accessmask |= O_RDONLY;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 if (NILP (mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
624 modemask = 0755; /* rwxr-xr-x */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 CHECK_INT (mode);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 modemask = XINT (mode);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 #ifdef HAVE_DBM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 if (NILP (type) || EQ (type, Qdbm))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
635 DBM *dbm = dbm_open (filename, accessmask, modemask);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
636 if (!dbm)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
637 return Qnil;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
638
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
639 dbase = allocate_database ();
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
640 dbase->dbm_handle = dbm;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
641 dbase->type = DB_DBM;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
642 dbase->funcs = &ndbm_func_block;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 goto db_done;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 }
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
645 #endif /* HAVE_DBM */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 #ifdef HAVE_BERKELEY_DB
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 if (NILP (type) || EQ (type, Qberkeley_db))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
650 DBTYPE real_subtype;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
651 DB *db;
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
652 int status;
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
653
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
654 if (EQ (subtype, Qhash) || NILP (subtype))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
655 real_subtype = DB_HASH;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
656 else if (EQ (subtype, Qbtree))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
657 real_subtype = DB_BTREE;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
658 else if (EQ (subtype, Qrecno))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
659 real_subtype = DB_RECNO;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
660 else
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
661 signal_simple_error ("Unsupported subtype", subtype);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
662
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
663 #if DB_VERSION_MAJOR == 1
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
664 db = dbopen (filename, accessmask, modemask, real_subtype, NULL);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
665 if (!db)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
666 return Qnil;
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
667 #else
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
668 /* Berkeley DB Version 2 has only the accessmask DB_CREATE and DB_RDONLY,
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
669 other flags shouldn't be set */
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
670 if (NILP (access_))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
671 {
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
672 accessmask = DB_CREATE;
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
673 }
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
674 else
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
675 {
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
676 char *acc;
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
677 CHECK_STRING (access_);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
678 acc = (char *) XSTRING_DATA (access_);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
679 accessmask = 0;
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
680
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
681 if (strchr (acc, '+'))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
682 accessmask |= DB_CREATE;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
683
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
684 if (strchr (acc, 'r') && !strchr (acc, 'w'))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
685 accessmask |= DB_RDONLY;
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
686 }
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
687 status = db_open (filename, real_subtype, accessmask, modemask, NULL , NULL, &db);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
688 if (status)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
689 return Qnil;
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
690 #endif /* DB_VERSION_MAJOR */
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 203
diff changeset
691
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
692 dbase = allocate_database ();
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
693 dbase->db_handle = db;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
694 dbase->type = DB_BERKELEY;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
695 dbase->funcs = &berk_func_block;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 goto db_done;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 }
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
698 #endif /* HAVE_BERKELEY_DB */
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
699
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 signal_simple_error ("Unsupported database type", type);
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 157
diff changeset
701 return Qnil;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 db_done:
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
704 dbase->live_p = 1;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 dbase->fname = file;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 dbase->mode = modemask;
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 157
diff changeset
707 dbase->access_ = accessmask;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 XSETDATABASE (retval, dbase);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 157
diff changeset
710 return retval;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
713 DEFUN ("put-database", Fput_database, 3, 4, 0, /*
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
714 Store KEY and VAL in DATABASE. If optional fourth arg REPLACE is
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 non-nil, replace any existing entry in the database.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
716 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
717 (key, val, dbase, replace))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
719 CHECK_LIVE_DATABASE (dbase);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 CHECK_STRING (key);
177
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 173
diff changeset
721 CHECK_STRING (val);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
723 {
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
724 int status =
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
725 XDATABASE (dbase)->funcs->put (XDATABASE (dbase), key, val, replace);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
726 return status ? Qt : Qnil;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
727 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
730 DEFUN ("remove-database", Fremove_database, 2, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 Remove KEY from DATABASE.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
732 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
733 (key, dbase))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
735 CHECK_LIVE_DATABASE (dbase);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 CHECK_STRING (key);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
738 return XDATABASE (dbase)->funcs->rem (XDATABASE (dbase), key) ? Qt : Qnil;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 }
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
740
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
741 DEFUN ("get-database", Fget_database, 2, 3, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 Find value for KEY in DATABASE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 If there is no corresponding value, return DEFAULT (defaults to nil).
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
744 */
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 157
diff changeset
745 (key, dbase, default_))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
748 CHECK_LIVE_DATABASE (dbase);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 CHECK_STRING (key);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
751 {
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
752 Lisp_Object retval =
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
753 XDATABASE (dbase)->funcs->get (XDATABASE (dbase), key);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
754 return NILP (retval) ? default_ : retval;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
755 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
758 DEFUN ("map-database", Fmapdatabase, 2, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 Map FUNCTION over entries in DATABASE, calling it with two args,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 each key and value in the database.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
761 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
762 (function, dbase))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
764 CHECK_LIVE_DATABASE (dbase);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
766 XDATABASE (dbase)->funcs->map (XDATABASE (dbase), function);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 177
diff changeset
767
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 syms_of_dbm (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 defsymbol (&Qdatabasep, "databasep");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 #ifdef HAVE_DBM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 defsymbol (&Qdbm, "dbm");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 #ifdef HAVE_BERKELEY_DB
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 defsymbol (&Qberkeley_db, "berkeley-db");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 defsymbol (&Qhash, "hash");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 defsymbol (&Qbtree, "btree");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 defsymbol (&Qrecno, "recno");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
785 DEFSUBR (Fopen_database);
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
786 DEFSUBR (Fdatabasep);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
787 DEFSUBR (Fmapdatabase);
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
788 DEFSUBR (Fput_database);
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
789 DEFSUBR (Fget_database);
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
790 DEFSUBR (Fremove_database);
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
791 DEFSUBR (Fdatabase_type);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
792 DEFSUBR (Fdatabase_subtype);
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
793 DEFSUBR (Fdatabase_last_error);
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
794 DEFSUBR (Fdatabase_live_p);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
795 DEFSUBR (Fdatabase_file_name);
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
796 DEFSUBR (Fclose_database);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 vars_of_dbm (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 #ifdef HAVE_DBM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 Fprovide (Qdbm);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 #ifdef HAVE_BERKELEY_DB
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 Fprovide (Qberkeley_db);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 }