Whitespace.

This commit is contained in:
dholland 2009-07-04 05:01:16 +00:00
parent b2f99339f0
commit cb89af2bfc
4 changed files with 591 additions and 591 deletions

View File

@ -1,49 +1,49 @@
/* $NetBSD: connect.c,v 1.7 2009/07/04 01:58:57 dholland Exp $ */
/* $NetBSD: connect.c,v 1.8 2009/07/04 05:01:16 dholland Exp $ */
/*
* Copyright (c) 1983-2003, Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* + Redistributions of source code must retain the above copyright
*
* + Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* + Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* + Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* + Neither the name of the University of California, San Francisco nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* + Neither the name of the University of California, San Francisco nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: connect.c,v 1.7 2009/07/04 01:58:57 dholland Exp $");
__RCSID("$NetBSD: connect.c,v 1.8 2009/07/04 05:01:16 dholland Exp $");
#endif /* not lint */
# include "hunt.h"
# include <signal.h>
# include <unistd.h>
#include "hunt.h"
#include <signal.h>
#include <unistd.h>
void
do_connect(char *name, char team, long enter_status)
{
static int32_t uid;
static int32_t mode;
static int32_t uid;
static int32_t mode;
if (uid == 0)
uid = htonl(getuid());
@ -54,16 +54,16 @@ do_connect(char *name, char team, long enter_status)
(void) write(Socket, &enter_status, LONGLEN);
(void) strcpy(Buf, ttyname(fileno(stderr)));
(void) write(Socket, Buf, NAMELEN);
# ifdef INTERNET
#ifdef INTERNET
if (Send_message != NULL)
mode = C_MESSAGE;
else
# endif
# ifdef MONITOR
#endif
#ifdef MONITOR
if (Am_monitor)
mode = C_MONITOR;
else
# endif
#endif
mode = C_PLAYER;
mode = htonl(mode);
(void) write(Socket, &mode, sizeof mode);

View File

@ -1,125 +1,125 @@
/* $NetBSD: hunt.c,v 1.31 2009/07/04 01:58:57 dholland Exp $ */
/* $NetBSD: hunt.c,v 1.32 2009/07/04 05:01:16 dholland Exp $ */
/*
* Copyright (c) 1983-2003, Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* + Redistributions of source code must retain the above copyright
*
* + Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* + Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* + Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* + Neither the name of the University of California, San Francisco nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* + Neither the name of the University of California, San Francisco nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: hunt.c,v 1.31 2009/07/04 01:58:57 dholland Exp $");
__RCSID("$NetBSD: hunt.c,v 1.32 2009/07/04 05:01:16 dholland Exp $");
#endif /* not lint */
# include <sys/param.h>
# include <sys/stat.h>
# include <sys/time.h>
# include <sys/poll.h>
# include <ctype.h>
# include <err.h>
# include <errno.h>
# include <curses.h>
# include <signal.h>
# include <stdlib.h>
# include <string.h>
# if !defined(USE_CURSES) && defined(BSD_RELEASE) && BSD_RELEASE >= 44
# include <termios.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/poll.h>
#include <ctype.h>
#include <err.h>
#include <errno.h>
#include <curses.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#if !defined(USE_CURSES) && defined(BSD_RELEASE) && BSD_RELEASE >= 44
#include <termios.h>
static struct termios saved_tty;
# endif
# include <unistd.h>
# include <ifaddrs.h>
#endif
#include <unistd.h>
#include <ifaddrs.h>
# include "hunt.h"
#include "hunt.h"
/*
* Some old versions of curses don't have these defined
*/
# if !defined(cbreak) && (!defined(BSD_RELEASE) || BSD_RELEASE < 44)
# define cbreak() crmode()
# endif
#if !defined(cbreak) && (!defined(BSD_RELEASE) || BSD_RELEASE < 44)
#define cbreak() crmode()
#endif
# if !defined(USE_CURSES) || !defined(TERMINFO)
# define beep() (void) putchar(CTRL('G'))
# endif
# if !defined(USE_CURSES)
# undef refresh
# define refresh() (void) fflush(stdout);
# endif
# ifdef USE_CURSES
# define clear_eol() clrtoeol()
# define put_ch addch
# define put_str addstr
# endif
#if !defined(USE_CURSES) || !defined(TERMINFO)
#define beep() (void) putchar(CTRL('G'))
#endif
#if !defined(USE_CURSES)
#undef refresh
#define refresh() (void) fflush(stdout);
#endif
#ifdef USE_CURSES
#define clear_eol() clrtoeol()
#define put_ch addch
#define put_str addstr
#endif
FLAG Last_player = FALSE;
# ifdef MONITOR
FLAG Am_monitor = FALSE;
# endif
FLAG Last_player = FALSE;
#ifdef MONITOR
FLAG Am_monitor = FALSE;
#endif
char Buf[BUFSIZ];
char Buf[BUFSIZ];
int Socket;
# ifdef INTERNET
char *Sock_host;
char *use_port;
FLAG Query_driver = FALSE;
char *Send_message = NULL;
FLAG Show_scores = FALSE;
# endif
int Socket;
#ifdef INTERNET
char *Sock_host;
char *use_port;
FLAG Query_driver = FALSE;
char *Send_message = NULL;
FLAG Show_scores = FALSE;
#endif
SOCKET Daemon;
# ifdef INTERNET
# define DAEMON_SIZE (sizeof Daemon)
# else
# define DAEMON_SIZE (sizeof Daemon - 1)
# endif
SOCKET Daemon;
#ifdef INTERNET
#define DAEMON_SIZE (sizeof Daemon)
#else
#define DAEMON_SIZE (sizeof Daemon - 1)
#endif
char map_key[256]; /* what to map keys to */
FLAG no_beep;
char map_key[256]; /* what to map keys to */
FLAG no_beep;
static char name[NAMELEN];
static char team = ' ';
static char name[NAMELEN];
static char team = ' ';
static int in_visual;
static int in_visual;
extern int cur_row, cur_col;
extern int cur_row, cur_col;
void dump_scores(SOCKET);
long env_init(long);
void fill_in_blanks(void);
void leave(int, const char *) __dead;
void leavex(int, const char *) __dead;
void fincurs(void);
int main(int, char *[]);
# ifdef INTERNET
void dump_scores(SOCKET);
long env_init(long);
void fill_in_blanks(void);
void leave(int, const char *) __dead;
void leavex(int, const char *) __dead;
void fincurs(void);
int main(int, char *[]);
#ifdef INTERNET
SOCKET *list_drivers(void);
# endif
#endif
extern int Otto_mode;
extern int Otto_mode;
/*
* main:
* Main program for local process
@ -127,9 +127,9 @@ extern int Otto_mode;
int
main(int ac, char **av)
{
char *term;
int c;
long enter_status;
char *term;
int c;
long enter_status;
enter_status = env_init((long) Q_CLOAK);
while ((c = getopt(ac, av, "Sbcfh:l:mn:op:qst:w:")) != -1) {
@ -146,21 +146,21 @@ main(int ac, char **av)
}
break;
case 'o':
# ifndef OTTO
#ifndef OTTO
warnx("The -o flag is reserved for future use.");
goto usage;
# else
#else
Otto_mode = TRUE;
break;
# endif
#endif
case 'm':
# ifdef MONITOR
#ifdef MONITOR
Am_monitor = TRUE;
# else
#else
warnx("The monitor was not compiled in.");
# endif
#endif
break;
# ifdef INTERNET
#ifdef INTERNET
case 'S':
Show_scores = TRUE;
break;
@ -177,7 +177,7 @@ main(int ac, char **av)
use_port = optarg;
Test_port = atoi(use_port);
break;
# else
#else
case 'S':
case 'q':
case 'w':
@ -185,16 +185,16 @@ main(int ac, char **av)
case 'p':
wanrx("Need TCP/IP for S, q, w, h, and p options.");
break;
# endif
#endif
case 'c':
enter_status = Q_CLOAK;
break;
case 'f':
# ifdef FLY
#ifdef FLY
enter_status = Q_FLY;
# else
#else
warnx("The flying code was not compiled in.");
# endif
#endif
break;
case 's':
enter_status = Q_SCAN;
@ -210,30 +210,30 @@ main(int ac, char **av)
exit(1);
}
}
# ifdef INTERNET
#ifdef INTERNET
if (optind + 1 < ac)
goto usage;
else if (optind + 1 == ac)
Sock_host = av[ac - 1];
# else
#else
if (optind > ac)
goto usage;
# endif
#endif
# ifdef INTERNET
#ifdef INTERNET
if (Show_scores) {
SOCKET *hosts;
SOCKET *hosts;
for (hosts = list_drivers(); hosts->sin_port != 0; hosts += 1)
dump_scores(*hosts);
exit(0);
}
if (Query_driver) {
SOCKET *hosts;
SOCKET *hosts;
for (hosts = list_drivers(); hosts->sin_port != 0; hosts += 1) {
struct hostent *hp;
int num_players;
struct hostent *hp;
int num_players;
hp = gethostbyaddr((char *) &hosts->sin_addr,
sizeof hosts->sin_addr, AF_INET);
@ -245,36 +245,36 @@ main(int ac, char **av)
}
exit(0);
}
# endif
# ifdef OTTO
#endif
#ifdef OTTO
if (Otto_mode)
(void) strncpy(name, "otto", NAMELEN);
else
# endif
#endif
fill_in_blanks();
(void) fflush(stdout);
if (!isatty(0) || (term = getenv("TERM")) == NULL)
errx(1, "no terminal type");
# ifdef USE_CURSES
#ifdef USE_CURSES
if (!initscr())
errx(0, "couldn't initialize screen");
(void) noecho();
(void) cbreak();
# else /* !USE_CURSES */
# if !defined(BSD_RELEASE) || BSD_RELEASE < 44
#else /* !USE_CURSES */
#if !defined(BSD_RELEASE) || BSD_RELEASE < 44
_tty_ch = 0;
# endif
#endif
gettmode();
(void) setterm(term);
(void) noecho();
(void) cbreak();
# if defined(BSD_RELEASE) && BSD_RELEASE >= 44
#if defined(BSD_RELEASE) && BSD_RELEASE >= 44
tcgetattr(0, &saved_tty);
# endif
#endif
_puts(TI);
_puts(VS);
# endif /* !USE_CURSES */
#endif /* !USE_CURSES */
in_visual = TRUE;
if (LINES < SCREEN_HEIGHT || COLS < SCREEN_WIDTH)
leavex(1, "Need a larger window");
@ -288,7 +288,7 @@ main(int ac, char **av)
#endif
for (;;) {
# ifdef INTERNET
#ifdef INTERNET
find_driver(TRUE);
if (Daemon.sin_port == 0)
@ -296,7 +296,7 @@ main(int ac, char **av)
jump_in:
do {
int option;
int option;
Socket = socket(SOCK_FAMILY, SOCK_STREAM, 0);
if (Socket < 0)
@ -316,7 +316,7 @@ main(int ac, char **av)
break;
sleep(1);
} while (close(Socket) == 0);
# else /* !INTERNET */
#else /* !INTERNET */
/*
* set up a socket
*/
@ -346,10 +346,10 @@ main(int ac, char **av)
sleep(2);
} while (connect(Socket, &Daemon, DAEMON_SIZE) < 0);
}
# endif
#endif
do_connect(name, team, enter_status);
# ifdef INTERNET
#ifdef INTERNET
if (Send_message != NULL) {
do_message();
if (enter_status == Q_MESSAGE)
@ -358,7 +358,7 @@ main(int ac, char **av)
/* don't continue as that will call find_driver */
goto jump_in;
}
# endif
#endif
playit();
if ((enter_status = quit(enter_status)) == Q_QUIT)
break;
@ -368,13 +368,13 @@ main(int ac, char **av)
return(0);
}
# ifdef INTERNET
# ifdef BROADCAST
#ifdef INTERNET
#ifdef BROADCAST
int
broadcast_vec(int s /*socket*/, struct sockaddr **vector)
{
int vec_cnt;
struct ifaddrs *ifp, *ip;
int vec_cnt;
struct ifaddrs *ifp, *ip;
*vector = NULL;
if (getifaddrs(&ifp) < 0)
@ -399,38 +399,38 @@ broadcast_vec(int s /*socket*/, struct sockaddr **vector)
freeifaddrs(ifp);
return vec_cnt;
}
# endif
#endif
SOCKET *
SOCKET *
list_drivers(void)
{
int option;
u_short msg;
u_short port_num;
static SOCKET test;
int test_socket;
socklen_t namelen;
char local_name[MAXHOSTNAMELEN + 1];
static int initial = TRUE;
static struct in_addr local_address;
struct hostent *hp;
# ifdef BROADCAST
static int brdc;
static SOCKET *brdv;
# else
u_long local_net;
# endif
int i;
unsigned j;
static SOCKET *listv;
static unsigned int listmax;
unsigned int listc;
struct pollfd set[1];
int option;
u_short msg;
u_short port_num;
static SOCKET test;
int test_socket;
socklen_t namelen;
char local_name[MAXHOSTNAMELEN + 1];
static int initial = TRUE;
static struct in_addr local_address;
struct hostent *hp;
#ifdef BROADCAST
static int brdc;
static SOCKET *brdv;
#else
u_long local_net;
#endif
int i;
unsigned j;
static SOCKET *listv;
static unsigned int listmax;
unsigned int listc;
struct pollfd set[1];
if (initial) { /* do one time initialization */
# ifndef BROADCAST
#ifndef BROADCAST
sethostent(1); /* don't bother to close host file */
# endif
#endif
if (gethostname(local_name, sizeof local_name) < 0) {
leavex(1, "Sorry, I have no name.");
/* NOTREACHED */
@ -473,11 +473,11 @@ list_drivers(void)
(struct sockaddr *) &test, DAEMON_SIZE);
}
# ifdef BROADCAST
#ifdef BROADCAST
if (initial)
brdc = broadcast_vec(test_socket, (void *) &brdv);
# ifdef SO_BROADCAST
#ifdef SO_BROADCAST
/* Sun's will broadcast even though this option can't be set */
option = 1;
if (setsockopt(test_socket, SOL_SOCKET, SO_BROADCAST,
@ -485,7 +485,7 @@ list_drivers(void)
leave(1, "setsockopt broadcast");
/* NOTREACHED */
}
# endif
#endif
/* send broadcast packets on all interfaces */
msg = htons(C_TESTMSG());
@ -503,7 +503,7 @@ list_drivers(void)
leave(1, "sendto");
/* NOTREACHED */
}
# else /* !BROADCAST */
#else /* !BROADCAST */
/* loop thru all hosts on local net and send msg to them. */
msg = htons(C_TESTMSG());
local_net = inet_netof(local_address);
@ -515,7 +515,7 @@ list_drivers(void)
(struct sockaddr *) &test, DAEMON_SIZE);
}
}
# endif
#endif
get_response:
namelen = DAEMON_SIZE;
@ -570,11 +570,11 @@ test_one_host:
void
find_driver(FLAG do_startup)
{
SOCKET *hosts;
SOCKET *hosts;
hosts = list_drivers();
if (hosts[0].sin_port != htons(0)) {
int i, c;
int i, c;
if (hosts[1].sin_port == htons(0)) {
Daemon = hosts[0];
@ -582,26 +582,26 @@ find_driver(FLAG do_startup)
}
/* go thru list and return host that matches daemon */
clear_the_screen();
# ifdef USE_CURSES
#ifdef USE_CURSES
move(1, 0);
# else
#else
mvcur(cur_row, cur_col, 1, 0);
cur_row = 1;
cur_col = 0;
# endif
#endif
put_str("Pick one:");
for (i = 0; i < HEIGHT - 4 && hosts[i].sin_port != htons(0);
i += 1) {
struct hostent *hp;
char buf[80];
struct hostent *hp;
char buf[80];
# ifdef USE_CURSES
#ifdef USE_CURSES
move(3 + i, 0);
# else
#else
mvcur(cur_row, cur_col, 3 + i, 0);
cur_row = 3 + i;
cur_col = 0;
# endif
#endif
hp = gethostbyaddr((char *) &hosts[i].sin_addr,
sizeof hosts[i].sin_addr, AF_INET);
(void) snprintf(buf, sizeof(buf),
@ -610,13 +610,13 @@ find_driver(FLAG do_startup)
: inet_ntoa(hosts->sin_addr));
put_str(buf);
}
# ifdef USE_CURSES
#ifdef USE_CURSES
move(4 + i, 0);
# else
#else
mvcur(cur_row, cur_col, 4 + i, 0);
cur_row = 4 + i;
cur_col = 0;
# endif
#endif
put_str("Enter letter: ");
refresh();
while (!islower(c = getchar()) || (c -= 'a') >= i) {
@ -638,10 +638,10 @@ find_driver(FLAG do_startup)
void
dump_scores(SOCKET host)
{
struct hostent *hp;
int s;
char buf[BUFSIZ];
int cnt;
struct hostent *hp;
int s;
char buf[BUFSIZ];
int cnt;
hp = gethostbyaddr((char *) &host.sin_addr, sizeof host.sin_addr,
AF_INET);
@ -658,34 +658,34 @@ dump_scores(SOCKET host)
(void) close(s);
}
# endif
#endif
void
start_driver(void)
{
int procid;
int procid;
# ifdef MONITOR
#ifdef MONITOR
if (Am_monitor) {
leavex(1, "No one playing.");
/* NOTREACHED */
}
# endif
#endif
# ifdef INTERNET
#ifdef INTERNET
if (Sock_host != NULL) {
sleep(3);
return;
}
# endif
#endif
# ifdef USE_CURSES
#ifdef USE_CURSES
move(HEIGHT, 0);
# else
#else
mvcur(cur_row, cur_col, HEIGHT, 0);
cur_row = HEIGHT;
cur_col = 0;
# endif
#endif
put_str("Starting...");
refresh();
procid = fork();
@ -694,27 +694,27 @@ start_driver(void)
}
if (procid == 0) {
(void) signal(SIGINT, SIG_IGN);
# ifndef INTERNET
#ifndef INTERNET
(void) close(Socket);
# else
#else
if (use_port == NULL)
# endif
#endif
execl(Driver, "HUNT", (char *) NULL);
# ifdef INTERNET
else
#ifdef INTERNET
else
execl(Driver, "HUNT", "-p", use_port, (char *) NULL);
# endif
#endif
/* only get here if exec failed */
(void) kill(getppid(), SIGUSR1); /* tell mom */
_exit(1);
}
# ifdef USE_CURSES
#ifdef USE_CURSES
move(HEIGHT, 0);
# else
#else
mvcur(cur_row, cur_col, HEIGHT, 0);
cur_row = HEIGHT;
cur_col = 0;
# endif
#endif
put_str("Connecting...");
refresh();
}
@ -765,7 +765,7 @@ sigusr1(int dummy __unused)
/* NOTREACHED */
}
# ifdef INTERNET
#ifdef INTERNET
/*
* sigalrm:
* Handle an alarm signal
@ -775,7 +775,7 @@ sigalrm(int dummy __unused)
{
return;
}
# endif
#endif
/*
* rmnl:
@ -784,7 +784,7 @@ sigalrm(int dummy __unused)
void
rmnl(char *s)
{
char *cp;
char *cp;
cp = strrchr(s, '\n');
if (cp != NULL)
@ -798,21 +798,21 @@ rmnl(char *s)
SIGNAL_TYPE
intr(int dummy __unused)
{
int ch;
int explained;
int y, x;
int ch;
int explained;
int y, x;
(void) signal(SIGINT, SIG_IGN);
# ifdef USE_CURSES
#ifdef USE_CURSES
getyx(stdscr, y, x);
move(HEIGHT, 0);
# else
#else
y = cur_row;
x = cur_col;
mvcur(cur_row, cur_col, HEIGHT, 0);
cur_row = HEIGHT;
cur_col = 0;
# endif
#endif
put_str("Really quit? ");
clear_eol();
refresh();
@ -830,13 +830,13 @@ intr(int dummy __unused)
}
else if (ch == 'n') {
(void) signal(SIGINT, intr);
# ifdef USE_CURSES
#ifdef USE_CURSES
move(y, x);
# else
#else
mvcur(cur_row, cur_col, y, x);
cur_row = y;
cur_col = x;
# endif
#endif
refresh();
return;
}
@ -854,21 +854,21 @@ void
fincurs(void)
{
if (in_visual) {
# ifdef USE_CURSES
#ifdef USE_CURSES
move(HEIGHT, 0);
refresh();
endwin();
# else /* !USE_CURSES */
#else /* !USE_CURSES */
mvcur(cur_row, cur_col, HEIGHT, 0);
(void) fflush(stdout); /* flush in case VE changes pages */
# if defined(BSD_RELEASE) && BSD_RELEASE >= 44
#if defined(BSD_RELEASE) && BSD_RELEASE >= 44
tcsetattr(0, TCSADRAIN, &__orig_termios);
# else
#else
resetty();
# endif
#endif
_puts(VE);
_puts(TE);
# endif /* !USE_CURSES */
#endif /* !USE_CURSES */
}
}
@ -906,35 +906,35 @@ leavex(int eval, const char *mesg)
SIGNAL_TYPE
tstp(int dummy __unused)
{
# if BSD_RELEASE < 44
static struct sgttyb tty;
# endif
int y, x;
#if BSD_RELEASE < 44
static struct sgttyb tty;
#endif
int y, x;
y = cur_row;
x = cur_col;
mvcur(cur_row, cur_col, HEIGHT, 0);
cur_row = HEIGHT;
cur_col = 0;
# if !defined(BSD_RELEASE) || BSD_RELEASE < 44
#if !defined(BSD_RELEASE) || BSD_RELEASE < 44
tty = _tty;
# endif
#endif
_puts(VE);
_puts(TE);
(void) fflush(stdout);
# if defined(BSD_RELEASE) && BSD_RELEASE >= 44
#if defined(BSD_RELEASE) && BSD_RELEASE >= 44
tcsetattr(0, TCSADRAIN, &__orig_termios);
# else
#else
resetty();
# endif
#endif
(void) kill(getpid(), SIGSTOP);
(void) signal(SIGTSTP, tstp);
# if defined(BSD_RELEASE) && BSD_RELEASE >= 44
#if defined(BSD_RELEASE) && BSD_RELEASE >= 44
tcsetattr(0, TCSADRAIN, &saved_tty);
# else
#else
_tty = tty;
ioctl(_tty_ch, TIOCSETP, &_tty);
# endif
#endif
_puts(TI);
_puts(VS);
cur_row = y;
@ -945,7 +945,7 @@ tstp(int dummy __unused)
}
#endif /* !defined(USE_CURSES) && defined(SIGTSTP) */
# if defined(BSD_RELEASE) && BSD_RELEASE < 43
#if defined(BSD_RELEASE) && BSD_RELEASE < 43
char *
strpbrk(char *s, char *brk)
{
@ -960,13 +960,13 @@ strpbrk(char *s, char *brk)
}
return (0);
}
# endif
#endif
long
env_init(long enter_status)
{
int i;
char *envp, *envname, *s;
int i;
char *envp, *envname, *s;
for (i = 0; i < 256; i++)
map_key[i] = (char) i;
@ -1001,7 +1001,7 @@ env_init(long enter_status)
strncpy(name, envname, NAMELEN);
envp = s + 1;
}
# ifdef INTERNET
#ifdef INTERNET
else if (strncmp(envp, "port=", s - envp + 1) == 0) {
use_port = s + 1;
Test_port = atoi(use_port);
@ -1030,7 +1030,7 @@ env_init(long enter_status)
*s = '\0';
envp = s + 1;
}
# endif
#endif
else if (strncmp(envp, "team=", s - envp + 1) == 0) {
team = *(s + 1);
if (!isdigit((unsigned char)team))
@ -1074,8 +1074,8 @@ env_init(long enter_status)
void
fill_in_blanks(void)
{
int i;
char *cp;
int i;
char *cp;
again:
if (name[0] != '\0') {

View File

@ -1,33 +1,33 @@
/* $NetBSD: otto.c,v 1.12 2009/07/04 01:58:57 dholland Exp $ */
# ifdef OTTO
/* $NetBSD: otto.c,v 1.13 2009/07/04 05:01:16 dholland Exp $ */
#ifdef OTTO
/*
* Copyright (c) 1983-2003, Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* + Redistributions of source code must retain the above copyright
*
* + Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* + Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* + Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* + Neither the name of the University of California, San Francisco nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* + Neither the name of the University of California, San Francisco nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
@ -45,114 +45,114 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: otto.c,v 1.12 2009/07/04 01:58:57 dholland Exp $");
__RCSID("$NetBSD: otto.c,v 1.13 2009/07/04 05:01:16 dholland Exp $");
#endif /* not lint */
# include <sys/time.h>
# include <curses.h>
# include <ctype.h>
# include <signal.h>
# include <stdlib.h>
# include <unistd.h>
# include "hunt.h"
#include <sys/time.h>
#include <curses.h>
#include <ctype.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include "hunt.h"
# undef WALL
# undef NORTH
# undef SOUTH
# undef WEST
# undef EAST
# undef FRONT
# undef LEFT
# undef BACK
# undef RIGHT
#undef WALL
#undef NORTH
#undef SOUTH
#undef WEST
#undef EAST
#undef FRONT
#undef LEFT
#undef BACK
#undef RIGHT
# ifdef HPUX
# define random rand
# endif
#ifdef HPUX
#define random rand
#endif
# ifndef USE_CURSES
extern char screen[SCREEN_HEIGHT][SCREEN_WIDTH2];
# define SCREEN(y, x) screen[y][x]
# else
# define SCREEN(y, x) mvinch(y, x)
# endif
#ifndef USE_CURSES
extern char screen[SCREEN_HEIGHT][SCREEN_WIDTH2];
#define SCREEN(y, x) screen[y][x]
#else
#define SCREEN(y, x) mvinch(y, x)
#endif
# ifndef DEBUG
# define STATIC static
# else
# define STATIC
# endif
#ifndef DEBUG
#define STATIC static
#else
#define STATIC
#endif
# define OPPONENT "{}i!"
# define PROPONENT "^v<>"
# define WALL "+\\/#*-|"
# define PUSHOVER " bg;*#&"
# define SHOTS "$@Oo:"
#define OPPONENT "{}i!"
#define PROPONENT "^v<>"
#define WALL "+\\/#*-|"
#define PUSHOVER " bg;*#&"
#define SHOTS "$@Oo:"
/* number of "directions" */
# define NUMDIRECTIONS 4
#define NUMDIRECTIONS 4
/* absolute directions (facings) - counterclockwise */
# define NORTH 0
# define WEST 1
# define SOUTH 2
# define EAST 3
# define ALLDIRS 0xf
#define NORTH 0
#define WEST 1
#define SOUTH 2
#define EAST 3
#define ALLDIRS 0xf
/* relative directions - counterclockwise */
# define FRONT 0
# define LEFT 1
# define BACK 2
# define RIGHT 3
#define FRONT 0
#define LEFT 1
#define BACK 2
#define RIGHT 3
# define ABSCHARS "NWSE"
# define RELCHARS "FLBR"
# define DIRKEYS "khjl"
#define ABSCHARS "NWSE"
#define RELCHARS "FLBR"
#define DIRKEYS "khjl"
STATIC char command[BUFSIZ];
STATIC int comlen;
STATIC char command[BUFSIZ];
STATIC int comlen;
# ifdef DEBUG
STATIC FILE *debug = NULL;
# endif
#ifdef DEBUG
STATIC FILE *debug = NULL;
#endif
# define DEADEND 0x1
# define ON_LEFT 0x2
# define ON_RIGHT 0x4
# define ON_SIDE (ON_LEFT|ON_RIGHT)
# define BEEN 0x8
# define BEEN_SAME 0x10
#define DEADEND 0x1
#define ON_LEFT 0x2
#define ON_RIGHT 0x4
#define ON_SIDE (ON_LEFT|ON_RIGHT)
#define BEEN 0x8
#define BEEN_SAME 0x10
struct item {
char what;
int distance;
int flags;
struct item {
char what;
int distance;
int flags;
};
STATIC struct item flbr[NUMDIRECTIONS];
STATIC struct item flbr[NUMDIRECTIONS];
# define fitem flbr[FRONT]
# define litem flbr[LEFT]
# define bitem flbr[BACK]
# define ritem flbr[RIGHT]
#define fitem flbr[FRONT]
#define litem flbr[LEFT]
#define bitem flbr[BACK]
#define ritem flbr[RIGHT]
STATIC int facing;
STATIC int row, col;
STATIC int num_turns; /* for wandering */
STATIC char been_there[HEIGHT][WIDTH2];
STATIC struct itimerval pause_time = { { 0, 0 }, { 0, 55000 }};
STATIC int facing;
STATIC int row, col;
STATIC int num_turns; /* for wandering */
STATIC char been_there[HEIGHT][WIDTH2];
STATIC struct itimerval pause_time = { { 0, 0 }, { 0, 55000 }};
STATIC void attack(int, struct item *);
STATIC void duck(int);
STATIC void face_and_move_direction(int, int);
STATIC int go_for_ammo(char);
STATIC void ottolook(int, struct item *);
STATIC void look_around(void);
STATIC SIGNAL_TYPE nothing(int);
STATIC int stop_look(struct item *, char, int, int);
STATIC void wander(void);
STATIC void attack(int, struct item *);
STATIC void duck(int);
STATIC void face_and_move_direction(int, int);
STATIC int go_for_ammo(char);
STATIC void ottolook(int, struct item *);
STATIC void look_around(void);
STATIC SIGNAL_TYPE nothing(int);
STATIC int stop_look(struct item *, char, int, int);
STATIC void wander(void);
extern int Otto_count;
extern int Otto_count;
STATIC SIGNAL_TYPE
nothing(int dummy __unused)
@ -162,16 +162,16 @@ nothing(int dummy __unused)
void
otto(int y, int x, char face)
{
int i;
int old_mask;
int i;
int old_mask;
# ifdef DEBUG
#ifdef DEBUG
if (debug == NULL) {
debug = fopen("bug", "w");
setbuf(debug, NULL);
}
fprintf(debug, "\n%c(%d,%d)", face, y, x);
# endif
#endif
(void) signal(SIGALRM, nothing);
old_mask = sigblock(sigmask(SIGALRM));
setitimer(ITIMER_REAL, &pause_time, NULL);
@ -180,11 +180,11 @@ otto(int y, int x, char face)
/* save away parameters so other functions may use/update info */
switch (face) {
case '^': facing = NORTH; break;
case '<': facing = WEST; break;
case 'v': facing = SOUTH; break;
case '>': facing = EAST; break;
default: abort();
case '^': facing = NORTH; break;
case '<': facing = WEST; break;
case 'v': facing = SOUTH; break;
case '>': facing = EAST; break;
default: abort();
}
row = y; col = x;
been_there[row][col] |= 1 << facing;
@ -205,12 +205,12 @@ otto(int y, int x, char face)
if (strchr(SHOTS, bitem.what) != NULL && !(bitem.what & ON_SIDE)) {
duck(BACK);
memset(been_there, 0, sizeof been_there);
# ifdef BOOTS
#ifdef BOOTS
} else if (go_for_ammo(BOOT_PAIR)) {
memset(been_there, 0, sizeof been_there);
} else if (go_for_ammo(BOOT)) {
memset(been_there, 0, sizeof been_there);
# endif
#endif
} else if (go_for_ammo(GMINE))
memset(been_there, 0, sizeof been_there);
else if (go_for_ammo(MINE))
@ -221,12 +221,12 @@ otto(int y, int x, char face)
done:
(void) write(Socket, command, comlen);
Otto_count += comlen;
# ifdef DEBUG
#ifdef DEBUG
(void) fwrite(command, 1, comlen, debug);
# endif
#endif
}
# define direction(abs,rel) (((abs) + (rel)) % NUMDIRECTIONS)
#define direction(abs,rel) (((abs) + (rel)) % NUMDIRECTIONS)
STATIC int
stop_look(struct item *itemp, char c, int dist, int side)
@ -240,10 +240,10 @@ stop_look(struct item *itemp, char c, int dist, int side)
case MINE:
case GMINE:
# ifdef BOOTS
#ifdef BOOTS
case BOOT:
case BOOT_PAIR:
# endif
#endif
if (itemp->distance == -1) {
itemp->distance = dist;
itemp->what = c;
@ -258,9 +258,9 @@ stop_look(struct item *itemp, char c, int dist, int side)
case GRENADE:
case SATCHEL:
case BOMB:
# ifdef OOZE
#ifdef OOZE
case SLIME:
# endif
#endif
if (itemp->distance == -1 || (!side
&& (itemp->flags & ON_SIDE
|| itemp->what == GMINE || itemp->what == MINE))) {
@ -302,8 +302,8 @@ stop_look(struct item *itemp, char c, int dist, int side)
STATIC void
ottolook(int rel_dir, struct item *itemp)
{
int r, c;
char ch;
int r, c;
char ch;
r = 0;
itemp->what = 0;
@ -402,33 +402,33 @@ ottolook(int rel_dir, struct item *itemp)
STATIC void
look_around(void)
{
int i;
int i;
for (i = 0; i < NUMDIRECTIONS; i++) {
ottolook(i, &flbr[i]);
# ifdef DEBUG
#ifdef DEBUG
fprintf(debug, " ottolook(%c)=%c(%d)(0x%x)",
RELCHARS[i], flbr[i].what, flbr[i].distance, flbr[i].flags);
# endif
#endif
}
}
/*
* as a side effect modifies facing and location (row, col)
* as a side effect modifies facing and location (row, col)
*/
STATIC void
face_and_move_direction(int rel_dir, int distance)
{
int old_facing;
char cmd;
int old_facing;
char cmd;
old_facing = facing;
cmd = DIRKEYS[facing = direction(facing, rel_dir)];
if (rel_dir != FRONT) {
int i;
struct item items[NUMDIRECTIONS];
int i;
struct item items[NUMDIRECTIONS];
command[comlen++] = toupper((unsigned char)cmd);
if (distance == 0) {
@ -443,10 +443,10 @@ face_and_move_direction(int rel_dir, int distance)
command[comlen++] = cmd;
switch (facing) {
case NORTH: row--; break;
case WEST: col--; break;
case SOUTH: row++; break;
case EAST: col++; break;
case NORTH: row--; break;
case WEST: col--; break;
case SOUTH: row++; break;
case EAST: col++; break;
}
if (distance == 0)
look_around();
@ -482,7 +482,7 @@ attack(int rel_dir, struct item *itemp)
STATIC void
duck(int rel_dir)
{
int dir;
int dir;
switch (dir = direction(facing, rel_dir)) {
@ -525,13 +525,13 @@ duck(int rel_dir)
}
/*
* go for the closest mine if possible
* go for the closest mine if possible
*/
STATIC int
go_for_ammo(char mine)
{
int i, rel_dir, dist;
int i, rel_dir, dist;
rel_dir = -1;
dist = WIDTH;
@ -557,7 +557,7 @@ go_for_ammo(char mine)
STATIC void
wander(void)
{
int i, j, rel_dir, dir_mask, dir_count;
int i, j, rel_dir, dir_mask, dir_count;
for (i = 0; i < NUMDIRECTIONS; i++)
if (!(flbr[i].flags & BEEN) || flbr[i].distance <= 1)
@ -579,22 +579,22 @@ wander(void)
((flbr[FRONT].flags & BEEN) ? 7 : HEIGHT)))
continue;
dir_mask |= 1 << j;
# ifdef notdef
#ifdef notdef
dir_count++;
# else
#else
dir_count = 1;
break;
# endif
#endif
}
# ifdef notdef
#ifdef notdef
if (dir_count == 0) {
duck(random() % NUMDIRECTIONS);
num_turns = 0;
return;
} else if (dir_count == 1)
# endif
#endif
rel_dir = ffs(dir_mask) - 1;
# ifdef notdef
#ifdef notdef
else {
rel_dir = ffs(dir_mask) - 1;
dir_mask &= ~(1 << rel_dir);
@ -605,16 +605,16 @@ wander(void)
dir_mask &= ~(1 << i);
}
}
# endif
#endif
if (rel_dir == FRONT)
num_turns++;
else
num_turns = 0;
# ifdef DEBUG
#ifdef DEBUG
fprintf(debug, " w(%c)", RELCHARS[rel_dir]);
# endif
#endif
face_and_move_direction(rel_dir, 1);
}
# endif /* OTTO */
#endif /* OTTO */

View File

@ -1,101 +1,101 @@
/* $NetBSD: playit.c,v 1.11 2009/07/04 01:58:57 dholland Exp $ */
/* $NetBSD: playit.c,v 1.12 2009/07/04 05:01:16 dholland Exp $ */
/*
* Copyright (c) 1983-2003, Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* + Redistributions of source code must retain the above copyright
*
* + Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* + Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* + Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* + Neither the name of the University of California, San Francisco nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* + Neither the name of the University of California, San Francisco nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: playit.c,v 1.11 2009/07/04 01:58:57 dholland Exp $");
__RCSID("$NetBSD: playit.c,v 1.12 2009/07/04 05:01:16 dholland Exp $");
#endif /* not lint */
# include <sys/file.h>
# include <sys/poll.h>
# include <err.h>
# include <errno.h>
# include <curses.h>
# include <ctype.h>
# include <signal.h>
# if defined(HPUX) || (defined(BSD_RELEASE) && BSD_RELEASE >= 44)
# include <termios.h>
# include <unistd.h>
# endif
# include "hunt.h"
#include <sys/file.h>
#include <sys/poll.h>
#include <err.h>
#include <errno.h>
#include <curses.h>
#include <ctype.h>
#include <signal.h>
#if defined(HPUX) || (defined(BSD_RELEASE) && BSD_RELEASE >= 44)
#include <termios.h>
#include <unistd.h>
#endif
#include "hunt.h"
# ifndef FREAD
# define FREAD 1
# endif
#ifndef FREAD
#define FREAD 1
#endif
# if !defined(USE_CURSES) || !defined(TERMINFO)
# define beep() (void) putchar(CTRL('G'))
# endif
# if !defined(USE_CURSES)
# undef refresh
# define refresh() (void) fflush(stdout);
# endif
# ifdef USE_CURSES
# define clear_eol() clrtoeol()
# define put_ch addch
# define put_str addstr
# endif
#if !defined(USE_CURSES) || !defined(TERMINFO)
#define beep() (void) putchar(CTRL('G'))
#endif
#if !defined(USE_CURSES)
#undef refresh
#define refresh() (void) fflush(stdout);
#endif
#ifdef USE_CURSES
#define clear_eol() clrtoeol()
#define put_ch addch
#define put_str addstr
#endif
static int nchar_send;
# ifndef USE_CURSES
char screen[SCREEN_HEIGHT][SCREEN_WIDTH2], blanks[SCREEN_WIDTH];
int cur_row, cur_col;
# endif
# ifdef OTTO
int Otto_count;
int Otto_mode;
static int otto_y, otto_x;
static char otto_face;
# endif
static int nchar_send;
#ifndef USE_CURSES
char screen[SCREEN_HEIGHT][SCREEN_WIDTH2], blanks[SCREEN_WIDTH];
int cur_row, cur_col;
#endif
#ifdef OTTO
int Otto_count;
int Otto_mode;
static int otto_y, otto_x;
static char otto_face;
#endif
# define MAX_SEND 5
# define STDIN 0
#define MAX_SEND 5
#define STDIN 0
/*
* ibuf is the input buffer used for the stream from the driver.
* It is small because we do not check for user input when there
* are characters in the input buffer.
*/
static int icnt = 0;
static unsigned char ibuf[256], *iptr = ibuf;
static int icnt = 0;
static unsigned char ibuf[256], *iptr = ibuf;
#define GETCHR() (--icnt < 0 ? getchr() : *iptr++)
#define GETCHR() (--icnt < 0 ? getchr() : *iptr++)
#if !defined(BSD_RELEASE) || BSD_RELEASE < 44
extern int _putchar();
extern int _putchar();
#endif
static unsigned char getchr(void);
static void send_stuff(void);
static unsigned char getchr(void);
static void send_stuff(void);
/*
* playit:
@ -105,9 +105,9 @@ static void send_stuff(void);
void
playit(void)
{
int ch;
int y, x;
u_int32_t version;
int ch;
int y, x;
u_int32_t version;
if (read(Socket, &version, LONGLEN) != LONGLEN) {
bad_con();
@ -118,29 +118,29 @@ playit(void)
/* NOTREACHED */
}
errno = 0;
# ifdef OTTO
#ifdef OTTO
Otto_count = 0;
# endif
#endif
nchar_send = MAX_SEND;
while ((ch = GETCHR()) != EOF) {
# ifdef DEBUG
#ifdef DEBUG
fputc(ch, stderr);
# endif
#endif
switch (ch & 0377) {
case MOVE:
y = GETCHR();
x = GETCHR();
# ifdef USE_CURSES
#ifdef USE_CURSES
move(y, x);
# else
#else
mvcur(cur_row, cur_col, y, x);
cur_row = y;
cur_col = x;
# endif
#endif
break;
case ADDCH:
ch = GETCHR();
# ifdef OTTO
#ifdef OTTO
switch (ch) {
case '<':
@ -148,15 +148,15 @@ playit(void)
case '^':
case 'v':
otto_face = ch;
# ifdef USE_CURSES
#ifdef USE_CURSES
getyx(stdscr, otto_y, otto_x);
# else
#else
otto_y = cur_row;
otto_x = cur_col;
# endif
#endif
break;
}
# endif
#endif
put_ch(ch);
break;
case CLRTOEOL:
@ -184,31 +184,31 @@ playit(void)
case READY:
refresh();
if (nchar_send < 0)
# if defined(HPUX) || (defined(BSD_RELEASE) && BSD_RELEASE >= 44)
#if defined(HPUX) || (defined(BSD_RELEASE) && BSD_RELEASE >= 44)
tcflush(STDIN, TCIFLUSH);
# else
# ifndef TCFLSH
#else
#ifndef TCFLSH
(void) ioctl(STDIN, TIOCFLUSH, &in);
# else
#else
(void) ioctl(STDIN, TCFLSH, 0);
# endif
# endif
#endif
#endif
nchar_send = MAX_SEND;
# ifndef OTTO
#ifndef OTTO
(void) GETCHR();
# else
#else
Otto_count -= (GETCHR() & 0xff);
if (!Am_monitor) {
# ifdef DEBUG
#ifdef DEBUG
fputc('0' + Otto_count, stderr);
# endif
#endif
if (Otto_count == 0 && Otto_mode)
otto(otto_y, otto_x, otto_face);
}
# endif
#endif
break;
default:
# ifdef OTTO
#ifdef OTTO
switch (ch) {
case '<':
@ -216,15 +216,15 @@ playit(void)
case '^':
case 'v':
otto_face = ch;
# ifdef USE_CURSES
#ifdef USE_CURSES
getyx(stdscr, otto_y, otto_x);
# else
#else
otto_y = cur_row;
otto_x = cur_col;
# endif
#endif
break;
}
# endif
#endif
put_ch(ch);
break;
}
@ -243,8 +243,8 @@ out:
static unsigned char
getchr(void)
{
struct pollfd set[2];
int nfds;
struct pollfd set[2];
int nfds;
set[0].fd = Socket;
set[0].events = POLLIN;
@ -280,9 +280,9 @@ one_more_time:
static void
send_stuff(void)
{
int count;
char *sp, *nsp;
static char inp[sizeof Buf];
int count;
char *sp, *nsp;
static char inp[sizeof Buf];
count = read(STDIN, Buf, sizeof Buf);
if (count <= 0)
@ -306,9 +306,9 @@ send_stuff(void)
nsp++;
count = nsp - inp;
if (count) {
# ifdef OTTO
#ifdef OTTO
Otto_count += count;
# endif
#endif
nchar_send -= count;
if (nchar_send < 0)
count += nchar_send;
@ -323,21 +323,21 @@ send_stuff(void)
int
quit(int old_status)
{
int explain, ch;
int explain, ch;
if (Last_player)
return Q_QUIT;
# ifdef OTTO
#ifdef OTTO
if (Otto_mode)
return Q_CLOAK;
# endif
# ifdef USE_CURSES
#endif
#ifdef USE_CURSES
move(HEIGHT, 0);
# else
#else
mvcur(cur_row, cur_col, HEIGHT, 0);
cur_row = HEIGHT;
cur_col = 0;
# endif
#endif
put_str("Re-enter game [ynwo]? ");
clear_eol();
explain = FALSE;
@ -350,16 +350,16 @@ quit(int old_status)
else if (ch == 'o')
break;
else if (ch == 'n') {
# ifndef INTERNET
#ifndef INTERNET
return Q_QUIT;
# else
# ifdef USE_CURSES
#else
#ifdef USE_CURSES
move(HEIGHT, 0);
# else
#else
mvcur(cur_row, cur_col, HEIGHT, 0);
cur_row = HEIGHT;
cur_col = 0;
# endif
#endif
put_str("Write a parting message [yn]? ");
clear_eol();
refresh();
@ -371,22 +371,22 @@ quit(int old_status)
if (ch == 'n')
return Q_QUIT;
}
# endif
#endif
}
# ifdef INTERNET
#ifdef INTERNET
else if (ch == 'w') {
static char buf[WIDTH + WIDTH % 2];
char *cp, c;
static char buf[WIDTH + WIDTH % 2];
char *cp, c;
get_message:
c = ch; /* save how we got here */
# ifdef USE_CURSES
#ifdef USE_CURSES
move(HEIGHT, 0);
# else
#else
mvcur(cur_row, cur_col, HEIGHT, 0);
cur_row = HEIGHT;
cur_col = 0;
# endif
#endif
put_str("Message: ");
clear_eol();
refresh();
@ -395,42 +395,42 @@ get_message:
refresh();
if ((ch = getchar()) == '\n' || ch == '\r')
break;
# if defined(TERMINFO) || BSD_RELEASE >= 44
#if defined(TERMINFO) || BSD_RELEASE >= 44
if (ch == erasechar())
# else
#else
if (ch == _tty.sg_erase)
# endif
#endif
{
if (cp > buf) {
# ifdef USE_CURSES
#ifdef USE_CURSES
int y, x;
getyx(stdscr, y, x);
move(y, x - 1);
# else
#else
mvcur(cur_row, cur_col, cur_row,
cur_col - 1);
cur_col -= 1;
# endif
#endif
cp -= 1;
clear_eol();
}
continue;
}
# if defined(TERMINFO) || BSD_RELEASE >= 44
#if defined(TERMINFO) || BSD_RELEASE >= 44
else if (ch == killchar())
# else
#else
else if (ch == _tty.sg_kill)
# endif
#endif
{
# ifdef USE_CURSES
#ifdef USE_CURSES
int y, x;
getyx(stdscr, y, x);
move(y, x - (cp - buf));
# else
#else
mvcur(cur_row, cur_col, cur_row,
cur_col - (cp - buf));
cur_col -= cp - buf;
# endif
#endif
cp = buf;
clear_eol();
continue;
@ -447,7 +447,7 @@ get_message:
Send_message = buf;
return (c == 'w') ? old_status : Q_MESSAGE;
}
# endif
#endif
beep();
if (!explain) {
put_str("(Yes, No, Write message, or Options) ");
@ -455,18 +455,18 @@ get_message:
}
}
# ifdef USE_CURSES
#ifdef USE_CURSES
move(HEIGHT, 0);
# else
#else
mvcur(cur_row, cur_col, HEIGHT, 0);
cur_row = HEIGHT;
cur_col = 0;
# endif
# ifdef FLY
#endif
#ifdef FLY
put_str("Scan, Cloak, Flying, or Quit? ");
# else
#else
put_str("Scan, Cloak, or Quit? ");
# endif
#endif
clear_eol();
refresh();
explain = FALSE;
@ -477,26 +477,26 @@ get_message:
return Q_SCAN;
else if (ch == 'c')
return Q_CLOAK;
# ifdef FLY
#ifdef FLY
else if (ch == 'f')
return Q_FLY;
# endif
#endif
else if (ch == 'q')
return Q_QUIT;
beep();
if (!explain) {
# ifdef FLY
#ifdef FLY
put_str("[SCFQ] ");
# else
#else
put_str("[SCQ] ");
# endif
#endif
explain = TRUE;
}
refresh();
}
}
# ifndef USE_CURSES
#ifndef USE_CURSES
void
put_ch(char ch)
{
@ -521,17 +521,17 @@ put_str(char *s)
while (*s)
put_ch(*s++);
}
# endif
#endif
void
clear_the_screen(void)
{
# ifdef USE_CURSES
#ifdef USE_CURSES
clear();
move(0, 0);
refresh();
# else
int i;
#else
int i;
if (blanks[0] == '\0')
for (i = 0; i < SCREEN_WIDTH; i++)
@ -579,42 +579,42 @@ clear_eol(void)
}
memcpy(&screen[cur_row][cur_col], blanks, SCREEN_WIDTH - cur_col);
}
# endif
#endif
void
redraw_screen(void)
{
# ifdef USE_CURSES
#ifdef USE_CURSES
clearok(stdscr, TRUE);
touchwin(stdscr);
# else
int i;
# ifndef NOCURSES
static int first = 1;
#else
int i;
#ifndef NOCURSES
static int first = 1;
if (first) {
curscr = newwin(SCREEN_HEIGHT, SCREEN_WIDTH, 0, 0);
if (curscr == NULL)
errx(1, "Can't create curscr");
# if !defined(BSD_RELEASE) || BSD_RELEASE < 44
#if !defined(BSD_RELEASE) || BSD_RELEASE < 44
for (i = 0; i < SCREEN_HEIGHT; i++)
curscr->_y[i] = screen[i];
# endif
#endif
first = 0;
}
# if defined(BSD_RELEASE) && BSD_RELEASE >= 44
#if defined(BSD_RELEASE) && BSD_RELEASE >= 44
for (i = 0; i < SCREEN_HEIGHT; i++) {
int j;
int j;
for (j = 0; j < SCREEN_WIDTH; j++)
curscr->lines[i]->line[j].ch = screen[i][j];
}
curscr->cury = cur_row;
curscr->curx = cur_col;
# else
#else
curscr->_cury = cur_row;
curscr->_curx = cur_col;
# endif
#endif
clearok(curscr, TRUE);
touchwin(curscr);
wrefresh(curscr);
@ -639,7 +639,7 @@ redraw_screen(void)
void
do_message(void)
{
u_int32_t version;
u_int32_t version;
if (read(Socket, &version, LONGLEN) != LONGLEN) {
bad_con();
@ -649,11 +649,11 @@ do_message(void)
bad_ver();
/* NOTREACHED */
}
# ifdef INTERNET
#ifdef INTERNET
if (write(Socket, Send_message, strlen(Send_message)) < 0) {
bad_con();
/* NOTREACHED */
}
# endif
#endif
(void) close(Socket);
}