comparison src/database.c @ 5118:e0db3c197671 ben-lisp-object

merge up to latest default branch, doesn't compile yet
author Ben Wing <ben@xemacs.org>
date Sat, 26 Dec 2009 21:18:49 -0600
parents 3742ea8250b5 0e1461b592ce
children d877c14318b3
comparison
equal deleted inserted replaced
5117:3742ea8250b5 5118:e0db3c197671
29 #include <config.h> 29 #include <config.h>
30 #include "lisp.h" 30 #include "lisp.h"
31 31
32 #include "sysfile.h" 32 #include "sysfile.h"
33 #include "buffer.h" 33 #include "buffer.h"
34 #include "file-coding.h"
34 35
35 #ifndef HAVE_DATABASE 36 #ifndef HAVE_DATABASE
36 #error HAVE_DATABASE not defined!! 37 #error HAVE_DATABASE not defined!!
37 #endif 38 #endif
38 39
43 slightly differently in the not quite yet standard <inttypes.h>. 44 slightly differently in the not quite yet standard <inttypes.h>.
44 See db.h for details of why we're resorting to this... */ 45 See db.h for details of why we're resorting to this... */
45 /* glibc 2.1 doesn't have this problem with DB 2.x */ 46 /* glibc 2.1 doesn't have this problem with DB 2.x */
46 #if !(defined __GLIBC__ && __GLIBC_MINOR__ >= 1) 47 #if !(defined __GLIBC__ && __GLIBC_MINOR__ >= 1)
47 #ifdef HAVE_INTTYPES_H 48 #ifdef HAVE_INTTYPES_H
49 #ifndef __BIT_TYPES_DEFINED__
48 #define __BIT_TYPES_DEFINED__ 50 #define __BIT_TYPES_DEFINED__
51 #endif
49 #include <inttypes.h> 52 #include <inttypes.h>
50 #if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__APPLE__) 53 #if !HAVE_U_INT8_T
51 typedef uint8_t u_int8_t; 54 typedef uint8_t u_int8_t;
55 #endif
56 #if !HAVE_U_INT16_T
52 typedef uint16_t u_int16_t; 57 typedef uint16_t u_int16_t;
58 #endif
59 #if !HAVE_U_INT32_T
53 typedef uint32_t u_int32_t; 60 typedef uint32_t u_int32_t;
61 #endif
54 #ifdef WE_DONT_NEED_QUADS 62 #ifdef WE_DONT_NEED_QUADS
63 #if !HAVE_U_INT64_T
55 typedef uint64_t u_int64_t; 64 typedef uint64_t u_int64_t;
65 #endif
56 #endif /* WE_DONT_NEED_QUADS */ 66 #endif /* WE_DONT_NEED_QUADS */
57 #endif /* __FreeBSD__ */
58 #endif /* HAVE_INTTYPES_H */ 67 #endif /* HAVE_INTTYPES_H */
59 #endif /* !(defined __GLIBC__ && __GLIBC_MINOR__ >= 1) */ 68 #endif /* !(defined __GLIBC__ && __GLIBC_MINOR__ >= 1) */
60 /* Berkeley DB wants __STDC__ to be defined; else if does `#define const' */ 69 /* Berkeley DB wants __STDC__ to be defined; else if does `#define const' */
61 #if ! defined (__STDC__) && ! defined(__cplusplus) 70 #if ! defined (__STDC__) && ! defined(__cplusplus)
62 #define __STDC__ 0 71 #define __STDC__ 0
74 Lisp_Object Qqueue; 83 Lisp_Object Qqueue;
75 #endif 84 #endif
76 #endif /* HAVE_BERKELEY_DB */ 85 #endif /* HAVE_BERKELEY_DB */
77 86
78 #ifdef HAVE_DBM 87 #ifdef HAVE_DBM
79 #include <ndbm.h> 88 #include NDBM_H_FILE
80 Lisp_Object Qdbm; 89 Lisp_Object Qdbm;
81 #endif /* HAVE_DBM */ 90 #endif /* HAVE_DBM */
82 91
83 Lisp_Object Vdatabase_coding_system; 92 Lisp_Object Vdatabase_coding_system;
84 93
172 181
173 write_fmt_string_lisp (printcharfun, "#<database \"%s\" (%s/%s/", 182 write_fmt_string_lisp (printcharfun, "#<database \"%s\" (%s/%s/",
174 3, db->fname, db->funcs->get_type (db), 183 3, db->fname, db->funcs->get_type (db),
175 db->funcs->get_subtype (db)); 184 db->funcs->get_subtype (db));
176 185
177 write_fmt_string (printcharfun, "%s) 0x%x>", 186 write_fmt_string (printcharfun, "%s) ",
178 (!DATABASE_LIVE_P (db) ? "closed" : 187 (!DATABASE_LIVE_P (db) ? "closed" :
179 (db->access_ & O_WRONLY) ? "writeonly" : 188 (db->access_ & O_WRONLY) ? "writeonly" :
180 (db->access_ & O_RDWR) ? "readwrite" : "readonly"), 189 (db->access_ & O_RDWR) ? "readwrite" : "readonly"));
181 db->header.uid); 190
191 write_fmt_string_lisp (printcharfun, "coding: %s ", 1,
192 XSYMBOL_NAME (XCODING_SYSTEM_NAME
193 (db->coding_system)));
194
195 write_fmt_string (printcharfun, "0x%x>", db->header.uid);
182 } 196 }
183 197
184 static void 198 static void
185 finalize_database (void *header, int for_disksave) 199 finalize_database (void *header, int for_disksave)
186 { 200 {
193 wrap_database (db)); 207 wrap_database (db));
194 } 208 }
195 db->funcs->close (db); 209 db->funcs->close (db);
196 } 210 }
197 211
198 DEFINE_NONDUMPABLE_LISP_OBJECT ("database", database, 212 DEFINE_NODUMP_LISP_OBJECT ("database", database,
199 mark_database, print_database, 213 mark_database, print_database,
200 finalize_database, 0, 0, 214 finalize_database, 0, 0,
201 database_description, 215 database_description,
202 Lisp_Database); 216 Lisp_Database);
203 217
271 for (keydatum = dbm_firstkey (db->dbm_handle); 285 for (keydatum = dbm_firstkey (db->dbm_handle);
272 keydatum.dptr != NULL; 286 keydatum.dptr != NULL;
273 keydatum = dbm_nextkey (db->dbm_handle)) 287 keydatum = dbm_nextkey (db->dbm_handle))
274 { 288 {
275 valdatum = dbm_fetch (db->dbm_handle, keydatum); 289 valdatum = dbm_fetch (db->dbm_handle, keydatum);
276 key = make_ext_string (keydatum.dptr, keydatum.dsize, 290 key = make_ext_string ((Extbyte *) keydatum.dptr, keydatum.dsize,
277 db->coding_system); 291 db->coding_system);
278 val = make_ext_string (valdatum.dptr, valdatum.dsize, 292 val = make_ext_string ((Extbyte *) valdatum.dptr, valdatum.dsize,
279 db->coding_system); 293 db->coding_system);
280 call2 (func, key, val); 294 call2 (func, key, val);
281 } 295 }
282 } 296 }
283 297
290 ALLOCA, (keydatum.dptr, keydatum.dsize), 304 ALLOCA, (keydatum.dptr, keydatum.dsize),
291 db->coding_system); 305 db->coding_system);
292 valdatum = dbm_fetch (db->dbm_handle, keydatum); 306 valdatum = dbm_fetch (db->dbm_handle, keydatum);
293 307
294 return (valdatum.dptr 308 return (valdatum.dptr
295 ? make_ext_string (valdatum.dptr, valdatum.dsize, 309 ? make_ext_string ((Extbyte *) valdatum.dptr, valdatum.dsize,
296 db->coding_system) 310 db->coding_system)
297 : Qnil); 311 : Qnil);
298 } 312 }
299 313
300 static int 314 static int
644 } 658 }
645 659
646 if (NILP (codesys)) 660 if (NILP (codesys))
647 codesys = Vdatabase_coding_system; 661 codesys = Vdatabase_coding_system;
648 662
649 codesys = get_coding_system_for_text_file (Vdatabase_coding_system, 1); 663 codesys = get_coding_system_for_text_file (codesys, 0);
650 664
651 #ifdef HAVE_DBM 665 #ifdef HAVE_DBM
652 if (NILP (type) || EQ (type, Qdbm)) 666 if (NILP (type) || EQ (type, Qdbm))
653 { 667 {
654 DBM *dbase = dbm_open (filename, accessmask, modemask); 668 DBM *dbase = dbm_open (filename, accessmask, modemask);