From dd54cd392e6906b7a19b1ad57ed1e5d748ad6c7c Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Mon, 8 Aug 2011 09:58:31 +0200 Subject: [PATCH] Allow deletion of last book move The book-edit function refused to delete the entiremove list, for no good reason. This limitation now has been lifted. Also the error message that the key for the current book entries is different from that of the currentposition has been suppressed if there were no entries found for the current position (so that the book is positioned at the next key), so that it is possible to add moves from scratch. --- book.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) diff --git a/book.c b/book.c index 4bc2521..3650b01 100644 --- a/book.c +++ b/book.c @@ -580,6 +580,7 @@ int TextToMoves(char *text, int moveNum, entry_t *entries) float dummy; int width = BOARD_RGHT - BOARD_LEFT; + entries[0].key = hashKey; // make sure key is returned even if no moves while((i=sscanf(text, "%f%%%d", &dummy, &w))==2 || (i=sscanf(text, "%d", &w))==1) { if(i == 2) text = strchr(text, '%') + 1; // skip percentage if(w == 1) text = strstr(text, "1 ") + 2; // skip weight that could be recognized as move number one @@ -651,11 +652,11 @@ void SaveToBook(char *text) int count = TextToMoves(text, currentMove, entries); int offset, i, len1=0, len2, readpos=0, writepos=0; FILE *f; - if(!count) return; + if(!count && !currentCount) return; f=fopen(appData.polyglotBook, "rb+"); if(!f){ DisplayError("Polyglot book not valid", 0); return; } offset=find_key(f, entries[0].key, &entry); - if(entries[0].key != entry.key) { + if(entries[0].key != entry.key && currentCount) { DisplayError("Hash keys are different", 0); fclose(f); return; @@ -680,3 +681,4 @@ void SaveToBook(char *text) } fclose(f); } + -- 1.7.0.4