summaryrefslogtreecommitdiff
path: root/chess-scid.el
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2008-09-01 21:49:34 -0400
committerJohn Wiegley <johnw@newartisans.com>2008-09-01 21:49:34 -0400
commit9823c6aafd43f33a19018d83286c262e763e383d (patch)
tree5243d37cc2d6764d88d3ddc5777fdaa5bec1d5b7 /chess-scid.el
parent27ab1491a24c7e3da19aec34e8dd7bdbb674294f (diff)
Report an error if we fail to find the beginning of a game loaded from
ChessDB, or fail to see its end. Also, give up to 10 seconds to wait for the result to come from ChessDB, polling every second to look for new output.
Diffstat (limited to 'chess-scid.el')
-rw-r--r--chess-scid.el39
1 files changed, 28 insertions, 11 deletions
diff --git a/chess-scid.el b/chess-scid.el
index b2e1db4..f622a52 100644
--- a/chess-scid.el
+++ b/chess-scid.el
@@ -6,6 +6,10 @@
;; compact.
;;
+(chess-message-catalog 'english
+ '((failed-load . "Failed to load game %d from ChessDB")
+ (failed-find-end . "Failed to locate end of game %d in ChessDB")))
+
(defvar chess-scid-process)
(make-variable-buffer-local 'chess-scid-process)
@@ -74,21 +78,34 @@
(format "sc_game load %d\n" (car args)))
(accept-process-output chess-scid-process)
(let ((here (point-max))
- (iterations 10))
+ (iterations 10)
+ found)
(process-send-string chess-scid-process "sc_game pgn\n")
(accept-process-output chess-scid-process)
(goto-char here)
(while (and (> (setq iterations (1- iterations)) 0)
- (not (or (looking-at "\\[")
- (and (search-forward "[" nil t)
- (goto-char (match-beginning 0))))))
- (accept-process-output chess-scid-process 1 0 t)))
- (let ((game (chess-pgn-to-game)))
- (when game
- (chess-game-set-data game 'database (current-buffer))
- (chess-game-set-data game 'database-index (car args))
- (chess-game-set-data game 'database-count (chess-scid-handler 'count))
- game)))
+ (not (and (or (looking-at "\\[")
+ (and (search-forward "[" nil t)
+ (goto-char (match-beginning 0))))
+ (setq found t))))
+ (accept-process-output chess-scid-process 1 0 t))
+ (if (not found)
+ (chess-error 'failed-load (car args))
+ (setq iterations 10 found nil here (point))
+ (while (and (> (setq iterations (1- iterations)) 0)
+ (not (and (re-search-forward "\\(\\*\\|1-0\\|0-1\\|1/2-1/2\\)" nil t)
+ (goto-char (match-beginning 0))
+ (setq found t))))
+ (accept-process-output chess-scid-process 1 0 t))
+ (if (not found)
+ (chess-error 'failed-find-end (car args))
+ (goto-char here)
+ (let ((game (chess-pgn-to-game)))
+ (when game
+ (chess-game-set-data game 'database (current-buffer))
+ (chess-game-set-data game 'database-index (car args))
+ (chess-game-set-data game 'database-count (chess-scid-handler 'count))
+ game))))))
((and (eq event 'query)
(eq (car args) 'tree-search))