From 518c8d6fbf0159e86c386e91d58a88403b8e0b3f Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sun, 19 Apr 2009 09:37:42 +0200 Subject: [PATCH] Empty out and remove sysdep_w32.c sysdep_w32.h Not much remains in sysdep_w32.c, and it's mostly for main.c. Move that there, and the rest to misc.h. --- src/client/Makefile.in | 17 ++++----- src/client/main.c | 62 ++++++++++++++++++++++++++++-- src/client/misc.h | 10 +++-- src/client/sysdep_w32.c | 85 ----------------------------------------- src/client/sysdep_w32.h | 50 ------------------------ 5 files changed, 72 insertions(+), 152 deletions(-) delete mode 100644 src/client/sysdep_w32.c delete mode 100644 src/client/sysdep_w32.h diff --git a/src/client/Makefile.in b/src/client/Makefile.in index 54805f509..8072b7142 100644 --- a/src/client/Makefile.in +++ b/src/client/Makefile.in @@ -55,8 +55,7 @@ VPATH = @srcdir@ prog = empire$E obj = expect.$O host.$O ipglob.$O linebuf.$O login.$O main.$O play.$O \ -ringbuf.$O secure.$O servcmd.$O sysdep_w32.$O termlib.$O version.$O \ -$(LIBOBJS) +ringbuf.$O secure.$O servcmd.$O termlib.$O version.$O $(LIBOBJS) all: $(prog) @@ -81,16 +80,15 @@ uninstall: rm $(mandir)/man6/empire.6 # FIXME generate from .d -expect.$O: misc.h sysdep_w32.h proto.h -host.$O: misc.h sysdep_w32.h +expect.$O: misc.h proto.h +host.$O: misc.h linebuf.$O: linebuf.h -login.$O: misc.h sysdep_w32.h proto.h -main.$O: misc.h sysdep_w32.h version.h -play.$O: linebuf.h misc.h sysdep_w32.h proto.h ringbuf.h secure.h +login.$O: misc.h proto.h +main.$O: misc.h version.h +play.$O: linebuf.h misc.h proto.h ringbuf.h secure.h ringbuf.$O: ringbuf.h secure.$O: ringbuf.h secure.h -servcmd.$O: misc.h sysdep_w32.h proto.h secure.h -sysdep_w32.$O: misc.h sysdep_w32.h +servcmd.$O: misc.h proto.h secure.h termlib.$O: misc.h version.$O: version.h $(obj): config.h @@ -101,6 +99,5 @@ login.$O: w32/unistd.h w32/w32types.h main.$O: w32/unistd.h w32/w32types.h play.$O: w32/sys/socket.h w32/unistd.h w32/w32types.h ringbuf.$O: w32/sys/uio.h w32/w32types.h -sysdep_w32.$O: w32/sys/socket.h w32/w32io.$O: misc.h w32/sys/uio.h w32/w32types.h w32/w32sockets.$O: w32/sys/socket.h w32/unistd.h w32/w32types.h diff --git a/src/client/main.c b/src/client/main.c index dea0a01d7..eb98d44cd 100644 --- a/src/client/main.c +++ b/src/client/main.c @@ -30,14 +30,17 @@ * Known contributors to this file: * Dave Pare, 1986 * Steve McClure, 1998 - * Ron Koenderink, 2004-2005 + * Ron Koenderink, 2004-2007 * Markus Armbruster, 2005-2009 */ #include #include -#ifndef _WIN32 +#ifdef _WIN32 +#include +#include "sys/socket.h" +#else #include #endif #include @@ -48,9 +51,16 @@ #define getuid() 0 #define getpwuid(uid) ((void)(uid), w32_getpw()) #define sysdep_init() w32_sysdep_init() -#else + +struct passwd { + char *pw_name; +}; + +static struct passwd *w32_getpw(void); +static void w32_sysdep_init(void); +#else /* !_WIN32 */ #define sysdep_init() ((void)0) -#endif +#endif /* !_WIN32 */ static void print_usage(char *program_name) @@ -147,3 +157,47 @@ main(int argc, char **argv) return 0; } + +#ifdef _WIN32 +/* + * Get Windows user name + */ +static struct passwd * +w32_getpw(void) +{ + static char unamebuf[128]; + static struct passwd pwd; + DWORD unamesize; + + unamesize = sizeof(unamebuf); + if (GetUserName(unamebuf, &unamesize)) { + pwd.pw_name = unamebuf; + if (unamesize == 0 || strlen(unamebuf) == 0) + pwd.pw_name = "nobody"; + } else + pwd.pw_name = "nobody"; + return &pwd; +} + +static void +w32_sysdep_init(void) +{ + int err; + + /* + * stdout is unbuffered under Windows if connected to a character + * device, and putchar() screws up when printing multibyte strings + * bytewise to an unbuffered stream. Switch stdout to line- + * buffered mode. Unfortunately, ISO C allows implementations to + * screw that up, and of course Windows does. Manual flushing + * after each prompt is required. + */ + setvbuf(stdout, NULL, _IOLBF, 4096); + + err = w32_socket_init(); + if (err != 0) { + printf("WSAStartup Failed, error code %d\n", err); + exit(1); + } +} +#endif diff --git a/src/client/misc.h b/src/client/misc.h index de7996450..171f8a968 100644 --- a/src/client/misc.h +++ b/src/client/misc.h @@ -35,9 +35,6 @@ #define MISC_H #include -#ifdef _WIN32 -#include "sysdep_w32.h" -#endif #define MAX(a, b) ((a) >= (b) ? (a) : (b)) #define MIN(a,b) ((a) < (b) ? (a) : (b)) @@ -58,6 +55,7 @@ void putse(void); #define putso() ((void)0) #define putse() ((void)0) #endif /* !HAVE_CURSES_TERMINFO */ + int recvline(int s, char *buf); int parseid(char *); int expect(int s, int match, char *buf); @@ -68,4 +66,10 @@ void sendcmd(int s, char *cmd, char *arg); void servercmd(int, char *, int); void outch(char); +#ifdef _MSC_VER +#define pclose _pclose +#define popen _popen +#define snprintf _snprintf +#endif + #endif diff --git a/src/client/sysdep_w32.c b/src/client/sysdep_w32.c deleted file mode 100644 index 46a213344..000000000 --- a/src/client/sysdep_w32.c +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Empire - A multi-player, client/server Internet based war game. - * Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak, - * Ken Stevens, Steve McClure - * - * 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 - * - * --- - * - * See files README, COPYING and CREDITS in the root of the source - * tree for related information and legal notices. It is expected - * that future projects/authors will amend these files as needed. - * - * --- - * - * sysdep_w32.c: system dependent functions for WIN32 environments - * - * Known contributors to this file: - * Ron Koenderink, 2007 - * Markus Armbruster, 2009 - */ - -#ifdef _WIN32 -#include - -#include -#include -#include "misc.h" -#include "sys/socket.h" - -/* - * Get user name in the WIN32 environment - */ -struct passwd * -w32_getpw(void) -{ - static char unamebuf[128]; - static struct passwd pwd; - DWORD unamesize; - - unamesize = sizeof(unamebuf); - if (GetUserName(unamebuf, &unamesize)) { - pwd.pw_name = unamebuf; - if (unamesize == 0 || strlen(unamebuf) == 0) - pwd.pw_name = "nobody"; - } else - pwd.pw_name = "nobody"; - return &pwd; -} - -void -w32_sysdep_init(void) -{ - int err; - - /* - * stdout is unbuffered under Windows if connected to a character - * device, and putchar() screws up when printing multibyte strings - * bytewise to an unbuffered stream. Switch stdout to line- - * buffered mode. Unfortunately, ISO C allows implementations to - * screw that up, and of course Windows does. Manual flushing - * after each prompt is required. - */ - setvbuf(stdout, NULL, _IOLBF, 4096); - - err = w32_socket_init(); - if (err != 0) { - printf("WSAStartup Failed, error code %d\n", err); - exit(1); - } -} - -#endif /* _WIN32 */ diff --git a/src/client/sysdep_w32.h b/src/client/sysdep_w32.h deleted file mode 100644 index 890690262..000000000 --- a/src/client/sysdep_w32.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Empire - A multi-player, client/server Internet based war game. - * Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak, - * Ken Stevens, Steve McClure - * - * 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 - * - * --- - * - * See files README, COPYING and CREDITS in the root of the source - * tree for related information and legal notices. It is expected - * that future projects/authors will amend these files as needed. - * - * --- - * - * sysdep_w32.h: system dependent support for WIN32 environments - * - * Known contributors to this file: - * Ron Koenderink, 2007 - * Markus Armbruster, 2009 - */ - -#ifndef _SYSDEF_W32_H -#include - -struct passwd { - char *pw_name; -}; - -extern struct passwd *w32_getpw(void); -extern void w32_sysdep_init(void); - -#ifdef _MSC_VER -#define pclose _pclose -#define popen _popen -#define snprintf _snprintf -#endif -#endif -- 2.43.0