From 9823c6aafd43f33a19018d83286c262e763e383d Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Mon, 1 Sep 2008 21:49:34 -0400 Subject: 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. --- chess-scid.el | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) (limited to 'chess-scid.el') 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)) -- cgit v1.2.3