Mercurial > hg > xemacs-beta
comparison src/database.c @ 149:538048ae2ab8 r20-3b1
Import from CVS: tag r20-3b1
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:36:16 +0200 |
parents | 1040fe1366ac |
children | 59463afc5666 |
comparison
equal
deleted
inserted
replaced
148:f659db2a1f73 | 149:538048ae2ab8 |
---|---|
19 Boston, MA 02111-1307, USA. */ | 19 Boston, MA 02111-1307, USA. */ |
20 | 20 |
21 /* Synched up with: Not in FSF. */ | 21 /* Synched up with: Not in FSF. */ |
22 | 22 |
23 /* Written by Bill Perry */ | 23 /* Written by Bill Perry */ |
24 /* Hacked on by Martin Buchholz */ | |
24 | 25 |
25 #include <config.h> | 26 #include <config.h> |
26 #include "lisp.h" | 27 #include "lisp.h" |
27 #include <errno.h> | 28 #include <errno.h> |
28 | 29 |
29 #ifdef HAVE_DATABASE | 30 #ifndef HAVE_DATABASE |
30 #include <database.h> /* Our include file */ | 31 #error database.c being compiled, but HAVE_DATABASE not defined! |
32 #endif /* HAVE_DATABASE */ | |
33 | |
34 #include <database.h> /* Our include file */ | |
35 | |
31 #ifdef HAVE_BERKELEY_DB | 36 #ifdef HAVE_BERKELEY_DB |
32 #include <db.h> /* Berkeley db access */ | 37 /* Work around Berkeley DB's use of int types which are defined |
33 #endif | 38 slightly differently in the not quite yet standard <inttypes.h>. |
34 #ifdef HAVE_DBM | 39 See db.h for details of why we're resorting to this... */ |
35 #include <ndbm.h> | 40 #ifdef HAVE_INTTYPES_H |
36 #endif | 41 #define __BIT_TYPES_DEFINED__ |
37 | 42 #include <inttypes.h> |
38 Lisp_Object Qdatabasep; | 43 typedef uint8_t u_int8_t; |
39 #ifdef HAVE_DBM | 44 typedef uint16_t u_int16_t; |
40 Lisp_Object Qdbm; | 45 typedef uint32_t u_int32_t; |
41 #endif | 46 #ifdef WE_DONT_NEED_QUADS |
42 #ifdef HAVE_BERKELEY_DB | 47 typedef uint64_t u_int64_t; |
48 #endif /* WE_DONT_NEED_QUADS */ | |
49 #endif /* HAVE_INTTYPES_H */ | |
50 #include DB_H_PATH /* Berkeley db's header file */ | |
43 Lisp_Object Qberkeley_db; | 51 Lisp_Object Qberkeley_db; |
44 Lisp_Object Qhash; | 52 Lisp_Object Qhash; |
45 Lisp_Object Qbtree; | 53 Lisp_Object Qbtree; |
46 Lisp_Object Qrecno; | 54 Lisp_Object Qrecno; |
47 #endif | 55 #endif /* HAVE_BERKELEY_DB */ |
56 | |
57 #ifdef HAVE_DBM | |
58 #include <ndbm.h> | |
59 Lisp_Object Qdbm; | |
60 #endif /* HAVE_DBM */ | |
61 | |
62 Lisp_Object Qdatabasep; | |
48 | 63 |
49 typedef enum { DB_DBM, DB_BERKELEY, DB_UNKNOWN } XEMACS_DB_TYPE; | 64 typedef enum { DB_DBM, DB_BERKELEY, DB_UNKNOWN } XEMACS_DB_TYPE; |
50 | 65 |
51 struct database_struct; | 66 struct database_struct; |
52 | 67 typedef struct database_struct database_struct; |
53 typedef struct _DB_FUNCS | 68 |
69 typedef struct | |
54 { | 70 { |
55 CONST char * (*get_subtype) (struct database_struct *); | 71 CONST char * (*get_subtype) (struct database_struct *); |
56 CONST char * (*get_type) (struct database_struct *); | 72 CONST char * (*get_type) (struct database_struct *); |
57 void * (*open_file) (CONST char *, Lisp_Object, int, int); | 73 void * (*open_file) (CONST char *, Lisp_Object, int, int); |
58 Lisp_Object (*get) (struct database_struct *, Lisp_Object); | 74 Lisp_Object (*get) (struct database_struct *, Lisp_Object); |
72 int mode; | 88 int mode; |
73 int ackcess; | 89 int ackcess; |
74 int dberrno; | 90 int dberrno; |
75 void *db_handle; | 91 void *db_handle; |
76 DB_FUNCS *funcs; | 92 DB_FUNCS *funcs; |
93 #ifdef MULE | |
94 Lisp_Object coding_system; | |
95 #endif | |
77 }; | 96 }; |
78 | 97 |
79 #define XDATABASE(x) XRECORD (x, database, struct database_struct) | 98 #define XDATABASE(x) XRECORD (x, database, struct database_struct) |
80 #define XSETDATABASE(x, p) XSETRECORD (x, p, database) | 99 #define XSETDATABASE(x, p) XSETRECORD (x, p, database) |
81 #define DATABASEP(x) RECORDP (x, database) | 100 #define DATABASEP(x) RECORDP (x, database) |
100 dbase->db_handle = NULL; | 119 dbase->db_handle = NULL; |
101 dbase->ackcess = 0; | 120 dbase->ackcess = 0; |
102 dbase->mode = 0; | 121 dbase->mode = 0; |
103 dbase->dberrno = 0; | 122 dbase->dberrno = 0; |
104 dbase->type = DB_UNKNOWN; | 123 dbase->type = DB_UNKNOWN; |
124 #ifdef MULE | |
125 dbase->coding_system = Fget_coding_system (Qbinary); | |
126 #endif | |
105 return (dbase); | 127 return (dbase); |
106 } | 128 } |
107 | 129 |
108 static Lisp_Object | 130 static Lisp_Object |
109 mark_database (Lisp_Object obj, void (*markobj) (Lisp_Object)) | 131 mark_database (Lisp_Object obj, void (*markobj) (Lisp_Object)) |
320 } | 342 } |
321 | 343 |
322 static Lisp_Object | 344 static Lisp_Object |
323 dbm_lasterr (struct database_struct *dbp) | 345 dbm_lasterr (struct database_struct *dbp) |
324 { | 346 { |
325 char *temp = strerror (dbp->dberrno); | 347 return Fstrerror (make_int (dbp->dberrno)); |
326 return (make_string ((unsigned char *) temp, strlen (temp))); | |
327 } | 348 } |
328 | 349 |
329 static void | 350 static void |
330 dbm_closeit (struct database_struct *db) | 351 dbm_closeit (struct database_struct *db) |
331 { | 352 { |
403 } | 424 } |
404 | 425 |
405 static Lisp_Object | 426 static Lisp_Object |
406 berkdb_lasterr (struct database_struct *dbp) | 427 berkdb_lasterr (struct database_struct *dbp) |
407 { | 428 { |
408 char *temp = strerror (dbp->dberrno); | 429 return Fstrerror (make_int (dbp->dberrno)); |
409 return (make_string ((unsigned char *) temp, strlen (temp))); | |
410 } | 430 } |
411 | 431 |
412 static Lisp_Object | 432 static Lisp_Object |
413 berkdb_get (struct database_struct *db, Lisp_Object key) | 433 berkdb_get (struct database_struct *db, Lisp_Object key) |
414 { | 434 { |
517 (obj)) | 537 (obj)) |
518 { | 538 { |
519 struct database_struct *db; | 539 struct database_struct *db; |
520 | 540 |
521 if (NILP (obj)) | 541 if (NILP (obj)) |
522 { | 542 return Fstrerror (make_int (errno)); |
523 char *temp = strerror (errno); | |
524 return (make_string ((unsigned char *) temp, strlen (temp))); | |
525 } | |
526 | 543 |
527 CHECK_DATABASE (obj); | 544 CHECK_DATABASE (obj); |
528 db = XDATABASE (obj); | 545 db = XDATABASE (obj); |
529 return (db->funcs->last_error (db)); | 546 return (db->funcs->last_error (db)); |
530 } | 547 } |
739 #endif | 756 #endif |
740 #ifdef HAVE_BERKELEY_DB | 757 #ifdef HAVE_BERKELEY_DB |
741 Fprovide (Qberkeley_db); | 758 Fprovide (Qberkeley_db); |
742 #endif | 759 #endif |
743 } | 760 } |
744 #endif /* HAVE_DATABASE */ |