X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=gnushogi%2Fbook.c;h=0e9560783658aa73f9cd5ab7f02f9d0891c35c9e;hb=8e08526b483296c7c932521fa9307ef0ee48f259;hp=6df98e6988866aca0b0f8daa1664d9ad3d48cdf5;hpb=31a87931cd4644f17e21114612ae2f348660bac1;p=gnushogi.git diff --git a/gnushogi/book.c b/gnushogi/book.c index 6df98e6..0e95607 100644 --- a/gnushogi/book.c +++ b/gnushogi/book.c @@ -576,46 +576,45 @@ static ULONG currentoffset; #define MAXOFFSET(B) ((B.booksize - 1) * sizeof_gdxdata + sizeof_gdxadmin) -#define HashOffset(hashkey, B) \ -{ \ - currentoffset = ((ULONG)hashkey % B.booksize) \ - * sizeof_gdxdata + sizeof_gdxadmin; \ +static void HashOffset(ULONG hashkey, struct gdxadmin *B) +{ + currentoffset = (hashkey % B->booksize) * sizeof_gdxdata + sizeof_gdxadmin; } -#define NextOffset(B) \ -{ \ - currentoffset += sizeof_gdxdata; \ - if (currentoffset > B.maxoffset) \ - currentoffset = sizeof_gdxadmin; \ +static void NextOffset(struct gdxadmin *B) +{ + currentoffset += sizeof_gdxdata; + if (currentoffset > B->maxoffset) + currentoffset = sizeof_gdxadmin; } -#define WriteAdmin() \ -{ \ - lseek(gfd, 0, 0); \ - write(gfd, (char *)&ADMIN, sizeof_gdxadmin); \ +static void WriteAdmin(void) +{ + lseek(gfd, 0, SEEK_SET); + write(gfd, (char *)&ADMIN, sizeof_gdxadmin); } -#define WriteData() \ -{ \ - if (mustwrite ) \ - { \ - lseek(gfd, currentoffset, 0); \ - write(gfd, (char *)&DATA, sizeof_gdxdata); \ - mustwrite = false; \ - } \ +static void WriteData(int *mustwrite) +{ + if (*mustwrite) + { + lseek(gfd, currentoffset, SEEK_SET); + write(gfd, (char *)&DATA, sizeof_gdxdata); + *mustwrite = false; + } } static int ReadAdmin(void) { - lseek(gfd, 0, 0); + lseek(gfd, 0, SEEK_SET); return (sizeof_gdxadmin == read(gfd, (char *)&ADMIN, sizeof_gdxadmin)); } static int ReadData(struct gdxdata *DATA) { - lseek(gfd, currentoffset, 0); + lseek(gfd, currentoffset, SEEK_SET); return (sizeof_gdxdata == read(gfd, (char *)DATA, sizeof_gdxdata)); } @@ -736,8 +735,8 @@ GetOpenings(void) * exist from some other opening. */ - WriteData(); - HashOffset(bhashkey, B); + WriteData(&mustwrite); + HashOffset(bhashkey, &B); first = true; while (true) @@ -774,12 +773,12 @@ GetOpenings(void) { DATA.flags &= (~LASTMOVE); mustwrite = true; - WriteData(); + WriteData(&mustwrite); } } } - NextOffset(B); + NextOffset(&B); first = false; } @@ -821,14 +820,14 @@ GetOpenings(void) { /* reset for next opening */ games++; - WriteData(); + WriteData(&mustwrite); RESET(); i = 0; side = black; } } - WriteData(); + WriteData(&mustwrite); fclose(fd); /* write admin rec with counts */ ADMIN.bookcount = B.bookcount; @@ -923,7 +922,7 @@ OpeningBook(unsigned short *hint) } x = 0; - HashOffset(hashkey, B); + HashOffset(hashkey, &B); #ifdef BOOKTEST printf("looking for book move, bhashbd = 0x%lx bhashkey = 0x%x\n", (ULONG)hashbd, HashValue(hashkey)); @@ -949,7 +948,7 @@ OpeningBook(unsigned short *hint) break; } - NextOffset(B); + NextOffset(&B); } #ifdef BOOKTEST