5 void AnnotatePositionHTML(TREE * RESTRICT tree, int wtm, FILE * annotate_out)
7 - char filename[32], html_piece;
8 + char filename[64], html_piece;
11 { 'q', 'r', 'b', 0, 'k', 'n', 'p', 0, 'P', 'N', 'K', 0, 'B', 'R', 'Q' };
13 for (rank = RANK8; rank >= RANK1; rank--) {
14 fprintf(annotate_out, "<TR>\n");
15 for (file = FILEA; file <= FILEH; file++) {
16 - (void) strcpy(filename, "bitmaps/");
17 + (void) strcpy(filename, "/usr/share/crafty/bitmaps/");
18 if ((rank + file) % 2)
19 (void) strcat(filename, "w");
22 fprintf(annotate_out, "\\usepackage{times}\n");
23 fprintf(annotate_out, "\\usepackage{a4wide}\n");
24 fprintf(annotate_out, "\\usepackage{chess}\n");
25 - fprintf(annotate_out, "\\usepackage{bdfchess}\n");
26 + fprintf(annotate_out, "%% \\usepackage{bdfchess}\n");
27 fprintf(annotate_out, "\\usepackage[T1]{fontenc}\n");
28 fprintf(annotate_out, "\n");
29 fprintf(annotate_out, "\\setlength{\\columnsep}{7mm}\n");
34 static lock_t lockDecode;
36 -extern "C" int TB_CRC_CHECK = 0;
37 +extern "C" int TB_CRC_CHECK;
38 +int TB_CRC_CHECK = 0;
39 static int cCompressed = 0;
40 static decode_block *rgpdbDecodeBlocks[CPUS];
45 *******************************************************************************
49 +#if defined(__alpha__)
51 # include <machine/builtins.h>
59 +#include <sys/stat.h>
60 +#include <sys/types.h>
65 #if defined(UNIX) || defined(AMIGA)
66 @@ -3230,8 +3234,58 @@
68 char crafty_rc_file_spec[FILENAME_MAX];
70 -/* Collect environmental variables */
71 - char *directory_spec = getenv("CRAFTY_BOOK_PATH");
73 + char *directory_spec;
76 + set log_path & rc_path to some reasonable value
77 + create default .craftyrc
80 + char l[128], *h = getenv("HOME");
84 + if(!h || strlen(h) > 100) h = "/tmp";
86 + sprintf(log_path, "%s/%s", h, ".crafty");
88 + if(stat(log_path, &st) || !S_ISDIR(st.st_mode)) {
89 + mkdir(log_path, 0755);
92 + sprintf(l, "%s/.craftyrc", rc_path);
94 + if((f = fopen(l, "w"))) {
95 + fprintf(f, "egtb\n");
102 + set book_path to some reasonable value
105 + char l[128], *h = getenv("HOME");
108 + if(!h || strlen(h) > 100) h = "/tmp";
109 + sprintf(book_path, "%s/%s", h, ".crafty");
111 + if(stat(book_path, &st) || !S_ISDIR(st.st_mode)) {
112 + mkdir(book_path, 0755);
115 + sprintf(l, "%s/book.bin", book_path);
116 + if(lstat(l, &st)) symlink("/usr/share/crafty/book.bin", l);
118 + sprintf(l, "%s/books.bin", book_path);
119 + if(lstat(l, &st)) symlink("/usr/share/crafty/books.bin", l);
122 + /* Collect environmental variables */
123 + directory_spec=getenv("CRAFTY_BOOK_PATH");
125 #if defined(NUMA) && defined(LINUX)
126 if (numa_available() >= 0) {
130 # with the large egtb.cpp code/templates.
133 +ARCH = $(shell uname -m | sed -e 's/^i./i3/')
135 +opt = -DCOMPACT_ATTACKS -DUSE_ATTACK_FUNCTIONS -DFAST -DDGT -DEGTB6
137 +# EGTB code seems to have problems with SMP
138 +ifneq ($(findstring $(ARCH),i386),)
139 + opt += -O2 -DUSE_ASSEMBLY_A -DUSE_ASSEMBLY_B # -DSMP -DCPUS=4
142 + opt += -O # -DSMP -DCPUS=4 -DMUTEX
147 - $(MAKE) -j linux-icc
150 @echo "You must specify the system which you want to compile for:"
153 LDFLAGS='$(LDFLAGS) +O3 +Onolimit $(CFLAGS)' \
157 + $(MAKE) target=LINUX \
159 + CFLAGS='$(CFLAGS) -Wall -pipe -D_REENTRANT' \
160 + CXFLAGS='$(CFLAGS) \
161 + -fforce-mem -fomit-frame-pointer' \
162 + LDFLAGS='$(LDFLAGS) -lpthread' \
166 $(MAKE) target=LINUX \
174 +#define safe_strcpy(dst, src) strncpy(dst, src, sizeof dst - 1)[sizeof dst - 1] = 0
176 /* last modified 10/10/05 */
178 *******************************************************************************
183 - strcpy(filename, args[2]);
184 + safe_strcpy(filename, args[2]);
185 strcat(filename, ".cpf");
186 file = fopen(filename, "w");
188 @@ -1129,7 +1131,7 @@
189 movenum = shared->move_number;
192 - strcpy(text, args[1]);
193 + safe_strcpy(text, args[1]);
194 sprintf(buffer, "reset %d", movenum);
197 @@ -1357,7 +1359,7 @@
198 char *readstat = (char *) -1;
201 - helpfile = fopen("crafty.hlp", "r");
202 + helpfile = fopen("/usr/share/crafty/crafty.hlp", "r");
204 printf("ERROR. Unable to open \"crafty.hlp\" -- help unavailable\n");
206 @@ -1858,7 +1860,7 @@
207 printf("file does not exist.\n");
210 - strcpy(title, args[2]);
211 + safe_strcpy(title, args[2]);
212 while (!feof(prob_file)) {
213 readstat = fgets(buffer, 128, prob_file);
215 @@ -2154,10 +2156,10 @@
219 - strcpy(pgn_white, args[1]);
220 + safe_strcpy(pgn_white, args[1]);
221 sprintf(pgn_black, "Crafty %s", version);
223 - strcpy(pgn_black, args[1]);
224 + safe_strcpy(pgn_black, args[1]);
225 sprintf(pgn_white, "Crafty %s", version);
227 Print(128, "Crafty %s vs %s\n", version, args[1]);
228 @@ -2368,14 +2370,14 @@
230 if (!strchr(args[1], '(')) {
231 if (strstr(args[0], "bookpath"))
232 - strcpy(book_path, args[1]);
233 + safe_strcpy(book_path, args[1]);
234 else if (strstr(args[0], "perspath"))
235 - strcpy(personality_path, args[1]);
236 + safe_strcpy(personality_path, args[1]);
237 else if (strstr(args[0], "logpath"))
238 - strcpy(log_path, args[1]);
239 + safe_strcpy(log_path, args[1]);
241 else if (strstr(args[0], "tbpath")) {
242 - strcpy(tb_path, args[1]);
243 + safe_strcpy(tb_path, args[1]);
244 EGTBlimit = IInitializeTb(tb_path);
245 Print(128, "%d piece tablebase files found\n", EGTBlimit);
246 if (0 != cbEGTBCompBytes)
247 @@ -2398,12 +2400,12 @@
248 if (strchr(args[1], ')')) {
249 *strchr(args[1], ')') = 0;
250 if (strstr(args[0], "bookpath"))
251 - strcpy(book_path, args[1] + 1);
252 + safe_strcpy(book_path, args[1] + 1);
253 else if (strstr(args[0], "logpath"))
254 - strcpy(log_path, args[1] + 1);
255 + safe_strcpy(log_path, args[1] + 1);
257 else if (strstr(args[0], "tbpath")) {
258 - strcpy(tb_path, args[1] + 1);
259 + safe_strcpy(tb_path, args[1] + 1);
260 EGTBlimit = IInitializeTb(tb_path);
261 Print(128, "%d piece tablebase files found\n", EGTBlimit);
262 if (0 != cbEGTBCompBytes)
268 # The program used for Sound Output
269 -my $playprg = "/usr/bin/esdplay";
270 +my $playprg = "/usr/bin/play";
272 # Where the sound files are located
273 -my $soundpath = "/opt/chess/sound";
274 +my $soundpath = "/usr/share/crafty/sound";
275 # Which language to use (each supported language is in a separate
276 # subdir of $soundpath)
277 -my $language = "english";
278 +my $language = "en";
280 # The move sent by crafty
283 # Set soundpath to the correct language
284 $soundpath = $soundpath . "/" . $language;
297 + 'O-O-O' => '0-0-0',
298 + 'Stalemate' => 'Stalemate',
299 + 'Drawaccept' => 'Drawaccept',
300 + 'Drawoffer' => 'Drawoffer',
301 + 'Resign' => 'Resign'
304 # First check some specials
305 -if (($move =~ /O-O/) || ($move eq "Stalemate") ||
306 - ($move eq "Drawaccept") || ($move eq "Drawoffer") ||
307 - ($move eq "Resign") || ($move eq "Checkmate")) {
308 - system("$playprg $soundpath/$move.wav");
311 + system("$playprg $soundpath/$moves{$move}.wav");
313 # Handle all normal moves. All that needs to be done is announce
314 # each character sent by crafty alone. Set some pause beteween each
317 for (my $i=0; $i<length($move); $i++) {
318 my $char = substr $move, $i, 1;
320 + if($i == 0 && $char =~ /[a-h]/) {
321 + system("$playprg $soundpath/Pawn.wav");
324 if ($char =~ /[^=]/) {
326 - system("$playprg $soundpath/x.wav");
327 + system("$playprg $soundpath/takes.wav");
328 system("usleep 400000");
330 elsif ($char =~ /#/) {
332 elsif ($char =~ /\+/) {
333 system("$playprg $soundpath/Check.wav");
335 + elsif ($char =~ /[1-8]/) {
336 + system("$playprg $soundpath/${char}from.wav");
338 + elsif ($char =~ /[a-h]/) {
339 + system("$playprg $soundpath/\U${char}\Efrom.wav");
341 + elsif ($char =~ /[QKNBR]/) {
342 + system("$playprg $soundpath/$piece{$char}.wav");
345 system("$playprg $soundpath/$char".".wav");
350 + system("$playprg $soundpath/click.wav");
355 @@ -133,10 +133,12 @@
356 float BookIn32f(unsigned char *ch)
359 - float *v2 = (float *) &v1;
362 v1 = (ch[3] << 24) | (ch[2] << 16) | (ch[1] << 8) | ch[0];
364 + memcpy(&v2, &v1, sizeof v2);
370 @@ -201,14 +203,15 @@
372 unsigned char *BookOut32f(float val)
375 - int *v2 = (int *) &v1;
378 + memcpy(&v2, &val, sizeof v2);
380 + convert_buff[3] = (v2 >> 24) & 0xff;
381 + convert_buff[2] = (v2 >> 16) & 0xff;
382 + convert_buff[1] = (v2 >> 8) & 0xff;
383 + convert_buff[0] = v2 & 0xff;
386 - convert_buff[3] = (*v2 >> 24) & 0xff;
387 - convert_buff[2] = (*v2 >> 16) & 0xff;
388 - convert_buff[1] = (*v2 >> 8) & 0xff;
389 - convert_buff[0] = *v2 & 0xff;
390 return (convert_buff);
393 @@ -1547,14 +1550,16 @@
394 if (vb & shared->display_options)
399 if (shared->time_limit > 99 || shared->tc_time_remaining > 6000 || vb == 4095) {
402 vfprintf(log_file, fmt, ap);
410 char *PrintKM(size_t val, int realK)