summaryrefslogtreecommitdiff
path: root/chess-database.el
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2002-04-28 16:09:14 +0000
committerJohn Wiegley <johnw@newartisans.com>2002-04-28 16:09:14 +0000
commit80ab4cec14452a641e741d372037dafda16ee871 (patch)
tree352324dc62ffbd3c9c651a7154a2e88338144641 /chess-database.el
parent7248e5c89f6d53d3f2a4ecf511167af929241f76 (diff)
*** no comment ***
Diffstat (limited to 'chess-database.el')
-rw-r--r--chess-database.el41
1 files changed, 27 insertions, 14 deletions
diff --git a/chess-database.el b/chess-database.el
index 9c48297..4903884 100644
--- a/chess-database.el
+++ b/chess-database.el
@@ -3,6 +3,17 @@
;; Basic code for manipulating game databases
;;
+(require 'chess-message)
+
+(defgroup chess-database nil
+ "Generic interface to chess database modules."
+ :group 'chess)
+
+(defcustom chess-database-modules '(chess-scid chess-file)
+ "List of database modules to try when `chess-database-open' is called."
+ :type '(repeat (symbol :tag "Module"))
+ :group 'chess-database)
+
(defvar chess-database-handler nil)
(make-variable-buffer-local 'chess-database-handler)
@@ -10,7 +21,7 @@
(chess-message-catalog 'english
'((no-such-database . "There is no such chess database module '%s'")))
-(defun chess-database-open (module file)
+(defun chess-database-do-open (module file)
"Returns the opened database object, or nil."
(let* ((name (symbol-name module))
(handler (intern-soft (concat name "-handler")))
@@ -24,6 +35,19 @@
(add-hook 'after-revert-hook 'chess-database-rescan nil t)
(current-buffer)))))
+(defun chess-database-open (file &optional module)
+ "Returns the opened database object, or nil."
+ (if module
+ (chess-database-do-open module file)
+ (let (result)
+ (setq module chess-database-modules)
+ (while module
+ (if (and (require (car module) nil t)
+ (setq result (chess-database-do-open (car module) file)))
+ (setq module nil)
+ (setq module (cdr module))))
+ result)))
+
(defsubst chess-database-command (database event &rest args)
(with-current-buffer database
(apply chess-database-handler event args)))
@@ -46,19 +70,8 @@
(defun chess-database-count (database)
(chess-database-command database 'count))
-(defun chess-database-read (database index-or-moniker)
- (if (integerp index-or-moniker)
- (chess-database-command database 'read index-or-moniker)
- (if (string-match "\\`\\([^:]+\\):\\([^#]+\\)#\\([0-9]+\\)\\'"
- index-or-moniker)
- (let* ((type (match-string 1 index-or-moniker))
- (path (match-string 2 index-or-moniker))
- (index (string-to-int
- (match-string 3 index-or-moniker)))
- (db (chess-database-open
- (intern (concat "chess-" type)) path)))
- (if db
- (chess-database-read db index))))))
+(defun chess-database-read (database index)
+ (chess-database-command database 'read index))
(defun chess-database-write (database game)
(chess-database-command database 'write game))