--- /dev/null
+--- Sjeng-Free-11.2/book.c.deb 2001-07-16 20:04:48.000000000 +0800
++++ Sjeng-Free-11.2/book.c 2005-07-03 19:43:03.000000000 +0800
+@@ -38,6 +40,10 @@
+ #define book_solid 4 /* = */
+ #define book_murky 5 /* ?! */
+
++#ifndef BOOK_PATH
++#define BOOK_PATH "/usr/share/games/sjeng"
++#endif
++
+ int init_book (void) {
+
+ /* simply read all the book moves into a book array. The book will be
+@@ -63,27 +69,27 @@
+
+ if (Variant == Normal)
+ {
+- if ((f_book = fopen ("normal.opn", "r")) == NULL)
++ if ((f_book = fopen (BOOK_PATH "/normal.opn", "r")) == NULL)
+ return FALSE;
+ }
+ else if (Variant == Crazyhouse)
+ {
+- if ((f_book = fopen ("zh.opn", "r")) == NULL)
++ if ((f_book = fopen (BOOK_PATH "/zh.opn", "r")) == NULL)
+ return FALSE;
+ }
+ else if (Variant == Suicide)
+ {
+- if ((f_book = fopen ("suicide.opn", "r")) == NULL)
++ if ((f_book = fopen (BOOK_PATH "/suicide.opn", "r")) == NULL)
+ return FALSE;
+ }
+ else if (Variant == Losers)
+ {
+- if ((f_book = fopen ("losers.opn", "r")) == NULL)
++ if ((f_book = fopen (BOOK_PATH "/losers.opn", "r")) == NULL)
+ return FALSE;
+ }
+ else
+ {
+- if ((f_book = fopen ("bug.opn", "r")) == NULL)
++ if ((f_book = fopen (BOOK_PATH "/bug.opn", "r")) == NULL)
+ return FALSE;
+ }
+
+--- Sjeng-Free-11.2/rcfile.c.deb 2001-09-28 18:19:18.000000000 +0800
++++ Sjeng-Free-11.2/rcfile.c 2005-07-03 20:09:07.000000000 +0800
+@@ -26,6 +26,14 @@
+ #include "extvars.h"
+ #include "config.h"
+
++/* Local name is relative to user's home directory */
++#define RC_LOCALNAME "/.sjeng/sjeng.rc"
++#ifndef SYSCONFDIR
++#define RC_GLOBALNAME "/etc/sjeng.rc"
++#else
++#define RC_GLOBALNAME SYSCONFDIR "/sjeng.rc"
++#endif
++
+ FILE *rcfile;
+ char line[STR_BUFF];
+
+@@ -51,8 +59,22 @@
+ {
+ int i;
+ unsigned int setc;
+-
+- if ((rcfile = fopen ("sjeng.rc", "r")) == NULL)
++ struct passwd *pw;
++ char rcname[STR_BUFF];
++
++ rcfile = NULL;
++ pw = getpwuid(getuid());
++ if (pw != NULL &&
++ strlen(pw->pw_dir) + strlen(RC_LOCALNAME) + 1 < STR_BUFF ) {
++ strcpy(rcname, pw->pw_dir);
++ strcat(rcname, RC_LOCALNAME);
++ rcfile = fopen(rcname, "r");
++ }
++ if (rcfile == NULL) {
++ rcfile = fopen(RC_GLOBALNAME, "r");
++ }
++
++ if (rcfile == NULL)
+ {
+ printf("No configuration file!\n");
+
+--- Sjeng-Free-11.2/sjeng.c.deb 2001-12-28 06:20:38.000000000 +0800
++++ Sjeng-Free-11.2/sjeng.c 2005-07-03 19:25:22.000000000 +0800
+@@ -27,6 +27,11 @@
+ \r
+ */\r
+ \r
++#include <sys/types.h>\r
++#include <sys/stat.h>\r
++#include <unistd.h>\r
++#include <pwd.h>\r
++\r
+ #include "sjeng.h"\r
+ #include "protos.h"\r
+ #include "extvars.h"\r
+@@ -106,7 +111,11 @@
+ int braindeadinterface;\r
+ int automode;\r
+ rtime_t xstart_time;\r
+- \r
++ char lrn_name[STR_BUFF];\r
++ int path_len;\r
++ struct passwd *pw;\r
++ struct stat st;\r
++\r
+ read_rcfile();\r
+ initialize_zobrist();\r
+ \r
+@@ -119,60 +128,88 @@
+ if (!init_book())\r
+ printf("No .OPN opening book found.\n");\r
+ \r
+- if ((lrn_standard = fopen ("standard.lrn", "rb+")) == NULL)\r
++ pw = getpwuid(getuid());\r
++ if (pw == NULL) {\r
++ perror("Unable to get home directory");\r
++ exit(1);\r
++ }\r
++ path_len = strlen(pw->pw_dir) + strlen("/.sjeng/");\r
++ if (path_len + 21 >= STR_BUFF) {\r
++ fprintf(stderr,"Home directory path too long\n");\r
++ exit(1);\r
++ }\r
++ strcpy(lrn_name, pw->pw_dir);\r
++ strcat(lrn_name, "/.sjeng/");\r
++\r
++ if (stat(lrn_name, &st) < 0) {\r
++ printf("Trying to create directory %s\n", lrn_name);\r
++ if (mkdir(lrn_name, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) {\r
++ perror("Unable to create directory");\r
++ exit(1);\r
++ }\r
++ }\r
++\r
++ strcpy(lrn_name + path_len, "standard.lrn");\r
++ if ((lrn_standard = fopen (lrn_name, "rb+")) == NULL)\r
+ {\r
+ printf("No standard learn file.\n");\r
+ \r
+- if ((lrn_standard = fopen ("standard.lrn", "wb+")) == NULL)\r
++ if ((lrn_standard = fopen (lrn_name, "wb+")) == NULL)\r
+ {\r
+ printf("Error creating standard learn file.\n");\r
+ }\r
+ else\r
+ {\r
+ fclose(lrn_standard);\r
+- lrn_standard = fopen ("standard.lrn", "rb+");\r
++ lrn_standard = fopen (lrn_name, "rb+");\r
+ }\r
+ }\r
+- if ((lrn_zh = fopen ("bug.lrn", "rb+")) == NULL)\r
++\r
++ strcpy(lrn_name + path_len, "bug.lrn");\r
++ if ((lrn_zh = fopen (lrn_name, "rb+")) == NULL)\r
+ {\r
+ printf("No crazyhouse learn file.\n");\r
+ \r
+- if ((lrn_zh = fopen ("bug.lrn", "wb+")) == NULL)\r
++ if ((lrn_zh = fopen (lrn_name, "wb+")) == NULL)\r
+ {\r
+ printf("Error creating crazyhouse learn file.\n");\r
+ }\r
+ else\r
+ {\r
+ fclose(lrn_zh);\r
+- lrn_zh = fopen ("bug.lrn", "rb+");\r
++ lrn_zh = fopen (lrn_name, "rb+");\r
+ }\r
+ }\r
+- if ((lrn_suicide = fopen ("suicide.lrn", "rb+")) == NULL)\r
++\r
++ strcpy(lrn_name + path_len, "suicide.lrn");\r
++ if ((lrn_suicide = fopen (lrn_name, "rb+")) == NULL)\r
+ {\r
+ printf("No suicide learn file.\n");\r
+ \r
+- if ((lrn_suicide = fopen ("suicide.lrn", "wb+")) == NULL)\r
++ if ((lrn_suicide = fopen (lrn_name, "wb+")) == NULL)\r
+ {\r
+ printf("Error creating suicide learn file.\n");\r
+ }\r
+ else\r
+ {\r
+ fclose(lrn_suicide);\r
+- lrn_suicide = fopen ("suicide.lrn", "rb+");\r
++ lrn_suicide = fopen (lrn_name, "rb+");\r
+ }\r
+ }\r
+- if ((lrn_losers = fopen ("losers.lrn", "rb+")) == NULL)\r
++\r
++ strcpy(lrn_name + path_len, "losers.lrn");\r
++ if ((lrn_losers = fopen (lrn_name, "rb+")) == NULL)\r
+ {\r
+ printf("No losers learn file.\n");\r
+ \r
+- if ((lrn_losers = fopen ("losers.lrn", "wb+")) == NULL)\r
++ if ((lrn_losers = fopen (lrn_name, "wb+")) == NULL)\r
+ {\r
+ printf("Error creating losers learn file.\n");\r
+ }\r
+ else\r
+ {\r
+ fclose(lrn_losers);\r
+- lrn_losers = fopen ("losers.lrn", "rb+");\r
++ lrn_losers = fopen (lrn_name, "rb+");\r
+ }\r
+ }\r
+ \r
+--- Sjeng-Free-11.2/newbook.c~ 2005-07-03 20:28:23.000000000 +0800
++++ Sjeng-Free-11.2/newbook.c 2005-07-03 21:00:52.000000000 +0800
+@@ -35,6 +35,10 @@
+ #error You need the GNU DBM library (GDBM). Go to ftp.gnu.org
+ #endif
+
++#ifndef BOOK_PATH
++#define BOOK_PATH "/usr/share/games/sjeng"
++#endif
++
+ typedef struct
+ {
+ unsigned long hashkey;
+@@ -465,13 +469,13 @@
+ srand(time(0));
+
+ if (Variant == Normal)
+- binbook = gdbm_open("nbook.bin", 16384, GDBM_READER, 0, NULL);
++ binbook = gdbm_open(BOOK_PATH "/nbook.bin", 16384, GDBM_READER, 0, NULL);
+ else if (Variant == Suicide)
+- binbook = gdbm_open("sbook.bin", 16384, GDBM_READER, 0, NULL);
++ binbook = gdbm_open(BOOK_PATH "/sbook.bin", 16384, GDBM_READER, 0, NULL);
+ else if (Variant == Losers)
+- binbook = gdbm_open("lbook.bin", 16384, GDBM_READER, 0, NULL);
++ binbook = gdbm_open(BOOK_PATH "/lbook.bin", 16384, GDBM_READER, 0, NULL);
+ else
+- binbook = gdbm_open("zbook.bin", 16384, GDBM_READER, 0, NULL);
++ binbook = gdbm_open(BOOK_PATH "/zbook.bin", 16384, GDBM_READER, 0, NULL);
+
+
+ if (binbook == NULL)
+--- Sjeng-Free-11.2/Makefile.am.bak 2001-09-12 17:32:27.000000000 +0800
++++ Sjeng-Free-11.2/Makefile.am 2005-07-03 21:05:34.000000000 +0800
+@@ -4,5 +4,9 @@
+ sjeng.c utils.c newbook.c proof.c neval.c rcfile.c\
+ leval.c draw.c see.c probe.c segtb.c\
+ protos.h extvars.h sjeng.h squares.h
++
++sjeng_CFLAGS = -DBOOK_PATH="\"$(datadir)/sjeng\"" \
++ -DSYSCONFDIR="\"$(sysconfdir)\""
++
+ EXTRA_DIST = TODO NEWS ChangeLog COPYING BUGS THANKS blob2.c sjeng.rc
+ SUBDIRS = books tests
+--- Sjeng-Free-11.2/segtb.c.bak 2005-07-03 22:31:07.000000000 +0800
++++ Sjeng-Free-11.2/segtb.c 2005-07-03 22:55:02.000000000 +0800
+@@ -30,13 +30,17 @@
+ #define FILE(x) ((x) & 7)
+ #define RANK(x) ((x) >> 3)
+
++#ifndef BOOK_PATH
++#define BOOK_PATH "/usr/share/games/sjeng"
++#endif
++
+ #define TWO_PIECE_SIZE 4096
+ #define TWO_PIECE_HASH(x,y,z) (((((x) << 5) | (y)) << 6) | (z))
+-#define TWO_PIECE_FILE "stb/2pieces.bin"
++#define TWO_PIECE_FILE BOOK_PATH "/stb/2pieces.bin"
+
+ #define THREE_PIECE_SIZE (64*TWO_PIECE_SIZE)
+ #define THREE_PIECE_HASH(x,y,z,w) (((((((x) << 5) | (y)) << 6) | (z)) << 6) | (w))
+-#define THREE_PIECE_FILE "stb/xxx.bin"
++#define THREE_PIECE_FILE BOOK_PATH "/stb/xxx.bin"
+
+ #define TABLE_KEY(x,y,z) (((((x) << 3) | (y)) << 3) | (z))
+
+@@ -510,9 +514,9 @@
+ /* generate the filename */
+
+ strcpy(fname, THREE_PIECE_FILE);
+- fname[4] = xpiece_char[w1_man];
+- fname[5] = xpiece_char[b1_man];
+- fname[6] = xpiece_char[b2_man];
++ fname[strlen(BOOK_PATH)+5] = xpiece_char[w1_man];
++ fname[strlen(BOOK_PATH)+6] = xpiece_char[b1_man];
++ fname[strlen(BOOK_PATH)+7] = xpiece_char[b2_man];
+
+ if(!(f = fopen(fname,"w"))) return 0;
+
+@@ -971,9 +975,9 @@
+ /* generate the filename */
+
+ strcpy(fname, THREE_PIECE_FILE);
+- fname[4]= xpiece_char[w1_man];
+- fname[5]= xpiece_char[b1_man];
+- fname[6]= xpiece_char[b2_man];
++ fname[strlen(BOOK_PATH)+5]= xpiece_char[w1_man];
++ fname[strlen(BOOK_PATH)+6]= xpiece_char[b1_man];
++ fname[strlen(BOOK_PATH)+7]= xpiece_char[b2_man];
+
+ if(!(f = fopen(fname,"r"))) return 0;
+
--- /dev/null
+--- Sjeng-Free-11.2/book.c.deb 2001-07-16 20:04:48.000000000 +0800
++++ Sjeng-Free-11.2/book.c 2005-07-03 19:25:22.000000000 +0800
+@@ -21,6 +21,8 @@
+
+ */
+
++#include <unistd.h>
++
+ #include "sjeng.h"
+ #include "protos.h"
+ #include "extvars.h"
+--- Sjeng-Free-11.2/ecache.c.deb 2001-12-28 06:25:20.000000000 +0800
++++ Sjeng-Free-11.2/ecache.c 2005-07-03 19:25:22.000000000 +0800
+@@ -29,7 +29,7 @@
+ {
+ unsigned long stored_hash;
+ unsigned long hold_hash;
+-unsigned int score;
++long int score;
+ } ECacheType;
+
+ /*ECacheType ECache[ECACHESIZE];*/
+@@ -40,7 +40,7 @@
+
+ void storeECache(long int score)
+ {
+- int index;
++ unsigned int index;
+
+ index = hash % ECacheSize;
+
+@@ -51,7 +51,7 @@
+
+ void checkECache(long int *score, int *in_cache)
+ {
+- int index;
++ unsigned int index;
+
+ ECacheProbes++;
+
+@@ -84,7 +84,7 @@
+ exit(EXIT_FAILURE);
+ }
+
+- printf("Allocated %lu eval cache entries, totalling %lu bytes.\n",
++ printf("Allocated %u eval cache entries, totalling %zu bytes.\n",
+ ECacheSize, sizeof(ECacheType)*ECacheSize);
+ return;
+ }
+--- Sjeng-Free-11.2/epd.c.deb 2001-07-23 03:27:36.000000000 +0800
++++ Sjeng-Free-11.2/epd.c 2005-07-03 19:25:22.000000000 +0800
+@@ -24,6 +24,7 @@
+ #include "sjeng.h"
+ #include "protos.h"
+ #include "extvars.h"
++#include <errno.h>
+
+ void setup_epd_line(char* inbuff)
+ {
+@@ -243,6 +244,10 @@
+ thinktime *= 100;
+
+ testsuite = fopen(testname, "r");
++ if (testsuite==NULL) {
++ fprintf(stderr, "Cannot open file %s: %s\n", testname, strerror(errno));
++ return;
++ }
+
+ while (fgets(readbuff, 2000, testsuite) != NULL)
+ {
+@@ -264,8 +269,8 @@
+ // cpu_end = clock();
+ // rdelay(2);
+
+- elapsed = (cpu_end-cpu_start)/(double) CLOCKS_PER_SEC;
+- printf("Time: %f\n", elapsed);
++ // elapsed = (cpu_end-cpu_start)/(double) CLOCKS_PER_SEC;
++ // printf("Time: %f\n", elapsed);
+
+ if (interrupt()) rinput(tempbuff, STR_BUFF, stdin);
+
+@@ -304,7 +309,7 @@
+
+ printf("Move ordering : %f%%\n", (((float)FHF*100)/(float)FH+1));
+
+- printf("Material score: %d Eval : %d\n", Material, eval());
++ printf("Material score: %d Eval : %ld\n", Material, eval());
+ printf("\n");
+
+ if (!forcedwin)
+@@ -329,5 +334,6 @@
+ };
+
+ printf("\n");
++ fclose(testsuite);
+ };
+
+--- Sjeng-Free-11.2/extvars.h.deb 2001-12-28 06:19:58.000000000 +0800
++++ Sjeng-Free-11.2/extvars.h 2005-07-03 19:25:22.000000000 +0800
+@@ -164,7 +164,7 @@
+ extern int havercfile;
+ extern int TTSize;
+ extern int PBSize;
+-extern int ECacheSize;
++extern unsigned int ECacheSize;
+
+ extern int my_rating, opp_rating;
+ extern int userealholdings;
+@@ -190,5 +190,3 @@
+
+
+
+-
+-
+--- Sjeng-Free-11.2/learn.c.deb 2001-09-28 18:14:13.000000000 +0800
++++ Sjeng-Free-11.2/learn.c 2005-07-03 19:25:22.000000000 +0800
+@@ -36,13 +36,13 @@
+ }
+ LearnType;
+
+-void Learn(int score, int best, int depth)
++void Learn(long score, int best, int depth)
+ {
+ int number = 0, next = 0;
+ LearnType draft;
+ FILE **lrnfile;
+
+- printf("Learning score: %d best: %d depth:%d hash: %X\n", score, best, depth, hash);
++ printf("Learning score: %ld best: %d depth:%d hash: %lX\n", score, best, depth, hash);
+
+ if (Variant == Normal)
+ {
+@@ -122,6 +122,7 @@
+ {
+ lrnfile = &lrn_losers;
+ }
++ else return; // Can this happen?
+
+ fseek(*lrnfile, 0, SEEK_SET);
+ fread(&number, sizeof(int), 1, *lrnfile);
+--- Sjeng-Free-11.2/leval.c.deb 2001-09-02 19:04:53.000000000 +0800
++++ Sjeng-Free-11.2/leval.c 2005-07-03 19:25:22.000000000 +0800
+@@ -120,13 +120,13 @@
+ long int losers_eval (void) {\r
+ \r
+ /* return a score for the current middlegame position: */\r
+- int srank, pawn_file, pawns[2][11], white_back_pawn[11], black_back_pawn[11];\r
++ int srank = 0, pawn_file = 0, pawns[2][11], white_back_pawn[11], black_back_pawn[11];\r
+ int isolated, backwards;\r
+ int i, a, j;\r
+ long int score = 0;\r
+ int in_cache;\r
+ int wp = 0, bp = 0;\r
+- int wks, bks;\r
++ int wks = 0, bks = 0;\r
+ int wpassp = 0, bpassp = 0;\r
+ int wpawns = 0, bpawns = 0;\r
+ \r
+--- Sjeng-Free-11.2/moves.c.deb 2001-06-07 06:12:46.000000000 +0800
++++ Sjeng-Free-11.2/moves.c 2005-07-03 19:25:22.000000000 +0800
+@@ -31,7 +31,7 @@
+ int numb_moves;
+ static move_s *genfor;
+
+-int fcaptures;
++bool fcaptures;
+ int gfrom;
+
+ int kingcap; /* break if we capture the king */
+--- Sjeng-Free-11.2/neval.c.deb 2001-06-29 03:48:09.000000000 +0800
++++ Sjeng-Free-11.2/neval.c 2005-07-03 19:25:22.000000000 +0800
+@@ -177,7 +177,7 @@
+ int in_cache;
+ int wp = 0, bp = 0, wn = 0, bn = 0, wb = 0, bb = 0,
+ wq = 0, bq = 0, wr = 0, br = 0;
+- int fwrook, fbrook, rwrook, rbrook;
++ int fwrook = 0, fbrook = 0, rwrook = 0, rbrook = 0;
+ int wpotential = 0, bpotential = 0, tmp;
+
+ in_cache = 0;
+@@ -818,7 +818,7 @@
+ int in_cache;
+ int wp = 0, bp = 0, wn = 0, bn = 0, wb = 0, bb = 0,
+ wq = 0, bq = 0, wr = 0, br = 0;\r
+- int rbrook, fbrook, rwrook,fwrook;
++ int rbrook = 0, fbrook = 0, rwrook = 0,fwrook = 0;
+
+ in_cache = 0;
+
+--- Sjeng-Free-11.2/newbook.c.deb 2001-06-07 06:12:39.000000000 +0800
++++ Sjeng-Free-11.2/newbook.c 2005-07-03 19:25:22.000000000 +0800
+@@ -43,7 +43,7 @@
+ typedef struct
+ {
+ unsigned long played;
+- signed long score;
++ long int score;
+ } posinfo_t;
+
+ typedef struct
+@@ -118,7 +118,6 @@
+ posinfo_t *pst;
+ datum index;
+ datum data;
+- int win = 0, loss = 0;
+ int ret;
+
+ /* fill in the key field */
+@@ -461,7 +460,7 @@
+ int raw;
+ int num_moves, i;
+ char output[6];
+- signed long scores[MOVE_BUFF], best_score = 0;
++ long int scores[MOVE_BUFF], best_score = 0;
+
+ srand(time(0));
+
+@@ -524,7 +523,7 @@
+
+ comp_to_coord(moves[i], output);
+
+- printf("Move %s: %ld times played, %d learned\n", output,
++ printf("Move %s: %ld times played, %ld learned\n", output,
+ ps->played, ps->score);
+
+ if ((ps->played + ps->score) >= PLAYTHRESHOLD)
+@@ -593,7 +592,7 @@
+
+ void book_learning(int result)
+ {
+- GDBM_FILE binbook;
++ GDBM_FILE binbook = NULL;
+ hashkey_t key;
+ posinfo_t *ps;
+ datum index;
+@@ -675,7 +674,7 @@
+ }\r
+ \r
+ /* don't 'overlearn' */\r
+- if (abs((ps->score)+pi) < (ps->played*5))\r
++ if ((unsigned long)labs((ps->score)+pi) < (ps->played*5))\r
+ {
+
+ printf("Learning opening %lu, played %lu, old score %ld, new score %ld\n",
+--- Sjeng-Free-11.2/probe.c.deb 2001-09-12 17:28:18.000000000 +0800
++++ Sjeng-Free-11.2/probe.c 2005-07-03 19:25:22.000000000 +0800
+@@ -121,7 +121,8 @@
+ #endif\r
+ }\r
+ \r
+-const static int EGTranslate(int sqidx)\r
++#ifdef USE_EGTB\r
++static int EGTranslate(int sqidx)\r
+ {\r
+ int r;\r
+ \r
+@@ -129,6 +130,7 @@
+ \r
+ return r;\r
+ }\r
++#endif\r
+ \r
+ int probe_egtb(void)\r
+ {\r
+--- Sjeng-Free-11.2/proof.c.deb 2001-12-28 06:52:15.000000000 +0800
++++ Sjeng-Free-11.2/proof.c 2005-07-03 19:25:22.000000000 +0800
+@@ -79,7 +79,7 @@
+ void losers_pn_eval (node_t *this);
+
+ unsigned char *membuff;
+-int bufftop = 0;
++unsigned int bufftop = 0;
+
+ void* Xmalloc(int size)
+ {
+@@ -506,7 +506,6 @@
+ int i;
+ move_s moves[MOVE_BUFF];
+ int l, num_moves;
+- int reploop;
+ int ic;
+
+ if (node->expanded)
+@@ -1024,7 +1023,7 @@
+ node_t *root;
+ node_t *mostproving;
+ node_t *currentnode;
+- int leastlooked, leastlooked_l, leastlooked_i;
++ int leastlooked, leastlooked_l = 0, leastlooked_i = 0;
+ int losers;
+ int xnodecount;
+ int firsts, alternates;
+@@ -1364,7 +1363,7 @@
+ #endif
+ {
+ #ifdef PN2
+- printf("P: %d D: %d N: %d S: %d Mem: %2.2fM Iters: %d ", root->proof, root->disproof, nodecount, frees, (((nodecount) * sizeof(node_t) / (float)(1024*1024))), iters);
++ printf("P: %d D: %d N: %d S: %ld Mem: %2.2fM Iters: %d ", root->proof, root->disproof, nodecount, frees, (((nodecount) * sizeof(node_t) / (float)(1024*1024))), iters);
+
+ printf ("PV: ");
+
+@@ -1415,7 +1414,7 @@
+ }
+ };
+
+- printf ("P: %d D: %d N: %d S: %d Mem: %2.2fM Iters: %d MaxDepth: %d\n", root->proof, root->disproof, nodecount, frees, (((nodecount) * sizeof (node_t) / (float) (1024 * 1024))), iters,maxply);
++ printf ("P: %d D: %d N: %d S: %ld Mem: %2.2fM Iters: %d MaxDepth: %d\n", root->proof, root->disproof, nodecount, frees, (((nodecount) * sizeof (node_t) / (float) (1024 * 1024))), iters,maxply);
+
+ if (xb_mode && post)
+ printf ("tellics whisper proof %d, disproof %d, %d nodes, %d forwards, %d iters, highest depth %d\n", root->proof, root->disproof, nodecount, forwards, iters, maxply);
+@@ -1608,7 +1607,7 @@
+ }
+ };
+
+- printf("P: %d D: %d N: %d S: %d Mem: %2.2fM Iters: %d\n", root->proof, root->disproof, nodecount, frees, (((nodecount) * sizeof(node_t) / (float)(1024*1024))), iters);
++ printf("P: %d D: %d N: %d S: %ld Mem: %2.2fM Iters: %d\n", root->proof, root->disproof, nodecount, frees, (((nodecount) * sizeof(node_t) / (float)(1024*1024))), iters);
+
+ while(currentnode != root)
+ {
+--- Sjeng-Free-11.2/protos.h.deb 2001-07-18 09:21:37.000000000 +0800
++++ Sjeng-Free-11.2/protos.h 2005-07-03 19:25:22.000000000 +0800
+@@ -67,7 +67,7 @@
+
+
+ void push_slidE (int target);
+-long int qsearch (int alpha, int beta, int depth);
++long int qsearch (long alpha, long beta, int depth);
+ void rdelay (int time_in_s);
+ long int rdifftime (rtime_t end, rtime_t start);
+ bool remove_one (int *marker, long int move_ordering[], int num_moves);
+@@ -75,8 +75,8 @@
+ void check_piece_square (void);
+ void rinput (char str[], int n, FILE *stream);
+ rtime_t rtime (void);
+-long int search (int alpha, int beta, int depth, int is_null);
+-move_s search_root (int alpha, int beta, int depth);
++long int search (long alpha, long beta, int depth, int is_null);
++move_s search_root (long alpha, long beta, int depth);
+ void start_up (void);
+ move_s think (void);
+ void toggle_bool (bool *var);
+@@ -111,14 +111,14 @@
+ move_s choose_book_move(void);
+ move_s choose_binary_book_move(void);
+
+-void StoreTT(int score, int alpha, int beta, int best , int threat, int depth);
+-void QStoreTT(int score, int alpha, int beta, int best);
+-int ProbeTT(int *score, int alpha, int beta, int *best, int *threat, int *donull, int depth);
+-int QProbeTT(int *score, int alpha, int beta, int *best);
+-void LearnStoreTT(int score, unsigned nhash, unsigned hhash, int tomove, int best, int depth);
++void StoreTT(long score, long alpha, long beta, int best , int threat, int depth);
++void QStoreTT(long score, long alpha, long beta, int best);
++int ProbeTT(long *score, long alpha, long beta, int *best, int *threat, int *donull, int depth);
++int QProbeTT(long *score, long alpha, long beta, int *best);
++void LearnStoreTT(long score, unsigned nhash, unsigned hhash, int tomove, int best, int depth);
+
+ void LoadLearn(void);
+-void Learn(int score, int best, int depth);
++void Learn(long score, int best, int depth);
+
+ void pinput (int n, FILE *stream);
+
+@@ -170,5 +170,9 @@
+ void gen_all_tables(void);
+ int egtb(int s);
+
++int load_2piece(void);
++int load_3piece(int w1_man, int b1_man, int b2_man, signed char *t);
++int init_segtb(void);
++
+ #endif
+
+--- Sjeng-Free-11.2/rcfile.c.deb 2001-09-28 18:19:18.000000000 +0800
++++ Sjeng-Free-11.2/rcfile.c 2005-07-03 19:25:22.000000000 +0800
+@@ -21,6 +21,10 @@
+
+ */
+
++#include <pwd.h>
++#include <unistd.h>
++#include <sys/types.h>
++
+ #include "sjeng.h"
+ #include "protos.h"
+ #include "extvars.h"
+@@ -30,7 +34,7 @@
+ char line[STR_BUFF];
+
+ int TTSize;
+-int ECacheSize;
++unsigned int ECacheSize;
+ int PBSize;
+
+ int cfg_booklearn;
+@@ -100,7 +104,7 @@
+
+ fgets(line, STR_BUFF, rcfile);
+ while (line[0] == '#') fgets(line, STR_BUFF, rcfile);
+- sscanf(line, "%d", &ECacheSize);
++ sscanf(line, "%u", &ECacheSize);
+
+ fgets(line, STR_BUFF, rcfile);
+ while (line[0] == '#') fgets(line, STR_BUFF, rcfile);
+@@ -181,6 +185,7 @@
+
+ sprintf(setcode, "%u", setc);
+
++ fclose(rcfile);
+ initialize_eval();
+ alloc_hash();
+ alloc_ecache();
+--- Sjeng-Free-11.2/search.c.deb 2001-12-28 06:20:56.000000000 +0800
++++ Sjeng-Free-11.2/search.c 2005-07-03 19:25:22.000000000 +0800
+@@ -264,7 +264,7 @@
+ }
+
+
+-long int qsearch (int alpha, int beta, int depth) {
++long int qsearch (long alpha, long beta, int depth) {
+
+ /* perform a quiscense search on the current node using alpha-beta with
+ negamax search */
+@@ -275,9 +275,10 @@
+ move_ordering[MOVE_BUFF],
+ see_values[MOVE_BUFF];
+ bool legal_move, no_moves = TRUE;
+- int sbest, best_score, best, delta, bound;
+- int originalalpha;
+- int oldtime;
++ long best_score, bound, delta;
++ int sbest, best;
++ long originalalpha;
++ long int oldtime;
+ int seev;
+
+ pv_length[ply] = ply;
+@@ -301,7 +302,7 @@
+ extendedtime = 1;
+ oldtime = time_for_move;
+ time_for_move += allocate_time();
+- printf("Extended from %d to %d, time left %d\n", oldtime,
++ printf("Extended from %ld to %ld, time left %ld\n", oldtime,
+ time_for_move,
+ time_left);
+ }
+@@ -473,7 +474,7 @@
+
+ }
+
+-long int search (int alpha, int beta, int depth, int is_null) {
++long int search (long alpha, long beta, int depth, int is_null) {
+
+ /* search the current node using alpha-beta with negamax search */
+
+@@ -481,16 +482,18 @@
+ int num_moves, i, j;
+ long int score = -INF, move_ordering[MOVE_BUFF], see_values[MOVE_BUFF];
+ bool no_moves, legal_move;
+- int bound, threat, donull, best, sbest, best_score, old_ep;
++ long int best_score, bound;
++ int threat, donull, best, sbest, old_ep;
+ bool incheck, first;
+- int extend, fscore, fmax, selective;
++ long int fscore, fmax;
++ int extend, selective;
+ move_s kswap;
+ int ksswap;
+- int originalalpha;
++ long originalalpha;
+ int afterincheck;
+ int legalmoves;
+ int dropcut;
+- int oldtime;
++ long int oldtime;
+ int egscore;
+ static const int rc_index[14] = {0,1,1,2,2,5,5,3,3,4,4,2,2,0};
+
+@@ -512,7 +515,7 @@
+ extendedtime = 1;
+ oldtime = time_for_move;
+ time_for_move += allocate_time();
+- printf("Extended from %d to %d, time left %d\n", oldtime,
++ printf("Extended from %ld to %ld, time left %ld\n", oldtime,
+ time_for_move,
+ time_left);
+ }
+@@ -826,11 +829,12 @@
+ afterincheck = f_in_check(&moves[0], i);
+ checks[ply] = afterincheck;
+
+- if (!afterincheck && ((Variant == Normal)
+- || (Variant == Suicide)
+- || (Variant == Losers)) && (depth < 3) &&
+- (((board[moves[i].target] == wpawn) && (rank(moves[i].target) >= 6)
+- || ((board[moves[i].target] == bpawn) && (rank(moves[i].target) <= 3)))))
++ if (!afterincheck
++ && ((Variant == Normal) || (Variant == Suicide) || (Variant == Losers))
++ && (depth < 3)
++ && (((board[moves[i].target] == wpawn) && (rank(moves[i].target) >= 6))
++ ||
++ ((board[moves[i].target] == bpawn) && (rank(moves[i].target) <= 3))))
+ {
+ extend++;
+ };
+@@ -1066,7 +1070,7 @@
+ }
+
+
+-move_s search_root (int originalalpha, int originalbeta, int depth) {
++move_s search_root (long originalalpha, long originalbeta, int depth) {
+
+ /* search the root node using alpha-beta with negamax search */
+
+@@ -1074,7 +1078,7 @@
+ int num_moves, i, j;
+ long int root_score = -INF, move_ordering[MOVE_BUFF], see_values[MOVE_BUFF];
+ bool no_moves, legal_move, first;
+- int alpha, beta;
++ long alpha, beta;
+ move_s kswap;
+ move_s oldbest;
+ int oldbestnum;
+@@ -1447,15 +1451,15 @@
+
+ move_s comp_move, temp_move, old_move;
+ int i, j, k;
+- long int elapsed, temp_score, true_score;
++ long int elapsed, temp_score = 0, true_score;
+ char postmove[STR_BUFF];
+ clock_t cpu_start, cpu_end;
+ float et = 0;
+- int alpha, beta;
++ long alpha, beta;
+ int tmptmp;
+ int rs;
+ move_s moves[MOVE_BUFF];
+- int l, lastlegal, ic;
++ int l, lastlegal = 0, ic;
+ int pn_restart;
+ int num_moves;
+ char output[8];
+@@ -1632,7 +1636,7 @@
+
+ if (pn_restart) time_for_move = (float)time_for_move * (float)2/((float)pn_restart+1.0);
+
+- printf("Time for move : %d\n", time_for_move);
++ printf("Time for move : %ld\n", time_for_move);
+
+ if (time_for_move > 50)
+ LoadLearn();
+@@ -1658,6 +1662,7 @@
+ if ((forcedwin || result) && (pn_move.target != dummy.target)
+ && !is_analyzing)
+ {
++ cpu_start = clock();
+ comp_move = pn_move;
+ }
+ else
+@@ -1861,7 +1866,7 @@
+ break;
+ }
+ }
+- for (j = 0; j < num_moves; j++)
++ for (j = 0, k = 0; j < num_moves; j++)
+ {
+ if (rootlosers[j]) k++;
+ }
+@@ -1883,7 +1888,7 @@
+ }
+ elapsed = rdifftime (rtime (), start_time);
+
+- printf("Used time : %d\n", elapsed);
++ printf("Used time : %ld\n", elapsed);
+
+ /* update our elapsed time_cushion: */
+ if (moves_to_tc && !is_pondering) {
+@@ -1937,7 +1942,7 @@
+
+ if ((et > 0) && (Variant != Bughouse))
+ {
+- printf("tellics whisper d%d %+.2f %sn: %ld qp: %.0f%% fh: %.0f%% c-x: %d r-x: %d 1-x: %d egtb: %d time: %.2f nps: %ld\n",
++ printf("tellics whisper d%d %+.2f %sn: %ld qp: %.0f%% fh: %.0f%% c-x: %ld r-x: %ld 1-x: %ld egtb: %d time: %.2f nps: %ld\n",
+ true_i_depth, (float)temp_score/100.0, postpv, nodes,
+ (((float)qnodes*100)/((float)nodes+1)),
+ ((float)FHF*100)/((float)(FH+1)),
+--- Sjeng-Free-11.2/segtb.c.deb 2001-12-28 06:46:41.000000000 +0800
++++ Sjeng-Free-11.2/segtb.c 2005-07-03 19:25:22.000000000 +0800
+@@ -742,10 +742,10 @@
+
+ int egtb(int s)
+ {
+- int w1_man, w2_man, b1_man, b2_man;
+- int w1, w2, b1, b2;
++ int w1_man = 0, w2_man = 0, b1_man = 0, b2_man = 0;
++ int w1 = 0, w2 = 0, b1 = 0, b2 = 0;
+ int w_count = 0, b_count = 0;
+- int i, t, temp, junk, bpc;
++ int i, t, temp, junk = 0, bpc;
+ signed char *table;
+
+ /* first figure out what kind of position we have */
+--- Sjeng-Free-11.2/seval.c.deb 2001-07-12 03:25:51.000000000 +0800
++++ Sjeng-Free-11.2/seval.c 2005-07-03 19:25:22.000000000 +0800
+@@ -121,8 +121,6 @@
+
+ static int black_saccers(int square)
+ {
+- register int ndir, a_sq;
+- register int basq, i;
+ register int f = FALSE;
+
+ /* for white pawn on square, any black
+@@ -148,8 +146,8 @@
+ f = TRUE;
+ }
+ else if (rank(square) == 4 &&
+- board[square + 35] == bpawn ||
+- board[square + 37] == bpawn)
++ (board[square + 35] == bpawn ||
++ board[square + 37] == bpawn))
+ {
+ f = TRUE;
+ }
+@@ -205,8 +203,6 @@
+ /* for black pawn on square, any black
+ * pieces that can sac themselves to it? */
+
+- register int ndir, a_sq;
+- register int basq, i;
+ register int f = FALSE;
+
+ /* for white pawn on square, any black
+@@ -232,8 +228,8 @@
+ f = TRUE;
+ }
+ else if (rank(square) == 5 &&
+- board[square - 35] == wpawn ||
+- board[square - 37] == wpawn)
++ (board[square - 35] == wpawn ||
++ board[square - 37] == wpawn))
+ {
+ f = TRUE;
+ }
+@@ -298,7 +294,7 @@
+ int isolated, backwards, i, a, j;
+ long int score = 0;
+ int in_cache;
+- int wb = 0, bb = 0, wbc, bbc;
++ int wb = 0, bb = 0, wbc = 0, bbc = 0;
+ int wk = 0, bk = 0, wr = 0, br = 0;
+ int wn = 0, bn = 0, wp = 0, bp = 0;
+
+--- Sjeng-Free-11.2/sjeng.c.deb 2001-12-28 06:20:38.000000000 +0800
++++ Sjeng-Free-11.2/sjeng.c 2005-07-03 19:25:22.000000000 +0800
+@@ -38,7 +38,7 @@
+ #include "config.h"\r
+ \r
+ char divider[50] = "-------------------------------------------------";\r
+-move_s dummy = {0,0,0,0,0};\r
++move_s dummy = {0,0,0,0,0,0};\r
+ \r
+ int board[144], moved[144], ep_square, white_to_move, comp_color, wking_loc,\r
+ bking_loc, white_castled, black_castled, result, ply, pv_length[PV_BUFF],\r
+@@ -90,7 +90,7 @@
+ FILE *lrn_suicide;\r
+ FILE *lrn_losers;\r
+ \r
+-int main (int argc, char *argv[]) {\r
++int main (void) {\r
+ \r
+ char input[STR_BUFF], *p, output[STR_BUFF];\r
+ char readbuff[STR_BUFF];\r
+@@ -98,10 +98,10 @@
+ int depth = 4;\r
+ bool force_mode, show_board;\r
+ double nps, elapsed;\r
+- clock_t cpu_start, cpu_end;\r
++ clock_t cpu_start = 0, cpu_end = 0;\r
+ move_s game_history[600];\r
+ move_x game_history_x[600];\r
+- int is_edit_mode, edit_color;\r
++ int is_edit_mode, edit_color = 0;\r
+ int pingnum;\r
+ int braindeadinterface;\r
+ int automode;\r
+@@ -334,10 +371,10 @@
+ \r
+ printf("Move ordering : %f%%\n", (((float)FHF*100)/(float)(FH+1)));\r
+ \r
+- printf("Material score: %d Eval : %d White hand: %d Black hand : %d\n", \r
++ printf("Material score: %d Eval : %ld White hand: %d Black hand : %d\n", \r
+ Material, eval(), white_hand_eval, black_hand_eval);\r
+ \r
+- printf("Hash : %X HoldHash : %X\n", hash, hold_hash);\r
++ printf("Hash : %lX HoldHash : %lX\n", hash, hold_hash);\r
+ \r
+ /* check to see if we mate our opponent with our current move: */\r
+ if (!result) {\r
+@@ -635,7 +672,7 @@
+ }\r
+ else if (!strcmp (input, "eval")) {\r
+ check_phase();\r
+- printf("Eval: %d\n", eval());\r
++ printf("Eval: %ld\n", eval());\r
+ }\r
+ else if (!strcmp (input, "go")) {\r
+ comp_color = white_to_move;\r
+@@ -667,7 +704,7 @@
+ time_cushion = 0; \r
+ }\r
+ else if (!strncmp (input, "rating", 6)) {\r
+- sscanf (input+7, "%ld %ld", &my_rating, &opp_rating);\r
++ sscanf (input+7, "%d %d", &my_rating, &opp_rating);\r
+ if (my_rating == 0) my_rating = 2000;\r
+ if (opp_rating == 0) opp_rating = 2000;\r
+ }\r
+@@ -729,6 +766,7 @@
+ printf("Move number : %d\n", move_number);\r
+ if (move_number > 0)\r
+ {\r
++ ply = 1;\r
+ path_x[0] = game_history_x[--move_number];\r
+ unmake(&game_history[move_number], 0);\r
+ reset_piece_square();\r
+@@ -738,10 +776,12 @@
+ else if (!strncmp (input, "remove", 5)) {\r
+ if (move_number > 1)\r
+ {\r
++ ply = 1;\r
+ path_x[0] = game_history_x[--move_number];\r
+ unmake(&game_history[move_number], 0);\r
+ reset_piece_square();\r
+ \r
++ ply = 1;\r
+ path_x[0] = game_history_x[--move_number];\r
+ unmake(&game_history[move_number], 0);\r
+ reset_piece_square();\r
+@@ -789,7 +829,7 @@
+ run_epd_testsuite();\r
+ }\r
+ else if (!strncmp (input, "st", 2)) {\r
+- sscanf(input+3, "%d", &fixed_time);\r
++ sscanf(input+3, "%ld", &fixed_time);\r
+ fixed_time = fixed_time * 100;\r
+ }\r
+ else if (!strncmp (input, "book", 4)) {\r
+--- Sjeng-Free-11.2/ttable.c.deb 2001-07-13 02:04:48.000000000 +0800
++++ Sjeng-Free-11.2/ttable.c 2005-07-03 19:25:22.000000000 +0800
+@@ -110,7 +110,7 @@
+
+ }
+
+-void QStoreTT(int score, int alpha, int beta, int best)
++void QStoreTT(long score, long alpha, long beta, int best)
+ {
+ unsigned long index;
+
+@@ -134,7 +134,7 @@
+ return;
+ }
+
+-void StoreTT(int score, int alpha, int beta, int best, int threat, int depth)
++void StoreTT(long score, long alpha, long beta, int best, int threat, int depth)
+ {
+ unsigned long index;
+
+@@ -216,7 +216,7 @@
+ return;
+ }
+
+-void LearnStoreTT(int score, unsigned nhash, unsigned hhash, int tomove, int best, int depth)
++void LearnStoreTT(long score, unsigned nhash, unsigned hhash, int tomove, int best, int depth)
+ {
+ unsigned long index;
+
+@@ -242,7 +242,7 @@
+
+ }
+
+-int ProbeTT(int *score, int alpha, int beta, int *best, int *threat, int *donull, int depth)
++int ProbeTT(long *score, long alpha, long beta, int *best, int *threat, int *donull, int depth)
+ {
+
+ unsigned long index;
+@@ -328,7 +328,7 @@
+
+ }
+
+-int QProbeTT(int *score, int alpha, int beta, int *best)
++int QProbeTT(long *score, long alpha, long beta, int *best)
+ {
+
+ unsigned long index;
+--- Sjeng-Free-11.2/utils.c.deb 2001-07-14 00:36:40.000000000 +0800
++++ Sjeng-Free-11.2/utils.c 2005-07-03 19:25:22.000000000 +0800
+@@ -529,7 +529,8 @@
+
+ void hash_extract_pv(int level, char str[])
+ {
+- int dummy, bm;
++ int bm, dummy_int;
++ long dummy_long;
+ move_s moves[MOVE_BUFF];
+ int num_moves;
+ char output[STR_BUFF];
+@@ -538,7 +539,7 @@
+ level--;
+ if (!level) return;
+
+- if(ProbeTT(&dummy, 0, 0, &bm, &dummy, &dummy, 0) != HMISS)
++ if(ProbeTT(&dummy_long, 0, 0, &bm, &dummy_int, &dummy_int, 0) != HMISS)
+ {
+ gen(&moves[0]);
+ num_moves = numb_moves;
+@@ -1342,7 +1343,7 @@
+ {
+ eval();
+ /* invalidate the ecache */
+- hash = (++hash) % ULONG_MAX;
++ ++hash;
+ }
+
+ cpu_end = clock ();