From: Yann Dirson Date: Tue, 4 Feb 2014 23:51:09 +0000 (+0100) Subject: Merge branch 'maint' X-Git-Url: http://winboard.nl/cgi-bin?p=gnushogi.git;a=commitdiff_plain;h=35b5979113b95569469056e8ea9bf3f79a4ff279;hp=ca6db121be811535ec9cd28a0fdcfe22c94a9b53 Merge branch 'maint' Conflicts: Makefile.in NEWS configure.ac xshogi/parser.y xshogi/scanner.l --- diff --git a/.gitignore b/.gitignore index 658125d..e5b81aa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,28 +1,38 @@ /config.h.in /configure +Makefile.in +.deps +/aclocal.m4 +/compile +/depcomp +/install-sh +/missing +/ylwrap +/stamp-h1 +/INSTALL + /autom4te.cache/ /config.log /config.status /config.h -/Makefile -/gnushogi/Makefile +Makefile /gnushogi/Makefile.profile -/doc/Makefile -/xshogi/Makefile *.o /gnushogi/pat2inc -/gnushogi/pattern.inc +/gnushogi/*-pattern.inc /gnushogi/gnushogi /gnushogi/gnushogi.bbk /gnushogi/gnuminishogi /gnushogi/gnuminishogi.bbk +/gnushogi/sizetest /win32/ /xshogi/scanner.c /xshogi/parser.c +/xshogi/parser.h /xshogi/xshogi /doc/gnushogi*.info diff --git a/INSTALL b/INSTALL deleted file mode 100644 index dba15ea..0000000 --- a/INSTALL +++ /dev/null @@ -1,74 +0,0 @@ -Installation procedure for GNU Shogi -==================================== - -If you've never installed a software package using a configure script before, -please read (or skim) the file "INSTALL.generic" which gives general -information on using configure scripts. This file contains information -specific to GNU shogi. - -The basic procedure: -------------------- - -1. Type 'configure --prefix='. If you - don't specify a prefix, it will be set to /usr/local. There are a few GNU - shogi-specific options you can use for this command; see below. - -2. Type 'make' to create gnushogi, the binary book file gnushogi.bbk, and - xshogi (the graphical interface to gnushogi). - -3. Type 'make install' to copy the binary book file to the library - destination directory and to copy the gnushogi executable to the - binary destination directory. - -4. OPTIONAL: - Type 'make clean' to remove object files and binaries from destination - source directory. - - -Configuration options specific to GNU shogi: -------------------------------------------- - -These only affect xshogi. - - --with-top-part-bitmaps Use top part of Kanji bitmaps only. - - --with-first-shogi-program=PROGNAME - Use PROGNAME as the first shogi program (default: gnushogi) - - --with-second-shogi-program=PROGNAME - Use PROGNAME as the second shogi program (default: gnushogi) - - --with-first-host=HOSTNAME - Use HOSTNAME as the machine on which the first shogi program - runs (default: localhost) - - --with-second-host=HOSTNAME - Use HOSTNAME as the machine on which the second shogi program - runs (default: localhost) - - --with-xshogi - Compile the xshogi graphical interface to GNU shogi (default: yes) - -If you don't want to compile xshogi, do -'configure --without-xshogi' - - -Other options: -------------- - -In the gnushogi directory, the file 'opts.h' includes a number of options that -can be set to configure the evaluator, to set the debugging level, etc. These -options will probably only be of interest to people who are hacking the source -code, with one exception: if you want to have your games automatically saved -on exit, #define LIST_ON_EXIT in this file. - - -Platforms GNU shogi is known to compile on: ------------------------------------------- - -Red Hat Linux 9.0 -Sun Solaris 2.6 - -Information about attempted or successful ports to other platforms would be -appreciated. If you submit such a report, please specify what you had to do -to get GNU shogi to compile and run successfully. diff --git a/INSTALL.generic b/INSTALL.generic deleted file mode 100644 index 3b50ea9..0000000 --- a/INSTALL.generic +++ /dev/null @@ -1,176 +0,0 @@ -Basic Installation -================== - - These are generic installation instructions. - - The `configure' shell script attempts to guess correct values for -various system-dependent variables used during compilation. It uses -those values to create a `Makefile' in each directory of the package. -It may also create one or more `.h' files containing system-dependent -definitions. Finally, it creates a shell script `config.status' that -you can run in the future to recreate the current configuration, a file -`config.cache' that saves the results of its tests to speed up -reconfiguring, and a file `config.log' containing compiler output -(useful mainly for debugging `configure'). - - If you need to do unusual things to compile the package, please try -to figure out how `configure' could check whether to do them, and mail -diffs or instructions to the address given in the `README' so they can -be considered for the next release. If at some point `config.cache' -contains results you don't want to keep, you may remove or edit it. - - The file `configure.in' is used to create `configure' by a program -called `autoconf'. You only need `configure.in' if you want to change -it or regenerate `configure' using a newer version of `autoconf'. - -The simplest way to compile this package is: - - 1. `cd' to the directory containing the package's source code and type - `./configure' to configure the package for your system. If you're - using `csh' on an old version of System V, you might need to type - `sh ./configure' instead to prevent `csh' from trying to execute - `configure' itself. - - Running `configure' takes a while. While running, it prints some - messages telling which features it is checking for. - - 2. Type `make' to compile the package. - - 3. Optionally, type `make check' to run any self-tests that come with - the package. - - 4. Type `make install' to install the programs and any data files and - documentation. - - 5. You can remove the program binaries and object files from the - source code directory by typing `make clean'. To also remove the - files that `configure' created (so you can compile the package for - a different kind of computer), type `make distclean'. There is - also a `make maintainer-clean' target, but that is intended mainly - for the package's developers. If you use it, you may have to get - all sorts of other programs in order to regenerate files that came - with the distribution. - -Compilers and Options -===================== - - Some systems require unusual options for compilation or linking that -the `configure' script does not know about. You can give `configure' -initial values for variables by setting them in the environment. Using -a Bourne-compatible shell, you can do that on the command line like -this: - CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure - -Or on systems that have the `env' program, you can do it like this: - env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure - -Compiling For Multiple Architectures -==================================== - - You can compile the package for more than one kind of computer at the -same time, by placing the object files for each architecture in their -own directory. To do this, you must use a version of `make' that -supports the `VPATH' variable, such as GNU `make'. `cd' to the -directory where you want the object files and executables to go and run -the `configure' script. `configure' automatically checks for the -source code in the directory that `configure' is in and in `..'. - - If you have to use a `make' that does not supports the `VPATH' -variable, you have to compile the package for one architecture at a time -in the source code directory. After you have installed the package for -one architecture, use `make distclean' before reconfiguring for another -architecture. - -Installation Names -================== - - By default, `make install' will install the package's files in -`/usr/local/bin', `/usr/local/man', etc. You can specify an -installation prefix other than `/usr/local' by giving `configure' the -option `--prefix=PATH'. - - You can specify separate installation prefixes for -architecture-specific files and architecture-independent files. If you -give `configure' the option `--exec-prefix=PATH', the package will use -PATH as the prefix for installing programs and libraries. -Documentation and other data files will still use the regular prefix. - - If the package supports it, you can cause programs to be installed -with an extra prefix or suffix on their names by giving `configure' the -option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. - -Optional Features -================= - - Some packages pay attention to `--enable-FEATURE' options to -`configure', where FEATURE indicates an optional part of the package. -They may also pay attention to `--with-PACKAGE' options, where PACKAGE -is something like `gnu-as' or `x' (for the X Window System). The -`README' should mention any `--enable-' and `--with-' options that the -package recognizes. - - For packages that use the X Window System, `configure' can usually -find the X include and library files automatically, but if it doesn't, -you can use the `configure' options `--x-includes=DIR' and -`--x-libraries=DIR' to specify their locations. - -Specifying the System Type -========================== - - There may be some features `configure' can not figure out -automatically, but needs to determine by the type of host the package -will run on. Usually `configure' can figure that out, but if it prints -a message saying it can not guess the host type, give it the -`--host=TYPE' option. TYPE can either be a short name for the system -type, such as `sun4', or a canonical name with three fields: - CPU-COMPANY-SYSTEM - -See the file `config.sub' for the possible values of each field. If -`config.sub' isn't included in this package, then this package doesn't -need to know the host type. - - If you are building compiler tools for cross-compiling, you can also -use the `--target=TYPE' option to select the type of system they will -produce code for and the `--build=TYPE' option to select the type of -system on which you are compiling the package. - -Sharing Defaults -================ - - If you want to set default values for `configure' scripts to share, -you can create a site shell script called `config.site' that gives -default values for variables like `CC', `cache_file', and `prefix'. -`configure' looks for `PREFIX/share/config.site' if it exists, then -`PREFIX/etc/config.site' if it exists. Or, you can set the -`CONFIG_SITE' environment variable to the location of the site script. -A warning: not all `configure' scripts look for a site script. - -Operation Controls -================== - - `configure' recognizes the following options to control how it -operates. - -`--cache-file=FILE' - Use and save the results of the tests in FILE instead of - `./config.cache'. Set FILE to `/dev/null' to disable caching, for - debugging `configure'. - -`--help' - Print a summary of the options to `configure', and exit. - -`--quiet' -`--silent' -`-q' - Do not print messages saying which checks are being made. - -`--srcdir=DIR' - Look for the package's source code in directory DIR. Usually - `configure' can determine that directory automatically. - -`--version' - Print the version of Autoconf used to generate the `configure' - script, and exit. - -`configure' also accepts some other, not widely useful, options. - diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..5239b43 --- /dev/null +++ b/Makefile.am @@ -0,0 +1,34 @@ +# +# Makefile for GNU Shogi +# +# Copyright (c) 2013 Yann Dirson and the Free Software Foundation +# +# This file is part of GNU Shogi. +# +# GNU Shogi is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 1, or (at your option) +# any later version. +# +# GNU Shogi is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Shogi; see the file COPYING. If not, write to +# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. +# + +SUBDIRS = gnushogi doc + +dist_noinst_DATA = \ + README.maint \ + ChangeLog.old \ + misc/gnushogi.pat \ + misc/gnuminishogi.pat \ + misc/gnushogi.tbk \ + misc/gnuminishogi.tbk + +dist_doc_DATA = \ + CONTRIB diff --git a/Makefile.in b/Makefile.in deleted file mode 100644 index 638a3e6..0000000 --- a/Makefile.in +++ /dev/null @@ -1,128 +0,0 @@ -# -# Makefile for GNU Shogi -# -# Copyright (c) 1993, 1994 Matthias Mutz -# Copyright (c) 1998, 1999 Michael Vanier and the Free Software Foundation -# Copyright (c) 2008, 2013, 2014 Yann Dirson and the Free Software Foundation -# -# GNU Shogi is based on GNU Chess -# Copyright (c) 1992 Free Software Foundation -# -# This file is part of GNU Shogi. -# -# GNU Shogi is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 1, or (at your option) -# any later version. -# -# GNU Shogi is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with GNU Shogi; see the file COPYING. If not, write to -# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. -# - -ROOT = @top_srcdir@ -BUILDROOT = @top_builddir@ -GNUSHOGIDIR = $(BUILDROOT)/gnushogi - -PROGNAME = @PROGNAME@ - -# -# Default targets. -# - -all : gnushogi_compile pat2inc bbk - - -# -# Primary targets. -# - -gnushogi_compile: - -cd $(GNUSHOGIDIR) && $(MAKE) $(PROGNAME) - -pat2inc: - -cd $(GNUSHOGIDIR) && $(MAKE) pat2inc - -sizetest: - -cd $(GNUSHOGIDIR) && $(MAKE) sizetest - -bbk: - -cd $(GNUSHOGIDIR) && $(MAKE) $(PROGNAME).bbk - - -# -# Alien target architectures -# - -win32/Makefile: misc/mkmakefile.mingw-on-cygwin - $< - -# -# Installation. -# - -install: gnushogi_install - -gnushogi_install: - -cd $(GNUSHOGIDIR) && $(MAKE) install - - - -# -# Cleanup. -# - -clean: gnushogi_clean doc_clean - -gnushogi_clean: - cd $(GNUSHOGIDIR) && $(MAKE) clean - -doc_clean: - cd $(BUILDROOT)/doc && $(MAKE) clean - - -# -# Building a distribution. -# - -DISTNAME = @PACKAGE_TARNAME@-@PACKAGE_VERSION@ - -dist: - $(MAKE) maintainerclean - rm -rf $(DISTNAME) - mkdir $(DISTNAME) - tar -cf - --exclude .git --exclude $(DISTNAME) $(ROOT) | (cd $(DISTNAME) && tar -xf -) - cd $(DISTNAME) && $(ROOT)/autogen.sh && $(ROOT)/configure - cd $(DISTNAME)/doc && $(MAKE) info - cd $(DISTNAME) && $(MAKE) win32/Makefile - cd $(DISTNAME) && $(MAKE) distclean - tar -zcf $(DISTNAME).tar.gz $(DISTNAME) - -# -# Return to a pristine pre-configuration state. -# - -DISTCLEANFILES = \ - config.cache config.log config.status config.h Makefile \ - $(GNUSHOGIDIR)/Makefile $(GNUSHOGIDIR)/Makefile.profile \ - autom4te.cache - -distclean: clean - rm -rf $(DISTCLEANFILES) - find -name '*~' | xargs rm -f - cd $(BUILDROOT)/doc && $(MAKE) distclean - -# -# Extra cleanup, for the maintainer only. -# - -MAINTAINERCLEANFILES = configure config.h.in win32/Makefile - -maintainerclean: distclean - rm -f $(MAINTAINERCLEANFILES) - cd $(BUILDROOT)/doc && $(MAKE) maintainerclean diff --git a/NEWS b/NEWS index 312e854..fc0694d 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,10 @@ GNU shogi news -------------- +Changes in version 1.5.0 (unreleased): + +* Build system switched from pure autoconf to automake + Changes in version 1.4.2 (unreleased): * XShogi is no longer included in the GNU Shogi source, it is diff --git a/TODO b/TODO index 48d2f19..ab9b5e0 100644 --- a/TODO +++ b/TODO @@ -1,7 +1,7 @@ Target for v1.5: -- refactor dspwrappers into a driver-like structure -- integrate H.G.Muller's work on the xboard protocol on top of that +- integrate H.G.Muller's work on the xboard protocol on top of new driver-like + display handling - deprecate xshogi in favor of xboard - make minishogi a run-time option rather than a compile-time one, using the "variant" mechanism of the xboard protocol @@ -10,12 +10,11 @@ Generic cleanups - switch cli parsing to getopt - hunt for extern's and prototypes spread all over the source -- use automake - hunt for more hardcoded variant-specific constants - position of captured pieces in curses mode - compile with bound-checker - add autosave mode to ease hunt for segfaults ? -- use 2D array for the board, get rid of the (i)nunmap stuff +- ? use 2D array for the board, get rid of the (i)nunmap stuff - fixup build procedure to support parallel make runs - investigate those preexisting "overflow in implicit constant conversion" warnings @@ -29,3 +28,13 @@ Minishogi-related stuff * OPENING_HINT - add minishogi stuff to the doc - use valid minishogi moves in online help + +Improvements + +- find out why the engine is so weak + - make it battle against Mutz-era gnushogi, and other engines, and + compare their evaluation results + - see what needs updating in book +- express available commands as display-dependant, instead of using if(XSHOGI) + - make "help" list commands available for current display +- make X and raw two different display drivers diff --git a/configure.ac b/configure.ac index cfc9b92..b312ce8 100644 --- a/configure.ac +++ b/configure.ac @@ -6,6 +6,7 @@ dnl Process this file with autoconf to produce a configure script. AC_PREREQ(2.57) AC_INIT([gnushogi],[1.4.1+],[https://savannah.gnu.org/bugs/?group=gnushogi]) +AM_INIT_AUTOMAKE AC_CONFIG_SRCDIR([gnushogi/gnushogi.h]) AC_CONFIG_HEADER(config.h) @@ -28,7 +29,8 @@ LIBCURSES= AS_IF([test "x$with_curses" != xno], [AC_CHECK_LIB([curses], [clrtoeol], [AC_SUBST([LIBCURSES], [-lcurses]) - AC_SUBST([CURSESDSP], [cursesdsp.o]) + AC_SUBST([CURSESDSP], [gnushogi-cursesdsp.o]) + AC_SUBST([CURSESDSPMINI], [gnuminishogi-cursesdsp.o]) AC_DEFINE([HAVE_LIBCURSES], [1], [Define if you have lib]) ], @@ -48,7 +50,7 @@ AC_CHECK_LIB([termcap], [tgoto]) if [[ $ac_cv_c_compiler_gnu = yes ]] then -WARNINGS="-Wall -Wno-implicit-int -Wstrict-prototypes -ansi -pedantic" +WARNINGS="-Wall -Wno-implicit-int -Wstrict-prototypes" CEXTRAFLAGS="-fsigned-char -funroll-loops" else # Who knows what warnings your compiler uses? diff --git a/doc/Makefile.am b/doc/Makefile.am new file mode 100644 index 0000000..fab0a4d --- /dev/null +++ b/doc/Makefile.am @@ -0,0 +1,37 @@ +# +# Documentation Makefile for GNU Shogi +# +# Copyright (c) 2013 Yann Dirson and the Free Software Foundation +# +# This file is part of GNU Shogi. +# +# GNU Shogi is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 1, or (at your option) +# any later version. +# +# GNU Shogi is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Shogi; see the file COPYING. If not, write to +# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. +# + +info_TEXINFOS = gnushogi.texi +AM_MAKEINFOHTMLFLAGS = --split=section + +dist_man_MANS = gnushogi.6 + +dist_doc_DATA = \ + BOOKFILES \ + PORTING \ + shogi.rules \ + tutorial1.gam \ + tutorial2.gam + +spell: + tr '[A-Z]' '[a-z]' < $(srcdir)/gnushogi.texi | tr -cd '[A-Za-z0-9_ \012]' | \ + tr -s '[ ]' '\012' | sort | uniq -c | sort -nr | spell | sort | uniq diff --git a/doc/Makefile.in b/doc/Makefile.in deleted file mode 100644 index 356926d..0000000 --- a/doc/Makefile.in +++ /dev/null @@ -1,46 +0,0 @@ -MAINTAINERCLEANFILES = *.info* -DISTCLEANFILES = *.ps *.html -CLEANFILES = *.log *.dvi *.aux *.dlog \ - *.cp *.cps *.fn *.ky *.pg *.toc *.tp *.vr - -SRCDIR = @srcdir@ - -info: - makeinfo $(SRCDIR)/gnushogi.texi - -dvi: - texi2dvi $(SRCDIR)/gnushogi.texi - -pdf: - texi2pdf $(SRCDIR)/gnushogi.texi - -# I do some egregious hacks to get around limitations of -# texi2html. - -html: - makeinfo --html --split=section $(SRCDIR)/gnushogi.texi - -ps: dvi - dvips -t letter gnushogi.dvi -o gnushogi.ps - -ps2: dvi - dvi2ps gnushogi.dvi > gnushogi.ps - -spell: - tr '[A-Z]' '[a-z]' < $(SRCDIR)/gnushogi.texi | tr -cd '[A-Za-z0-9_ \012]' | \ - tr -s '[ ]' '\012' | sort | uniq -c | sort -nr | spell | sort | uniq - -clean: - @for file in $(CLEANFILES); \ - do if [ -f $$file ]; then rm $$file; fi; \ - done - -distclean: clean - @for file in $(DISTCLEANFILES); \ - do if [ -f $$file ]; then rm $$file; fi; \ - done - -maintainerclean: distclean - @for file in $(MAINTAINERCLEANFILES); \ - do if [ -f $$file ]; then rm $$file; fi; \ - done diff --git a/gnushogi/Makefile.am b/gnushogi/Makefile.am new file mode 100644 index 0000000..9cd9a4c --- /dev/null +++ b/gnushogi/Makefile.am @@ -0,0 +1,131 @@ +# +# Makefile for GNU Shogi +# +# Copyright (c) 2013 Yann Dirson and the Free Software Foundation +# +# This file is part of GNU Shogi. +# +# GNU Shogi is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 1, or (at your option) +# any later version. +# +# GNU Shogi is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Shogi; see the file COPYING. If not, write to +# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. +# + +pkgbindatadir = $(pkglibdir) + +bin_PROGRAMS = gnushogi gnuminishogi +noinst_PROGRAMS = pat2inc sizetest + +pkgbindata_DATA = gnushogi.bbk +# gnuminishogi.bbk would be empty + +AM_CFLAGS = @CEXTRAFLAGS@ @WARNINGS@ + +# The hashfile is a record of positions seen. It is used by +# GNU Shogi to avoid making the same mistakes, a form of learning. + +HASH = -DHASHFILE=\"$(pkglibdir)/$(PROGNAME).hsh\" + + +# The "book" is a record of the first few moves, for playing good +# moves easily and quickly, saving time, and irritating the human +# opponent. + +TEXTBOOK = -DBOOK=\"$(pkglibdir)/$(PROGNAME).tbk\" +BINBOOK = -DBINBOOK=\"$(pkglibdir)/$(PROGNAME).bbk\" + + +# The pattern file contains various opening patterns. The program tries to +# obtain such a pattern in the opening stage. Sequences of opening +# patterns may be described in order to support the correct order of moves. + +gnushogi_CPPFLAGS = \ + -DHASHFILE=\"$(pkglibdir)/gnushogi.hsh\" \ + -DBOOK=\"$(pkglibdir)/gnushogi.tbk\" \ + -DBINBOOK=\"$(pkglibdir)/gnushogi.bbk\" +gnuminishogi_CPPFLAGS = \ + -DMINISHOGI \ + -DHASHFILE=\"$(pkglibdir)/gnuminishogi.hsh\" \ + -DBOOK=\"$(pkglibdir)/gnuminishogi.tbk\" \ + -DBINBOOK=\"$(pkglibdir)/gnuminishogi.bbk\" + +noinst_HEADERS = \ + book.h \ + debug.h \ + eval.h \ + gnushogi.h \ + opts.h \ + pattern.h + +COMMONSOURCES = \ + globals.c \ + init-common.c \ + pattern-common.c + +NOTCOMMONFILES = \ + attacks.c \ + book.c \ + commondsp.c \ + eval.c \ + genmove.c \ + init.c \ + pattern.c \ + rawdsp.c \ + search.c \ + tcontrl.c \ + util.c + +gnushogi_SOURCES = \ + main.c \ + $(NOTCOMMONFILES) \ + $(COMMONSOURCES) +gnuminishogi_SOURCES = \ + main.c \ + $(NOTCOMMONFILES) \ + $(COMMONSOURCES) + +EXTRA_gnushogi_SOURCES = \ + cursesdsp.c +EXTRA_gnuminishogi_SOURCES = \ + cursesdsp.c + +BUILT_SOURCES = \ + gnushogi-pattern.inc \ + gnuminishogi-pattern.inc + +gnushogi_DEPENDENCIES = @CURSESDSP@ +gnushogi_LDADD = @CURSESDSP@ @LIBCURSES@ +gnuminishogi_DEPENDENCIES = @CURSESDSPMINI@ +gnuminishogi_LDADD = @CURSESDSPMINI@ @LIBCURSES@ + +pat2inc_SOURCES = \ + pat2inc.c \ + makepattern.c \ + $(COMMONSOURCES) + +pat2inc_LDADD = @LIBCURSES@ + +gnushogi-pattern.inc: $(top_srcdir)/misc/gnushogi.pat pat2inc$(EXEEXT) + ./pat2inc $< $@ +gnuminishogi-pattern.inc: $(top_srcdir)/misc/gnuminishogi.pat pat2inc$(EXEEXT) + ./pat2inc $< $@ + +gnushogi.bbk: $(top_srcdir)/misc/gnushogi.tbk gnushogi$(EXEEXT) + rm -f $@ + cat $< > _tmp_t + echo quit | ./gnushogi -R -b _tmp_t -B $@ -S 8000 -P 40 3 0 + rm _tmp_t +gnuminishogi.bbk: $(top_srcdir)/misc/gnuminishogi.tbk gnuminishogi$(EXEEXT) + rm -f $@ + cat $< > _tmp_t + echo quit | ./gnuminishogi -R -b _tmp_t -B $@ -S 8000 -P 40 3 0 + rm _tmp_t diff --git a/gnushogi/Makefile.in b/gnushogi/Makefile.in deleted file mode 100644 index 60d5c7b..0000000 --- a/gnushogi/Makefile.in +++ /dev/null @@ -1,293 +0,0 @@ -# -# Makefile for GNU Shogi -# -# Copyright (c) 1993, 1994 Matthias Mutz -# Copyright (c) 1998, 1999 Michael Vanier and the Free Software Foundation -# Copyright (c) 2008, 2013, 2014 Yann Dirson and the Free Software Foundation -# -# GNU Shogi is based on GNU Chess -# Copyright (c) 1992 Free Software Foundation -# -# This file is part of GNU Shogi. -# -# GNU Shogi is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or (at your option) -# any later version. -# -# GNU Shogi is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with GNU Shogi; see the file COPYING. -# If not, see . -# - -# -# gnushogi is GNU shogi, for raw text, curses, or x output. -# gnuminishogi is GNU minishogi, for raw text, curses, or x output. -# pat2inc converts pattern textfile to "pattern.inc" include file. -# sizetest shows the memory usage of the main data structures. -# - -SHELL = /bin/sh -INSTALL = @INSTALL@ -INSTALL_DATA = @INSTALL_DATA@ -INSTALL_PROGRAM = @INSTALL_PROGRAM@ -ROOT = @top_srcdir@ -SRCDIR = @srcdir@ - -VPATH=$(SRCDIR) - -PROGNAME=@PROGNAME@ - -# Installation directory. -prefix = @prefix@ - -# Where the binaries live. -BINDIR = $(prefix)/bin - -# Where the language description, the book, and the -# persistent hashtable live. -LIBDIR = $(prefix)/lib/$(PROGNAME) - -# Where the man page goes. -MANDIR = $(prefix)/man/man6 - -# Where the info file goes. -INFODIR = $(prefix)/info - -# For _pow external -LIBS = -lm - -# Display routines. -LCURSES = @LIBCURSES@ - - -# -# C compiler and compiler options. -# - -CC = @CC@ -CWARNINGS = @WARNINGS@ -CEXTRAFLAGS = @CEXTRAFLAGS@ -CFLAGS = @CFLAGS@ $(HASH) $(CEXTRAFLAGS) $(CWARNINGS) -I. -I@top_builddir@ -I$(ROOT) -LDFLAGS = @LDFLAGS@ - -# The hashfile is a record of positions seen. It is used by -# GNU Shogi to avoid making the same mistakes, a form of learning. - -HASH = -DHASHFILE=\"$(LIBDIR)/$(PROGNAME).hsh\" - - -# The "book" is a record of the first few moves, for playing good -# moves easily and quickly, saving time, and irritating the human -# opponent. - -TEXTBOOK = -DBOOK=\"$(LIBDIR)/$(PROGNAME).tbk\" -BINBOOK = -DBINBOOK=\"$(LIBDIR)/$(PROGNAME).bbk\" - - -# The pattern file contains various opening patterns. The program tries to -# obtain such a pattern in the opening stage. Sequences of opening -# patterns may be described in order to support the correct order of moves. - -PATTERNFILE=$(ROOT)/misc/$(PROGNAME).pat -PATTERN = -DPATTERNFILE=\"$(PATTERNFILE)\" - - -all: - @echo No target specified. - - -# -# Source files. -# - -COMMONFILES = \ - globals.o \ - init-common.o \ - pattern-common.o - -NOTCOMMONFILES = \ - attacks.o \ - book.o \ - commondsp.o \ - @CURSESDSP@ \ - dspwrappers.o \ - eval.o \ - genmove.o \ - init.o \ - pattern.o \ - rawdsp.o \ - search.o \ - tcontrl.o \ - util.o - -GNUSHOGI_FILES = $(COMMONFILES) $(NOTCOMMONFILES) main.o - - -PAT2INCFILES = $(COMMONFILES) makepattern.o pat2inc.o - - -# -# Primary targets. -# - -$(PROGNAME): - $(CC) $(CFLAGS) -o $(PROGNAME) $(GNUSHOGI_FILES) $(LDFLAGS) $(LCURSES) $(LIBS) - -pat2inc: - $(CC) $(CFLAGS) -o pat2inc $(PAT2INCFILES) $(LDFLAGS) $(LCURSES) $(LIBS) - -sizetest: - $(CC) $(CFLAGS) -o sizetest sizetest.o $(LDFLAGS) $(LIBS) - -profile: - $(MAKE) -f Makefile.profile gnushogi - -# -# Object files. -# - -# Common files. - -attacks.o: attacks.c - $(CC) $(CFLAGS) -c $< - -book.o: book.c - $(CC) $(CFLAGS) $(TEXTBOOK) $(BINBOOK) -c $< - -commondsp.o: commondsp.c - $(CC) $(CFLAGS) -c $< - -cursesdsp.o: cursesdsp.c - $(CC) $(CFLAGS) -c $< - -dspwrappers.o: dspwrappers.c - $(CC) $(CFLAGS) -c $< - -genmove.o: genmove.c - $(CC) $(CFLAGS) -c $< - -globals.o: globals.c - $(CC) $(CFLAGS) -c $< - -eval.o: eval.c - $(CC) $(CFLAGS) -c $< - -init.o: init.c - $(CC) $(CFLAGS) -c $< - -init-common.o: init-common.c - $(CC) $(CFLAGS) $(LANGF) -c $< - -main.o: main.c - $(CC) $(CFLAGS) $(BINBOOK) -c $< - -# To create "pattern.inc" with "pat2inc", the external -# pattern textfile must be used. - -makepattern.o: makepattern.c - $(CC) $(CFLAGS) $(PATTERN) -c $< - -pattern.o: pattern.c - $(CC) $(CFLAGS) -c $< - -pattern-common.o: pattern-common.c - $(CC) $(CFLAGS) -c $< - -rawdsp.o: rawdsp.c - $(CC) $(CFLAGS) -c $< - -search.o: search.c - $(CC) $(CFLAGS) -c $< - -tcontrl.o: tcontrl.c - $(CC) $(CFLAGS) -c $< - -util.o: util.c - $(CC) $(CFLAGS) -c $< - - -# Files specific to particular targets. - -pat2inc.o: pat2inc.c - $(CC) $(CFLAGS) -c $< - -sizetest.o: sizetest.c - $(CC) $(CFLAGS) -c $< - -pattern.inc: $(PATTERNFILE) pat2inc - ./pat2inc - -# -# Other targets. -# - -$(PROGNAME).bbk: - @if [ -f ./$(PROGNAME).bbk ]; then rm ./$(PROGNAME).bbk; fi - echo quit > test - cat $(ROOT)/misc/$(PROGNAME).tbk > _tmp_t - cat test | ./$(PROGNAME) -R -b _tmp_t -B ./$(PROGNAME).bbk -S 8000 -P 40 3 0 - rm test _tmp_t - @echo - - -# -# Installation. -# - -install: $(PROGNAME) - strip $(PROGNAME) - $(INSTALL_PROGRAM) -d $(BINDIR) - $(INSTALL_PROGRAM) -d $(LIBDIR) - $(INSTALL_PROGRAM) -d $(MANDIR) - $(INSTALL_PROGRAM) -d $(INFODIR) - $(INSTALL_PROGRAM) $(PROGNAME) $(BINDIR) - $(INSTALL_DATA) $(ROOT)/doc/gnushogi.6 $(MANDIR) - $(INSTALL_DATA) $(ROOT)/doc/gnushogi.info* $(INFODIR) - $(INSTALL_DATA) $(PROGNAME).bbk $(LIBDIR)/$(PROGNAME).bbk - - -# -# Cleanup. -# - -CLEANFILES = *.o gnushogi gnuminishogi sizetest pat2inc CLp* *.bbk - -clean: - @for file in $(CLEANFILES); do \ - if [ -f $$file ]; then rm $$file; fi; \ - done - - -# -# Dependencies. -# - -$(PROGNAME): $(GNUSHOGI_FILES) -pat2inc: $(PAT2INCFILES) -sizetest: sizetest.o -attacks.o: attacks.c gnushogi.h -book.o: book.c gnushogi.h -commondsp.o: commondsp.c gnushogi.h -cursesdsp.o: cursesdsp.c gnushogi.h -dspwrappers.o: dspwrappers.c gnushogi.h -genmove.o: genmove.c gnushogi.h -globals.o: globals.c gnushogi.h -eval.o: eval.c eval.h gnushogi.h $(SRCDIR)/pattern.h -init.o: init.c gnushogi.h $(SRCDIR)/pattern.h -main.o: main.c gnushogi.h -makepattern.o: pattern.c gnushogi.h $(SRCDIR)/pattern.h -pattern.o: pattern.c gnushogi.h $(SRCDIR)/pattern.h pattern.inc -rawdsp.o: rawdsp.c gnushogi.h -search.o: search.c gnushogi.h -tcontrl.o: tcontrl.c gnushogi.h -util.o: util.c gnushogi.h -pat2inc.o: pat2inc.c $(SRCDIR)/pattern.h $(SRCDIR)/gnushogi.h -sizetest.o: sizetest.c $(SRCDIR)/gnushogi.h $(SRCDIR)/eval.h -$(PROGNAME).bbk: $(PROGNAME) - diff --git a/gnushogi/book.c b/gnushogi/book.c index 009e409..6bf2af9 100644 --- a/gnushogi/book.c +++ b/gnushogi/book.c @@ -117,8 +117,8 @@ Balgbr(short f, short t, short flag) short piece = flag & pmask; bmvstr[0][0] = pxx[piece]; bmvstr[0][1] = '*'; - bmvstr[0][2] = cxx[column(t)]; - bmvstr[0][3] = rxx[row(t)]; + bmvstr[0][2] = COL_NAME(column(t)); + bmvstr[0][3] = ROW_NAME(row(t)); bmvstr[0][4] = bmvstr[2][0] = '\0'; strcpy(bmvstr[1], bmvstr[0]); bmvstr[1][1] = '\''; @@ -130,10 +130,10 @@ Balgbr(short f, short t, short flag) /* algebraic notation */ /* bmvstr[0]: 7g7f bmvstr[1]: * (+)P7g7f(+) bmvstr[2]: (+)P7f(+) */ - bmvstr[0][0] = cxx[column(f)]; - bmvstr[0][1] = rxx[row(f)]; - bmvstr[0][2] = cxx[column(t)]; - bmvstr[0][3] = rxx[row(t)]; + bmvstr[0][0] = COL_NAME(column(f)); + bmvstr[0][1] = ROW_NAME(row(f)); + bmvstr[0][2] = COL_NAME(column(t)); + bmvstr[0][3] = ROW_NAME(row(t)); bmvstr[0][4] = '\0'; if (promoted) @@ -366,7 +366,7 @@ RESET(void) static int -Vparse (FILE * fd, USHORT *mv, USHORT *flags, USHORT side, int moveno) +Vparse (FILE * fd, USHORT *mv, USHORT *flags, int moveno) { int c, i; char s[255]; @@ -647,7 +647,7 @@ GetOpenings(void) { short i; int mustwrite = false, first; - unsigned short xside, side; + unsigned short side; short c; USHORT mv, flags; unsigned int x; @@ -716,11 +716,10 @@ GetOpenings(void) { /* setvbuf(fd, buffr, _IOFBF, 2048); */ side = black; - xside = white; hashbd = hashkey = 0; i = 0; - while ((c = Vparse(fd, &mv, &flags, side, i)) >= 0) + while ((c = Vparse(fd, &mv, &flags, i)) >= 0) { if (c == 1) { @@ -822,7 +821,6 @@ GetOpenings(void) computer = opponent; opponent = computer ^ 1; - xside = side; side = side ^ 1; } else if (i > 0) @@ -833,8 +831,6 @@ GetOpenings(void) RESET(); i = 0; side = black; - xside = white; - } } @@ -876,8 +872,8 @@ GetOpenings(void) } - sprintf(msg, "Book used %d(%d).", B.bookcount, B.booksize); - ShowMessage(msg); + sprintf(msg, "Book used %lu(%lu).", B.bookcount, B.booksize); + dsp->ShowMessage(msg); } /* Set everything back to start the game. */ @@ -887,7 +883,7 @@ GetOpenings(void) /* Now get ready to play .*/ if (!B.bookcount) { - ShowMessage("Can't find book."); + dsp->ShowMessage("Can't find book."); Book = 0; } } @@ -895,7 +891,7 @@ GetOpenings(void) /* - * OpeningBook(hint, side) + * OpeningBook(hint) * * Go through each of the opening lines of play and check for a match with * the current game listing. If a match occurs, generate a random @@ -907,7 +903,7 @@ GetOpenings(void) */ int -OpeningBook(unsigned short *hint, short side) +OpeningBook(unsigned short *hint) { unsigned short r, m; int possibles = TrPnt[2] - TrPnt[1]; diff --git a/gnushogi/commondsp.c b/gnushogi/commondsp.c index 49b3805..90a3ca0 100644 --- a/gnushogi/commondsp.c +++ b/gnushogi/commondsp.c @@ -50,8 +50,9 @@ #include "gnushogi.h" char mvstr[4][6]; -char *InPtr; -int InBackground = false; +int mycnt1, mycnt2; +static char *InPtr; +struct display *dsp = &raw_display; #if defined(BOOKTEST) @@ -93,20 +94,20 @@ movealgbr(short m, char *s) s++; *s = '*'; s++; - *s = cxx[column(t)]; + *s = COL_NAME(column(t)); s++; - *s = rxx[row(t)]; + *s = ROW_NAME(row(t)); s++; } else { - *s = cxx[column(f)]; + *s = COL_NAME(column(f)); s++; - *s = rxx[row(f)]; + *s = ROW_NAME(row(f)); s++; - *s = cxx[column(t)]; + *s = COL_NAME(column(t)); s++; - *s = rxx[row(t)]; + *s = ROW_NAME(row(t)); s++; if (flag & promote) @@ -128,8 +129,6 @@ movealgbr(short m, char *s) #endif /* BOOKTEST */ - - /* * Generate move strings in different formats. * @@ -139,7 +138,10 @@ movealgbr(short m, char *s) * - NO_SQUARES <= f NO_SQUARES + 2*NO_PIECES dropped piece modulo NO_PIECES * - t & 0x7f target square * - t & 0x80 promotion flag - * - flag FIXME: must be zero ? + * - flag + * - if flag & dropmask, piece type encoded in flag & pmask + * + * FIXME: that makes 2 ways to specify drops and promotions, why ? * * OUTPUT: * - GLOBAL mvstr @@ -168,8 +170,8 @@ algbr(short f, short t, short flag) if ((f == t) && ((f != 0) || (t != 0))) { - if (!barebones) { - Printf("error in algbr: FROM=TO=%d, flag=0x%4x\n", t, flag); + if (!XSHOGI) { + dsp->Printf("error in algbr: FROM=TO=%d, flag=0x%4x\n", t, flag); } mvstr[0][0] = mvstr[1][0] = mvstr[2][0] = mvstr[3][0] = '\0'; @@ -180,8 +182,8 @@ algbr(short f, short t, short flag) mvstr[0][0] = pxx[piece]; mvstr[0][1] = '*'; - mvstr[0][2] = cxx[column(t)]; - mvstr[0][3] = rxx[row(t)]; + mvstr[0][2] = COL_NAME(column(t)); + mvstr[0][3] = ROW_NAME(row(t)); mvstr[0][4] = '\0'; strcpy(mvstr[1], mvstr[0]); strcpy(mvstr[2], mvstr[0]); @@ -189,20 +191,27 @@ algbr(short f, short t, short flag) } else if ((f != 0) || (t != 0)) { - /* algebraic notation */ - mvstr[0][0] = cxx[column(f)]; - mvstr[0][1] = rxx[row(f)]; - mvstr[0][2] = cxx[column(t)]; - mvstr[0][3] = rxx[row(t)]; - mvstr[0][4] = mvstr[3][0] = '\0'; + /* pure coordinates notation */ + mvstr[0][0] = COL_NAME(column(f)); + mvstr[0][1] = ROW_NAME(row(f)); + mvstr[0][2] = COL_NAME(column(t)); + mvstr[0][3] = ROW_NAME(row(t)); + mvstr[0][4] = '\0'; + + /* algebraic notation without disambiguation */ mvstr[1][0] = pxx[board[f]]; + mvstr[1][1] = mvstr[0][2]; /* to column */ + mvstr[1][2] = mvstr[0][3]; /* to row */ + mvstr[1][3] = '\0'; + /* algebraic notation with row disambiguation */ mvstr[2][0] = mvstr[1][0]; mvstr[2][1] = mvstr[0][1]; + mvstr[2][2] = mvstr[0][2]; /* to column */ + mvstr[2][3] = mvstr[0][3]; /* to row */ + mvstr[2][4] = '\0'; - mvstr[2][2] = mvstr[1][1] = mvstr[0][2]; /* to column */ - mvstr[2][3] = mvstr[1][2] = mvstr[0][3]; /* to row */ - mvstr[2][4] = mvstr[1][3] = '\0'; + /* algebraic notation with column disambiguation */ strcpy(mvstr[3], mvstr[2]); mvstr[3][1] = mvstr[0][0]; @@ -221,7 +230,6 @@ algbr(short f, short t, short flag) } - /* * Compare the string 's' to the list of legal moves available for the * opponent. If a match is found, make the move on the board. @@ -302,7 +310,7 @@ VerifyMove(char *s, VerifyMove_mode iop, unsigned short *mv) if (SqAttacked(PieceList[opponent][0], computer, &blocked)) { UnmakeMove(opponent, &xnode, &tempb, &tempc, &tempsf, &tempst); - AlwaysShowMessage("Illegal move (in check) %s", s); + dsp->AlwaysShowMessage("Illegal move (in check) %s", s); return false; } else @@ -310,7 +318,7 @@ VerifyMove(char *s, VerifyMove_mode iop, unsigned short *mv) if (iop == VERIFY_AND_TRY_MODE) return true; - UpdateDisplay(xnode.f, xnode.t, 0, (short) xnode.flags); + dsp->UpdateDisplay(xnode.f, xnode.t, 0, (short) xnode.flags); GameList[GameCnt].depth = GameList[GameCnt].score = 0; GameList[GameCnt].nodes = 0; ElapsedTime(COMPUTE_AND_INIT_MODE); @@ -335,7 +343,7 @@ VerifyMove(char *s, VerifyMove_mode iop, unsigned short *mv) char buf[20]; sprintf(buf, "%s mates!\n", ColorStr[opponent]); - ShowMessage(buf); + dsp->ShowMessage(buf); flag.mate = true; } } @@ -344,21 +352,20 @@ VerifyMove(char *s, VerifyMove_mode iop, unsigned short *mv) } } - AlwaysShowMessage("Illegal move (no match) %s", s); + dsp->AlwaysShowMessage("Illegal move (no match) %s", s); - if (!barebones && (cnt > 1)) + if (!XSHOGI && (cnt > 1)) { sprintf(buffer, "Ambiguous Move %s!", s); - ShowMessage(buffer); + dsp->ShowMessage(buffer); } return false; } - static int -parser(char *f, int side, short *fpiece) +parser(char *f, short *fpiece) { int c1, r1, c2, r2; short i, p = false; @@ -406,7 +413,6 @@ skip() } - void skipb() { @@ -415,8 +421,25 @@ skipb() } +void RequestInputString(char* buffer, unsigned bufsize) +{ + static char fmt[10]; + int ret = snprintf(fmt, sizeof(fmt), "%%%us", bufsize); + if (ret < 0 ) { + perror("RequestInputString snprintf"); + exit(1); + } + if (ret >= sizeof(fmt)) { + fprintf(stderr, + "Insufficient format-buffer size in %s for bufsize=%u\n", + __FUNCTION__, bufsize); + exit(1); + } + dsp->doRequestInputString(fmt, buffer); +} -void + +static void GetGame(void) { FILE *fd; @@ -428,7 +451,7 @@ GetGame(void) if (savefile[0]) { strcpy(fname, savefile); } else { - ShowMessage("Enter file name: "); + dsp->ShowMessage("Enter file name: "); RequestInputString(fname, sizeof(fname)-1); } @@ -580,7 +603,7 @@ GetGame(void) InPtr = fname; skipb(); g = &GameList[GameCnt]; - g->gmove = parser(InPtr, side, &g->fpiece); + g->gmove = parser(InPtr, &g->fpiece); skip(); g->score = atoi(InPtr); skip(); @@ -633,14 +656,13 @@ GetGame(void) ZeroRPT(); InitializeStats(); - UpdateDisplay(0, 0, 1, 0); + dsp->UpdateDisplay(0, 0, 1, 0); Sdepth = 0; hint = 0; } - -void +static void SaveGame(void) { FILE *fd; @@ -653,7 +675,7 @@ SaveGame(void) if (savefile[0]) { strcpy(fname, savefile); } else { - ShowMessage("Enter file name: "); + dsp->ShowMessage("Enter file name: "); RequestInputString(fname, sizeof(fname)-1); } @@ -778,22 +800,21 @@ SaveGame(void) fclose(fd); - ShowMessage("Game saved"); + dsp->ShowMessage("Game saved"); } else { - ShowMessage("Could not open file"); + dsp->ShowMessage("Could not open file"); } } - /* * GetXGame, SaveXGame and BookGame used to only be defined if * xshogi wasn't defined -- wonder why? */ -void +static void GetXGame(void) { FILE *fd; @@ -802,7 +823,7 @@ GetXGame(void) short sq; short side, isp; - ShowMessage("Enter file name: "); + dsp->ShowMessage("Enter file name: "); RequestInputString(fname, sizeof(fname)-1); if (fname[0] == '\0') @@ -916,13 +937,13 @@ GetXGame(void) Game50 = 1; ZeroRPT(); InitializeStats(); - UpdateDisplay(0, 0, 1, 0); + dsp->UpdateDisplay(0, 0, 1, 0); Sdepth = 0; hint = 0; } -void +static void SaveXGame(void) { FILE *fd; @@ -931,7 +952,7 @@ SaveXGame(void) short sq, piece; short side, isp; - ShowMessage("Enter file name: "); + dsp->ShowMessage("Enter file name: "); RequestInputString(fname, sizeof(fname)-1); if (fname[0] == '\0') @@ -1002,7 +1023,7 @@ SaveXGame(void) } -void +static void BookSave(void) { FILE *fd; @@ -1013,7 +1034,7 @@ BookSave(void) strcpy(fname, savefile); } else { /* Enter file name */ - ShowMessage("Enter file name: "); + dsp->ShowMessage("Enter file name: "); RequestInputString(fname, sizeof(fname)-1); } @@ -1085,16 +1106,15 @@ BookSave(void) fclose(fd); - ShowMessage("Game saved"); + dsp->ShowMessage("Game saved"); } else { - ShowMessage("Could not open file"); + dsp->ShowMessage("Could not open file"); } } - void ListGame(void) { @@ -1222,8 +1242,7 @@ ListGame(void) } - -void +static void FlagMove(char c) { switch(c) @@ -1245,13 +1264,11 @@ FlagMove(char c) } - - /* * Undo the most recent half-move. */ -void +static void Undo(void) { short f, t; @@ -1300,69 +1317,15 @@ Undo(void) flag.mate = false; Sdepth = 0; player = player ^ 1; - ShowSidetoMove(); - UpdateDisplay(0, 0, 1, 0); + dsp->ShowSidetoMove(); + dsp->UpdateDisplay(0, 0, 1, 0); if (flag.regularstart) Book = false; } - -void -FlagString(unsigned short flags, char *s) -{ - short l, piece; - *s = '\0'; - - if (flags & promote) - strcat(s, " promote"); - - if (flags & dropmask) - strcat(s, " drop:"); - - if ((piece = (flags & pmask))) - { - l = strlen(s); - - if (is_promoted[piece]) - s[l++] = '+'; - - s[l++] = pxx[piece]; - s[l] = '\0'; - } - - if (flags & capture) - strcat(s, " capture"); - - if (flags & exact) - strcat(s, " exact"); - - if (flags & tesuji) - strcat(s, " tesuji"); - - if (flags & check) - strcat(s, " check"); - - if (flags & draw) - strcat(s, " draw"); - - if (flags & stupid) - strcat(s, " stupid"); - - if (flags & questionable) - strcat(s, " questionable"); - - if (flags & kingattack) - strcat(s, " kingattack"); - - if (flags & book) - strcat(s, " book"); -} - - - -void +static void TestSpeed(void(*f)(short side, short ply, short in_check, short blockable), unsigned j) @@ -1412,15 +1375,14 @@ TestSpeed(void(*f)(short side, short ply, else et = 1; - ShowNodeCnt(cnt); + dsp->ShowNodeCnt(cnt); } - -void +static void TestPSpeed(short(*f) (short side), unsigned j) { - short i; + unsigned i; long cnt, t1, t2; #ifdef HAVE_GETTIMEOFDAY struct timeval tv; @@ -1450,24 +1412,22 @@ TestPSpeed(short(*f) (short side), unsigned j) else et = 1; - ShowNodeCnt(cnt); + dsp->ShowNodeCnt(cnt); } - -void -SetOppTime(char *s) +static void +SetOppTime(char *time) { - char *time; int m, t, sec; sec = 0; - time = &s[strlen("otime")]; t = (int)strtol(time, &time, 10); if (*time == ':') { time++; + /* FIXME: sec is parsed but ignored */ sec = (int)strtol(time, &time, 10); } @@ -1489,20 +1449,18 @@ SetOppTime(char *s) } - -void -SetMachineTime(char *s) +static void +SetMachineTime(char *time) { - char *time; int m, t, sec; - time = &s[strlen("time")]; sec = 0; t = (int)strtol(time, &time, 10); if (*time == ':') { time++; + /* FIXME: sec is parsed but ignored */ sec = (int)strtol(time, &time, 10); } @@ -1524,24 +1482,19 @@ SetMachineTime(char *s) } - - - /* FIXME! This is truly the function from hell! */ /* * Process the user's command. If easy mode is OFF (the computer is thinking * on opponents time) and the program is out of book, then make the 'hint' * move on the board and call SelectMove() to find a response. The user - * terminates the search by entering ^C (quit siqnal) before entering a - * command. If the opponent does not make the hint move, then set Sdepth to - * zero. + * terminates the search by entering a command. If the opponent does not make + * the hint move, then set Sdepth to zero. */ void InputCommand(char *command) { - int eof = 0; short have_shown_prompt = false; short ok, done, is_move = false; unsigned short mv; @@ -1568,10 +1521,8 @@ InputCommand(char *command) algbr((short) hint >> 8, (short) hint & 0xff, false); strcpy(s, mvstr[0]); -#if !defined NOPOST if (flag.post) - GiveHint(); -#endif + dsp->GiveHint(); /* do the hint move */ if (VerifyMove(s, VERIFY_AND_TRY_MODE, &mv)) @@ -1579,7 +1530,7 @@ InputCommand(char *command) Sdepth = 0; #ifdef QUIETBACKGROUND - ShowPrompt(); + dsp->ShowPrompt(); have_shown_prompt = true; #endif /* QUIETBACKGROUND */ @@ -1626,7 +1577,7 @@ InputCommand(char *command) { #endif /* QUIETBACKGROUND */ - ShowPrompt(); + dsp->ShowPrompt(); #ifdef QUIETBACKGROUND } @@ -1635,21 +1586,16 @@ InputCommand(char *command) #endif /* QUIETBACKGROUND */ if (command == NULL) { - if (NOT_CURSES) - s[0] = '\0'; - - eof = GetString(sx); + int eof = dsp->GetString(sx); + if (eof) + dsp->ExitShogi(); } else { strcpy(sx, command); done = true; } - sscanf(sx, "%s", s); - - if (eof) - ExitShogi(); - - if (s[0] == '\0') + /* extract first word */ + if (sscanf(sx, "%s", s) < 1) continue; if (strcmp(s, "bd") == 0) /* bd -- display board */ @@ -1660,8 +1606,8 @@ InputCommand(char *command) if (old_xshogi) display_type = DISPLAY_RAW; - ClearScreen(); - UpdateDisplay(0, 0, 1, 0); + dsp->ClearScreen(); + dsp->UpdateDisplay(0, 0, 1, 0); if (old_xshogi) display_type = DISPLAY_X; @@ -1672,27 +1618,21 @@ InputCommand(char *command) } else if (strcmp(s, "alg") == 0) { - /* noop */ ; /* alg */ + /* noop */ ; } else if ((strcmp(s, "quit") == 0) || (strcmp(s, "exit") == 0)) { flag.quit = true; } -#if !defined NOPOST - else if (strcmp(s, "post") == 0) - { - flag.post = !flag.post; - } -#endif else if ((strcmp(s, "set") == 0) || (strcmp(s, "edit") == 0)) { - EditBoard(); + dsp->EditBoard(); } - else if ((strcmp(s, "setup") == 0)) + else if (strcmp(s, "setup") == 0) { - SetupBoard(); + dsp->SetupBoard(); } else if (strcmp(s, "first") == 0) { @@ -1716,7 +1656,7 @@ InputCommand(char *command) } else if (strcmp(s, "help") == 0) { - help(); + dsp->help(); } else if (strcmp(s, "material") == 0) { @@ -1742,16 +1682,19 @@ InputCommand(char *command) else if (strcmp(s, "new") == 0) { NewGame(); - UpdateDisplay(0, 0, 1, 0); + dsp->UpdateDisplay(0, 0, 1, 0); } else if (strcmp(s, "list") == 0) { ListGame(); } - else if ((strcmp(s, "level") == 0) - || (strcmp(s, "clock") == 0)) + else if (strcmp(s, "level") == 0) { - SelectLevel(sx); + dsp->SelectLevel(sx + strlen("level")); + } + else if (strcmp(s, "clock") == 0) + { + dsp->SelectLevel(sx + strlen("clock")); } else if (strcmp(s, "hash") == 0) { @@ -1767,19 +1710,19 @@ InputCommand(char *command) } else if (strcmp(s, "time") == 0) { - SetMachineTime(sx); + SetMachineTime(sx + strlen("time")); } else if (strcmp(s, "otime") == 0) { - SetOppTime(sx); + SetOppTime(sx + strlen("otime")); } else if (strcmp(s, "Awindow") == 0) { - ChangeAlphaWindow(); + dsp->ChangeAlphaWindow(); } else if (strcmp(s, "Bwindow") == 0) { - ChangeBetaWindow(); + dsp->ChangeBetaWindow(); } else if (strcmp(s, "rcptr") == 0) { @@ -1787,7 +1730,7 @@ InputCommand(char *command) } else if (strcmp(s, "hint") == 0) { - GiveHint(); + dsp->GiveHint(); } else if (strcmp(s, "both") == 0) { @@ -1801,8 +1744,8 @@ InputCommand(char *command) else if (strcmp(s, "reverse") == 0) { flag.reverse = !flag.reverse; - ClearScreen(); - UpdateDisplay(0, 0, 1, 0); + dsp->ClearScreen(); + dsp->UpdateDisplay(0, 0, 1, 0); } else if (strcmp(s, "switch") == 0) { @@ -1880,11 +1823,15 @@ InputCommand(char *command) } else if (strcmp(s, "depth") == 0) { - ChangeSearchDepth(); + dsp->ChangeSearchDepth(sx + strlen("depth")); + } + else if (strcmp(s, "sd") == 0) + { + dsp->ChangeSearchDepth(sx + strlen("sd")); } else if (strcmp(s, "hashdepth") == 0) { - ChangeHashDepth(); + dsp->ChangeHashDepth(); } else if (strcmp(s, "random") == 0) { @@ -1904,26 +1851,26 @@ InputCommand(char *command) } else if (strcmp(s, "contempt") == 0) { - SetContempt(); + dsp->SetContempt(); } else if (strcmp(s, "xwndw") == 0) { - ChangeXwindow(); + dsp->ChangeXwindow(); } else if (strcmp(s, "rv") == 0) { flag.rv = !flag.rv; - UpdateDisplay(0, 0, 1, 0); + dsp->UpdateDisplay(0, 0, 1, 0); } else if (strcmp(s, "coords") == 0) { flag.coords = !flag.coords; - UpdateDisplay(0, 0, 1, 0); + dsp->UpdateDisplay(0, 0, 1, 0); } else if (strcmp(s, "stars") == 0) { flag.stars = !flag.stars; - UpdateDisplay(0, 0, 1, 0); + dsp->UpdateDisplay(0, 0, 1, 0); } else if (!XSHOGI && strcmp(s, "moves") == 0) { @@ -1941,44 +1888,44 @@ InputCommand(char *command) #endif SwagHt = 0; - ShowMessage("Testing MoveList Speed"); + dsp->ShowMessage("Testing MoveList Speed"); temp = generate_move_flags; generate_move_flags = true; TestSpeed(MoveList, 1); generate_move_flags = temp; - ShowMessage("Testing CaptureList Speed"); + dsp->ShowMessage("Testing CaptureList Speed"); TestSpeed(CaptureList, 1); - ShowMessage("Testing Eval Speed"); + dsp->ShowMessage("Testing Eval Speed"); ExaminePosition(opponent); TestPSpeed(ScorePosition, 1); } else if (!XSHOGI && strcmp(s, "test") == 0) { #ifdef SLOW_CPU - ShowMessage("Testing MoveList Speed"); + dsp->ShowMessage("Testing MoveList Speed"); TestSpeed(MoveList, 2000); - ShowMessage("Testing CaptureList Speed"); + dsp->ShowMessage("Testing CaptureList Speed"); TestSpeed(CaptureList, 3000); - ShowMessage("Testing Eval Speed"); + dsp->ShowMessage("Testing Eval Speed"); ExaminePosition(opponent); TestPSpeed(ScorePosition, 1500); #else - ShowMessage("Testing MoveList Speed"); + dsp->ShowMessage("Testing MoveList Speed"); TestSpeed(MoveList, 20000); - ShowMessage("Testing CaptureList Speed"); + dsp->ShowMessage("Testing CaptureList Speed"); TestSpeed(CaptureList, 30000); - ShowMessage("Testing Eval Speed"); + dsp->ShowMessage("Testing Eval Speed"); ExaminePosition(opponent); TestPSpeed(ScorePosition, 15000); #endif } else if (!XSHOGI && strcmp(s, "p") == 0) { - ShowPostnValues(); + dsp->ShowPostnValues(); } else if (!XSHOGI && strcmp(s, "debug") == 0) { - DoDebug(); + dsp->DoDebug(); } else { @@ -1994,7 +1941,7 @@ InputCommand(char *command) if (rpt >= 3) { DRAW = DRAW_REPETITION; - ShowMessage(DRAW); + dsp->ShowMessage(DRAW); GameList[GameCnt].flags |= draw; flag.mate = true; @@ -2025,48 +1972,5 @@ InputCommand(char *command) printf("%d. %s %ld\n", ++mycnt2, s, TimeControl.clock[player] * 10); } - -#ifdef notdef /* optional pass best line to frontend with move */ -# if !defined NOPOST - - if (flag.post && !flag.mate) - { - int i; - - printf(" %6d ", MSCORE); - - for (i = 1; MV[i] > 0; i++) - { - algbr((short) (MV[i] >> 8), (short) (MV[i] & 0xFF), false); - printf("%5s ", mvstr[0]); - } - } -# endif - printf("\n"); -#endif } } - - - - -void -SetTimeControl(void) -{ - if (TCflag) - { - TimeControl.moves[black] = TimeControl.moves[white] = TCmoves; - TimeControl.clock[black] += 6000L * TCminutes + TCseconds * 100; - TimeControl.clock[white] += 6000L * TCminutes + TCseconds * 100; - } - else - { - TimeControl.moves[black] = TimeControl.moves[white] = 0; - TimeControl.clock[black] = TimeControl.clock[white] = 0; - } - - flag.onemove = (TCmoves == 1); - et = 0; - ElapsedTime(COMPUTE_AND_INIT_MODE); -} - diff --git a/gnushogi/cursesdsp.c b/gnushogi/cursesdsp.c index ee492b2..bf37999 100644 --- a/gnushogi/cursesdsp.c +++ b/gnushogi/cursesdsp.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -44,7 +45,6 @@ #include #include "gnushogi.h" -#include "cursesdsp.h" #if HAVE_UNISTD_H #include @@ -62,23 +62,22 @@ #define FLUSH_SCANW fflush(stdout), scanw -int mycnt1, mycnt2; - #define TAB (58) #define VIR_C(s) ((flag.reverse) ? (NO_COLS - 1 - column(s)) : column(s)) #define VIR_R(s) ((flag.reverse) ? (NO_ROWS - 1 - row(s)) : row(s)) -unsigned short MV[MAXDEPTH]; -int MSCORE; -char *DRAW; +/**************************************** + * forward declarations + ****************************************/ -/* Forward declarations. */ /* FIXME: change this name, puh-leeze! */ - static void UpdateCatched(void); static void DrawPiece(short sq); static void ShowScore(short score); +static void Curses_UpdateDisplay(short f, short t, short redraw, short isspec); +static void Curses_Die(int sig); +static void Curses_ShowSidetoMove(void); /**************************************** * Trivial output functions. @@ -92,7 +91,7 @@ ClearEoln(void) } -void +static void Curses_ClearScreen(void) { clear(); @@ -108,14 +107,6 @@ gotoXY(short x, short y) static void -ClearMessage(void) -{ - gotoXY(TAB, 6); - ClearEoln(); -} - - -void Curses_ShowCurrentMove(short pnt, short f, short t) { algbr(f, t, false); @@ -124,7 +115,7 @@ Curses_ShowCurrentMove(short pnt, short f, short t) } -void +static void Curses_ShowDepth(char ch) { gotoXY(TAB, 4); @@ -133,7 +124,7 @@ Curses_ShowDepth(char ch) } -void +static void Curses_ShowGameType(void) { if (flag.post) @@ -144,7 +135,7 @@ Curses_ShowGameType(void) } -void +static void ShowHeader(void) { gotoXY(TAB, 2); @@ -152,13 +143,13 @@ ShowHeader(void) } -void +static void Curses_ShowLine(unsigned short *bstline) { } -void +static void Curses_ShowMessage(char *s) { gotoXY(TAB, 6); @@ -167,32 +158,38 @@ Curses_ShowMessage(char *s) } -void -Curses_AlwaysShowMessage(const char *format, va_list ap) +static void +Curses_AlwaysShowMessage(const char *format, ...) { static char buffer[60]; + va_list ap; + va_start(ap, format); vsnprintf(buffer, sizeof(buffer), format, ap); Curses_ShowMessage(buffer); + va_end(ap); } -void -Curses_Printf(const char *format, va_list ap) +static void +Curses_Printf(const char *format, ...) { static char buffer[60]; + va_list ap; + va_start(ap, format); vsnprintf(buffer, sizeof(buffer), format, ap); printw("%s", buffer); + va_end(ap); } -void +static void Curses_doRequestInputString(const char* fmt, char* buffer) { FLUSH_SCANW(fmt, buffer); } -int +static int Curses_GetString(char* sx) { fflush(stdout); @@ -200,7 +197,7 @@ Curses_GetString(char* sx) } -void +static void Curses_ShowNodeCnt(long NodeCnt) { gotoXY(TAB, 22); @@ -211,7 +208,7 @@ Curses_ShowNodeCnt(long NodeCnt) } -void +static void Curses_ShowPatternCount(short side, short n) { if (flag.post) @@ -236,7 +233,7 @@ ShowPlayers(void) } -void +static void Curses_ShowPrompt(void) { Curses_ShowSidetoMove(); @@ -246,7 +243,7 @@ Curses_ShowPrompt(void) } -void +static void Curses_ShowResponseTime(void) { if (flag.post) @@ -260,7 +257,7 @@ Curses_ShowResponseTime(void) } -void +static void Curses_ShowResults(short score, unsigned short *bstline, char ch) { unsigned char d, ply; @@ -304,7 +301,7 @@ ShowScore(short score) } -void +static void Curses_ShowSidetoMove(void) { gotoXY(TAB, 14); @@ -313,7 +310,7 @@ Curses_ShowSidetoMove(void) } -void +static void Curses_ShowStage(void) { gotoXY(TAB, 19); @@ -326,7 +323,7 @@ Curses_ShowStage(void) * End of trivial output routines. ****************************************/ -void +static void Curses_Initialize(void) { signal(SIGINT, Curses_Die); @@ -336,7 +333,7 @@ Curses_Initialize(void) } -void +static void Curses_ExitShogi(void) { if (!nolist) @@ -352,7 +349,7 @@ Curses_ExitShogi(void) } -void +static void Curses_Die(int sig) { char s[80]; @@ -371,7 +368,7 @@ Curses_Die(int sig) } -void +static void Curses_TerminateSearch(int sig) { signal(SIGINT, SIG_IGN); @@ -387,7 +384,7 @@ Curses_TerminateSearch(int sig) } -void +static void Curses_help(void) { Curses_ClearScreen(); @@ -455,7 +452,7 @@ static const short y0[2] = { 20, 4 }; * P* will put a pawn to the captured pieces. */ -void +static void Curses_EditBoard(void) { short a, c, sq, i; @@ -604,7 +601,7 @@ UpdateCatched() } -void +static void Curses_SearchStartStuff(short side) { short i; @@ -620,7 +617,7 @@ Curses_SearchStartStuff(short side) } -void +static void Curses_OutputMove(void) { @@ -675,7 +672,7 @@ Curses_OutputMove(void) t = (l + h) >> 1; } - ShowNodeCnt(NodeCnt); + Curses_ShowNodeCnt(NodeCnt); gotoXY(TAB, 23); printw("Max Tree = %5d", t); ClearEoln(); @@ -685,7 +682,7 @@ Curses_OutputMove(void) } -void +static void Curses_UpdateClocks(void) { short m, s; @@ -717,7 +714,7 @@ Curses_UpdateClocks(void) printw("%d:%02d ", m, s); if (flag.post) - ShowNodeCnt(NodeCnt); + Curses_ShowNodeCnt(NodeCnt); refresh(); } @@ -764,13 +761,11 @@ DrawPiece(short sq) /* * Curses_ShowPostnValue(): must have called ExaminePosition() first */ -void +static void Curses_ShowPostnValue(short sq) { - short score; - gotoXY(4 + 5 * VIR_C(sq), 5 + 2 * (7 - VIR_R(sq))); /* CHECKME */ - score = ScorePosition(color[sq]); + (void) ScorePosition(color[sq]); if (color[sq] != neutral) #if defined SAVE_SVALUE @@ -789,7 +784,7 @@ Curses_ShowPostnValue(short sq) } -void +static void Curses_ShowPostnValues(void) { short sq, score; @@ -809,7 +804,7 @@ Curses_ShowPostnValues(void) } -void +static void Curses_UpdateDisplay(short f, short t, short redraw, short isspec) { short i, sq, z; @@ -927,7 +922,7 @@ Curses_UpdateDisplay(short f, short t, short redraw, short isspec) } -void +static void Curses_ChangeAlphaWindow(void) { Curses_ShowMessage("WAwindow = "); @@ -937,7 +932,7 @@ Curses_ChangeAlphaWindow(void) } -void +static void Curses_ChangeBetaWindow(void) { Curses_ShowMessage("WBwindow = "); @@ -947,7 +942,7 @@ Curses_ChangeBetaWindow(void) } -void +static void Curses_GiveHint(void) { char s[40]; @@ -966,8 +961,8 @@ Curses_GiveHint(void) } -void -Curses_ChangeSearchDepth(void) +static void +Curses_ChangeSearchDepth(char* sx) { Curses_ShowMessage("depth = "); FLUSH_SCANW("%hd", &MaxSearchDepth); @@ -975,7 +970,7 @@ Curses_ChangeSearchDepth(void) } -void +static void Curses_ChangeHashDepth(void) { Curses_ShowMessage("hashdepth = "); @@ -985,7 +980,7 @@ Curses_ChangeHashDepth(void) } -void +static void Curses_SetContempt(void) { Curses_ShowMessage("contempt = "); @@ -993,7 +988,7 @@ Curses_SetContempt(void) } -void +static void Curses_ChangeXwindow(void) { Curses_ShowMessage("xwndw= "); @@ -1001,7 +996,7 @@ Curses_ChangeXwindow(void) } -void +static void Curses_SelectLevel(char *sx) { int item; @@ -1111,7 +1106,7 @@ Curses_SelectLevel(char *sx) } -void +static void Curses_DoDebug(void) { short c, p, sq, tp, tc, tsq, score; @@ -1158,7 +1153,7 @@ Curses_DoDebug(void) } -void +static void Curses_DoTable(short table[NO_SQUARES]) { short sq; @@ -1172,7 +1167,7 @@ Curses_DoTable(short table[NO_SQUARES]) } -void +static void Curses_PollForInput(void) { int i; @@ -1198,8 +1193,53 @@ Curses_PollForInput(void) } -void +static void Curses_SetupBoard(void) { Curses_ShowMessage("'setup' command is not supported in Cursesmode"); } + + +struct display curses_display = +{ + .ChangeAlphaWindow = Curses_ChangeAlphaWindow, + .ChangeBetaWindow = Curses_ChangeBetaWindow, + .ChangeHashDepth = Curses_ChangeHashDepth, + .ChangeSearchDepth = Curses_ChangeSearchDepth, + .ChangeXwindow = Curses_ChangeXwindow, + .ClearScreen = Curses_ClearScreen, + .DoDebug = Curses_DoDebug, + .DoTable = Curses_DoTable, + .EditBoard = Curses_EditBoard, + .ExitShogi = Curses_ExitShogi, + .GiveHint = Curses_GiveHint, + .Initialize = Curses_Initialize, + .ShowNodeCnt = Curses_ShowNodeCnt, + .OutputMove = Curses_OutputMove, + .PollForInput = Curses_PollForInput, + .SetContempt = Curses_SetContempt, + .SearchStartStuff = Curses_SearchStartStuff, + .SelectLevel = Curses_SelectLevel, + .ShowCurrentMove = Curses_ShowCurrentMove, + .ShowDepth = Curses_ShowDepth, + .ShowGameType = Curses_ShowGameType, + .ShowLine = Curses_ShowLine, + .ShowMessage = Curses_ShowMessage, + .AlwaysShowMessage = Curses_AlwaysShowMessage, + .Printf = Curses_Printf, + .doRequestInputString = Curses_doRequestInputString, + .GetString = Curses_GetString, + .SetupBoard = Curses_SetupBoard, + .ShowPatternCount = Curses_ShowPatternCount, + .ShowPostnValue = Curses_ShowPostnValue, + .ShowPostnValues = Curses_ShowPostnValues, + .ShowPrompt = Curses_ShowPrompt, + .ShowResponseTime = Curses_ShowResponseTime, + .ShowResults = Curses_ShowResults, + .ShowSidetoMove = Curses_ShowSidetoMove, + .ShowStage = Curses_ShowStage, + .TerminateSearch = Curses_TerminateSearch, + .UpdateClocks = Curses_UpdateClocks, + .UpdateDisplay = Curses_UpdateDisplay, + .help = Curses_help, +}; diff --git a/gnushogi/cursesdsp.h b/gnushogi/cursesdsp.h deleted file mode 100644 index a936254..0000000 --- a/gnushogi/cursesdsp.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * FILE: cursesdsp.h - * - * Curses interface for GNU Shogi. - * - * ---------------------------------------------------------------------- - * Copyright (c) 1993, 1994, 1995 Matthias Mutz - * Copyright (c) 1999 Michael Vanier and the Free Software Foundation - * Copyright (c) 2008, 2013, 2014 Yann Dirson and the Free Software Foundation - * - * GNU SHOGI is based on GNU CHESS - * - * Copyright (c) 1988, 1989, 1990 John Stanback - * Copyright (c) 1992 Free Software Foundation - * - * This file is part of GNU SHOGI. - * - * GNU Shogi is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 3 of the License, - * or (at your option) any later version. - * - * GNU Shogi is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License along - * with GNU Shogi; see the file COPYING. If not, see - * . - * ---------------------------------------------------------------------- - * - */ - -#ifndef _CURSESDSP_H_ -#define _CURSESDSP_H_ - -#include "gnushogi.h" - -/* The following are common to rawdsp.h and cursesdsp.h */ - -void Curses_ChangeAlphaWindow(void); -void Curses_ChangeBetaWindow(void); -void Curses_ChangeHashDepth(void); -void Curses_ChangeSearchDepth(void); -void Curses_ChangeXwindow(void); -void Curses_ClearScreen(void); -void Curses_Die(int sig); -void Curses_DoDebug(void); -void Curses_DoTable(short table[NO_SQUARES]); -void Curses_EditBoard(void); -void Curses_ExitShogi(void); -void Curses_GiveHint(void); -void Curses_Initialize(void); -void Curses_ShowNodeCnt(long NodeCnt); -void Curses_OutputMove(void); -void Curses_PollForInput(void); -void Curses_SearchStartStuff(short side); -void Curses_SelectLevel(char *sx); -void Curses_SetContempt(void); -void Curses_ShowCurrentMove(short pnt, short f, short t); -void Curses_ShowDepth(char ch); -void Curses_ShowGameType(void); -void Curses_ShowLine(unsigned short *bstline); -void Curses_ShowMessage(char *s); -void Curses_AlwaysShowMessage(const char *format, va_list ap); -void Curses_Printf(const char *format, va_list ap); -void Curses_doRequestInputString(const char* fmt, char* buffer); -int Curses_GetString(char* sx); -void Curses_SetupBoard(void); -void Curses_ShowPatternCount(short side, short n); -void Curses_ShowPostnValue(short sq); -void Curses_ShowPostnValues(void); -void Curses_ShowPrompt(void); -void Curses_ShowResponseTime(void); -void Curses_ShowResults(short score, unsigned short *bstline, char ch); -void Curses_ShowSidetoMove(void); -void Curses_ShowStage(void); -void Curses_TerminateSearch(int sig); -void Curses_UpdateClocks(void); -void Curses_UpdateDisplay(short f, short t, short redraw, short isspec); -void Curses_help(void); - -#endif /* _CURSESDSP_H_ */ diff --git a/gnushogi/dspwrappers.c b/gnushogi/dspwrappers.c deleted file mode 100644 index d7f23c8..0000000 --- a/gnushogi/dspwrappers.c +++ /dev/null @@ -1,164 +0,0 @@ -/* - * FILE: dspwrappers.c - * - * Wrapper functions which call analogous functions in rawdsp.c - * or cursesdsp.c depending on the interface. - * - * ---------------------------------------------------------------------- - * Copyright (c) 1993, 1994, 1995 Matthias Mutz - * Copyright (c) 1999 Michael Vanier and the Free Software Foundation - * Copyright (c) 2008, 2013, 2014 Yann Dirson and the Free Software Foundation - * - * GNU SHOGI is based on GNU CHESS - * - * Copyright (c) 1988, 1989, 1990 John Stanback - * Copyright (c) 1992 Free Software Foundation - * - * This file is part of GNU SHOGI. - * - * GNU Shogi is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 3 of the License, - * or (at your option) any later version. - * - * GNU Shogi is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License along - * with GNU Shogi; see the file COPYING. If not, see - * . - * ---------------------------------------------------------------------- - * - */ - -/* request *snprintf prototypes*/ -#define _POSIX_C_SOURCE 200112L - -#include "gnushogi.h" -#include "dspwrappers.h" -#include "rawdsp.h" -#include "cursesdsp.h" - -#include - -#define CASE_DSP_RAW(func,args) \ - case DISPLAY_RAW: \ - case DISPLAY_X: \ - func args; \ - break - -#ifdef HAVE_LIBCURSES -#define CASE_DSP_CURSES(func,args) \ - case DISPLAY_CURSES: \ - func args; \ - break; -#else -#define CASE_DSP_CURSES(func,args) -#endif - -#define DISPLAY_FUNC(func,argsdecl,args) \ - void func argsdecl \ - { \ - switch (display_type) { \ - CASE_DSP_RAW(Raw_ ## func, args); \ - CASE_DSP_CURSES(Curses_ ## func, args); \ - } \ - } -#define DISPLAY_VOIDFUNC(func) \ - DISPLAY_FUNC(func,(void),()) - -#define DISPLAY_STDARGFUNC(func,argsdecl,last,args) \ - void func argsdecl \ - { \ - va_list ap; \ - va_start(ap, last); \ - switch (display_type) { \ - CASE_DSP_RAW(Raw_ ## func, args); \ - CASE_DSP_CURSES(Curses_ ## func, args); \ - } \ - va_end(ap); \ - } - -DISPLAY_VOIDFUNC(ChangeAlphaWindow) -DISPLAY_VOIDFUNC(ChangeBetaWindow) -DISPLAY_VOIDFUNC(ChangeHashDepth) -DISPLAY_VOIDFUNC(ChangeSearchDepth) -DISPLAY_VOIDFUNC(ChangeXwindow) -DISPLAY_VOIDFUNC(ClearScreen) -DISPLAY_VOIDFUNC(DoDebug) -DISPLAY_FUNC(DoTable, (short table[NO_SQUARES]), (table)) -DISPLAY_VOIDFUNC(EditBoard) -DISPLAY_VOIDFUNC(ExitShogi) -DISPLAY_VOIDFUNC(GiveHint) -DISPLAY_VOIDFUNC(Initialize) -DISPLAY_FUNC(ShowNodeCnt, (long NodeCnt), (NodeCnt)) -DISPLAY_VOIDFUNC(OutputMove) -DISPLAY_VOIDFUNC(PollForInput) -DISPLAY_VOIDFUNC(SetContempt) -DISPLAY_FUNC(SearchStartStuff, (short side), (side)) -DISPLAY_FUNC(SelectLevel, (char *sx), (sx)) -DISPLAY_VOIDFUNC(SetupBoard) -DISPLAY_FUNC(ShowCurrentMove, (short pnt, short f, short t), (pnt, f, t)) -DISPLAY_FUNC(ShowDepth, (char ch), (ch)) -DISPLAY_VOIDFUNC(ShowGameType) -DISPLAY_FUNC(ShowLine, (unsigned short *bstline), (bstline)) -DISPLAY_FUNC(ShowMessage, (char *s), (s)) -DISPLAY_STDARGFUNC(AlwaysShowMessage, (const char *format, ...), format, (format, ap)) -DISPLAY_STDARGFUNC(Printf, (const char *format, ...), format, (format, ap)) -DISPLAY_FUNC(ShowPatternCount, (short side, short n), (side, n)) -DISPLAY_FUNC(ShowPostnValue, (short sq), (sq)) -DISPLAY_VOIDFUNC(ShowPostnValues) -DISPLAY_VOIDFUNC(ShowPrompt) -DISPLAY_VOIDFUNC(ShowResponseTime) -DISPLAY_FUNC(ShowResults, (short score, unsigned short *bstline, char ch), (score, bstline, ch)) -DISPLAY_VOIDFUNC(ShowSidetoMove) -DISPLAY_VOIDFUNC(ShowStage) -DISPLAY_FUNC(TerminateSearch, (int sig), (sig)) -DISPLAY_VOIDFUNC(UpdateClocks) -DISPLAY_FUNC(UpdateDisplay, (short f, short t, short redraw, short isspec), (f, t, redraw, isspec)) -DISPLAY_VOIDFUNC(help) - -DISPLAY_FUNC(doRequestInputString, (const char* fmt, char* buffer), (fmt, buffer)) -void RequestInputString(char* buffer, unsigned bufsize) -{ - static char fmt[10]; - int ret = snprintf(fmt, sizeof(fmt), "%%%us", bufsize); - if (ret >= sizeof(fmt)) { - fprintf(stderr, - "Insufficient format-buffer size in %s for bufsize=%u\n", - __FUNCTION__, bufsize); - exit(1); - } - doRequestInputString(fmt, buffer); -} - -/*********/ - -#define CASE_DSPFUNC_RAW(func,args) \ - case DISPLAY_RAW: \ - case DISPLAY_X: \ - return (func args); \ - break - -#ifdef HAVE_LIBCURSES -#define CASE_DSPFUNC_CURSES(func,args) \ - case DISPLAY_CURSES: \ - return (func args); \ - break; -#else -#define CASE_DSPFUNC_CURSES(func,args) -#endif - -#define DISPLAY_INTFUNC(func,argsdecl,args) \ - int func argsdecl \ - { \ - switch (display_type) { \ - CASE_DSPFUNC_RAW(Raw_ ## func, args); \ - CASE_DSPFUNC_CURSES(Curses_ ## func, args); \ - } \ - assert(0); \ - } - -DISPLAY_INTFUNC(GetString, (char* sx), (sx)) diff --git a/gnushogi/dspwrappers.h b/gnushogi/dspwrappers.h deleted file mode 100644 index bcb6189..0000000 --- a/gnushogi/dspwrappers.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * FILE: dspwrappers.h - * - * Wrapper functions which call analogous functions in rawdsp.c - * or cursesdsp.c depending on the interface. - * - * ---------------------------------------------------------------------- - * Copyright (c) 1993, 1994, 1995 Matthias Mutz - * Copyright (c) 1999 Michael Vanier and the Free Software Foundation - * Copyright (c) 2008, 2013, 2014 Yann Dirson and the Free Software Foundation - * - * GNU SHOGI is based on GNU CHESS - * - * Copyright (c) 1988, 1989, 1990 John Stanback - * Copyright (c) 1992 Free Software Foundation - * - * This file is part of GNU SHOGI. - * - * GNU Shogi is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 3 of the License, - * or (at your option) any later version. - * - * GNU Shogi is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License along - * with GNU Shogi; see the file COPYING. If not, see - * . - * ---------------------------------------------------------------------- - * - */ - -#ifndef _DSPWRAPPERS_H_ -#define _DSPWRAPPERS_H_ - -#include - -extern void ChangeAlphaWindow(void); -extern void ChangeBetaWindow(void); -extern void ChangeHashDepth(void); -extern void ChangeSearchDepth(void); -extern void ChangeXwindow(void); -extern void ClearScreen(void); -extern void DoDebug(void); -extern void DoTable(short table[NO_SQUARES]); -extern void EditBoard(void); -extern void ExitShogi(void); -extern void GiveHint(void); -extern void Initialize(void); -extern void ShowNodeCnt(long NodeCnt); -extern void OutputMove(void); -extern void PollForInput(void); -extern void SetContempt(void); -extern void SearchStartStuff(short side); -extern void SelectLevel(char *sx); -extern void ShowCurrentMove(short pnt, short f, short t); -extern void ShowDepth(char ch); -extern void ShowGameType(void); -extern void ShowLine(unsigned short *bstline); -extern void ShowMessage(char *s); -extern void AlwaysShowMessage(const char *format, ...); -extern void Printf(const char *format, ...); -extern void RequestInputString(char* buffer, unsigned bufsize); -extern int GetString(char* sx); -extern void SetupBoard(void); -extern void ShowPatternCount(short side, short n); -extern void ShowPostnValue(short sq); -extern void ShowPostnValues(void); -extern void ShowPrompt(void); -extern void ShowResponseTime(void); -extern void ShowResults(short score, unsigned short *bstline, char ch); -extern void ShowSidetoMove(void); -extern void ShowStage(void); -extern void TerminateSearch(int sig); -extern void UpdateClocks(void); -extern void UpdateDisplay(short f, short t, short redraw, short isspec); -extern void help(void); - -#endif /* _DSPWRAPPERS_H_ */ diff --git a/gnushogi/eval.c b/gnushogi/eval.c index cbae968..12197a2 100644 --- a/gnushogi/eval.c +++ b/gnushogi/eval.c @@ -33,9 +33,6 @@ #include "gnushogi.h" #include "pattern.h" -extern void -ShowStage(void); - /* Hash table for preventing multiple scoring of the same position */ int EADD = 0; /* number of writes to the cache table */ @@ -1263,13 +1260,12 @@ trapped(short sq) static int -AttackedPieceValue(short sq, short side) +AttackedPieceValue(short sq) { - short s, ds; + short s; s = 0; - ds = -fv1[HUNGP] * 2; hung[c1]++; shung[sq]++; @@ -1427,7 +1423,7 @@ PawnValue(short sq, short side) */ static inline int -LanceValue(short sq, short side) +LanceValue(short sq) { short s = 0, ds, ad; @@ -1457,7 +1453,7 @@ LanceValue(short sq, short side) */ static inline int -KnightValue(short sq, short side) +KnightValue(short sq) { short s = 0, ad; short ds, checked_trapped = false; @@ -1494,7 +1490,7 @@ KnightValue(short sq, short side) */ static inline int -SilverValue(short sq, short side) +SilverValue(short sq) { short s= 0, ds, ad; @@ -1542,7 +1538,7 @@ SilverValue(short sq, short side) */ static inline int -GoldValue(short sq, short side) +GoldValue(short sq) { short s = 0, ds, ad; @@ -1584,7 +1580,7 @@ GoldValue(short sq, short side) */ static inline int -BishopValue(short sq, short side) +BishopValue(short sq) { short s = 0, ds, ad; @@ -1719,7 +1715,7 @@ RookValue(short sq, short side) */ static inline int -PPawnValue(short sq, short side) +PPawnValue(short sq) { short s = 0, ds, ad; @@ -1736,7 +1732,7 @@ PPawnValue(short sq, short side) */ static inline int -PLanceValue(short sq, short side) +PLanceValue(short sq) { short s = 0, ds, ad; @@ -1752,7 +1748,7 @@ PLanceValue(short sq, short side) */ static inline int -PKnightValue(short sq, short side) +PKnightValue(short sq) { short s = 0, ds, ad; @@ -1769,7 +1765,7 @@ PKnightValue(short sq, short side) */ static inline int -PSilverValue(short sq, short side) +PSilverValue(short sq) { short s = 0, ds, ad; @@ -1785,7 +1781,7 @@ PSilverValue(short sq, short side) */ static inline int -PBishopValue(short sq, short side) +PBishopValue(short sq) { short s = 0, ds, ad; @@ -1801,7 +1797,7 @@ PBishopValue(short sq, short side) */ static inline int -PRookValue(short sq, short side) +PRookValue(short sq) { short s = 0, ds, ad; @@ -1819,7 +1815,7 @@ PRookValue(short sq, short side) */ static inline int -KingValue(short sq, short side) +KingValue(short sq) { short s = 0, ds; @@ -1905,7 +1901,7 @@ PieceValue(short sq, short side) if (a1 == 0) { /* undefended piece */ - s += AttackedPieceValue(sq, side); + s += AttackedPieceValue(sq); } else { @@ -1916,7 +1912,7 @@ PieceValue(short sq, short side) if (attack_value < piece_value) { /* attacked by a weaker piece */ - s += AttackedPieceValue(sq, side) / 2; + s += AttackedPieceValue(sq) / 2; } else if (abs(attack_value - piece_value) < 10) { @@ -1983,24 +1979,24 @@ PieceValue(short sq, short side) #ifndef MINISHOGI case lance: - s += LanceValue(sq, side); + s += LanceValue(sq); break; case knight: - s += KnightValue(sq, side); + s += KnightValue(sq); break; #endif case silver: - s += SilverValue(sq, side); + s += SilverValue(sq); break; case gold: - s += GoldValue(sq, side); + s += GoldValue(sq); break; case bishop: - s += BishopValue(sq, side); + s += BishopValue(sq); break; case rook: @@ -2008,33 +2004,33 @@ PieceValue(short sq, short side) break; case king: - s += KingValue(sq, side); + s += KingValue(sq); break; case ppawn: - s += PPawnValue(sq, side); + s += PPawnValue(sq); break; #ifndef MINISHOGI case plance: - s += PLanceValue(sq, side); + s += PLanceValue(sq); break; case pknight: - s += PKnightValue(sq, side); + s += PKnightValue(sq); break; #endif case psilver: - s += PSilverValue(sq, side); + s += PSilverValue(sq); break; case pbishop: - s += PBishopValue(sq, side); + s += PBishopValue(sq); break; case prook: - s += PRookValue(sq, side); + s += PRookValue(sq); break; } @@ -2139,7 +2135,7 @@ UpdatePatterns(short side, short GameCnt) } if (flag.post) - ShowPatternCount(side, n); + dsp->ShowPatternCount(side, n); if (os != END_OF_SEQUENCES) update_advance_bonus(side, os); @@ -2531,8 +2527,8 @@ DetermineGameType(short side_to_move) } else { - ShowPatternCount(black, -1); - ShowPatternCount(white, -1); + dsp->ShowPatternCount(black, -1); + dsp->ShowPatternCount(white, -1); } } @@ -2709,7 +2705,7 @@ DetermineStage(short side) stage = 0; if (flag.post) - ShowStage(); + dsp->ShowStage(); /* Determine stage dependant weights */ @@ -2745,6 +2741,7 @@ DetermineStage(short side) void UpdateWeights(short stage) { + /* FIXME: this was emptied between 1.1p02 ans 1.2p03, do we keep it ? */ } diff --git a/gnushogi/genmove.c b/gnushogi/genmove.c index ae91939..208966d 100644 --- a/gnushogi/genmove.c +++ b/gnushogi/genmove.c @@ -246,12 +246,12 @@ gives_check_flag(unsigned short *flags, short side, short f, short t) inline static void -Link(short side, short piece, +Link(short side, short from, short to, unsigned short local_flag, short s) { if (*TrP == TREE) { - ShowMessage("TREE overflow\n"); + dsp->ShowMessage("TREE overflow\n"); } else { @@ -341,8 +341,8 @@ PromotionPossible(short color, short f, short t, short p) } -inline int -NonPromotionPossible(short color, short f, +static inline int +NonPromotionPossible(short color, short t, short p) { switch (p) @@ -401,7 +401,7 @@ NonPromotionPossible(short color, short f, /* bonus for possible next moves */ inline static short -field_bonus(short ply, short side, short piece, +field_bonus(short side, short piece, short f, short t, unsigned short *local_flag) { short s, u, ptyp; @@ -621,7 +621,7 @@ LinkMove(short ply, short f, if (score_if_impossible < 0) { /* The move is flagged as illegal. */ - Link(side, piece, + Link(side, f, t, local_flag, score_if_impossible); return; @@ -730,7 +730,7 @@ LinkMove(short ply, short f, s -= 16 / Captured[side][silver]; #if defined DROPBONUS - s += field_bonus(ply, side, piece, f, t, &local_flag); + s += field_bonus(side, piece, f, t, &local_flag); if (s == 10 && piece != pawn) local_flag |= questionable; @@ -819,7 +819,7 @@ LinkMove(short ply, short f, else { #if defined FIELDBONUS - s += field_bonus(ply, side, piece, f, t, &local_flag); + s += field_bonus(side, piece, f, t, &local_flag); #endif } } @@ -871,7 +871,7 @@ LinkMove(short ply, short f, if (try_link || GenerateAllMoves) { - Link(side, piece, f, t, local_flag, + Link(side, f, t, local_flag, s - ((SCORE_LIMIT + 1000) * 2)); } @@ -1041,7 +1041,7 @@ GenMoves(short ply, short sq, short side, LinkMove(ply, sq, u, local_flag | promote, xside, true); if ((possible - = NonPromotionPossible(color[sq], sq, u, piece))) + = NonPromotionPossible(color[sq], u, piece))) { LinkMove(ply, sq, u, local_flag, xside, possible); } @@ -1497,7 +1497,7 @@ CaptureList(short side, short ply, if ((PP = PromotionPossible(color[sq], sq, u, piece))) { - Link(side, piece, + Link(side, sq, u, capture | promote, (*value)[stage][board[u]] #if !defined SAVE_SVALUE @@ -1508,7 +1508,7 @@ CaptureList(short side, short ply, if (!PP || flag.tsume) { - Link(side, piece, + Link(side, sq, u, capture, (*value)[stage][board[u]] #if !defined SAVE_SVALUE diff --git a/gnushogi/gnushogi.h b/gnushogi/gnushogi.h index 7cd5a49..29d9abe 100644 --- a/gnushogi/gnushogi.h +++ b/gnushogi/gnushogi.h @@ -44,6 +44,8 @@ #include "debug.h" #include "opts.h" /* Various option-setting #defines. */ +#include + /* * Display options. */ @@ -58,14 +60,11 @@ typedef enum { extern display_t display_type; #define XSHOGI (display_type == DISPLAY_X) -#define NOT_CURSES ((display_type == DISPLAY_X) \ - || (display_type == DISPLAY_RAW)) /* Miscellaneous globals. */ extern short hard_time_limit; /* If you exceed time limit, you lose. */ -extern short barebones; /* Don't print of stats for x interface. */ extern short nolist; /* Don't list game after exit. */ @@ -171,12 +170,14 @@ extern void movealgbr(short m, char *s); #define NO_PTYPE_PIECES 11 #define NO_COLS 5 #define NO_ROWS 5 +#define NO_CAMP_ROWS 1 #else #define NO_PIECES 15 #define MAX_CAPTURED 19 #define NO_PTYPE_PIECES 15 #define NO_COLS 9 #define NO_ROWS 9 +#define NO_CAMP_ROWS 3 #endif #define NO_SQUARES (NO_COLS*NO_ROWS) @@ -229,13 +230,8 @@ extern void movealgbr(short m, char *s); /* board properties */ -#ifndef MINISHOGI -#define InBlackCamp(sq) ((sq) < 27) -#define InWhiteCamp(sq) ((sq) > 53) -#else -#define InBlackCamp(sq) ((sq) < 5) -#define InWhiteCamp(sq) ((sq) > 19) -#endif +#define InBlackCamp(sq) ((sq) < (NO_COLS * NO_CAMP_ROWS)) +#define InWhiteCamp(sq) ((sq) >= (NO_COLS * (NO_ROWS - NO_CAMP_ROWS))) #define InPromotionZone(side, sq) \ (((side) == black) ? InWhiteCamp(sq) : InBlackCamp(sq)) @@ -330,13 +326,9 @@ enum { #ifndef MINISHOGI #define pxx (" PLNSGBRPLNSBRK ") #define qxx (" plnsgbrplnsbrk ") -#define rxx ("ihgfedcba") -#define cxx ("987654321") #else #define pxx (" PSGBRPSBRK ") #define qxx (" psgbrpsbrk ") -#define rxx ("edcba") -#define cxx ("54321") #endif /***************** Table limits ********************************************/ @@ -683,8 +675,6 @@ extern long znodes; extern char ColorStr[2][10]; extern char mvstr[4][6]; -extern unsigned short MV[MAXDEPTH]; -extern int MSCORE; extern int mycnt1, mycnt2; extern short ahead; extern struct leaf rootnode; @@ -915,10 +905,8 @@ extern void Unlock_data(void); /* init.c */ extern void Initialize_dist(void); /* init.c */ extern void Initialize_eval(void); /* eval.c */ extern void NewGame(void); -extern int parse(FILE * fd, unsigned short *mv, - short side, char *opening); extern void GetOpenings(void); -extern int OpeningBook(unsigned short *hint, short side); +extern int OpeningBook(unsigned short *hint); typedef enum { @@ -965,7 +953,6 @@ PutInTTable(short side, short score, short depth, short ply, - short alpha, short beta, unsigned short mv); @@ -1125,6 +1112,55 @@ typedef enum extern int VerifyMove(char *s, VerifyMove_mode iop, unsigned short *mv); extern unsigned short TTage; -#include "dspwrappers.h" /* Display functions. */ +/* display driver framework */ + +struct display +{ + void (*ChangeAlphaWindow)(void); + void (*ChangeBetaWindow)(void); + void (*ChangeHashDepth)(void); + void (*ChangeSearchDepth)(char *sx); + void (*ChangeXwindow)(void); + void (*ClearScreen)(void); + void (*DoDebug)(void); + void (*DoTable)(short table[NO_SQUARES]); + void (*EditBoard)(void); + void (*ExitShogi)(void); + void (*GiveHint)(void); + void (*Initialize)(void); + void (*ShowNodeCnt)(long NodeCnt); + void (*OutputMove)(void); + void (*PollForInput)(void); + void (*SetContempt)(void); + void (*SearchStartStuff)(short side); + void (*SelectLevel)(char *sx); + void (*ShowCurrentMove)(short pnt, short f, short t); + void (*ShowDepth)(char ch); + void (*ShowGameType)(void); + void (*ShowLine)(unsigned short *bstline); + void (*ShowMessage)(char *s); + void (*AlwaysShowMessage)(const char *format, ...); + void (*Printf)(const char *format, ...); + void (*doRequestInputString)(const char* fmt, char* buffer); + int (*GetString)(char* sx); + void (*SetupBoard)(void); + void (*ShowPatternCount)(short side, short n); + void (*ShowPostnValue)(short sq); + void (*ShowPostnValues)(void); + void (*ShowPrompt)(void); + void (*ShowResponseTime)(void); + void (*ShowResults)(short score, unsigned short *bstline, char ch); + void (*ShowSidetoMove)(void); + void (*ShowStage)(void); + void (*TerminateSearch)(int sig); + void (*UpdateClocks)(void); + void (*UpdateDisplay)(short f, short t, short redraw, short isspec); + void (*help)(void); +}; + +extern struct display *dsp; + +extern struct display raw_display; +extern struct display curses_display; #endif /* _GNUSHOGI_H_ */ diff --git a/gnushogi/init-common.c b/gnushogi/init-common.c index 061c7f9..1f71994 100644 --- a/gnushogi/init-common.c +++ b/gnushogi/init-common.c @@ -150,7 +150,7 @@ Initialize_data(void) if (x >= 0) { - ShowMessage("datatype 'small_short' is unsigned; " + dsp->ShowMessage("datatype 'small_short' is unsigned; " "check gnushogi.h\n"); return 1; } @@ -163,7 +163,7 @@ Initialize_data(void) { sprintf(buffer, "Cannot allocate %ld bytes for search tree", (long)n); - ShowMessage(buffer); + dsp->ShowMessage(buffer); return 1; } @@ -173,7 +173,7 @@ Initialize_data(void) if (!hashcode) { sprintf(buffer, "Cannot allocate %ld bytes for hashcode", (long)n); - ShowMessage(buffer); + dsp->ShowMessage(buffer); return 1; } @@ -185,7 +185,7 @@ Initialize_data(void) sprintf(buffer, "Cannot allocate %ld bytes for drop_hashcode", (long)n); - ShowMessage(buffer); + dsp->ShowMessage(buffer); return 1; } @@ -197,7 +197,7 @@ Initialize_data(void) sprintf(buffer, "Cannot allocate %ld bytes for game record", (long)n); - ShowMessage(buffer); + dsp->ShowMessage(buffer); return 1; } @@ -214,7 +214,7 @@ Initialize_data(void) { sprintf(buffer, "cannot allocate %ld space for nextdir %d", (long)(n), i); - ShowMessage(buffer); + dsp->ShowMessage(buffer); } nextdir[i] = NULL; @@ -229,7 +229,7 @@ Initialize_data(void) { sprintf(buffer, "cannot allocate %ld space for nextpos %d", (long)(n), i); - ShowMessage(buffer); + dsp->ShowMessage(buffer); } use_nextpos = false; @@ -247,7 +247,7 @@ Initialize_data(void) if (!value) { - ShowMessage("cannot allocate value space"); + dsp->ShowMessage("cannot allocate value space"); return 1; } @@ -256,7 +256,7 @@ Initialize_data(void) if (!fscore) { - ShowMessage("cannot allocate fscore space"); + dsp->ShowMessage("cannot allocate fscore space"); return 1; } @@ -268,7 +268,7 @@ Initialize_data(void) { sprintf(buffer, "Cannot allocate %ld bytes for history table", (long)sizeof_history); - ShowMessage(buffer); + dsp->ShowMessage(buffer); use_history = false; } #endif @@ -284,7 +284,7 @@ Initialize_data(void) { sprintf(buffer, "Cannot allocate %ld bytes for cache table %ld", (long)n, (long)i); - ShowMessage(buffer); + dsp->ShowMessage(buffer); use_etable = false; } } @@ -334,7 +334,7 @@ Initialize_data(void) { sprintf(buffer, "Cannot allocate %ld bytes for transposition table", (long)(2 * n)); - ShowMessage(buffer); + dsp->ShowMessage(buffer); ttable[0] = ttable[1] = NULL; } #endif /* ttblsz */ @@ -345,7 +345,7 @@ Initialize_data(void) if (!distdata) { - ShowMessage("cannot allocate distdata space..."); + dsp->ShowMessage("cannot allocate distdata space..."); use_distdata = false; } #endif diff --git a/gnushogi/init.c b/gnushogi/init.c index 742b754..679b382 100644 --- a/gnushogi/init.c +++ b/gnushogi/init.c @@ -50,8 +50,6 @@ */ short hard_time_limit = 1; -short barebones = 0; /* Suppress printing of statistics - * (mainly for xshogi). */ #ifdef LIST_ON_EXIT short nolist = 0; /* List the game after exit. */ #else @@ -592,7 +590,7 @@ NewGame(void) } ClearCaptured(); - ClearScreen(); + dsp->ClearScreen(); InitializeStats(); #ifdef HAVE_GETTIMEOFDAY @@ -615,9 +613,9 @@ NewGame(void) if (TCflag) SetTimeControl(); else if (MaxResponseTime == 0) - SelectLevel(sx); + dsp->SelectLevel(sx); - UpdateDisplay(0, 0, 1, 0); + dsp->UpdateDisplay(0, 0, 1, 0); GetOpenings(); GetOpeningPatterns(&max_opening_sequence); @@ -667,16 +665,14 @@ InitMain(void) TCflag = true; OperatorTime = 0; - barebones = 1; } else { TCflag = false; OperatorTime = 0; - barebones = 0; } - Initialize(); + dsp->Initialize(); Initialize_dist(); Initialize_eval(); #if !defined SAVE_NEXTPOS @@ -726,6 +722,6 @@ ExitMain(void) #endif /* HASHFILE */ #endif /* ttblsz */ - ExitShogi(); + dsp->ExitShogi(); } diff --git a/gnushogi/main.c b/gnushogi/main.c index 7551512..d9fae21 100644 --- a/gnushogi/main.c +++ b/gnushogi/main.c @@ -81,17 +81,14 @@ main (int argc, char **argv) binbookfile = NULL; #endif } - break; #ifdef BINBOOK case 'B': argc--; argv++; - if (argc > 0) binbookfile = argv[0]; - break; #endif @@ -99,7 +96,7 @@ main (int argc, char **argv) case 'C': /* Curses interface. */ display_type = DISPLAY_CURSES; - + dsp = &curses_display; break; #endif @@ -108,17 +105,14 @@ main (int argc, char **argv) hash = ((argv[0][0] == '-') ? false : true); break; - case 'l': argc--; argv++; if (argc > 0) Lang = argv[0]; - break; - case 'L': argc--; argv++; @@ -127,34 +121,28 @@ main (int argc, char **argv) strcpy(listfile, argv[0]); break; - case 's': argc--; argv++; if (argc > 0) strcpy(savefile, argv[0]); - break; - case 'P': argc--; argv++; if (argc > 0) bookmaxply = atoi(argv[0]); - break; - case 'R': /* Raw text interface. */ display_type = DISPLAY_RAW; - + dsp = &raw_display; break; - case 'S': argc--; argv++; @@ -170,23 +158,18 @@ main (int argc, char **argv) if (argc > 0) rehash = atoi(argv[0]); - if (rehash > MAXrehash) rehash = MAXrehash; - break; - case 'T': argc--; argv++; if (argc > 0) ttblsize = atoi(argv[0]); - - if ((ttblsize <= MINTTABLE)) + if (ttblsize <= MINTTABLE) ttblsize = (MINTTABLE) + 1; - break; #ifdef HASHFILE @@ -230,7 +213,6 @@ main (int argc, char **argv) return 0; - case 't': /* Create or test persistent transposition table. */ hashfile = fopen(HASHFILE, RWA_ACC); @@ -272,7 +254,7 @@ main (int argc, char **argv) } } - printf("The file contains %d entries out of max %d\n", nr[0], i); + printf("The file contains %d entries out of max %ld\n", nr[0], i); for (j = 1; j < MAXDEPTH; j++) printf("%d ", nr[j]); @@ -282,7 +264,6 @@ main (int argc, char **argv) return 0; - #endif /* HASHFILE */ #endif /* ttblsz */ @@ -294,20 +275,17 @@ main (int argc, char **argv) case 'X': /* X interface. */ display_type = DISPLAY_X; - + dsp = &raw_display; break; - case 'x': argc--; argv++; if (argc > 0) xwin = argv[0]; - break; - default: fputs("Usage: gnushogi [-a] [-t] [-c size] [-s savefile][-l listfile] [-x xwndw]\n", stderr); exit(1); diff --git a/gnushogi/makepattern.c b/gnushogi/makepattern.c index 0d510d9..ef1a937 100644 --- a/gnushogi/makepattern.c +++ b/gnushogi/makepattern.c @@ -37,15 +37,18 @@ #define MAX_OPENING_SEQUENCE 20 #define MAX_PATTERN 200 -static char *patternfile = PATTERNFILE; small_short pattern_data[MAX_PATTERN_DATA]; /* minimal ShowMessage to avoid dependency on extraneous display code */ -void -ShowMessage(char *s) +static void +Dummy_ShowMessage(char *s) { printf("%s\n", s); } +static struct display dummydsp = { + .ShowMessage = Dummy_ShowMessage, +}; +struct display *dsp = &dummydsp; #define is_digit(c) (((c) >= '0') && ((c) <= '9')) #define is_alpha(c) ((((c) >= 'a') && ((c) <= 'z')) \ @@ -121,7 +124,7 @@ ScanPiece(char **s, small_short *side, /* determine column */ for (c = 0; c < NO_COLS; c++) { - if (**s == cxx[c]) + if (**s == COL_NAME(c)) { (*s)++; break; @@ -134,7 +137,7 @@ ScanPiece(char **s, small_short *side, /* determine row */ for (r = 0; r < NO_ROWS; r++) { - if (**s == rxx[r]) + if (**s == ROW_NAME(r)) { (*s)++; break; @@ -188,74 +191,73 @@ ScanPattern (char *s, short *pindex) void -ReadOpeningSequences (short *pindex) +ReadOpeningSequences (short *pindex, const char* patternfile) { FILE *fd; char s[256]; short max_pattern = 0; short max_opening_sequence = 0; - if ((fd = fopen (patternfile, "r")) == NULL) - fd = fopen ("gnushogi.pat", "r"); + fd = fopen (patternfile, "r"); - if (fd != NULL) - { - *pindex = 0; + if (fd == NULL) { + sprintf(s, "no pattern file '%s'", patternfile); + dsp->ShowMessage(s); + return; + } - while (fgets (s, 256, fd) != NULL) + *pindex = 0; + + while (fgets (s, 256, fd) != NULL) + { + if (*s == '#') + { + /* comment, skip line */ + } + else if (is_alpha(*s)) { - if (*s == '#') + if (max_opening_sequence++ > 0) { - /* comment, skip line */ + pattern_data[(*pindex)++] = END_OF_PATTERNS; } - else if (is_alpha(*s)) - { - if (max_opening_sequence++ > 0) - { - pattern_data[(*pindex)++] = END_OF_PATTERNS; - } - pattern_data[(*pindex)++] = ValueOfOpeningName(s); + pattern_data[(*pindex)++] = ValueOfOpeningName(s); + } + else + { + if (ScanPattern(s, pindex)) + { + dsp->ShowMessage("error in pattern sequence..."); + exit(1); } else { - if (ScanPattern(s, pindex)) - { - ShowMessage("error in pattern sequence..."); - exit(1); - } - else - { - max_pattern++; - } + max_pattern++; } } + } - pattern_data[(*pindex)++] = END_OF_PATTERNS; - pattern_data[(*pindex)++] = END_OF_SEQUENCES; + pattern_data[(*pindex)++] = END_OF_PATTERNS; + pattern_data[(*pindex)++] = END_OF_SEQUENCES; - sprintf(s, - "Pattern: %d bytes for %d sequences with %d patterns.\n", - *pindex, max_opening_sequence, max_pattern); - ShowMessage(s); + sprintf(s, + "Pattern: %d bytes for %d sequences with %d patterns.\n", + *pindex, max_opening_sequence, max_pattern); + dsp->ShowMessage(s); - fclose(fd); - } else { - sprintf(s, "no pattern file '%s'", patternfile); - ShowMessage(s); - } + fclose(fd); } void -WriteOpeningSequences (short pindex) +WriteOpeningSequences (short pindex, const char* patternincfile) { FILE *fd; short n = 0; short max_pattern = 0; short max_opening_sequence = 0; - fd = fopen ("pattern.inc", "w"); + fd = fopen (patternincfile, "w"); fprintf(fd, "#define MAX_PATTERN_DATA %d\n\n", pindex); fprintf(fd, "small_short pattern_data[MAX_PATTERN_DATA] =\n{\n"); diff --git a/gnushogi/opts.h b/gnushogi/opts.h index a12bf3c..546da1c 100644 --- a/gnushogi/opts.h +++ b/gnushogi/opts.h @@ -66,8 +66,8 @@ * Don't print post information in background (easy mode OFF) */ -#define QUIETBACKGROUND -/* #undef QUIETBACKGROUND */ +/* #define QUIETBACKGROUND */ +#undef QUIETBACKGROUND /* diff --git a/gnushogi/pat2inc.c b/gnushogi/pat2inc.c index 1382261..1299e2a 100644 --- a/gnushogi/pat2inc.c +++ b/gnushogi/pat2inc.c @@ -36,8 +36,8 @@ #include "pattern.h" -extern void ReadOpeningSequences(short *pindex); -extern void WriteOpeningSequences(short pindex); +extern void ReadOpeningSequences(short *pindex, const char* patternfile); +extern void WriteOpeningSequences(short pindex, const char* patternincfile); small_short board[NO_SQUARES]; small_short color[NO_SQUARES]; @@ -47,6 +47,13 @@ main(int argc, char **argv) { short sq, side, max_pattern_data; + if (argc != 3) { + fprintf(stderr, "Usage: %s gnushogi.pat pattern.inc\n", argv[0]); + exit(1); + } + char* patternfile = argv[1]; + char* patternincfile = argv[2]; + #ifdef TEST_DISTANCE short d; char s[80]; @@ -84,8 +91,8 @@ main(int argc, char **argv) #endif - ReadOpeningSequences(&max_pattern_data); - WriteOpeningSequences(max_pattern_data); + ReadOpeningSequences(&max_pattern_data, patternfile); + WriteOpeningSequences(max_pattern_data, patternincfile); return 0; } diff --git a/gnushogi/pattern.c b/gnushogi/pattern.c index 05d15ca..349cd94 100644 --- a/gnushogi/pattern.c +++ b/gnushogi/pattern.c @@ -34,7 +34,11 @@ #include "pattern.h" /* "pat2inc" generates constants and pattern_data */ -#include "pattern.inc" +#ifndef MINISHOGI +# include "gnushogi-pattern.inc" +#else +# include "gnuminishogi-pattern.inc" +#endif struct Pattern_rec Pattern[MAX_PATTERN]; struct OpeningSequence_rec OpeningSequence[MAX_OPENING_SEQUENCE]; diff --git a/gnushogi/rawdsp.c b/gnushogi/rawdsp.c index b0e4084..0a4e473 100644 --- a/gnushogi/rawdsp.c +++ b/gnushogi/rawdsp.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -42,57 +43,48 @@ #endif #include "gnushogi.h" -#include "rawdsp.h" -unsigned short MV[MAXDEPTH]; -int MSCORE; - -int mycnt1, mycnt2; -char *DRAW; -extern char *InPtr; -extern short pscore[]; +/**************************************** + * forward declarations + ****************************************/ +static void Raw_UpdateDisplay(short f, short t, short redraw, short isspec); /**************************************** * Trivial output functions. ****************************************/ -void +static void Raw_ClearScreen(void) { - if (!barebones && !XSHOGI) + if (!XSHOGI) printf("\n"); } -void +static void Raw_ShowPrompt(void) { - if (!barebones && !XSHOGI) - { + if (!XSHOGI) fputs("\nYour move is? ", stdout); - } } -void +static void Raw_ShowCurrentMove(short pnt, short f, short t) { } -void +static void Raw_ShowDepth(char ch) { - if (!barebones && !XSHOGI) - { - printf("Depth= %d%c ", Sdepth, ch); - printf("\n"); - } + if (!XSHOGI) + printf("Depth= %d%c \n", Sdepth, ch); } -void +static void Raw_ShowGameType(void) { if (flag.post) @@ -100,7 +92,7 @@ Raw_ShowGameType(void) } -void +static void Raw_ShowLine(unsigned short *bstline) { int i; @@ -118,7 +110,7 @@ Raw_ShowLine(unsigned short *bstline) } -void +static void Raw_ShowMessage(char *s) { if (!XSHOGI) @@ -126,41 +118,54 @@ Raw_ShowMessage(char *s) } -void -Raw_AlwaysShowMessage(const char *format, va_list ap) +static void +Raw_AlwaysShowMessage(const char *format, ...) { + va_list ap; + va_start(ap, format); vprintf(format, ap); printf("\n"); + va_end(ap); } -void -Raw_Printf(const char *format, va_list ap) +static void +Raw_Printf(const char *format, ...) { + va_list ap; + va_start(ap, format); vprintf(format, ap); + va_end(ap); } -void +static void Raw_doRequestInputString(const char* fmt, char* buffer) { scanf(fmt, buffer); } -int +static int Raw_GetString(char* sx) { int eof = 0; + char *nl; sx[0] = '\0'; while(!eof && !sx[0]) eof = (fgets(sx, 80, stdin) == NULL); + + /* remove any trailing newline */ + nl = strchr(sx, '\n'); + if (nl) + nl[0] = '\0'; + return eof; } -void +static void Raw_ShowNodeCnt(long NodeCnt) { printf("Nodes = %ld Nodes/sec = %ld\n", @@ -168,7 +173,7 @@ Raw_ShowNodeCnt(long NodeCnt) } -void +static void Raw_ShowPatternCount(short side, short n) { if (flag.post) @@ -176,13 +181,13 @@ Raw_ShowPatternCount(short side, short n) } -void +static void Raw_ShowResponseTime(void) { } -void +static void Raw_ShowResults(short score, unsigned short *bstline, char ch) { if (flag.post && !XSHOGI) @@ -195,13 +200,13 @@ Raw_ShowResults(short score, unsigned short *bstline, char ch) } -void +static void Raw_ShowSidetoMove(void) { } -void +static void Raw_ShowStage(void) { printf("stage = %d\n", stage); @@ -213,7 +218,7 @@ Raw_ShowStage(void) * End of trivial output routines. ****************************************/ -void +static void Raw_Initialize(void) { mycnt1 = mycnt2 = 0; @@ -245,7 +250,7 @@ Raw_Initialize(void) } -void +static void Raw_ExitShogi(void) { /* CHECKME: what purpose does this next statement serve? */ @@ -258,20 +263,7 @@ Raw_ExitShogi(void) } -void -Raw_Die(int sig) -{ - char s[80]; - - Raw_ShowMessage("Abort? "); - scanf("%s", s); - - if (strcmp(s, "yes") == 0) - Raw_ExitShogi(); -} - - -void +static void Raw_TerminateSearch(int sig) { #ifdef INTERRUPT_TEST @@ -285,35 +277,53 @@ Raw_TerminateSearch(int sig) } -void +static void Raw_help(void) { Raw_ClearScreen(); printf("GNU Shogi %s command summary\n", PACKAGE_VERSION); - printf("----------------------------------" - "------------------------------\n"); - fputs ("7g7f move from 7g to 7f quit Exit Shogi\n", stdout); - printf("S6h move silver to 6h beep turn %s\n", (flag.beep) ? "OFF" : "ON"); - printf("2d2c+ move to 2c and promote material turn %s\n", (flag.material) ? "OFF" : "ON"); - printf("P*5e drop pawn to 5e easy turn %s\n", (flag.easy) ? "OFF" : "ON"); - printf("tsume toggle tsume mode hash turn %s\n", (flag.hash) ? "OFF" : "ON"); - fputs ("bd redraw board reverse board display\n", stdout); - printf("list game to shogi.lst book turn %s used %d of %d\n", (Book) ? "OFF" : "ON", bookcount, booksize); - fputs ("undo undo last ply remove take back a move\n", stdout); - fputs ("edit edit board force toggle manual move mode\n", stdout); - fputs ("switch sides with computer both computer match\n", stdout); - fputs ("black computer plays black white computer plays white\n", stdout); - fputs ("depth set search depth clock set time control\n", stdout); - fputs ("post principle variation hint suggest a move\n", stdout); - fputs ("save game to file get game from file\n", stdout); - printf("xsave pos. to xshogi file xget" - " pos. from xshogi file\n"); - fputs("random randomize play new start new game\n", stdout); - printf("--------------------------------" - "--------------------------------\n"); + printf("----------------------------------------------------------------\n"); + printf("7g7f move from 7g to 7f quit Exit Shogi\n"); + printf("S6h move silver to 6h beep turn %s\n", + (flag.beep) ? "OFF" : "ON"); + printf("2d2c+ move to 2c and promote material turn %s\n", + (flag.material) ? "OFF" : "ON"); + printf("P*5e drop pawn to 5e easy turn %s\n", + (flag.easy) ? "OFF" : "ON"); + printf("tsume toggle tsume mode hash turn %s\n", + (flag.hash) ? "OFF" : "ON"); + printf("bd redraw board reverse board display\n"); + printf("list game to shogi.lst book turn %s used %d of %d\n", + (Book) ? "OFF" : "ON", bookcount, booksize); + printf("undo undo last ply remove take back a move\n"); + printf("edit edit board force toggle manual move mode\n"); + printf("switch sides with computer both computer match\n"); + printf("black computer plays black white computer plays white\n"); + printf("sd set search depth clock set time control\n"); + printf("post principle variation hint suggest a move\n"); + printf("save game to file get game from file\n"); + printf("xsave pos. to xshogi file xget pos. from xshogi file\n"); + printf("random randomize play new start new game\n"); + printf("setup first \n"); + printf("go computer plays now material turn %s\n", + flag.material ? "OFF" : "ON"); + printf("level time control gamein \n"); + printf("time set engine clock otime set opponent clock\n"); + printf("Awindow Bwindow \n"); + printf("rcptr turn %3s bsave book save\n", + flag.rcptr ? "OFF" : "ON "); + printf("hashdepth hard turn easy OFF\n"); + printf("contempt xwndw \n"); + printf("rv turn %3s coords turn %s\n", + flag.rv ? "OFF" : "ON ", flag.coords ? "OFF" : "ON"); + printf("stars turn %3s moves \n", + flag.stars ? "OFF" : "ON "); + printf("test p \n"); + printf("debug depth alias for 'sd'\n"); + printf("----------------------------------------------------------------\n"); printf("Computer: %-12s Opponent: %s\n", ColorStr[computer], ColorStr[opponent]); - printf("Depth: %-12d Response time: %d sec\n", + printf("Depth: %-12d Response time: %ld sec\n", MaxSearchDepth, MaxResponseTime/100); printf("Random: %-12s Easy mode: %s\n", (dither) ? "ON" : "OFF", (flag.easy) ? "ON" : "OFF"); @@ -321,7 +331,7 @@ Raw_help(void) (flag.beep) ? "ON" : "OFF", (flag.hash) ? "ON" : "OFF"); printf("Tsume: %-12s Force: %s\n", (flag.tsume) ? "ON" : "OFF", (flag.force) ? "ON" : "OFF"); - printf("Time Control %s %d moves %d sec %d add %d depth\n", + printf("Time Control %s %d moves %ld sec %d add %d depth\n", (TCflag) ? "ON" : "OFF", TimeControl.moves[black], TimeControl.clock[black] / 100, TCadd/100, MaxSearchDepth); @@ -332,7 +342,7 @@ Raw_help(void) * Set up a board position. Pieces are entered by typing the piece followed * by the location. For example, Nf3 will place a knight on square f3. */ -void +static void Raw_EditBoard(void) { short a, r, c, sq, i, found; @@ -433,7 +443,7 @@ Raw_EditBoard(void) * Nine lines of nine characters are used to setup the board. 9a-1a is the * first line. White pieces are represented by uppercase characters. */ -void +static void Raw_SetupBoard(void) { short r, c, sq, i; @@ -483,7 +493,7 @@ Raw_SetupBoard(void) } -void +static void Raw_SearchStartStuff(short side) { if (flag.post) @@ -495,7 +505,7 @@ Raw_SearchStartStuff(short side) } -void +static void Raw_OutputMove(void) { if (flag.illegal) @@ -508,15 +518,11 @@ Raw_OutputMove(void) goto nomove; if (XSHOGI) - { /* add remaining time in milliseconds to xshogi */ printf("%d. ... %s %ld\n", ++mycnt1, mvstr[0], (TimeControl.clock[player] - et) * 10); - } else - { printf("%d. ... %s\n", ++mycnt1, mvstr[0]); - } nomove: if ((root->flags & draw) || (root->score == -(SCORE_LIMIT + 999)) @@ -561,39 +567,29 @@ Raw_OutputMove(void) summary: if (root->flags & draw) - { fputs("Drawn game!\n", stdout); - } else if (root->score == -(SCORE_LIMIT + 999)) - { printf("%s mates!\n", ColorStr[opponent]); - } else if (root->score == (SCORE_LIMIT + 998)) - { printf("%s mates!\n", ColorStr[computer]); - } #ifdef VERYBUGGY - else if (!barebones && (root->score < -SCORE_LIMIT)) - { + else if (!XSHOGI && (root->score < -SCORE_LIMIT)) printf("%s has a forced mate in %d moves!\n", ColorStr[opponent], SCORE_LIMIT + 999 + root->score - 1); - } - else if (!barebones && (root->score > SCORE_LIMIT)) - { + else if (!XSHOGI && (root->score > SCORE_LIMIT)) printf("%s has a forced mate in %d moves!\n", ColorStr[computer], SCORE_LIMIT + 998 - root->score - 1); - } #endif /* VERYBUGGY */ } -void +static void Raw_UpdateClocks(void) { } -void +static void Raw_UpdateDisplay(short f, short t, short redraw, short isspec) { @@ -652,7 +648,7 @@ Raw_UpdateDisplay(short f, short t, short redraw, short isspec) } -void +static void Raw_ChangeAlphaWindow(void) { printf("WAwindow: "); @@ -662,7 +658,7 @@ Raw_ChangeAlphaWindow(void) } -void +static void Raw_ChangeBetaWindow(void) { printf("WBwindow: "); @@ -672,7 +668,7 @@ Raw_ChangeBetaWindow(void) } -void +static void Raw_GiveHint(void) { if (hint) @@ -685,31 +681,20 @@ Raw_GiveHint(void) } -void +static void Raw_SelectLevel(char *sx) { + /* FIXME: NO_SQUARES is nonsense here */ + char T[NO_SQUARES + 1], *p; - char T[NO_SQUARES + 1], *p, *q; - - if ((p = strstr(sx, "level")) != NULL) - p += strlen("level"); - else if ((p = strstr(sx, "clock")) != NULL) - p += strlen("clock"); - - strcat(sx, "XX"); - q = T; - *q = '\0'; + strncpy(T, sx, NO_SQUARES); + T[NO_SQUARES] = '\0'; - for (; *p != 'X'; *q++ = *p++); - - *q = '\0'; - - /* line empty ask for input */ + /* if line empty, ask for input */ if (!T[0]) { fputs("Enter #moves #minutes: ", stdout); fgets(T, NO_SQUARES + 1, stdin); - strcat(T, "XX"); } /* skip blackspace */ @@ -719,6 +704,7 @@ Raw_SelectLevel(char *sx) if (*p == 'f') { /* its a fischer clock game */ + char *q; p++; TCminutes = (short)strtol(p, &q, 10); TCadd = (short)strtol(q, NULL, 10) *100; @@ -728,6 +714,7 @@ Raw_SelectLevel(char *sx) else { /* regular game */ + char *q; TCadd = 0; TCmoves = (short)strtol(p, &q, 10); TCminutes = (short)strtol(q, &q, 10); @@ -767,16 +754,22 @@ Raw_SelectLevel(char *sx) } -void -Raw_ChangeSearchDepth(void) +static void +Raw_ChangeSearchDepth(char *sx) { - printf("depth = "); - scanf("%hd", &MaxSearchDepth); + char buf[80+1]; + strncpy(buf, sx, 80); buf[80] = '\0'; + /* if line empty, ask for input */ + if (!buf[0]) { + printf("depth = "); + fgets(buf, 80+1, stdin); + } + sscanf(buf, "%hd", &MaxSearchDepth); TCflag = !(MaxSearchDepth > 0); } -void +static void Raw_ChangeHashDepth(void) { printf("hashdepth = "); @@ -786,7 +779,7 @@ Raw_ChangeHashDepth(void) } -void +static void Raw_SetContempt(void) { printf("contempt = "); @@ -794,7 +787,7 @@ Raw_SetContempt(void) } -void +static void Raw_ChangeXwindow(void) { printf("xwndw = "); @@ -806,11 +799,10 @@ Raw_ChangeXwindow(void) * Raw_ShowPostnValue(short sq) * must have called ExaminePosition() first */ -void +static void Raw_ShowPostnValue(short sq) { - short score; - score = ScorePosition(color[sq]); + (void) ScorePosition(color[sq]); if (color[sq] != neutral) { @@ -827,7 +819,7 @@ Raw_ShowPostnValue(short sq) } -void +static void Raw_DoDebug(void) { short c, p, sq, tp, tc, tsq, score, j, k; @@ -905,7 +897,7 @@ Raw_DoDebug(void) } -void +static void Raw_DoTable(short table[NO_SQUARES]) { short sq, j, k; @@ -924,7 +916,7 @@ Raw_DoTable(short table[NO_SQUARES]) } -void +static void Raw_ShowPostnValues(void) { short sq, score, j, k; @@ -949,7 +941,7 @@ Raw_ShowPostnValues(void) } -void +static void Raw_PollForInput(void) { #ifdef WIN32 @@ -957,12 +949,12 @@ Raw_PollForInput(void) if (!PeekNamedPipe(GetStdHandle(STD_INPUT_HANDLE), NULL, 0, NULL, &cnt, NULL)) cnt = 1; #else - static struct pollfd pollfds[1] = { /* [0] = */ { /* .fd = */ STDIN_FILENO, - /* .events = */ POLLIN } }; + static struct pollfd pollfds[1] = { [0] = { .fd = STDIN_FILENO, + .events = POLLIN } }; int cnt = poll(pollfds, sizeof(pollfds)/sizeof(pollfds[0]), 0); if (cnt < 0) { perror("polling standard input"); - ExitShogi(); + Raw_ExitShogi(); } #endif if (cnt) { /* if anything to read, or error occured */ @@ -971,3 +963,47 @@ Raw_PollForInput(void) flag.bothsides = false; } } + +struct display raw_display = +{ + .ChangeAlphaWindow = Raw_ChangeAlphaWindow, + .ChangeBetaWindow = Raw_ChangeBetaWindow, + .ChangeHashDepth = Raw_ChangeHashDepth, + .ChangeSearchDepth = Raw_ChangeSearchDepth, + .ChangeXwindow = Raw_ChangeXwindow, + .ClearScreen = Raw_ClearScreen, + .DoDebug = Raw_DoDebug, + .DoTable = Raw_DoTable, + .EditBoard = Raw_EditBoard, + .ExitShogi = Raw_ExitShogi, + .GiveHint = Raw_GiveHint, + .Initialize = Raw_Initialize, + .ShowNodeCnt = Raw_ShowNodeCnt, + .OutputMove = Raw_OutputMove, + .PollForInput = Raw_PollForInput, + .SetContempt = Raw_SetContempt, + .SearchStartStuff = Raw_SearchStartStuff, + .SelectLevel = Raw_SelectLevel, + .ShowCurrentMove = Raw_ShowCurrentMove, + .ShowDepth = Raw_ShowDepth, + .ShowGameType = Raw_ShowGameType, + .ShowLine = Raw_ShowLine, + .ShowMessage = Raw_ShowMessage, + .AlwaysShowMessage = Raw_AlwaysShowMessage, + .Printf = Raw_Printf, + .doRequestInputString = Raw_doRequestInputString, + .GetString = Raw_GetString, + .SetupBoard = Raw_SetupBoard, + .ShowPatternCount = Raw_ShowPatternCount, + .ShowPostnValue = Raw_ShowPostnValue, + .ShowPostnValues = Raw_ShowPostnValues, + .ShowPrompt = Raw_ShowPrompt, + .ShowResponseTime = Raw_ShowResponseTime, + .ShowResults = Raw_ShowResults, + .ShowSidetoMove = Raw_ShowSidetoMove, + .ShowStage = Raw_ShowStage, + .TerminateSearch = Raw_TerminateSearch, + .UpdateClocks = Raw_UpdateClocks, + .UpdateDisplay = Raw_UpdateDisplay, + .help = Raw_help, +}; diff --git a/gnushogi/rawdsp.h b/gnushogi/rawdsp.h deleted file mode 100644 index 952b8c5..0000000 --- a/gnushogi/rawdsp.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * FILE: rawdsp.h - * - * Raw text interface for GNU Shogi. - * - * ---------------------------------------------------------------------- - * Copyright (c) 1993, 1994, 1995 Matthias Mutz - * Copyright (c) 1999 Michael Vanier and the Free Software Foundation - * Copyright (c) 2008, 2013, 2014 Yann Dirson and the Free Software Foundation - * - * GNU SHOGI is based on GNU CHESS - * - * Copyright (c) 1988, 1989, 1990 John Stanback - * Copyright (c) 1992 Free Software Foundation - * - * This file is part of GNU SHOGI. - * - * GNU Shogi is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 3 of the License, - * or (at your option) any later version. - * - * GNU Shogi is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License along - * with GNU Shogi; see the file COPYING. If not, see - * . - * ---------------------------------------------------------------------- - * - */ - -#ifndef _RAWDSP_H_ -#define _RAWDSP_H_ - -#include "gnushogi.h" - -/* The following are common to rawdsp.h and cursesdsp.h */ - -void Raw_ChangeAlphaWindow(void); -void Raw_ChangeBetaWindow(void); -void Raw_ChangeHashDepth(void); -void Raw_ChangeSearchDepth(void); -void Raw_ChangeXwindow(void); -void Raw_ClearScreen(void); -void Raw_Die(int sig); -void Raw_DoDebug(void); -void Raw_DoTable(short table[NO_SQUARES]); -void Raw_EditBoard(void); -void Raw_ExitShogi(void); -void Raw_GiveHint(void); -void Raw_Initialize(void); -void Raw_ShowNodeCnt(long NodeCnt); -void Raw_OutputMove(void); -void Raw_PollForInput(void); -void Raw_SearchStartStuff(short side); -void Raw_SelectLevel(char *sx); -void Raw_SetContempt(void); -void Raw_ShowCurrentMove(short pnt, short f, short t); -void Raw_ShowDepth(char ch); -void Raw_ShowGameType(void); -void Raw_ShowLine(unsigned short *bstline); -void Raw_ShowMessage(char *s); -void Raw_AlwaysShowMessage(const char *format, va_list ap); -void Raw_Printf(const char *format, va_list ap); -void Raw_doRequestInputString(const char* fmt, char* buffer); -int Raw_GetString(char* sx); -void Raw_SetupBoard(void); -void Raw_ShowPatternCount(short side, short n); -void Raw_ShowPostnValue(short sq); -void Raw_ShowPostnValues(void); -void Raw_ShowPrompt(void); -void Raw_ShowResponseTime(void); -void Raw_ShowResults(short score, unsigned short *bstline, char ch); -void Raw_ShowSidetoMove(void); -void Raw_ShowStage(void); -void Raw_TerminateSearch(int sig); -void Raw_UpdateClocks(void); -void Raw_UpdateDisplay(short f, short t, short redraw, short isspec); -void Raw_help(void); - -#endif /* _RAWDSP_H_ */ - diff --git a/gnushogi/search.c b/gnushogi/search.c index 84850e7..1c4bbf7 100644 --- a/gnushogi/search.c +++ b/gnushogi/search.c @@ -181,7 +181,7 @@ SelectMove(short side, SelectMove_mode iop) #ifdef QUIETBACKGROUND if (!background) #endif /* QUIETBACKGROUND */ - ShowResponseTime(); + dsp->ShowResponseTime(); ExtraTime = 0; @@ -190,12 +190,12 @@ SelectMove(short side, SelectMove_mode iop) #ifdef QUIETBACKGROUND if (!background) #endif /* QUIETBACKGROUND */ - ShowSidetoMove(); + dsp->ShowSidetoMove(); #ifdef QUIETBACKGROUND if (!background) #endif /* QUIETBACKGROUND */ - SearchStartStuff(side); + dsp->SearchStartStuff(side); #ifdef HISTORY array_zero(history, sizeof_history); @@ -259,7 +259,7 @@ SelectMove(short side, SelectMove_mode iop) if (flag.regularstart && Book) { - flag.timeout = bookflag = OpeningBook(&hint, side); + flag.timeout = bookflag = OpeningBook(&hint); if (TCflag) ResponseTime += ResponseTime; @@ -305,7 +305,7 @@ SelectMove(short side, SelectMove_mode iop) # ifdef QUIETBACKGROUND if (!background) #endif /* QUIETBACKGROUND */ - ShowDepth(' '); + dsp->ShowDepth(' '); /* search at this level returns score of PV */ score = search(side, 1, Sdepth, alpha, beta, PrVar, &rpt); @@ -321,7 +321,7 @@ SelectMove(short side, SelectMove_mode iop) #ifdef QUIETBACKGROUND if (!background) #endif /* QUIETBACKGROUND */ - ShowDepth('-'); + dsp->ShowDepth('-'); if (TCflag && TCcount < MAXTCCOUNTR) { @@ -343,7 +343,7 @@ SelectMove(short side, SelectMove_mode iop) #ifdef QUIETBACKGROUND if (!background) #endif /* QUIETBACKGROUND */ - ShowDepth('+'); + dsp->ShowDepth('+'); score = search(side, 1, Sdepth, -(SCORE_LIMIT + 999), (SCORE_LIMIT + 999), PrVar, &rpt); @@ -396,7 +396,7 @@ SelectMove(short side, SelectMove_mode iop) #ifdef QUIETBACKGROUND if (!background) #endif /* QUIETBACKGROUND */ - ShowResults(score, PrVar, '.'); + dsp->ShowResults(score, PrVar, '.'); } /********************** end of main loop ***************************/ @@ -453,7 +453,7 @@ SelectMove(short side, SelectMove_mode iop) ElapsedTime(COMPUTE_AND_INIT_MODE); /* update time control info */ - OutputMove(); + dsp->OutputMove(); /* if mate set flag */ if ((score == -(SCORE_LIMIT + 999) || score == (SCORE_LIMIT + 998))) @@ -581,7 +581,7 @@ search(short side, #ifdef QUIETBACKGROUND if (!background) #endif - ShowResponseTime(); + dsp->ShowResponseTime(); } else if (!TCflag && flag.musttimeout && Sdepth > MINDEPTH) { @@ -711,7 +711,7 @@ search(short side, && (ProbeFTable(side, depth, ply, &alpha, &beta, &score) == true)) { - PutInTTable(side, score, depth, ply, alpha, beta, PV); + PutInTTable(side, score, depth, ply, beta, PV); bstline[ply] = PV; bstline[ply + 1] = 0; @@ -862,7 +862,6 @@ search(short side, nxtline[ply + 1] = 0; /* if at top level */ -#if !defined NOPOST if (ply == 1) { /* at the top update search status */ @@ -871,10 +870,9 @@ search(short side, #ifdef QUIETBACKGROUND if (!background) #endif /* QUIETBACKGROUND */ - ShowCurrentMove(pnt, node->f, node->t); + dsp->ShowCurrentMove(pnt, node->f, node->t); } } -#endif if (!(node->flags & exact)) { @@ -985,15 +983,15 @@ search(short side, { if (best > beta) { - ShowResults(best, bstline, '+'); + dsp->ShowResults(best, bstline, '+'); } else if (best < alpha) { - ShowResults(best, bstline, '-'); + dsp->ShowResults(best, bstline, '-'); } else { - ShowResults (best, bstline, '&'); + dsp->ShowResults(best, bstline, '&'); } } #ifdef QUIETBACKGROUND @@ -1026,13 +1024,13 @@ search(short side, { # ifdef HASHFILE /* MCV: warning: this confuses the formatter. */ if (use_ttable - && PutInTTable(side, best, depth, ply, alpha, beta, mv) + && PutInTTable(side, best, depth, ply, beta, mv) && hashfile && (depth > HashDepth) && (GameCnt < HashMoveLimit)) # else if (use_ttable - && PutInTTable(side, best, depth, ply, alpha, beta, mv)) + && PutInTTable(side, best, depth, ply, beta, mv)) # endif { PutInFTable(side, best, depth, ply, @@ -1117,8 +1115,8 @@ UpdatePieceList(short side, short sq, UpdatePieceList_mode iop) /* Make or Unmake drop move. */ -void -drop(short side, short piece, short f, short t, short iop) +static void +drop(short side, short piece, short t, short iop) { if (iop == 1) { @@ -1286,7 +1284,7 @@ MakeMove(short side, *tempst = svalue[t]; #endif - (void)drop(side, g->fpiece, f, t, 1); + (void)drop(side, g->fpiece, t, 1); } else { @@ -1414,7 +1412,7 @@ UnmakeMove(short side, if (node->flags & dropmask) { - (void)drop(side, (node->flags & pmask), f, t, 2); + (void)drop(side, (node->flags & pmask), t, 2); #if !defined SAVE_SVALUE svalue[t] = *tempst; diff --git a/gnushogi/tcontrl.c b/gnushogi/tcontrl.c index a9ec0d3..2ce4416 100644 --- a/gnushogi/tcontrl.c +++ b/gnushogi/tcontrl.c @@ -346,7 +346,7 @@ CheckForTimeout(int score, int globalscore, int Jscore, int zwndw) #endif if (flag.timeout) - ShowMessage("timeout"); + dsp->ShowMessage("timeout"); } @@ -366,7 +366,7 @@ ElapsedTime(ElapsedTime_mode iop) struct timeval tv; #endif - PollForInput(); + dsp->PollForInput(); #ifdef HAVE_GETTIMEOFDAY gettimeofday(&tv, NULL); @@ -411,6 +411,27 @@ ElapsedTime(ElapsedTime_mode iop) #ifdef QUIETBACKGROUND if (!background) #endif - UpdateClocks(); + dsp->UpdateClocks(); } } + + +void +SetTimeControl(void) +{ + if (TCflag) + { + TimeControl.moves[black] = TimeControl.moves[white] = TCmoves; + TimeControl.clock[black] += 6000L * TCminutes + TCseconds * 100; + TimeControl.clock[white] += 6000L * TCminutes + TCseconds * 100; + } + else + { + TimeControl.moves[black] = TimeControl.moves[white] = 0; + TimeControl.clock[black] = TimeControl.clock[white] = 0; + } + + flag.onemove = (TCmoves == 1); + et = 0; + ElapsedTime(COMPUTE_AND_INIT_MODE); +} diff --git a/gnushogi/util.c b/gnushogi/util.c index 0d1611e..927f3d8 100644 --- a/gnushogi/util.c +++ b/gnushogi/util.c @@ -36,9 +36,9 @@ unsigned int TTadd = 0; short recycle; short ISZERO = 1; - +#if 0 int -parse(FILE * fd, unsigned short *mv, short side, char *opening) +parse(FILE * fd, unsigned short *mv, char *opening) { int c, i, r1, r2, c1, c2; char s[128]; @@ -100,7 +100,7 @@ parse(FILE * fd, unsigned short *mv, short side, char *opening) return 1; } - +#endif /* * The field of a hashtable is computed as follows: @@ -174,7 +174,7 @@ ProbeTTable (short side, { HashCol++; - if (!barebones) + if (!XSHOGI) { ShowMessage("ttable collision detected"); ShowBD(ptbl->bd); @@ -227,7 +227,6 @@ PutInTTable(short side, short score, short depth, short ply, - short alpha, short beta, unsigned short mv) { diff --git a/install-sh b/install-sh deleted file mode 100755 index ebc6691..0000000 --- a/install-sh +++ /dev/null @@ -1,250 +0,0 @@ -#! /bin/sh -# -# install - install a program, script, or datafile -# This comes from X11R5 (mit/util/scripts/install.sh). -# -# Copyright 1991 by the Massachusetts Institute of Technology -# -# Permission to use, copy, modify, distribute, and sell this software and its -# documentation for any purpose is hereby granted without fee, provided that -# the above copyright notice appear in all copies and that both that -# copyright notice and this permission notice appear in supporting -# documentation, and that the name of M.I.T. not be used in advertising or -# publicity pertaining to distribution of the software without specific, -# written prior permission. M.I.T. makes no representations about the -# suitability of this software for any purpose. It is provided "as is" -# without express or implied warranty. -# -# Calling this script install-sh is preferred over install.sh, to prevent -# `make' implicit rules from creating a file called install from it -# when there is no Makefile. -# -# This script is compatible with the BSD install script, but was written -# from scratch. It can only install one file at a time, a restriction -# shared with many OS's install programs. - - -# set DOITPROG to echo to test this script - -# Don't use :- since 4.3BSD and earlier shells don't like it. -doit="${DOITPROG-}" - - -# put in absolute paths if you don't have them in your path; or use env. vars. - -mvprog="${MVPROG-mv}" -cpprog="${CPPROG-cp}" -chmodprog="${CHMODPROG-chmod}" -chownprog="${CHOWNPROG-chown}" -chgrpprog="${CHGRPPROG-chgrp}" -stripprog="${STRIPPROG-strip}" -rmprog="${RMPROG-rm}" -mkdirprog="${MKDIRPROG-mkdir}" - -transformbasename="" -transform_arg="" -instcmd="$mvprog" -chmodcmd="$chmodprog 0755" -chowncmd="" -chgrpcmd="" -stripcmd="" -rmcmd="$rmprog -f" -mvcmd="$mvprog" -src="" -dst="" -dir_arg="" - -while [ x"$1" != x ]; do - case $1 in - -c) instcmd="$cpprog" - shift - continue;; - - -d) dir_arg=true - shift - continue;; - - -m) chmodcmd="$chmodprog $2" - shift - shift - continue;; - - -o) chowncmd="$chownprog $2" - shift - shift - continue;; - - -g) chgrpcmd="$chgrpprog $2" - shift - shift - continue;; - - -s) stripcmd="$stripprog" - shift - continue;; - - -t=*) transformarg=`echo $1 | sed 's/-t=//'` - shift - continue;; - - -b=*) transformbasename=`echo $1 | sed 's/-b=//'` - shift - continue;; - - *) if [ x"$src" = x ] - then - src=$1 - else - # this colon is to work around a 386BSD /bin/sh bug - : - dst=$1 - fi - shift - continue;; - esac -done - -if [ x"$src" = x ] -then - echo "install: no input file specified" - exit 1 -else - true -fi - -if [ x"$dir_arg" != x ]; then - dst=$src - src="" - - if [ -d $dst ]; then - instcmd=: - else - instcmd=mkdir - fi -else - -# Waiting for this to be detected by the "$instcmd $src $dsttmp" command -# might cause directories to be created, which would be especially bad -# if $src (and thus $dsttmp) contains '*'. - - if [ -f $src -o -d $src ] - then - true - else - echo "install: $src does not exist" - exit 1 - fi - - if [ x"$dst" = x ] - then - echo "install: no destination specified" - exit 1 - else - true - fi - -# If destination is a directory, append the input filename; if your system -# does not like double slashes in filenames, you may need to add some logic - - if [ -d $dst ] - then - dst="$dst"/`basename $src` - else - true - fi -fi - -## this sed command emulates the dirname command -dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` - -# Make sure that the destination directory exists. -# this part is taken from Noah Friedman's mkinstalldirs script - -# Skip lots of stat calls in the usual case. -if [ ! -d "$dstdir" ]; then -defaultIFS=' -' -IFS="${IFS-${defaultIFS}}" - -oIFS="${IFS}" -# Some sh's can't handle IFS=/ for some reason. -IFS='%' -set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'` -IFS="${oIFS}" - -pathcomp='' - -while [ $# -ne 0 ] ; do - pathcomp="${pathcomp}${1}" - shift - - if [ ! -d "${pathcomp}" ] ; - then - $mkdirprog "${pathcomp}" - else - true - fi - - pathcomp="${pathcomp}/" -done -fi - -if [ x"$dir_arg" != x ] -then - $doit $instcmd $dst && - - if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi && - if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi && - if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi && - if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi -else - -# If we're going to rename the final executable, determine the name now. - - if [ x"$transformarg" = x ] - then - dstfile=`basename $dst` - else - dstfile=`basename $dst $transformbasename | - sed $transformarg`$transformbasename - fi - -# don't allow the sed command to completely eliminate the filename - - if [ x"$dstfile" = x ] - then - dstfile=`basename $dst` - else - true - fi - -# Make a temp file name in the proper directory. - - dsttmp=$dstdir/#inst.$$# - -# Move or copy the file name to the temp name - - $doit $instcmd $src $dsttmp && - - trap "rm -f ${dsttmp}" 0 && - -# and set any options; do chmod last to preserve setuid bits - -# If any of these fail, we abort the whole thing. If we want to -# ignore errors from any of these, just make sure not to ignore -# errors from the above "$doit $instcmd $src $dsttmp" command. - - if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi && - if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi && - if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi && - if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi && - -# Now rename the file to the real destination. - - $doit $rmcmd -f $dstdir/$dstfile && - $doit $mvcmd $dsttmp $dstdir/$dstfile - -fi && - - -exit 0