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.
This commit is contained in:
Markus Armbruster 2009-04-19 09:37:42 +02:00
parent 4d40a27542
commit 518c8d6fbf
5 changed files with 72 additions and 152 deletions

View file

@ -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

View file

@ -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 <config.h>
#include <stdlib.h>
#ifndef _WIN32
#ifdef _WIN32
#include <windows.h>
#include "sys/socket.h"
#else
#include <pwd.h>
#endif
#include <unistd.h>
@ -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

View file

@ -35,9 +35,6 @@
#define MISC_H
#include <stdio.h>
#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

View file

@ -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 <config.h>
#include <stdlib.h>
#include <windows.h>
#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 */

View file

@ -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 <stdio.h>
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