comparison 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
comparison
equal deleted inserted replaced
208:f427b8ec4379 209:41ff10fd062f
110 #define XDATABASE(x) XRECORD (x, database, struct database) 110 #define XDATABASE(x) XRECORD (x, database, struct database)
111 #define XSETDATABASE(x, p) XSETRECORD (x, p, database) 111 #define XSETDATABASE(x, p) XSETRECORD (x, p, database)
112 #define DATABASEP(x) RECORDP (x, database) 112 #define DATABASEP(x) RECORDP (x, database)
113 #define GC_DATABASEP(x) GC_RECORDP (x, database) 113 #define GC_DATABASEP(x) GC_RECORDP (x, database)
114 #define CHECK_DATABASE(x) CHECK_RECORD (x, database) 114 #define CHECK_DATABASE(x) CHECK_RECORD (x, database)
115 #define CONCHECK_DATABASE(x) CONCHECK_RECORD (x, database)
115 #define DATABASE_LIVE_P(x) (x->live_p) 116 #define DATABASE_LIVE_P(x) (x->live_p)
116 static Lisp_Object mark_database (Lisp_Object, void (*) (Lisp_Object)); 117 static Lisp_Object mark_database (Lisp_Object, void (*) (Lisp_Object));
117 static void print_database (Lisp_Object, Lisp_Object, int); 118 static void print_database (Lisp_Object, Lisp_Object, int);
118 static void finalize_database (void *, int); 119 static void finalize_database (void *, int);
119 DEFINE_LRECORD_IMPLEMENTATION ("database", database, 120 DEFINE_LRECORD_IMPLEMENTATION ("database", database,
127 signal_simple_error ("Attempting to access closed database", db); \ 128 signal_simple_error ("Attempting to access closed database", db); \
128 } while (0) 129 } while (0)
129 130
130 131
131 static struct database * 132 static struct database *
132 new_database (void) 133 allocate_database (void)
133 { 134 {
134 struct database *dbase = 135 struct database *dbase =
135 alloc_lcrecord_type (struct database, lrecord_database); 136 alloc_lcrecord_type (struct database, lrecord_database);
136 137
137 dbase->fname = Qnil; 138 dbase->fname = Qnil;
162 } 163 }
163 164
164 static void 165 static void
165 print_database (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag) 166 print_database (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
166 { 167 {
168 char buf[64];
167 struct database *dbase = XDATABASE (obj); 169 struct database *dbase = XDATABASE (obj);
168 char buf[200];
169 170
170 if (print_readably) 171 if (print_readably)
171 { 172 error ("printing unreadable object #<database 0x%x>", dbase->header.uid);
172 error ("printing unreadable object #<database 0x%x>", dbase->header.uid); 173
173 } 174 write_c_string ("#<database \"", printcharfun);
174 else 175 print_internal (dbase->fname, printcharfun, 0);
175 { 176 sprintf (buf, "\" (%s/%s/%s) 0x%x>",
176 sprintf (buf, "#<database \"%s\" (%s/%s/%s) 0x%x>", 177 dbase->funcs->get_type (dbase),
177 XSTRING_DATA (dbase->fname), 178 dbase->funcs->get_subtype (dbase),
178 dbase->funcs->get_type (dbase), 179 (!DATABASE_LIVE_P (dbase) ? "closed" :
179 dbase->funcs->get_subtype (dbase), 180 (dbase->access_ & O_WRONLY) ? "writeonly" :
180 (!DATABASE_LIVE_P (dbase) ? "closed" : 181 (dbase->access_ & O_RDWR) ? "readwrite" : "readonly"),
181 (dbase->access_ & O_WRONLY) ? "writeonly" : 182 dbase->header.uid);
182 (dbase->access_ & O_RDWR) ? "readwrite" : "readonly"), 183 write_c_string (buf, printcharfun);
183 dbase->header.uid);
184 write_c_string (buf, printcharfun);
185 }
186 } 184 }
187 185
188 static void 186 static void
189 finalize_database (void *header, int for_disksave) 187 finalize_database (void *header, int for_disksave)
190 { 188 {
636 { 634 {
637 DBM *dbm = dbm_open (filename, accessmask, modemask); 635 DBM *dbm = dbm_open (filename, accessmask, modemask);
638 if (!dbm) 636 if (!dbm)
639 return Qnil; 637 return Qnil;
640 638
641 dbase = new_database (); 639 dbase = allocate_database ();
642 dbase->dbm_handle = dbm; 640 dbase->dbm_handle = dbm;
643 dbase->type = DB_DBM; 641 dbase->type = DB_DBM;
644 dbase->funcs = &ndbm_func_block; 642 dbase->funcs = &ndbm_func_block;
645 goto db_done; 643 goto db_done;
646 } 644 }
689 status = db_open (filename, real_subtype, accessmask, modemask, NULL , NULL, &db); 687 status = db_open (filename, real_subtype, accessmask, modemask, NULL , NULL, &db);
690 if (status) 688 if (status)
691 return Qnil; 689 return Qnil;
692 #endif /* DB_VERSION_MAJOR */ 690 #endif /* DB_VERSION_MAJOR */
693 691
694 dbase = new_database (); 692 dbase = allocate_database ();
695 dbase->db_handle = db; 693 dbase->db_handle = db;
696 dbase->type = DB_BERKELEY; 694 dbase->type = DB_BERKELEY;
697 dbase->funcs = &berk_func_block; 695 dbase->funcs = &berk_func_block;
698 goto db_done; 696 goto db_done;
699 } 697 }