annotate src/database.c @ 187:b405438285a2 r20-3b20

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