tDodgy "Win32/Unix portability" module, dopeos.c, removed. Portability function… | |
git clone git://src.adamsgaard.dk/vaccinewars | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 35939c0229fb0782b3b559f710958696c5c67b16 | |
parent 4740cc4af3b79373ce36943b8a88287e21ce8835 | |
Author: Ben Webb <[email protected]> | |
Date: Fri, 1 Mar 2002 12:51:13 +0000 | |
Dodgy "Win32/Unix portability" module, dopeos.c, removed. Portability functions | |
are now in util.c (and try to use autoconf tests rather than host type | |
wherever possible - e.g. !HAVE_GETOPT rather than CYGWIN). The "curses | |
emulation" code for Win32 is now in the cursesport/ subdirectory, and is | |
included only when necessary, just like the gtkport stuff. | |
Diffstat: | |
M config.h.in | 3 +++ | |
M configure | 16 +++++++++++++++- | |
M configure.in | 6 +++++- | |
M src/AIPlayer.c | 2 +- | |
M src/Makefile.am | 13 +++++++++---- | |
M src/Makefile.in | 21 ++++++++++++--------- | |
M src/curses_client/curses_client.c | 14 +++++++++++--- | |
A src/cursesport/Makefile.am | 6 ++++++ | |
A src/cursesport/Makefile.in | 325 +++++++++++++++++++++++++++++… | |
A src/cursesport/cursesport.c | 263 +++++++++++++++++++++++++++++… | |
A src/cursesport/cursesport.h | 106 ++++++++++++++++++++++++++++++ | |
D src/dopeos.c | 479 -----------------------------… | |
D src/dopeos.h | 172 ------------------------------ | |
M src/dopewars.c | 2 +- | |
M src/dopewars.h | 2 +- | |
M src/gui_client/gtk_client.c | 2 +- | |
M src/message.c | 2 +- | |
M src/network.h | 4 ++++ | |
M src/serverside.c | 4 +--- | |
A src/util.c | 242 +++++++++++++++++++++++++++++… | |
A src/util.h | 79 +++++++++++++++++++++++++++++… | |
M src/winmain.c | 4 +--- | |
22 files changed, 1087 insertions(+), 680 deletions(-) | |
--- | |
diff --git a/config.h.in b/config.h.in | |
t@@ -118,6 +118,9 @@ | |
/* Define if you have the gethostbyname function. */ | |
#undef HAVE_GETHOSTBYNAME | |
+/* Define if you have the getopt function. */ | |
+#undef HAVE_GETOPT | |
+ | |
/* Define if you have the getopt_long function. */ | |
#undef HAVE_GETOPT_LONG | |
diff --git a/configure b/configure | |
t@@ -4280,7 +4280,7 @@ fi | |
fi | |
-for ac_func in strdup strstr getopt_long fork | |
+for ac_func in strdup strstr getopt getopt_long fork | |
do | |
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 | |
echo "configure:4287: checking for $ac_func" >&5 | |
t@@ -4588,6 +4588,16 @@ else | |
GTKPORT_FALSE= | |
fi | |
+ | |
+ | |
+if test "$CURSES_CLIENT" = "yes"; then | |
+ CURSESPORT_TRUE= | |
+ CURSESPORT_FALSE='#' | |
+else | |
+ CURSESPORT_TRUE='#' | |
+ CURSESPORT_FALSE= | |
+fi | |
+ | |
trap '' 1 2 15 | |
cat > confcache <<\EOF | |
# This file is a shell script that caches the results of configure | |
t@@ -4695,6 +4705,7 @@ src/Makefile | |
src/gui_client/Makefile | |
src/curses_client/Makefile | |
src/gtkport/Makefile | |
+src/cursesport/Makefile | |
doc/Makefile | |
intl/Makefile | |
po/Makefile.in config.h" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15 | |
t@@ -4785,6 +4796,8 @@ s%@CURSES_CLIENT_TRUE@%$CURSES_CLIENT_TRUE%g | |
s%@CURSES_CLIENT_FALSE@%$CURSES_CLIENT_FALSE%g | |
s%@GTKPORT_TRUE@%$GTKPORT_TRUE%g | |
s%@GTKPORT_FALSE@%$GTKPORT_FALSE%g | |
+s%@CURSESPORT_TRUE@%$CURSESPORT_TRUE%g | |
+s%@CURSESPORT_FALSE@%$CURSESPORT_FALSE%g | |
CEOF | |
EOF | |
t@@ -4831,6 +4844,7 @@ src/Makefile | |
src/gui_client/Makefile | |
src/curses_client/Makefile | |
src/gtkport/Makefile | |
+src/cursesport/Makefile | |
doc/Makefile | |
intl/Makefile | |
po/Makefile.in"} | |
diff --git a/configure.in b/configure.in | |
t@@ -195,7 +195,7 @@ dnl Checks for library functions. | |
AC_FUNC_MEMCMP | |
AC_FUNC_SETVBUF_REVERSED | |
AC_FUNC_STRFTIME | |
-AC_CHECK_FUNCS(strdup strstr getopt_long fork) | |
+AC_CHECK_FUNCS(strdup strstr getopt getopt_long fork) | |
dnl Enable networking by default under Win32, but on Unix systems | |
dnl make it dependent on the availability of select and socket | |
t@@ -252,12 +252,16 @@ AM_CONDITIONAL(CURSES_CLIENT, test "$CURSES_CLIENT" = "y… | |
dnl Compile in the gtkport stuff for any kind of GUI | |
AM_CONDITIONAL(GTKPORT, test "$GUI_CLIENT" = "yes" -o "$GUI_SERVER" = "yes") | |
+dnl Compile in the cursesport stuff for the curses client only | |
+AM_CONDITIONAL(CURSESPORT, test "$CURSES_CLIENT" = "yes") | |
+ | |
AC_OUTPUT([ | |
Makefile | |
src/Makefile | |
src/gui_client/Makefile | |
src/curses_client/Makefile | |
src/gtkport/Makefile | |
+src/cursesport/Makefile | |
doc/Makefile | |
intl/Makefile | |
po/Makefile.in], | |
diff --git a/src/AIPlayer.c b/src/AIPlayer.c | |
t@@ -29,11 +29,11 @@ | |
#include <sys/types.h> | |
#include <errno.h> | |
#include <glib.h> | |
-#include "dopeos.h" | |
#include "dopewars.h" | |
#include "message.h" | |
#include "nls.h" | |
#include "tstring.h" | |
+#include "util.h" | |
#include "AIPlayer.h" | |
#if NETWORKING | |
diff --git a/src/Makefile.am b/src/Makefile.am | |
t@@ -13,12 +13,17 @@ GTKPORTSUBDIR = gtkport | |
GTKPORTDEP = gtkport/libgtkport.a | |
endif | |
-SUBDIRS = $(GUISUBDIR) $(CURSESSUBDIR) $(GTKPORTSUBDIR) | |
-dopewars_DEPENDENCIES = @INTLLIBS@ @WNDRES@ $(GUIDEP) $(CURSESDEP) $(GTKPORTDE… | |
-dopewars_LDADD = $(GUIDEP) $(CURSESDEP) $(GTKPORTDEP) @GTK_LIBS@ @INTLLIBS@ @W… | |
+if CURSESPORT | |
+CURSESPORTSUBDIR = cursesport | |
+CURSESPORTDEP = cursesport/libcursesport.a | |
+endif | |
+ | |
+SUBDIRS = $(GUISUBDIR) $(CURSESSUBDIR) $(GTKPORTSUBDIR) $(CURSESPORTSUBDIR) | |
+dopewars_DEPENDENCIES = @INTLLIBS@ @WNDRES@ $(GUIDEP) $(CURSESDEP) $(GTKPORTDE… | |
+dopewars_LDADD = $(GUIDEP) $(CURSESDEP) $(GTKPORTDEP) $(CURSESPORTDEP) @GTK_LI… | |
bin_PROGRAMS = dopewars | |
-dopewars_SOURCES = admin.c admin.h AIPlayer.c AIPlayer.h dopeos.c dopeos.h \ | |
+dopewars_SOURCES = admin.c admin.h AIPlayer.c AIPlayer.h util.c util.h \ | |
dopewars.c dopewars.h error.c error.h message.c message.h \ | |
network.c network.h nls.h serverside.c serverside.h \ | |
tstring.c tstring.h winmain.c winmain.h | |
diff --git a/src/Makefile.in b/src/Makefile.in | |
t@@ -102,12 +102,15 @@ localedir = @localedir@ | |
@GTKPORT_TRUE@GTKPORTSUBDIR = @GTKPORT_TRUE@gtkport | |
@GTKPORT_TRUE@GTKPORTDEP = @GTKPORT_TRUE@gtkport/libgtkport.a | |
-SUBDIRS = $(GUISUBDIR) $(CURSESSUBDIR) $(GTKPORTSUBDIR) | |
-dopewars_DEPENDENCIES = @INTLLIBS@ @WNDRES@ $(GUIDEP) $(CURSESDEP) $(GTKPORTDE… | |
-dopewars_LDADD = $(GUIDEP) $(CURSESDEP) $(GTKPORTDEP) @GTK_LIBS@ @INTLLIBS@ @W… | |
+@CURSESPORT_TRUE@CURSESPORTSUBDIR = @CURSESPORT_TRUE@cursesport | |
+@CURSESPORT_TRUE@CURSESPORTDEP = @CURSESPORT_TRUE@cursesport/libcursesport.a | |
+ | |
+SUBDIRS = $(GUISUBDIR) $(CURSESSUBDIR) $(GTKPORTSUBDIR) $(CURSESPORTSUBDIR) | |
+dopewars_DEPENDENCIES = @INTLLIBS@ @WNDRES@ $(GUIDEP) $(CURSESDEP) $(GTKPORTDE… | |
+dopewars_LDADD = $(GUIDEP) $(CURSESDEP) $(GTKPORTDEP) $(CURSESPORTDEP) @GTK_LI… | |
bin_PROGRAMS = dopewars | |
-dopewars_SOURCES = admin.c admin.h AIPlayer.c AIPlayer.h dopeos.c dopeos.h \ | |
+dopewars_SOURCES = admin.c admin.h AIPlayer.c AIPlayer.h util.c util.h \ | |
dopewars.c dopewars.h error.c error.h message.c message.h \ | |
network.c network.h nls.h serverside.c serverside.h \ | |
tstring.c tstring.h winmain.c winmain.h | |
t@@ -127,7 +130,7 @@ PROGRAMS = $(bin_PROGRAMS) | |
CPPFLAGS = @CPPFLAGS@ | |
LDFLAGS = @LDFLAGS@ | |
LIBS = @LIBS@ | |
-dopewars_OBJECTS = admin.o AIPlayer.o dopeos.o dopewars.o error.o \ | |
+dopewars_OBJECTS = admin.o AIPlayer.o util.o dopewars.o error.o \ | |
message.o network.o serverside.o tstring.o winmain.o | |
dopewars_LDFLAGS = | |
CFLAGS = @CFLAGS@ | |
t@@ -141,10 +144,10 @@ DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXIN… | |
TAR = gtar | |
GZIP_ENV = --best | |
-DIST_SUBDIRS = gui_client curses_client gtkport | |
-DEP_FILES = .deps/AIPlayer.P .deps/admin.P .deps/dopeos.P \ | |
-.deps/dopewars.P .deps/error.P .deps/message.P .deps/network.P \ | |
-.deps/serverside.P .deps/tstring.P .deps/winmain.P | |
+DIST_SUBDIRS = gui_client curses_client gtkport cursesport | |
+DEP_FILES = .deps/AIPlayer.P .deps/admin.P .deps/dopewars.P \ | |
+.deps/error.P .deps/message.P .deps/network.P .deps/serverside.P \ | |
+.deps/tstring.P .deps/util.P .deps/winmain.P | |
SOURCES = $(dopewars_SOURCES) | |
OBJECTS = $(dopewars_OBJECTS) | |
diff --git a/src/curses_client/curses_client.c b/src/curses_client/curses_clien… | |
t@@ -35,7 +35,7 @@ | |
#include <errno.h> | |
#include <glib.h> | |
#include "curses_client.h" | |
-#include "dopeos.h" | |
+#include "cursesport/cursesport.h" | |
#include "dopewars.h" | |
#include "message.h" | |
#include "nls.h" | |
t@@ -48,6 +48,16 @@ static void PrintHighScore(char *Data); | |
static int ResizedFlag; | |
static SCREEN *cur_screen; | |
+#define PromptAttr (COLOR_PAIR(1)) | |
+#define TextAttr (COLOR_PAIR(2)) | |
+#define LocationAttr (COLOR_PAIR(3)|A_BOLD) | |
+#define TitleAttr (COLOR_PAIR(4)) | |
+#define StatsAttr (COLOR_PAIR(5)) | |
+#define DebtAttr (COLOR_PAIR(6)) | |
+ | |
+/* Current size of the screen */ | |
+static int Width, Depth; | |
+ | |
#ifdef NETWORKING | |
static enum { | |
CM_SERVER, CM_PROMPT, CM_META, CM_SINGLE | |
t@@ -308,10 +318,8 @@ static gboolean SelectServerFromMetaServer(Player *Play, … | |
if (FD_ISSET(0, &readfds)) { | |
/* So that Ctrl-L works */ | |
c = getch(); | |
-#ifndef CYGWIN | |
if (c == '\f') | |
wrefresh(curscr); | |
-#endif | |
} | |
if (RespondToSelect | |
(&MetaConn->NetBuf, &readfds, &writefds, NULL, &DoneOK)) { | |
diff --git a/src/cursesport/Makefile.am b/src/cursesport/Makefile.am | |
t@@ -0,0 +1,6 @@ | |
+noinst_LIBRARIES = libcursesport.a | |
+libcursesport_a_SOURCES = cursesport.c cursesport.h | |
+libcursesport_a_DEPENDENCIES = @INTLLIBS@ | |
+INCLUDES = -I../../intl -I${srcdir} -I${srcdir}/.. -I../.. | |
+LDADD = @INTLLIBS@ | |
+DEFS = @DEFS@ -DLOCALEDIR=\"${localedir}\" | |
diff --git a/src/cursesport/Makefile.in b/src/cursesport/Makefile.in | |
t@@ -0,0 +1,325 @@ | |
+# Makefile.in generated automatically by automake 1.4-p5 from Makefile.am | |
+ | |
+# Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc. | |
+# This Makefile.in is free software; the Free Software Foundation | |
+# gives unlimited permission to copy and/or distribute it, | |
+# with or without modifications, as long as this notice is preserved. | |
+ | |
+# This program is distributed in the hope that it will be useful, | |
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without | |
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A | |
+# PARTICULAR PURPOSE. | |
+ | |
+ | |
+SHELL = @SHELL@ | |
+ | |
+srcdir = @srcdir@ | |
+top_srcdir = @top_srcdir@ | |
+VPATH = @srcdir@ | |
+prefix = @prefix@ | |
+exec_prefix = @exec_prefix@ | |
+ | |
+bindir = @bindir@ | |
+sbindir = @sbindir@ | |
+libexecdir = @libexecdir@ | |
+datadir = @datadir@ | |
+sysconfdir = @sysconfdir@ | |
+sharedstatedir = @sharedstatedir@ | |
+localstatedir = @localstatedir@ | |
+libdir = @libdir@ | |
+infodir = @infodir@ | |
+mandir = @mandir@ | |
+includedir = @includedir@ | |
+oldincludedir = /usr/include | |
+ | |
+DESTDIR = | |
+ | |
+pkgdatadir = $(datadir)/@PACKAGE@ | |
+pkglibdir = $(libdir)/@PACKAGE@ | |
+pkgincludedir = $(includedir)/@PACKAGE@ | |
+ | |
+top_builddir = ../.. | |
+ | |
+ACLOCAL = @ACLOCAL@ | |
+AUTOCONF = @AUTOCONF@ | |
+AUTOMAKE = @AUTOMAKE@ | |
+AUTOHEADER = @AUTOHEADER@ | |
+ | |
+INSTALL = @INSTALL@ | |
+INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS) | |
+INSTALL_DATA = @INSTALL_DATA@ | |
+INSTALL_SCRIPT = @INSTALL_SCRIPT@ | |
+transform = @program_transform_name@ | |
+ | |
+NORMAL_INSTALL = : | |
+PRE_INSTALL = : | |
+POST_INSTALL = : | |
+NORMAL_UNINSTALL = : | |
+PRE_UNINSTALL = : | |
+POST_UNINSTALL = : | |
+host_alias = @host_alias@ | |
+host_triplet = @host@ | |
+BUILD_INCLUDED_LIBINTL = @BUILD_INCLUDED_LIBINTL@ | |
+CATALOGS = @CATALOGS@ | |
+CATOBJEXT = @CATOBJEXT@ | |
+CC = @CC@ | |
+DATADIRNAME = @DATADIRNAME@ | |
+GENCAT = @GENCAT@ | |
+GLIBC21 = @GLIBC21@ | |
+GLIB_CFLAGS = @GLIB_CFLAGS@ | |
+GLIB_CONFIG = @GLIB_CONFIG@ | |
+GLIB_LIBS = @GLIB_LIBS@ | |
+GMOFILES = @GMOFILES@ | |
+GMSGFMT = @GMSGFMT@ | |
+GTK_CFLAGS = @GTK_CFLAGS@ | |
+GTK_CONFIG = @GTK_CONFIG@ | |
+GTK_LIBS = @GTK_LIBS@ | |
+INSTOBJEXT = @INSTOBJEXT@ | |
+INTLBISON = @INTLBISON@ | |
+INTLLIBS = @INTLLIBS@ | |
+INTLOBJS = @INTLOBJS@ | |
+INTL_LIBTOOL_SUFFIX_PREFIX = @INTL_LIBTOOL_SUFFIX_PREFIX@ | |
+LIBICONV = @LIBICONV@ | |
+MAKEINFO = @MAKEINFO@ | |
+MKINSTALLDIRS = @MKINSTALLDIRS@ | |
+MSGFMT = @MSGFMT@ | |
+PACKAGE = @PACKAGE@ | |
+POFILES = @POFILES@ | |
+POSUB = @POSUB@ | |
+RANLIB = @RANLIB@ | |
+USE_INCLUDED_LIBINTL = @USE_INCLUDED_LIBINTL@ | |
+USE_NLS = @USE_NLS@ | |
+VERSION = @VERSION@ | |
+WNDRES = @WNDRES@ | |
+localedir = @localedir@ | |
+ | |
+noinst_LIBRARIES = libcursesport.a | |
+libcursesport_a_SOURCES = cursesport.c cursesport.h | |
+libcursesport_a_DEPENDENCIES = @INTLLIBS@ | |
+INCLUDES = -I../../intl -I${srcdir} -I${srcdir}/.. -I../.. | |
+LDADD = @INTLLIBS@ | |
+DEFS = @DEFS@ -DLOCALEDIR=\"${localedir}\" | |
+mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs | |
+CONFIG_HEADER = ../../config.h | |
+CONFIG_CLEAN_FILES = | |
+LIBRARIES = $(noinst_LIBRARIES) | |
+ | |
+CPPFLAGS = @CPPFLAGS@ | |
+LDFLAGS = @LDFLAGS@ | |
+LIBS = @LIBS@ | |
+libcursesport_a_LIBADD = | |
+libcursesport_a_OBJECTS = cursesport.o | |
+AR = ar | |
+CFLAGS = @CFLAGS@ | |
+COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(… | |
+CCLD = $(CC) | |
+LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ | |
+DIST_COMMON = Makefile.am Makefile.in | |
+ | |
+ | |
+DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) | |
+ | |
+TAR = gtar | |
+GZIP_ENV = --best | |
+DEP_FILES = .deps/cursesport.P | |
+SOURCES = $(libcursesport_a_SOURCES) | |
+OBJECTS = $(libcursesport_a_OBJECTS) | |
+ | |
+all: all-redirect | |
+.SUFFIXES: | |
+.SUFFIXES: .S .c .o .s | |
+$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) | |
+ cd $(top_srcdir) && $(AUTOMAKE) --gnu src/cursesport/Makefile | |
+ | |
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(BUILT_SOURCES) | |
+ cd $(top_builddir) \ | |
+ && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status | |
+ | |
+ | |
+mostlyclean-noinstLIBRARIES: | |
+ | |
+clean-noinstLIBRARIES: | |
+ -test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES) | |
+ | |
+distclean-noinstLIBRARIES: | |
+ | |
+maintainer-clean-noinstLIBRARIES: | |
+ | |
+.s.o: | |
+ $(COMPILE) -c $< | |
+ | |
+.S.o: | |
+ $(COMPILE) -c $< | |
+ | |
+mostlyclean-compile: | |
+ -rm -f *.o core *.core | |
+ | |
+clean-compile: | |
+ | |
+distclean-compile: | |
+ -rm -f *.tab.c | |
+ | |
+maintainer-clean-compile: | |
+ | |
+libcursesport.a: $(libcursesport_a_OBJECTS) $(libcursesport_a_DEPENDENCIES) | |
+ -rm -f libcursesport.a | |
+ $(AR) cru libcursesport.a $(libcursesport_a_OBJECTS) $(libcursesport_a… | |
+ $(RANLIB) libcursesport.a | |
+ | |
+tags: TAGS | |
+ | |
+ID: $(HEADERS) $(SOURCES) $(LISP) | |
+ list='$(SOURCES) $(HEADERS)'; \ | |
+ unique=`for i in $$list; do echo $$i; done | \ | |
+ awk ' { files[$$0] = 1; } \ | |
+ END { for (i in files) print i; }'`; \ | |
+ here=`pwd` && cd $(srcdir) \ | |
+ && mkid -f$$here/ID $$unique $(LISP) | |
+ | |
+TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP) | |
+ tags=; \ | |
+ here=`pwd`; \ | |
+ list='$(SOURCES) $(HEADERS)'; \ | |
+ unique=`for i in $$list; do echo $$i; done | \ | |
+ awk ' { files[$$0] = 1; } \ | |
+ END { for (i in files) print i; }'`; \ | |
+ test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \ | |
+ || (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o … | |
+ | |
+mostlyclean-tags: | |
+ | |
+clean-tags: | |
+ | |
+distclean-tags: | |
+ -rm -f TAGS ID | |
+ | |
+maintainer-clean-tags: | |
+ | |
+distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir) | |
+ | |
+subdir = src/cursesport | |
+ | |
+distdir: $(DISTFILES) | |
+ here=`cd $(top_builddir) && pwd`; \ | |
+ top_distdir=`cd $(top_distdir) && pwd`; \ | |
+ distdir=`cd $(distdir) && pwd`; \ | |
+ cd $(top_srcdir) \ | |
+ && $(AUTOMAKE) --include-deps --build-dir=$$here --srcdir-name=$(top… | |
+ @for file in $(DISTFILES); do \ | |
+ d=$(srcdir); \ | |
+ if test -d $$d/$$file; then \ | |
+ cp -pr $$d/$$file $(distdir)/$$file; \ | |
+ else \ | |
+ test -f $(distdir)/$$file \ | |
+ || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ | |
+ || cp -p $$d/$$file $(distdir)/$$file || :; \ | |
+ fi; \ | |
+ done | |
+ | |
+DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :) | |
+ | |
+-include $(DEP_FILES) | |
+ | |
+mostlyclean-depend: | |
+ | |
+clean-depend: | |
+ | |
+distclean-depend: | |
+ -rm -rf .deps | |
+ | |
+maintainer-clean-depend: | |
+ | |
+%.o: %.c | |
+ @echo '$(COMPILE) -c $<'; \ | |
+ $(COMPILE) -Wp,-MD,.deps/$(*F).pp -c $< | |
+ @-cp .deps/$(*F).pp .deps/$(*F).P; \ | |
+ tr ' ' '\012' < .deps/$(*F).pp \ | |
+ | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \ | |
+ >> .deps/$(*F).P; \ | |
+ rm .deps/$(*F).pp | |
+ | |
+%.lo: %.c | |
+ @echo '$(LTCOMPILE) -c $<'; \ | |
+ $(LTCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $< | |
+ @-sed -e 's/^\([^:]*\)\.o[ ]*:/\1.lo \1.o :/' \ | |
+ < .deps/$(*F).pp > .deps/$(*F).P; \ | |
+ tr ' ' '\012' < .deps/$(*F).pp \ | |
+ | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \ | |
+ >> .deps/$(*F).P; \ | |
+ rm -f .deps/$(*F).pp | |
+info-am: | |
+info: info-am | |
+dvi-am: | |
+dvi: dvi-am | |
+check-am: all-am | |
+check: check-am | |
+installcheck-am: | |
+installcheck: installcheck-am | |
+install-exec-am: | |
+install-exec: install-exec-am | |
+ | |
+install-data-am: | |
+install-data: install-data-am | |
+ | |
+install-am: all-am | |
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am | |
+install: install-am | |
+uninstall-am: | |
+uninstall: uninstall-am | |
+all-am: Makefile $(LIBRARIES) | |
+all-redirect: all-am | |
+install-strip: | |
+ $(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install | |
+installdirs: | |
+ | |
+ | |
+mostlyclean-generic: | |
+ | |
+clean-generic: | |
+ | |
+distclean-generic: | |
+ -rm -f Makefile $(CONFIG_CLEAN_FILES) | |
+ -rm -f config.cache config.log stamp-h stamp-h[0-9]* | |
+ | |
+maintainer-clean-generic: | |
+mostlyclean-am: mostlyclean-noinstLIBRARIES mostlyclean-compile \ | |
+ mostlyclean-tags mostlyclean-depend mostlyclean-generic | |
+ | |
+mostlyclean: mostlyclean-am | |
+ | |
+clean-am: clean-noinstLIBRARIES clean-compile clean-tags clean-depend \ | |
+ clean-generic mostlyclean-am | |
+ | |
+clean: clean-am | |
+ | |
+distclean-am: distclean-noinstLIBRARIES distclean-compile \ | |
+ distclean-tags distclean-depend distclean-generic \ | |
+ clean-am | |
+ | |
+distclean: distclean-am | |
+ | |
+maintainer-clean-am: maintainer-clean-noinstLIBRARIES \ | |
+ maintainer-clean-compile maintainer-clean-tags \ | |
+ maintainer-clean-depend maintainer-clean-generic \ | |
+ distclean-am | |
+ @echo "This command is intended for maintainers to use;" | |
+ @echo "it deletes files that may require special tools to rebuild." | |
+ | |
+maintainer-clean: maintainer-clean-am | |
+ | |
+.PHONY: mostlyclean-noinstLIBRARIES distclean-noinstLIBRARIES \ | |
+clean-noinstLIBRARIES maintainer-clean-noinstLIBRARIES \ | |
+mostlyclean-compile distclean-compile clean-compile \ | |
+maintainer-clean-compile tags mostlyclean-tags distclean-tags \ | |
+clean-tags maintainer-clean-tags distdir mostlyclean-depend \ | |
+distclean-depend clean-depend maintainer-clean-depend info-am info \ | |
+dvi-am dvi check check-am installcheck-am installcheck install-exec-am \ | |
+install-exec install-data-am install-data install-am install \ | |
+uninstall-am uninstall all-redirect all-am all installdirs \ | |
+mostlyclean-generic distclean-generic clean-generic \ | |
+maintainer-clean-generic clean mostlyclean distclean maintainer-clean | |
+ | |
+ | |
+# Tell versions [3.59,3.63) of GNU make to not export all variables. | |
+# Otherwise a system limit (for SysV at least) may be exceeded. | |
+.NOEXPORT: | |
diff --git a/src/cursesport/cursesport.c b/src/cursesport/cursesport.c | |
t@@ -0,0 +1,263 @@ | |
+/************************************************************************ | |
+ * cursesport.c Portability functions to enable curses applications * | |
+ * to be built on Win32 systems * | |
+ * Copyright (C) 1998-2002 Ben Webb * | |
+ * Email: [email protected] * | |
+ * WWW: http://dopewars.sourceforge.net/ * | |
+ * * | |
+ * This program 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 2 * | |
+ * of the License, or (at your option) any later version. * | |
+ * * | |
+ * This program 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 this program; if not, write to the Free Software * | |
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * | |
+ * MA 02111-1307, USA. * | |
+ ************************************************************************/ | |
+ | |
+#ifdef HAVE_CONFIG_H | |
+#include <config.h> | |
+#endif | |
+ | |
+#include "cursesport.h" | |
+ | |
+#ifdef CYGWIN /* Code for native Win32 build under Cygwin */ | |
+ | |
+int COLS, LINES; | |
+ | |
+static int Width, Depth; | |
+static CHAR_INFO RealScreen[25][80], VirtualScreen[25][80]; | |
+static HANDLE hOut, hIn; | |
+static WORD CurAttr = 0; | |
+static int CurX, CurY; | |
+static WORD Attr[10]; | |
+ | |
+void refresh(void) | |
+{ | |
+ int y; | |
+ COORD size, offset; | |
+ SMALL_RECT screenpos; | |
+ | |
+ for (y = 0; y < Depth; y++) { | |
+ if (memcmp(&RealScreen[y][0], &VirtualScreen[y][0], | |
+ sizeof(CHAR_INFO) * Width) != 0) { | |
+ memcpy(&RealScreen[y][0], &VirtualScreen[y][0], | |
+ Width * sizeof(CHAR_INFO)); | |
+ size.X = Width; | |
+ size.Y = 1; | |
+ offset.X = offset.Y = 0; | |
+ screenpos.Left = 0; | |
+ screenpos.Top = y; | |
+ screenpos.Right = Width - 1; | |
+ screenpos.Bottom = y; | |
+ WriteConsoleOutput(hOut, &VirtualScreen[y][0], size, | |
+ offset, &screenpos); | |
+ } | |
+ } | |
+} | |
+ | |
+static HANDLE WINAPI GetConHandle(TCHAR *pszName) | |
+{ | |
+ SECURITY_ATTRIBUTES sa; | |
+ | |
+ sa.nLength = sizeof(sa); | |
+ sa.lpSecurityDescriptor = NULL; | |
+ sa.bInheritHandle = TRUE; | |
+ return CreateFile(pszName, GENERIC_READ | GENERIC_WRITE, | |
+ FILE_SHARE_READ | FILE_SHARE_WRITE, | |
+ &sa, OPEN_EXISTING, (DWORD)0, (HANDLE)0); | |
+} | |
+ | |
+SCREEN *newterm(void *a, void *b, void *c) | |
+{ | |
+ COORD coord; | |
+ int i; | |
+ | |
+ coord.X = 80; | |
+ coord.Y = 25; | |
+ Width = COLS = 80; | |
+ Depth = LINES = 25; | |
+ CurAttr = 1 << 8; | |
+ CurX = 0; | |
+ CurY = 0; | |
+ for (i = 0; i < 10; i++) | |
+ Attr[i] = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN; | |
+ hOut = GetConHandle("CONOUT$"); | |
+ hIn = GetConHandle("CONIN$"); | |
+ SetConsoleMode(hIn, 0); | |
+ return NULL; | |
+} | |
+ | |
+void start_color(void) | |
+{ | |
+} | |
+ | |
+void init_pair(int index, WORD fg, WORD bg) | |
+{ | |
+ if (index >= 0 && index < 10) { | |
+ Attr[index] = 0; | |
+ switch (fg) { | |
+ case COLOR_MAGENTA: | |
+ Attr[index] |= (FOREGROUND_RED + FOREGROUND_BLUE); | |
+ break; | |
+ case COLOR_BLUE: | |
+ Attr[index] |= FOREGROUND_BLUE; | |
+ break; | |
+ case COLOR_RED: | |
+ Attr[index] |= FOREGROUND_RED; | |
+ break; | |
+ case COLOR_WHITE: | |
+ Attr[index] |= (FOREGROUND_RED + FOREGROUND_BLUE + FOREGROUND_GREEN); | |
+ break; | |
+ } | |
+ switch (bg) { | |
+ case COLOR_MAGENTA: | |
+ Attr[index] |= (BACKGROUND_RED + BACKGROUND_BLUE); | |
+ break; | |
+ case COLOR_BLUE: | |
+ Attr[index] |= BACKGROUND_BLUE; | |
+ break; | |
+ case COLOR_RED: | |
+ Attr[index] |= BACKGROUND_RED; | |
+ break; | |
+ case COLOR_WHITE: | |
+ Attr[index] |= (BACKGROUND_RED + BACKGROUND_BLUE + BACKGROUND_GREEN); | |
+ break; | |
+ } | |
+ } | |
+} | |
+ | |
+void cbreak(void) | |
+{ | |
+} | |
+ | |
+void noecho(void) | |
+{ | |
+} | |
+ | |
+void nodelay(void *a, char b) | |
+{ | |
+} | |
+ | |
+void keypad(void *a, char b) | |
+{ | |
+} | |
+ | |
+void curs_set(BOOL visible) | |
+{ | |
+ CONSOLE_CURSOR_INFO ConCurInfo; | |
+ | |
+ move(CurY, CurX); | |
+ ConCurInfo.dwSize = 10; | |
+ ConCurInfo.bVisible = visible; | |
+ SetConsoleCursorInfo(hOut, &ConCurInfo); | |
+} | |
+ | |
+void endwin(void) | |
+{ | |
+ CurAttr = 0; | |
+ refresh(); | |
+ curs_set(1); | |
+} | |
+ | |
+void move(int y, int x) | |
+{ | |
+ COORD coord; | |
+ | |
+ CurX = x; | |
+ CurY = y; | |
+ coord.X = x; | |
+ coord.Y = y; | |
+ SetConsoleCursorPosition(hOut, coord); | |
+} | |
+ | |
+void attrset(WORD newAttr) | |
+{ | |
+ CurAttr = newAttr; | |
+} | |
+ | |
+void addstr(char *str) | |
+{ | |
+ int i; | |
+ | |
+ for (i = 0; i < strlen(str); i++) | |
+ addch(str[i]); | |
+ move(CurY, CurX); | |
+} | |
+ | |
+void addch(int ch) | |
+{ | |
+ int attr; | |
+ | |
+ VirtualScreen[CurY][CurX].Char.AsciiChar = ch % 256; | |
+ attr = ch >> 8; | |
+ if (attr > 0) | |
+ VirtualScreen[CurY][CurX].Attributes = Attr[attr]; | |
+ else | |
+ VirtualScreen[CurY][CurX].Attributes = Attr[CurAttr >> 8]; | |
+ if (++CurX >= Width) { | |
+ CurX = 0; | |
+ if (++CurY >= Depth) | |
+ CurY = 0; | |
+ } | |
+} | |
+ | |
+void mvaddstr(int y, int x, char *str) | |
+{ | |
+ move(y, x); | |
+ addstr(str); | |
+} | |
+ | |
+void mvaddch(int y, int x, int ch) | |
+{ | |
+ move(y, x); | |
+ addch(ch); | |
+} | |
+ | |
+/* | |
+ * Waits for the user to press a key. | |
+ */ | |
+int bgetch(void) | |
+{ | |
+ DWORD NumRead; | |
+ char Buffer[10]; | |
+ | |
+ refresh(); | |
+ ReadConsole(hIn, Buffer, 1, &NumRead, NULL); | |
+ return (int)(Buffer[0]); | |
+} | |
+ | |
+void standout(void) | |
+{ | |
+} | |
+ | |
+void standend(void) | |
+{ | |
+} | |
+ | |
+#else /* Code for Unix build */ | |
+ | |
+/* | |
+ * Calls the curses getch() function; if the key pressed is Ctrl-L | |
+ * then automatically clears and redraws the screen, otherwise | |
+ * passes the key back to the calling routine. | |
+ */ | |
+int bgetch() | |
+{ | |
+ int c; | |
+ | |
+ c = getch(); | |
+ while (c == '\f') { | |
+ wrefresh(curscr); | |
+ c = getch(); | |
+ } | |
+ return c; | |
+} | |
+ | |
+#endif /* CYGWIN */ | |
diff --git a/src/cursesport/cursesport.h b/src/cursesport/cursesport.h | |
t@@ -0,0 +1,106 @@ | |
+/************************************************************************ | |
+ * cursesport.h Portability functions to enable curses applications * | |
+ * to be built on Win32 systems * | |
+ * Copyright (C) 1998-2002 Ben Webb * | |
+ * Email: [email protected] * | |
+ * WWW: http://dopewars.sourceforge.net/ * | |
+ * * | |
+ * This program 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 2 * | |
+ * of the License, or (at your option) any later version. * | |
+ * * | |
+ * This program 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 this program; if not, write to the Free Software * | |
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * | |
+ * MA 02111-1307, USA. * | |
+ ************************************************************************/ | |
+ | |
+#ifndef __CURSESPORT_H__ | |
+#define __CURSESPORT_H__ | |
+ | |
+#ifdef HAVE_CONFIG_H | |
+#include <config.h> | |
+#endif | |
+ | |
+#ifdef CYGWIN /* Definitions for native Win32 build */ | |
+#include <windows.h> | |
+#include <string.h> | |
+ | |
+#include <stdio.h> | |
+#include <conio.h> | |
+ | |
+extern int COLS, LINES; | |
+ | |
+#define COLOR_MAGENTA 1 | |
+#define COLOR_BLACK 2 | |
+#define COLOR_WHITE 3 | |
+#define COLOR_BLUE 4 | |
+#define COLOR_RED 5 | |
+ | |
+#define COLOR_PAIR(i) ((i) << 8) | |
+ | |
+#define ACS_VLINE 179 | |
+#define ACS_ULCORNER 218 | |
+#define ACS_HLINE 196 | |
+#define ACS_URCORNER 191 | |
+#define ACS_TTEE 194 | |
+#define ACS_LLCORNER 192 | |
+#define ACS_LRCORNER 217 | |
+#define ACS_BTEE 193 | |
+#define ACS_LTEE 195 | |
+#define ACS_RTEE 180 | |
+ | |
+typedef int SCREEN; | |
+ | |
+#define stdscr 0 | |
+#define curscr 0 | |
+#define KEY_ENTER 13 | |
+#define KEY_BACKSPACE 8 | |
+#define A_BOLD 0 | |
+ | |
+SCREEN *newterm(void *, void *, void *); | |
+void refresh(void); | |
+#define wrefresh(win) refresh() | |
+void start_color(void); | |
+void init_pair(int index, WORD fg, WORD bg); | |
+void cbreak(void); | |
+void noecho(void); | |
+void nodelay(void *, char); | |
+void keypad(void *, char); | |
+void curs_set(BOOL visible); | |
+void endwin(void); | |
+void move(int y, int x); | |
+void attrset(WORD newAttr); | |
+void addstr(char *str); | |
+void addch(int ch); | |
+void mvaddstr(int x, int y, char *str); | |
+void mvaddch(int x, int y, int ch); | |
+ | |
+#define erase() clear_screen() | |
+ | |
+void standout(void); | |
+void standend(void); | |
+void endwin(void); | |
+ | |
+#else /* Definitions for Unix build */ | |
+ | |
+/* Include a suitable curses-type library */ | |
+#if HAVE_LIBNCURSES | |
+#include <ncurses.h> | |
+#elif HAVE_LIBCURSES | |
+#include <curses.h> | |
+#elif HAVE_LIBCUR_COLR | |
+#include <curses_colr/curses.h> | |
+#endif | |
+ | |
+#endif /* CYGWIN */ | |
+ | |
+int bgetch(void); | |
+ | |
+#endif /* __CURSESPORT_H__ */ | |
diff --git a/src/dopeos.c b/src/dopeos.c | |
t@@ -1,479 +0,0 @@ | |
-/************************************************************************ | |
- * dopeos.c dopewars - operating-system-specific functions * | |
- * Copyright (C) 1998-2002 Ben Webb * | |
- * Email: [email protected] * | |
- * WWW: http://dopewars.sourceforge.net/ * | |
- * * | |
- * This program 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 2 * | |
- * of the License, or (at your option) any later version. * | |
- * * | |
- * This program 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 this program; if not, write to the Free Software * | |
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * | |
- * MA 02111-1307, USA. * | |
- ************************************************************************/ | |
- | |
-#ifdef HAVE_CONFIG_H | |
-#include <config.h> | |
-#endif | |
- | |
-#include "dopeos.h" | |
-#include "dopewars.h" | |
- | |
-#ifdef CYGWIN /* Code for native Win32 build under Cygwin */ | |
- | |
-#include <conio.h> | |
- | |
-CHAR_INFO RealScreen[25][80], VirtualScreen[25][80]; | |
-HANDLE hOut, hIn; | |
- | |
-void refresh() | |
-{ | |
- int y; | |
- COORD size, offset; | |
- SMALL_RECT screenpos; | |
- | |
- for (y = 0; y < Depth; y++) { | |
- if (memcmp(&RealScreen[y][0], &VirtualScreen[y][0], | |
- sizeof(CHAR_INFO) * Width) != 0) { | |
- memcpy(&RealScreen[y][0], &VirtualScreen[y][0], | |
- Width * sizeof(CHAR_INFO)); | |
- size.X = Width; | |
- size.Y = 1; | |
- offset.X = offset.Y = 0; | |
- screenpos.Left = 0; | |
- screenpos.Top = y; | |
- screenpos.Right = Width - 1; | |
- screenpos.Bottom = y; | |
- WriteConsoleOutput(hOut, &VirtualScreen[y][0], size, | |
- offset, &screenpos); | |
- } | |
- } | |
-} | |
- | |
-HANDLE WINAPI GetConHandle(TCHAR *pszName) | |
-{ | |
- SECURITY_ATTRIBUTES sa; | |
- | |
- sa.nLength = sizeof(sa); | |
- sa.lpSecurityDescriptor = NULL; | |
- sa.bInheritHandle = TRUE; | |
- return CreateFile(pszName, GENERIC_READ | GENERIC_WRITE, | |
- FILE_SHARE_READ | FILE_SHARE_WRITE, | |
- &sa, OPEN_EXISTING, (DWORD)0, (HANDLE)0); | |
-} | |
- | |
-WORD CurAttr = 0, TextAttr = 2 << 8; | |
-WORD PromptAttr = 1 << 8, TitleAttr = 4 << 8; | |
-WORD LocationAttr = 3 << 8, StatsAttr = 5 << 8, DebtAttr = 6 << 8; | |
-int Width, Depth, CurX, CurY; | |
-char *optarg; | |
-WORD Attr[10]; | |
-HWND hwndMain; | |
- | |
-SCREEN *newterm(void *a, void *b, void *c) | |
-{ | |
- COORD coord; | |
- int i; | |
- | |
- coord.X = 80; | |
- coord.Y = 25; | |
- Width = 80; | |
- Depth = 25; | |
- CurAttr = TextAttr; | |
- CurX = 0; | |
- CurY = 0; | |
- for (i = 0; i < 10; i++) | |
- Attr[i] = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN; | |
- hOut = GetConHandle("CONOUT$"); | |
- hIn = GetConHandle("CONIN$"); | |
- SetConsoleMode(hIn, 0); | |
- return NULL; | |
-} | |
- | |
-void start_color() | |
-{ | |
-} | |
- | |
-void init_pair(int index, WORD fg, WORD bg) | |
-{ | |
- if (index >= 0 && index < 10) { | |
- Attr[index] = 0; | |
- switch (fg) { | |
- case COLOR_MAGENTA: | |
- Attr[index] |= (FOREGROUND_RED + FOREGROUND_BLUE); | |
- break; | |
- case COLOR_BLUE: | |
- Attr[index] |= FOREGROUND_BLUE; | |
- break; | |
- case COLOR_RED: | |
- Attr[index] |= FOREGROUND_RED; | |
- break; | |
- case COLOR_WHITE: | |
- Attr[index] |= (FOREGROUND_RED + FOREGROUND_BLUE + FOREGROUND_GREEN); | |
- break; | |
- } | |
- switch (bg) { | |
- case COLOR_MAGENTA: | |
- Attr[index] |= (BACKGROUND_RED + BACKGROUND_BLUE); | |
- break; | |
- case COLOR_BLUE: | |
- Attr[index] |= BACKGROUND_BLUE; | |
- break; | |
- case COLOR_RED: | |
- Attr[index] |= BACKGROUND_RED; | |
- break; | |
- case COLOR_WHITE: | |
- Attr[index] |= (BACKGROUND_RED + BACKGROUND_BLUE + BACKGROUND_GREEN); | |
- break; | |
- } | |
- } | |
-} | |
- | |
-void cbreak() | |
-{ | |
-} | |
- | |
-void noecho() | |
-{ | |
-} | |
- | |
-void nodelay(void *a, char b) | |
-{ | |
-} | |
- | |
-void keypad(void *a, char b) | |
-{ | |
-} | |
- | |
-void curs_set(BOOL visible) | |
-{ | |
- CONSOLE_CURSOR_INFO ConCurInfo; | |
- | |
- move(CurY, CurX); | |
- ConCurInfo.dwSize = 10; | |
- ConCurInfo.bVisible = visible; | |
- SetConsoleCursorInfo(hOut, &ConCurInfo); | |
-} | |
- | |
-void endwin() | |
-{ | |
- CurAttr = 0; | |
- refresh(); | |
- curs_set(1); | |
-} | |
- | |
-void move(int y, int x) | |
-{ | |
- COORD coord; | |
- | |
- CurX = x; | |
- CurY = y; | |
- coord.X = x; | |
- coord.Y = y; | |
- SetConsoleCursorPosition(hOut, coord); | |
-} | |
- | |
-void attrset(WORD newAttr) | |
-{ | |
- CurAttr = newAttr; | |
-} | |
- | |
-void addstr(char *str) | |
-{ | |
- int i; | |
- | |
- for (i = 0; i < strlen(str); i++) | |
- addch(str[i]); | |
- move(CurY, CurX); | |
-} | |
- | |
-void addch(int ch) | |
-{ | |
- int attr; | |
- | |
- VirtualScreen[CurY][CurX].Char.AsciiChar = ch % 256; | |
- attr = ch >> 8; | |
- if (attr > 0) | |
- VirtualScreen[CurY][CurX].Attributes = Attr[attr]; | |
- else | |
- VirtualScreen[CurY][CurX].Attributes = Attr[CurAttr >> 8]; | |
- if (++CurX >= Width) { | |
- CurX = 0; | |
- if (++CurY >= Depth) | |
- CurY = 0; | |
- } | |
-} | |
- | |
-void mvaddstr(int y, int x, char *str) | |
-{ | |
- move(y, x); | |
- addstr(str); | |
-} | |
- | |
-void mvaddch(int y, int x, int ch) | |
-{ | |
- move(y, x); | |
- addch(ch); | |
-} | |
- | |
-/* | |
- * Waits for the user to press a key. | |
- */ | |
-int bgetch() | |
-{ | |
- DWORD NumRead; | |
- char Buffer[10]; | |
- | |
- refresh(); | |
- ReadConsole(hIn, Buffer, 1, &NumRead, NULL); | |
- return (int)(Buffer[0]); | |
-} | |
- | |
-char *index(const char *str, int ch) | |
-{ | |
- int i; | |
- | |
- for (i = 0; i < strlen(str); i++) { | |
- if (str[i] == ch) | |
- return str + i; | |
- } | |
- return NULL; | |
-} | |
- | |
-static int apos = 0; | |
- | |
-int getopt(int argc, char *const argv[], const char *str) | |
-{ | |
- int i, c; | |
- char *pt; | |
- | |
- while (apos < argc && argv[apos]) { | |
- if (argv[apos][0] != '-') { | |
- apos++; | |
- return 0; | |
- } | |
- for (i = 1; i < strlen(argv[apos]); i++) { | |
- c = argv[apos][i]; | |
- pt = index(str, c); | |
- if (pt) { | |
- argv[apos][i] = '-'; | |
- if (*(pt + 1) == ':') { | |
- if (apos + 1 < argc && i == strlen(argv[apos]) - 1) { | |
- apos++; | |
- optarg = argv[apos]; | |
- apos++; | |
- } else | |
- return 0; | |
- } | |
- return c; | |
- } | |
- } | |
- apos++; | |
- } | |
- return EOF; | |
-} | |
- | |
-void sigemptyset(int *mask) | |
-{ | |
-} | |
- | |
-void sigaddset(int *mask, int sig) | |
-{ | |
-} | |
- | |
-int sigaction(int sig, struct sigaction *sact, char *pt) | |
-{ | |
- return 0; | |
-} | |
- | |
-void sigprocmask(int flag, int *mask, char *pt) | |
-{ | |
-} | |
- | |
-void standout() | |
-{ | |
-} | |
- | |
-void standend() | |
-{ | |
-} | |
- | |
-gboolean IsKeyPressed() | |
-{ | |
- INPUT_RECORD ConsoleIn; | |
- DWORD NumConsoleIn; | |
- | |
- while (PeekConsoleInput(hIn, &ConsoleIn, 1, &NumConsoleIn) | |
- && NumConsoleIn == 1) { | |
- if (ConsoleIn.EventType == KEY_EVENT | |
- && ConsoleIn.Event.KeyEvent.bKeyDown) { | |
- return TRUE; | |
- } else { | |
- ReadConsoleInput(hIn, &ConsoleIn, 1, &NumConsoleIn); | |
- } | |
- } | |
- return FALSE; | |
-} | |
- | |
-int bselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, | |
- struct timeval *tm) | |
-{ | |
- int retval; | |
- struct timeval tv, *tp; | |
- fd_set localread, localexcept; | |
- char CheckKbHit = 0, KeyRead; | |
- | |
- if (nfds == 0 && tm) { | |
- Sleep(tm->tv_sec * 1000 + tm->tv_usec / 1000); | |
- return 0; | |
- } | |
- if (FD_ISSET(0, readfds)) { | |
- if (nfds == 1) | |
- return 1; | |
- tp = &tv; | |
- CheckKbHit = 1; | |
- FD_CLR(0, readfds); | |
- } else | |
- tp = tm; | |
- KeyRead = 0; | |
- while (1) { | |
- tv.tv_sec = 0; | |
- tv.tv_usec = 250000; | |
- | |
- if (readfds) | |
- memcpy(&localread, readfds, sizeof(fd_set)); | |
- if (exceptfds) | |
- memcpy(&localexcept, exceptfds, sizeof(fd_set)); | |
- if (CheckKbHit && IsKeyPressed()) | |
- tv.tv_usec = 0; | |
- retval = select(nfds, readfds, writefds, exceptfds, tp); | |
- if (retval == SOCKET_ERROR) | |
- return retval; | |
- if (CheckKbHit && IsKeyPressed()) { | |
- retval++; | |
- FD_SET(0, readfds); | |
- } | |
- if (retval > 0 || !CheckKbHit) | |
- break; | |
- if (CheckKbHit && tm) { | |
- if (tm->tv_usec >= 250000) | |
- tm->tv_usec -= 250000; | |
- else if (tm->tv_sec) { | |
- tm->tv_usec += 750000; | |
- tm->tv_sec--; | |
- } else | |
- break; | |
- } | |
- if (readfds) | |
- memcpy(readfds, &localread, sizeof(fd_set)); | |
- if (exceptfds) | |
- memcpy(exceptfds, &localexcept, sizeof(fd_set)); | |
- } | |
- return retval; | |
-} | |
- | |
-/* We don't do locking under Win32 right now */ | |
-int ReadLock(FILE * fp) | |
-{ | |
- return 0; | |
-} | |
- | |
-int WriteLock(FILE * fp) | |
-{ | |
- return 0; | |
-} | |
- | |
-void ReleaseLock(FILE * fp) | |
-{ | |
-} | |
- | |
-#else /* Code for Unix build */ | |
- | |
-#ifdef HAVE_UNISTD_H | |
-#include <unistd.h> | |
-#endif | |
- | |
-#ifdef HAVE_STDLIB_H | |
-#include <stdlib.h> | |
-#endif | |
- | |
-#ifdef HAVE_FCNTL_H | |
-#include <fcntl.h> | |
-#endif | |
- | |
-int Width, Depth; | |
- | |
-#ifdef CURSES_CLIENT | |
-/* | |
- * Calls the curses getch() function; if the key pressed is Ctrl-L | |
- * then automatically clears and redraws the screen, otherwise | |
- * passes the key back to the calling routine. | |
- */ | |
-int bgetch() | |
-{ | |
- int c; | |
- | |
- c = getch(); | |
- while (c == '\f') { | |
- wrefresh(curscr); | |
- c = getch(); | |
- } | |
- return c; | |
-} | |
-#endif | |
- | |
-static int DoLock(FILE * fp, int l_type) | |
-{ | |
- struct flock lk; | |
- | |
- lk.l_type = l_type; | |
- lk.l_whence = lk.l_start = lk.l_len = 0; | |
- lk.l_pid = 0; | |
- | |
- while (1) { | |
- if (fcntl(fileno(fp), F_SETLKW, &lk) == 0) | |
- return 0; | |
- else if (errno != EINTR) | |
- return 1; | |
- } | |
- return 1; | |
-} | |
- | |
-int ReadLock(FILE * fp) | |
-{ | |
- return DoLock(fp, F_RDLCK); | |
-} | |
- | |
-int WriteLock(FILE * fp) | |
-{ | |
- return DoLock(fp, F_WRLCK); | |
-} | |
- | |
-void ReleaseLock(FILE * fp) | |
-{ | |
- DoLock(fp, F_UNLCK); | |
-} | |
- | |
-#endif /* CYGWIN */ | |
- | |
-/* | |
- * On systems with select, sleep for "microsec" microseconds. | |
- */ | |
-void MicroSleep(int microsec) | |
-{ | |
-#if HAVE_SELECT | |
- struct timeval tv; | |
- | |
- tv.tv_sec = 0; | |
- tv.tv_usec = microsec; | |
- bselect(0, NULL, NULL, NULL, &tv); | |
-#endif | |
-} | |
diff --git a/src/dopeos.h b/src/dopeos.h | |
t@@ -1,172 +0,0 @@ | |
-/************************************************************************ | |
- * dopeos.h dopewars - operating system-specific function * | |
- * definitions * | |
- * Copyright (C) 1998-2002 Ben Webb * | |
- * Email: [email protected] * | |
- * WWW: http://dopewars.sourceforge.net/ * | |
- * * | |
- * This program 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 2 * | |
- * of the License, or (at your option) any later version. * | |
- * * | |
- * This program 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 this program; if not, write to the Free Software * | |
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * | |
- * MA 02111-1307, USA. * | |
- ************************************************************************/ | |
- | |
-#ifndef __DOPEOS_H__ | |
-#define __DOPEOS_H__ | |
- | |
-#ifdef HAVE_CONFIG_H | |
-#include <config.h> | |
-#endif | |
- | |
-#ifdef CYGWIN /* Definitions for native Win32 build */ | |
-#include <windows.h> | |
-#include <string.h> | |
- | |
-#include <stdio.h> | |
- | |
-void refresh(); | |
-HANDLE WINAPI GetConHandle(TCHAR *pszName); | |
-extern WORD TextAttr, PromptAttr, TitleAttr; | |
-extern WORD LocationAttr, StatsAttr, DebtAttr; | |
-extern int Width, Depth; | |
- | |
-#define COLOR_MAGENTA 1 | |
-#define COLOR_BLACK 2 | |
-#define COLOR_WHITE 3 | |
-#define COLOR_BLUE 4 | |
-#define COLOR_RED 5 | |
- | |
-#define SIGWINCH 0 | |
-#define SIGPIPE 0 | |
-#define SIG_BLOCK 0 | |
-#define SIG_UNBLOCK 0 | |
- | |
-struct sigaction { | |
- void *sa_handler; | |
- int sa_flags; | |
- int sa_mask; | |
-}; | |
- | |
-void sigemptyset(int *mask); | |
-void sigaddset(int *mask, int sig); | |
-int sigaction(int sig, struct sigaction *sact, char *pt); | |
-void sigprocmask(int flag, int *mask, char *pt); | |
- | |
-#define COLS Width | |
-#define LINES Depth | |
- | |
-#define ACS_VLINE 179 | |
-#define ACS_ULCORNER 218 | |
-#define ACS_HLINE 196 | |
-#define ACS_URCORNER 191 | |
-#define ACS_TTEE 194 | |
-#define ACS_LLCORNER 192 | |
-#define ACS_LRCORNER 217 | |
-#define ACS_BTEE 193 | |
-#define ACS_LTEE 195 | |
-#define ACS_RTEE 180 | |
- | |
-typedef int SCREEN; | |
- | |
-#define stdscr 0 | |
-#define curscr 0 | |
-#define KEY_ENTER 13 | |
-#define KEY_BACKSPACE 8 | |
-#define A_BOLD 0 | |
- | |
-SCREEN *newterm(void *, void *, void *); | |
-void start_color(); | |
-void init_pair(int index, WORD fg, WORD bg); | |
-void cbreak(); | |
-void noecho(); | |
-void nodelay(void *, char); | |
-void keypad(void *, char); | |
-void curs_set(BOOL visible); | |
-void endwin(); | |
-void move(int y, int x); | |
-void attrset(WORD newAttr); | |
-void addstr(char *str); | |
-void addch(int ch); | |
-void mvaddstr(int x, int y, char *str); | |
-void mvaddch(int x, int y, int ch); | |
-int bgetch(); | |
- | |
-#define erase() clear_screen() | |
-char *index(const char *str, int ch); | |
-int getopt(int argc, char *const argv[], const char *str); | |
-extern char *optarg; | |
- | |
-typedef int ssize_t; | |
-void standout(); | |
-void standend(); | |
-void endwin(); | |
-int bselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfs, | |
- struct timeval *tm); | |
- | |
-#else /* Definitions for Unix build */ | |
- | |
-#include <sys/types.h> | |
- | |
-#include <stdio.h> | |
-#include <errno.h> | |
- | |
-/* Only include sys/wait.h on those systems which support it */ | |
-#if HAVE_SYS_WAIT_H | |
-#include <sys/wait.h> | |
-#endif | |
- | |
-/* Include a suitable curses-type library */ | |
-#if HAVE_LIBNCURSES | |
-#include <ncurses.h> | |
-#elif HAVE_LIBCURSES | |
-#include <curses.h> | |
-#elif HAVE_LIBCUR_COLR | |
-#include <curses_colr/curses.h> | |
-#endif | |
- | |
-extern int Width, Depth; | |
- | |
-#define PromptAttr (COLOR_PAIR(1)) | |
-#define TextAttr (COLOR_PAIR(2)) | |
-#define LocationAttr (COLOR_PAIR(3)|A_BOLD) | |
-#define TitleAttr (COLOR_PAIR(4)) | |
-#define StatsAttr (COLOR_PAIR(5)) | |
-#define DebtAttr (COLOR_PAIR(6)) | |
- | |
-#ifdef CURSES_CLIENT | |
-int bgetch(void); | |
-#else | |
-/* When not using curses, fall back to stdio's getchar() function */ | |
-#define bgetch getchar | |
-#endif | |
- | |
-#define bselect select | |
- | |
-#endif /* CYGWIN */ | |
- | |
-void MicroSleep(int microsec); | |
- | |
-int ReadLock(FILE * fp); | |
-int WriteLock(FILE * fp); | |
-void ReleaseLock(FILE * fp); | |
- | |
-/* Now make definitions if they haven't been done properly */ | |
-#ifndef WEXITSTATUS | |
-#define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8) | |
-#endif | |
- | |
-#ifndef WIFEXITED | |
-#define WIFEXITED(stat_val) (((stat_val) & 255) == 0) | |
-#endif | |
- | |
-#endif /* __DOPEOS_H__ */ | |
diff --git a/src/dopewars.c b/src/dopewars.c | |
t@@ -43,12 +43,12 @@ | |
#include <glib.h> | |
#include <stdarg.h> | |
#include "admin.h" | |
-#include "dopeos.h" | |
#include "message.h" | |
#include "nls.h" | |
#include "serverside.h" | |
#include "tstring.h" | |
#include "AIPlayer.h" | |
+#include "util.h" | |
#include "winmain.h" | |
#ifdef CURSES_CLIENT | |
diff --git a/src/dopewars.h b/src/dopewars.h | |
t@@ -43,9 +43,9 @@ | |
#endif | |
#include <glib.h> | |
-#include "dopeos.h" | |
#include "error.h" | |
#include "network.h" | |
+#include "util.h" | |
/* Make price_t be a long long if the type is supported by the compiler */ | |
#if SIZEOF_LONG_LONG == 0 | |
diff --git a/src/gui_client/gtk_client.c b/src/gui_client/gtk_client.c | |
t@@ -28,13 +28,13 @@ | |
#include <ctype.h> | |
#include <string.h> | |
-#include "dopeos.h" | |
#include "dopewars.h" | |
#include "gtk_client.h" | |
#include "message.h" | |
#include "nls.h" | |
#include "serverside.h" | |
#include "tstring.h" | |
+#include "util.h" | |
#include "gtkport/gtkport.h" | |
#include "dopewars-pill.xpm" | |
#include "optdialog.h" | |
diff --git a/src/message.c b/src/message.c | |
t@@ -36,13 +36,13 @@ | |
#include <string.h> | |
#include <stdlib.h> | |
#include <glib.h> | |
-#include "dopeos.h" | |
#include "dopewars.h" | |
#include "message.h" | |
#include "network.h" | |
#include "nls.h" | |
#include "serverside.h" | |
#include "tstring.h" | |
+#include "util.h" | |
/* Maximum sizes (in bytes) of read and write buffers - connections should | |
* be dropped if either buffer is filled */ | |
diff --git a/src/network.h b/src/network.h | |
t@@ -28,6 +28,9 @@ | |
#endif | |
/* Various includes necessary for select() calls */ | |
+#ifdef CYGWIN | |
+#include <windows.h> | |
+#else | |
#include <sys/types.h> | |
/* Be careful not to include both sys/time.h and time.h on those systems | |
* which don't like it */ | |
t@@ -45,6 +48,7 @@ | |
#ifdef HAVE_UNISTD_H | |
#include <unistd.h> | |
#endif | |
+#endif | |
#include <glib.h> | |
diff --git a/src/serverside.c b/src/serverside.c | |
t@@ -46,13 +46,13 @@ | |
#include <errno.h> | |
#include <stdlib.h> | |
#include <glib.h> | |
-#include "dopeos.h" | |
#include "dopewars.h" | |
#include "message.h" | |
#include "network.h" | |
#include "nls.h" | |
#include "serverside.h" | |
#include "tstring.h" | |
+#include "util.h" | |
#ifdef GUI_SERVER | |
#include "gtkport/gtkport.h" | |
t@@ -965,7 +965,6 @@ Player *HandleNewConnection(void) | |
if ((ClientSock = accept(ListenSock, (struct sockaddr *)&ClientAddr, | |
&cadsize)) == -1) { | |
perror("accept socket"); | |
- bgetch(); | |
exit(1); | |
} | |
dopelog(2, _("got connection from %s"), inet_ntoa(ClientAddr.sin_addr)); | |
t@@ -1157,7 +1156,6 @@ void ServerLoop() | |
continue; | |
} | |
perror("select"); | |
- bgetch(); | |
break; | |
} | |
FirstServer = HandleTimeouts(FirstServer); | |
diff --git a/src/util.c b/src/util.c | |
t@@ -0,0 +1,242 @@ | |
+/************************************************************************ | |
+ * util.c Miscellaneous utility and portability functions * | |
+ * Copyright (C) 1998-2002 Ben Webb * | |
+ * Email: [email protected] * | |
+ * WWW: http://dopewars.sourceforge.net/ * | |
+ * * | |
+ * This program 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 2 * | |
+ * of the License, or (at your option) any later version. * | |
+ * * | |
+ * This program 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 this program; if not, write to the Free Software * | |
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * | |
+ * MA 02111-1307, USA. * | |
+ ************************************************************************/ | |
+ | |
+#ifdef HAVE_CONFIG_H | |
+#include <config.h> | |
+#endif | |
+ | |
+#ifdef HAVE_UNISTD_H | |
+#include <unistd.h> | |
+#endif | |
+ | |
+#ifdef HAVE_STDLIB_H | |
+#include <stdlib.h> | |
+#endif | |
+ | |
+#ifdef HAVE_FCNTL_H | |
+#include <fcntl.h> | |
+#endif | |
+ | |
+#ifdef CYGWIN | |
+#include <conio.h> | |
+#endif | |
+ | |
+#include "util.h" | |
+#include "dopewars.h" | |
+ | |
+#ifndef HAVE_GETOPT | |
+char *optarg; | |
+ | |
+static int apos = 0; | |
+ | |
+int getopt(int argc, char *const argv[], const char *str) | |
+{ | |
+ int i, c; | |
+ char *pt; | |
+ | |
+ while (apos < argc && argv[apos]) { | |
+ if (argv[apos][0] != '-') { | |
+ apos++; | |
+ return 0; | |
+ } | |
+ for (i = 1; i < strlen(argv[apos]); i++) { | |
+ c = argv[apos][i]; | |
+ pt = strchr(str, c); | |
+ if (pt) { | |
+ argv[apos][i] = '-'; | |
+ if (*(pt + 1) == ':') { | |
+ if (apos + 1 < argc && i == strlen(argv[apos]) - 1) { | |
+ apos++; | |
+ optarg = argv[apos]; | |
+ apos++; | |
+ } else | |
+ return 0; | |
+ } | |
+ return c; | |
+ } | |
+ } | |
+ apos++; | |
+ } | |
+ return EOF; | |
+} | |
+#endif /* HAVE_GETOPT */ | |
+ | |
+ | |
+#ifdef CYGWIN /* Code for native Win32 build under Cygwin */ | |
+ | |
+void sigemptyset(int *mask) | |
+{ | |
+} | |
+ | |
+void sigaddset(int *mask, int sig) | |
+{ | |
+} | |
+ | |
+int sigaction(int sig, struct sigaction *sact, char *pt) | |
+{ | |
+ return 0; | |
+} | |
+ | |
+void sigprocmask(int flag, int *mask, char *pt) | |
+{ | |
+} | |
+ | |
+/*static gboolean IsKeyPressed() | |
+{ | |
+ INPUT_RECORD ConsoleIn; | |
+ DWORD NumConsoleIn; | |
+ | |
+ while (PeekConsoleInput(hIn, &ConsoleIn, 1, &NumConsoleIn) | |
+ && NumConsoleIn == 1) { | |
+ if (ConsoleIn.EventType == KEY_EVENT | |
+ && ConsoleIn.Event.KeyEvent.bKeyDown) { | |
+ return TRUE; | |
+ } else { | |
+ ReadConsoleInput(hIn, &ConsoleIn, 1, &NumConsoleIn); | |
+ } | |
+ } | |
+ return FALSE; | |
+}*/ | |
+ | |
+int bselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, | |
+ struct timeval *tm) | |
+{ | |
+ int retval; | |
+ struct timeval tv, *tp; | |
+ fd_set localread, localexcept; | |
+ char CheckKbHit = 0, KeyRead; | |
+ | |
+ if (nfds == 0 && tm) { | |
+ Sleep(tm->tv_sec * 1000 + tm->tv_usec / 1000); | |
+ return 0; | |
+ } | |
+ if (FD_ISSET(0, readfds)) { | |
+ if (nfds == 1) | |
+ return 1; | |
+ tp = &tv; | |
+ CheckKbHit = 1; | |
+ FD_CLR(0, readfds); | |
+ } else | |
+ tp = tm; | |
+ KeyRead = 0; | |
+ while (1) { | |
+ tv.tv_sec = 0; | |
+ tv.tv_usec = 250000; | |
+ | |
+ if (readfds) | |
+ memcpy(&localread, readfds, sizeof(fd_set)); | |
+ if (exceptfds) | |
+ memcpy(&localexcept, exceptfds, sizeof(fd_set)); | |
+ if (CheckKbHit && kbhit()) | |
+ tv.tv_usec = 0; | |
+ retval = select(nfds, readfds, writefds, exceptfds, tp); | |
+ if (retval == SOCKET_ERROR) | |
+ return retval; | |
+ if (CheckKbHit && kbhit()) { | |
+ retval++; | |
+ FD_SET(0, readfds); | |
+ } | |
+ if (retval > 0 || !CheckKbHit) | |
+ break; | |
+ if (CheckKbHit && tm) { | |
+ if (tm->tv_usec >= 250000) | |
+ tm->tv_usec -= 250000; | |
+ else if (tm->tv_sec) { | |
+ tm->tv_usec += 750000; | |
+ tm->tv_sec--; | |
+ } else | |
+ break; | |
+ } | |
+ if (readfds) | |
+ memcpy(readfds, &localread, sizeof(fd_set)); | |
+ if (exceptfds) | |
+ memcpy(exceptfds, &localexcept, sizeof(fd_set)); | |
+ } | |
+ return retval; | |
+} | |
+ | |
+/* We don't do locking under Win32 right now */ | |
+int ReadLock(FILE * fp) | |
+{ | |
+ return 0; | |
+} | |
+ | |
+int WriteLock(FILE * fp) | |
+{ | |
+ return 0; | |
+} | |
+ | |
+void ReleaseLock(FILE * fp) | |
+{ | |
+} | |
+ | |
+#else /* Code for Unix build */ | |
+ | |
+#include <errno.h> | |
+ | |
+static int DoLock(FILE * fp, int l_type) | |
+{ | |
+ struct flock lk; | |
+ | |
+ lk.l_type = l_type; | |
+ lk.l_whence = lk.l_start = lk.l_len = 0; | |
+ lk.l_pid = 0; | |
+ | |
+ while (1) { | |
+ if (fcntl(fileno(fp), F_SETLKW, &lk) == 0) | |
+ return 0; | |
+ else if (errno != EINTR) | |
+ return 1; | |
+ } | |
+ return 1; | |
+} | |
+ | |
+int ReadLock(FILE * fp) | |
+{ | |
+ return DoLock(fp, F_RDLCK); | |
+} | |
+ | |
+int WriteLock(FILE * fp) | |
+{ | |
+ return DoLock(fp, F_WRLCK); | |
+} | |
+ | |
+void ReleaseLock(FILE * fp) | |
+{ | |
+ DoLock(fp, F_UNLCK); | |
+} | |
+ | |
+#endif /* CYGWIN */ | |
+ | |
+/* | |
+ * On systems with select, sleep for "microsec" microseconds. | |
+ */ | |
+void MicroSleep(int microsec) | |
+{ | |
+#if HAVE_SELECT || CYGWIN | |
+ struct timeval tv; | |
+ | |
+ tv.tv_sec = 0; | |
+ tv.tv_usec = microsec; | |
+ bselect(0, NULL, NULL, NULL, &tv); | |
+#endif | |
+} | |
diff --git a/src/util.h b/src/util.h | |
t@@ -0,0 +1,79 @@ | |
+/************************************************************************ | |
+ * util.h Miscellaneous utility and portability functions * | |
+ * Copyright (C) 1998-2002 Ben Webb * | |
+ * Email: [email protected] * | |
+ * WWW: http://dopewars.sourceforge.net/ * | |
+ * * | |
+ * This program 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 2 * | |
+ * of the License, or (at your option) any later version. * | |
+ * * | |
+ * This program 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 this program; if not, write to the Free Software * | |
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * | |
+ * MA 02111-1307, USA. * | |
+ ************************************************************************/ | |
+ | |
+#ifndef __UTIL_H__ | |
+#define __UTIL_H__ | |
+ | |
+#ifdef HAVE_CONFIG_H | |
+#include <config.h> | |
+#endif | |
+ | |
+#include <stdio.h> | |
+ | |
+#ifdef CYGWIN /* Definitions for native Win32 build */ | |
+#include <windows.h> | |
+#include <string.h> | |
+ | |
+#define SIGWINCH 0 | |
+#define SIGPIPE 0 | |
+#define SIG_BLOCK 0 | |
+#define SIG_UNBLOCK 0 | |
+ | |
+typedef int ssize_t; | |
+ | |
+struct sigaction { | |
+ void *sa_handler; | |
+ int sa_flags; | |
+ int sa_mask; | |
+}; | |
+ | |
+void sigemptyset(int *mask); | |
+void sigaddset(int *mask, int sig); | |
+int sigaction(int sig, struct sigaction *sact, char *pt); | |
+void sigprocmask(int flag, int *mask, char *pt); | |
+int bselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfs, | |
+ struct timeval *tm); | |
+#else /* Definitions for Unix build */ | |
+#define bselect select | |
+#endif /* CYGWIN */ | |
+ | |
+#ifndef HAVE_GETOPT | |
+int getopt(int argc, char *const argv[], const char *str); | |
+extern char *optarg; | |
+#endif | |
+ | |
+void MicroSleep(int microsec); | |
+ | |
+int ReadLock(FILE *fp); | |
+int WriteLock(FILE *fp); | |
+void ReleaseLock(FILE *fp); | |
+ | |
+/* Now make definitions if they haven't been done properly */ | |
+#ifndef WEXITSTATUS | |
+#define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8) | |
+#endif | |
+ | |
+#ifndef WIFEXITED | |
+#define WIFEXITED(stat_val) (((stat_val) & 255) == 0) | |
+#endif | |
+ | |
+#endif /* __UTIL_H__ */ | |
diff --git a/src/winmain.c b/src/winmain.c | |
t@@ -31,10 +31,10 @@ | |
#include <glib.h> | |
#include <stdlib.h> | |
-#include "dopeos.h" | |
#include "dopewars.h" | |
#include "nls.h" | |
#include "tstring.h" | |
+#include "util.h" | |
#include "AIPlayer.h" | |
#include "message.h" | |
#include "serverside.h" | |
t@@ -56,7 +56,6 @@ static void ServerLogMessage(const gchar *log_domain, | |
GLogLevelFlags log_level, | |
const gchar *message, gpointer user_data) | |
{ | |
- DWORD NumChar; | |
GString *text; | |
text = GetLogString(log_level, message); | |
t@@ -317,7 +316,6 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevI… | |
LogMask() | G_LOG_LEVEL_MESSAGE | | |
G_LOG_LEVEL_WARNING, ServerLogMessage, NULL); | |
g_set_print_handler(ServerPrintFunc); | |
- newterm(NULL, NULL, NULL); | |
AIPlayerLoop(); | |
} else { | |
switch (WantedClient) { |