From e75ea4e8865601c2aa5e3dd329003f96f5883b3a Mon Sep 17 00:00:00 2001 From: xukl Date: Fri, 13 Apr 2018 19:38:13 +0800 Subject: [PATCH] Use patch file. --- README.md | 28 +- hunt.c | 1144 ---------------------------------------------- otto.c | 629 ------------------------- patch.c | 106 ----- patch.h | 125 ----- patch_file.patch | 161 +++++++ 6 files changed, 166 insertions(+), 2027 deletions(-) delete mode 100644 hunt.c delete mode 100644 otto.c delete mode 100644 patch.c delete mode 100644 patch.h create mode 100644 patch_file.patch diff --git a/README.md b/README.md index fb79820..dfd10ef 100644 --- a/README.md +++ b/README.md @@ -13,34 +13,16 @@ See [bsdgames](https://packages.debian.org/wheezy/bsdgames). ### Environments -You should have Cygwin on Windows or msys2 on Windows with the ``ncurses`` lib. +You should have Cygwin on Windows or msys2 on Windows with the ``ncurses-devel`` lib. -### Make - -Just get into the root directory of this repo and type `make`. - -## Contents - -patch.c at hunt/, hunt.c and otto.c at hunt/hunt. - - -### patch.h +### Apply patches -Included by **otto.c**. - -Some definations like `sigblock`, `sigmask`, etc, are added here. - -These code are copied from **glibc**. - - -### hunt.c - -Add check `ip->ifa_broadaddr` against `NULL`. +`patch -p0 < patch_file.patch` +### Make -### otto.c +Generate the makefile, then `make`. -Include ../patch.h. ## Run diff --git a/hunt.c b/hunt.c deleted file mode 100644 index fd91f6b..0000000 --- a/hunt.c +++ /dev/null @@ -1,1144 +0,0 @@ -/* $NetBSD: hunt.c,v 1.23 2004/11/05 21:30:32 dsl 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 - * met: - * - * + 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 - * 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 - * 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 - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#ifndef lint -__RCSID("$NetBSD: hunt.c,v 1.23 2004/11/05 21:30:32 dsl Exp $"); -#endif /* not lint */ - -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# if !defined(USE_CURSES) && defined(BSD_RELEASE) && BSD_RELEASE >= 44 -# include -static struct termios saved_tty; -# endif -# include -# include - -# 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(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 - -#ifndef MAXHOSTNAMELEN -#define MAXHOSTNAMELEN 256 -#endif - -FLAG Last_player = FALSE; -# ifdef MONITOR -FLAG Am_monitor = FALSE; -# endif - -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 - -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; - -static char name[NAMELEN]; -static char team = ' '; - -static int in_visual; - -extern int cur_row, cur_col; - -void dump_scores(SOCKET); -long env_init(long); -void fill_in_blanks(void); -void leave(int, const char *) __attribute__((__noreturn__)); -void leavex(int, const char *) __attribute__((__noreturn__)); -void fincurs(void); -int main(int, char *[]); -# ifdef INTERNET -SOCKET *list_drivers(void); -# endif - -extern int Otto_mode; -/* - * main: - * Main program for local process - */ -int -main(ac, av) - int ac; - char **av; -{ - char *term; - int c; - long enter_status; - - /* Revoke setgid privileges */ - setregid(getgid(), getgid()); - - enter_status = env_init((long) Q_CLOAK); - while ((c = getopt(ac, av, "Sbcfh:l:mn:op:qst:w:")) != -1) { - switch (c) { - case 'l': /* rsh compatibility */ - case 'n': - (void) strncpy(name, optarg, NAMELEN); - break; - case 't': - team = *optarg; - if (!isdigit((unsigned char)team)) { - warnx("Team names must be numeric"); - team = ' '; - } - break; - case 'o': -# ifndef OTTO - warnx("The -o flag is reserved for future use."); - goto usage; -# else - Otto_mode = TRUE; - break; -# endif - case 'm': -# ifdef MONITOR - Am_monitor = TRUE; -# else - warnx("The monitor was not compiled in."); -# endif - break; -# ifdef INTERNET - case 'S': - Show_scores = TRUE; - break; - case 'q': /* query whether hunt is running */ - Query_driver = TRUE; - break; - case 'w': - Send_message = optarg; - break; - case 'h': - Sock_host = optarg; - break; - case 'p': - use_port = optarg; - Test_port = atoi(use_port); - break; -# else - case 'S': - case 'q': - case 'w': - case 'h': - case 'p': - wanrx("Need TCP/IP for S, q, w, h, and p options."); - break; -# endif - case 'c': - enter_status = Q_CLOAK; - break; - case 'f': -# ifdef FLY - enter_status = Q_FLY; -# else - warnx("The flying code was not compiled in."); -# endif - break; - case 's': - enter_status = Q_SCAN; - break; - case 'b': - no_beep = !no_beep; - break; - default: - usage: - fputs( -"usage:\thunt [-qmcsfS] [-n name] [-t team] [-p port] [-w message] [host]\n", - stderr); - exit(1); - } - } -# ifdef INTERNET - if (optind + 1 < ac) - goto usage; - else if (optind + 1 == ac) - Sock_host = av[ac - 1]; -# else - if (optind > ac) - goto usage; -# endif - -# ifdef INTERNET - if (Show_scores) { - SOCKET *hosts; - - for (hosts = list_drivers(); hosts->sin_port != 0; hosts += 1) - dump_scores(*hosts); - exit(0); - } - if (Query_driver) { - SOCKET *hosts; - - for (hosts = list_drivers(); hosts->sin_port != 0; hosts += 1) { - struct hostent *hp; - int num_players; - - hp = gethostbyaddr((char *) &hosts->sin_addr, - sizeof hosts->sin_addr, AF_INET); - num_players = ntohs(hosts->sin_port); - printf("%d player%s hunting on %s!\n", - num_players, (num_players == 1) ? "" : "s", - hp != NULL ? hp->h_name : - inet_ntoa(hosts->sin_addr)); - } - exit(0); - } -# endif -# ifdef OTTO - if (Otto_mode) - (void) strncpy(name, "otto", NAMELEN); - else -# endif - fill_in_blanks(); - - (void) fflush(stdout); - if (!isatty(0) || (term = getenv("TERM")) == NULL) - errx(1, "no terminal type"); -# ifdef USE_CURSES - initscr(); - (void) noecho(); - (void) cbreak(); -# else /* !USE_CURSES */ -# if !defined(BSD_RELEASE) || BSD_RELEASE < 44 - _tty_ch = 0; -# endif - gettmode(); - (void) setterm(term); - (void) noecho(); - (void) cbreak(); -# if defined(BSD_RELEASE) && BSD_RELEASE >= 44 - tcgetattr(0, &saved_tty); -# endif - _puts(TI); - _puts(VS); -# endif /* !USE_CURSES */ - in_visual = TRUE; - if (LINES < SCREEN_HEIGHT || COLS < SCREEN_WIDTH) - leavex(1, "Need a larger window"); - clear_the_screen(); - (void) signal(SIGINT, intr); - (void) signal(SIGTERM, sigterm); - (void) signal(SIGUSR1, sigusr1); - (void) signal(SIGPIPE, SIG_IGN); -#if !defined(USE_CURSES) && defined(SIGTSTP) - (void) signal(SIGTSTP, tstp); -#endif - - for (;;) { -# ifdef INTERNET - find_driver(TRUE); - - if (Daemon.sin_port == 0) - leavex(1, "Game not found, try again"); - - jump_in: - do { - int option; - - Socket = socket(SOCK_FAMILY, SOCK_STREAM, 0); - if (Socket < 0) - err(1, "socket"); - option = 1; -#ifdef SO_USELOOPBACK - if (setsockopt(Socket, SOL_SOCKET, SO_USELOOPBACK, - &option, sizeof option) < 0) - warn("setsockopt loopback"); -#endif - errno = 0; - if (connect(Socket, (struct sockaddr *) &Daemon, - DAEMON_SIZE) < 0) { - if (errno != ECONNREFUSED) { - leave(1, "connect"); - } - } - else - break; - sleep(1); - } while (close(Socket) == 0); -# else /* !INTERNET */ - /* - * set up a socket - */ - - if ((Socket = socket(SOCK_FAMILY, SOCK_STREAM, 0)) < 0) - err(1, "socket"); - - /* - * attempt to connect the socket to a name; if it fails that - * usually means that the driver isn't running, so we start - * up the driver. - */ - - Daemon.sun_family = SOCK_FAMILY; - (void) strcpy(Daemon.sun_path, Sock_name); - if (connect(Socket, &Daemon, DAEMON_SIZE) < 0) { - if (errno != ENOENT) { - leavex(1, "connect2"); - } - start_driver(); - - do { - (void) close(Socket); - if ((Socket = socket(SOCK_FAMILY, SOCK_STREAM, - 0)) < 0) - err(1, "socket"); - sleep(2); - } while (connect(Socket, &Daemon, DAEMON_SIZE) < 0); - } -# endif - - do_connect(name, team, enter_status); -# ifdef INTERNET - if (Send_message != NULL) { - do_message(); - if (enter_status == Q_MESSAGE) - break; - Send_message = NULL; - /* don't continue as that will call find_driver */ - goto jump_in; - } -# endif - playit(); - if ((enter_status = quit(enter_status)) == Q_QUIT) - break; - } - leavex(0, (char *) NULL); - /* NOTREACHED */ - return(0); -} - -# ifdef INTERNET -# ifdef BROADCAST -int -broadcast_vec(s, vector) - int s; /* socket */ - struct sockaddr **vector; -{ - int vec_cnt; - struct ifaddrs *ifp, *ip; - - *vector = NULL; - if (getifaddrs(&ifp) < 0) - return 0; - - vec_cnt = 0; - for (ip = ifp; ip; ip = ip->ifa_next) - if ((ip->ifa_broadaddr != NULL) && - (ip->ifa_addr->sa_family == AF_INET) && - (ip->ifa_flags & IFF_BROADCAST)) - vec_cnt++; - - *vector = (struct sockaddr *) - malloc(vec_cnt * sizeof(struct sockaddr_in)); - if (*vector == NULL) - leave(1, "Out of memory!"); - - vec_cnt = 0; - for (ip = ifp; ip; ip = ip->ifa_next) - if ((ip->ifa_broadaddr != NULL) && - (ip->ifa_addr->sa_family == AF_INET) && - (ip->ifa_flags & IFF_BROADCAST)) - memcpy(&(*vector)[vec_cnt++], ip->ifa_broadaddr, - sizeof(struct sockaddr_in)); - - freeifaddrs(ifp); - return vec_cnt; -} -# endif - -SOCKET * -list_drivers() -{ - int option; - u_short msg; - u_short port_num; - static SOCKET test; - int test_socket; - int 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; - static SOCKET *listv; - static unsigned int listmax; - unsigned int listc; - struct pollfd set[1]; - - if (initial) { /* do one time initialization */ -# ifndef BROADCAST - sethostent(1); /* don't bother to close host file */ -# endif - if (gethostname(local_name, sizeof local_name) < 0) { - leavex(1, "Sorry, I have no name."); - /* NOTREACHED */ - } - local_name[sizeof(local_name) - 1] = '\0'; - if ((hp = gethostbyname(local_name)) == NULL) { - leavex(1, "Can't find myself."); - /* NOTREACHED */ - } - local_address = * ((struct in_addr *) hp->h_addr); - - listmax = 20; - listv = (SOCKET *) malloc(listmax * sizeof (SOCKET)); - if (listv == NULL) - leave(1, "Out of memory!"); - } else if (Sock_host != NULL) - return listv; /* address already valid */ - - test_socket = socket(SOCK_FAMILY, SOCK_DGRAM, 0); - if (test_socket < 0) { - leave(1, "socket system call failed"); - /* NOTREACHED */ - } - test.sin_family = SOCK_FAMILY; - test.sin_port = htons(Test_port); - listc = 0; - - if (Sock_host != NULL) { /* explicit host given */ - if ((hp = gethostbyname(Sock_host)) == NULL) { - leavex(1, "Unknown host"); - /* NOTREACHED */ - } - test.sin_addr = *((struct in_addr *) hp->h_addr); - goto test_one_host; - } - - if (!initial) { - /* favor host of previous session by broadcasting to it first */ - test.sin_addr = Daemon.sin_addr; - msg = htons(C_PLAYER); /* Must be playing! */ - (void) sendto(test_socket, (char *) &msg, sizeof msg, 0, - (struct sockaddr *) &test, DAEMON_SIZE); - } - -# ifdef BROADCAST - if (initial) - brdc = broadcast_vec(test_socket, (void *) &brdv); - -# 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, - &option, sizeof option) < 0) { - leave(1, "setsockopt broadcast"); - /* NOTREACHED */ - } -# endif - - /* send broadcast packets on all interfaces */ - msg = htons(C_TESTMSG()); - for (i = 0; i < brdc; i++) { - test.sin_addr = brdv[i].sin_addr; - if (sendto(test_socket, (char *) &msg, sizeof msg, 0, - (struct sockaddr *) &test, DAEMON_SIZE) < 0) { - leave(1, "sendto"); - /* NOTREACHED */ - } - } - test.sin_addr = local_address; - if (sendto(test_socket, (char *) &msg, sizeof msg, 0, - (struct sockaddr *) &test, DAEMON_SIZE) < 0) { - leave(1, "sendto"); - /* NOTREACHED */ - } -# else /* !BROADCAST */ - /* loop thru all hosts on local net and send msg to them. */ - msg = htons(C_TESTMSG()); - local_net = inet_netof(local_address); - sethostent(0); /* rewind host file */ - while (hp = gethostent()) { - if (local_net == inet_netof(* ((struct in_addr *) hp->h_addr))){ - test.sin_addr = * ((struct in_addr *) hp->h_addr); - (void) sendto(test_socket, (char *) &msg, sizeof msg, 0, - (struct sockaddr *) &test, DAEMON_SIZE); - } - } -# endif - -get_response: - namelen = DAEMON_SIZE; - errno = 0; - set[0].fd = test_socket; - set[0].events = POLLIN; - for (;;) { - if (listc + 1 >= listmax) { - listmax += 20; - listv = (SOCKET *) realloc((char *) listv, - listmax * sizeof(SOCKET)); - if (listv == NULL) - leave(1, "Out of memory!"); - } - - if (poll(set, 1, 1000) == 1 && - recvfrom(test_socket, (char *) &port_num, sizeof(port_num), - 0, (struct sockaddr *) &listv[listc], &namelen) > 0) { - /* - * Note that we do *not* convert from network to host - * order since the port number *should* be in network - * order: - */ - for (i = 0; (unsigned)i < listc; i += 1) - if (listv[listc].sin_addr.s_addr - == listv[i].sin_addr.s_addr) - break; - if ((unsigned)i == listc) - listv[listc++].sin_port = port_num; - continue; - } - - if (errno != 0 && errno != EINTR) { - leave(1, "poll/recvfrom"); - /* NOTREACHED */ - } - - /* terminate list with local address */ - listv[listc].sin_family = SOCK_FAMILY; - listv[listc].sin_addr = local_address; - listv[listc].sin_port = htons(0); - - (void) close(test_socket); - initial = FALSE; - return listv; - } - -test_one_host: - msg = htons(C_TESTMSG()); - (void) sendto(test_socket, (char *) &msg, sizeof msg, 0, - (struct sockaddr *) &test, DAEMON_SIZE); - goto get_response; -} - -void -find_driver(do_startup) - FLAG do_startup; -{ - SOCKET *hosts; - - hosts = list_drivers(); - if (hosts[0].sin_port != htons(0)) { - int i, c; - - if (hosts[1].sin_port == htons(0)) { - Daemon = hosts[0]; - return; - } - /* go thru list and return host that matches daemon */ - clear_the_screen(); -# ifdef USE_CURSES - move(1, 0); -# else - mvcur(cur_row, cur_col, 1, 0); - cur_row = 1; - cur_col = 0; -# 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]; - -# ifdef USE_CURSES - move(3 + i, 0); -# else - mvcur(cur_row, cur_col, 3 + i, 0); - cur_row = 3 + i; - cur_col = 0; -# endif - hp = gethostbyaddr((char *) &hosts[i].sin_addr, - sizeof hosts[i].sin_addr, AF_INET); - (void) sprintf(buf, "%8c %.64s", 'a' + i, - hp != NULL ? hp->h_name - : inet_ntoa(hosts->sin_addr)); - put_str(buf); - } -# ifdef USE_CURSES - move(4 + i, 0); -# else - mvcur(cur_row, cur_col, 4 + i, 0); - cur_row = 4 + i; - cur_col = 0; -# endif - put_str("Enter letter: "); - refresh(); - while (!islower(c = getchar()) || (c -= 'a') >= i) { - beep(); - refresh(); - } - Daemon = hosts[c]; - clear_the_screen(); - return; - } - if (!do_startup) - return; - - start_driver(); - sleep(2); - find_driver(FALSE); -} - -void -dump_scores(host) - SOCKET host; -{ - struct hostent *hp; - int s; - char buf[BUFSIZ]; - int cnt; - - hp = gethostbyaddr((char *) &host.sin_addr, sizeof host.sin_addr, - AF_INET); - printf("\n%s:\n", hp != NULL ? hp->h_name : inet_ntoa(host.sin_addr)); - fflush(stdout); - - s = socket(SOCK_FAMILY, SOCK_STREAM, 0); - if (s < 0) - err(1, "socket"); - if (connect(s, (struct sockaddr *) &host, sizeof host) < 0) - err(1, "connect"); - while ((cnt = read(s, buf, BUFSIZ)) > 0) - write(fileno(stdout), buf, cnt); - (void) close(s); -} - -# endif - -void -start_driver() -{ - int procid; - -# ifdef MONITOR - if (Am_monitor) { - leavex(1, "No one playing."); - /* NOTREACHED */ - } -# endif - -# ifdef INTERNET - if (Sock_host != NULL) { - sleep(3); - return; - } -# endif - -# ifdef USE_CURSES - move(HEIGHT, 0); -# else - mvcur(cur_row, cur_col, HEIGHT, 0); - cur_row = HEIGHT; - cur_col = 0; -# endif - put_str("Starting..."); - refresh(); - procid = fork(); - if (procid == -1) { - leave(1, "fork failed."); - } - if (procid == 0) { - (void) signal(SIGINT, SIG_IGN); -# ifndef INTERNET - (void) close(Socket); -# else - if (use_port == NULL) -# endif - execl(Driver, "HUNT", (char *) NULL); -# ifdef INTERNET - else - execl(Driver, "HUNT", "-p", use_port, (char *) NULL); -# endif - /* only get here if exec failed */ - (void) kill(getppid(), SIGUSR1); /* tell mom */ - _exit(1); - } -# ifdef USE_CURSES - move(HEIGHT, 0); -# else - mvcur(cur_row, cur_col, HEIGHT, 0); - cur_row = HEIGHT; - cur_col = 0; -# endif - put_str("Connecting..."); - refresh(); -} - -/* - * bad_con: - * We had a bad connection. For the moment we assume that this - * means the game is full. - */ -void -bad_con() -{ - leavex(1, "The game is full. Sorry."); - /* NOTREACHED */ -} - -/* - * bad_ver: - * version number mismatch. - */ -void -bad_ver() -{ - leavex(1, "Version number mismatch. No go."); - /* NOTREACHED */ -} - -/* - * sigterm: - * Handle a terminate signal - */ -SIGNAL_TYPE -sigterm(dummy) - int dummy __attribute__((__unused__)); -{ - leavex(0, (char *) NULL); - /* NOTREACHED */ -} - - -/* - * sigusr1: - * Handle a usr1 signal - */ -SIGNAL_TYPE -sigusr1(dummy) - int dummy __attribute__((__unused__)); -{ - leavex(1, "Unable to start driver. Try again."); - /* NOTREACHED */ -} - -# ifdef INTERNET -/* - * sigalrm: - * Handle an alarm signal - */ -SIGNAL_TYPE -sigalrm(dummy) - int dummy __attribute__((__unused__)); -{ - return; -} -# endif - -/* - * rmnl: - * Remove a '\n' at the end of a string if there is one - */ -void -rmnl(s) - char *s; -{ - char *cp; - - cp = strrchr(s, '\n'); - if (cp != NULL) - *cp = '\0'; -} - -/* - * intr: - * Handle a interrupt signal - */ -SIGNAL_TYPE -intr(dummy) - int dummy __attribute__((__unused__)); -{ - int ch; - int explained; - int y, x; - - (void) signal(SIGINT, SIG_IGN); -# ifdef USE_CURSES - getyx(stdscr, y, x); - move(HEIGHT, 0); -# else - y = cur_row; - x = cur_col; - mvcur(cur_row, cur_col, HEIGHT, 0); - cur_row = HEIGHT; - cur_col = 0; -# endif - put_str("Really quit? "); - clear_eol(); - refresh(); - explained = FALSE; - for (;;) { - ch = getchar(); - if (isupper(ch)) - ch = tolower(ch); - if (ch == 'y') { - if (Socket != 0) { - (void) write(Socket, "q", 1); - (void) close(Socket); - } - leavex(0, (char *) NULL); - } - else if (ch == 'n') { - (void) signal(SIGINT, intr); -# ifdef USE_CURSES - move(y, x); -# else - mvcur(cur_row, cur_col, y, x); - cur_row = y; - cur_col = x; -# endif - refresh(); - return; - } - if (!explained) { - put_str("(Yes or No) "); - refresh(); - explained = TRUE; - } - beep(); - refresh(); - } -} - -void fincurs() -{ - if (in_visual) { -# ifdef USE_CURSES - move(HEIGHT, 0); - refresh(); - endwin(); -# 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 - tcsetattr(0, TCSADRAIN, &__orig_termios); -# else - resetty(); -# endif - _puts(VE); - _puts(TE); -# endif /* !USE_CURSES */ - } -} - -/* - * leave: - * Leave the game somewhat gracefully, restoring all current - * tty stats. - */ -void -leave(eval, mesg) - int eval; - const char *mesg; -{ - int serrno = errno; - fincurs(); - errno = serrno; - err(eval, mesg ? mesg : ""); -} - -/* - * leave: - * Leave the game somewhat gracefully, restoring all current - * tty stats. - */ -void -leavex(eval, mesg) - int eval; - const char *mesg; -{ - fincurs(); - errx(eval, mesg ? mesg : ""); -} - -#if !defined(USE_CURSES) && defined(SIGTSTP) -/* - * tstp: - * Handle stop and start signals - */ -SIGNAL_TYPE -tstp(dummy) - int dummy; -{ -# 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 - tty = _tty; -# endif - _puts(VE); - _puts(TE); - (void) fflush(stdout); -# if defined(BSD_RELEASE) && BSD_RELEASE >= 44 - tcsetattr(0, TCSADRAIN, &__orig_termios); -# else - resetty(); -# endif - (void) kill(getpid(), SIGSTOP); - (void) signal(SIGTSTP, tstp); -# if defined(BSD_RELEASE) && BSD_RELEASE >= 44 - tcsetattr(0, TCSADRAIN, &saved_tty); -# else - _tty = tty; - ioctl(_tty_ch, TIOCSETP, &_tty); -# endif - _puts(TI); - _puts(VS); - cur_row = y; - cur_col = x; - _puts(tgoto(CM, cur_row, cur_col)); - redraw_screen(); - (void) fflush(stdout); -} -#endif /* !defined(USE_CURSES) && defined(SIGTSTP) */ - -# if defined(BSD_RELEASE) && BSD_RELEASE < 43 -char * -strpbrk(s, brk) - char *s, *brk; -{ - char *p; - c; - - while (c = *s) { - for (p = brk; *p; p++) - if (c == *p) - return (s); - s++; - } - return (0); -} -# endif - -long -env_init(enter_status) - long enter_status; -{ - int i; - char *envp, *envname, *s; - - for (i = 0; i < 256; i++) - map_key[i] = (char) i; - - envname = NULL; - if ((envp = getenv("HUNT")) != NULL) { - while ((s = strpbrk(envp, "=,")) != NULL) { - if (strncmp(envp, "cloak,", s - envp + 1) == 0) { - enter_status = Q_CLOAK; - envp = s + 1; - } - else if (strncmp(envp, "scan,", s - envp + 1) == 0) { - enter_status = Q_SCAN; - envp = s + 1; - } - else if (strncmp(envp, "fly,", s - envp + 1) == 0) { - enter_status = Q_FLY; - envp = s + 1; - } - else if (strncmp(envp, "nobeep,", s - envp + 1) == 0) { - no_beep = TRUE; - envp = s + 1; - } - else if (strncmp(envp, "name=", s - envp + 1) == 0) { - envname = s + 1; - if ((s = strchr(envp, ',')) == NULL) { - *envp = '\0'; - strncpy(name, envname, NAMELEN); - break; - } - *s = '\0'; - strncpy(name, envname, NAMELEN); - envp = s + 1; - } -# ifdef INTERNET - else if (strncmp(envp, "port=", s - envp + 1) == 0) { - use_port = s + 1; - Test_port = atoi(use_port); - if ((s = strchr(envp, ',')) == NULL) { - *envp = '\0'; - break; - } - *s = '\0'; - envp = s + 1; - } - else if (strncmp(envp, "host=", s - envp + 1) == 0) { - Sock_host = s + 1; - if ((s = strchr(envp, ',')) == NULL) { - *envp = '\0'; - break; - } - *s = '\0'; - envp = s + 1; - } - else if (strncmp(envp, "message=", s - envp + 1) == 0) { - Send_message = s + 1; - if ((s = strchr(envp, ',')) == NULL) { - *envp = '\0'; - break; - } - *s = '\0'; - envp = s + 1; - } -# endif - else if (strncmp(envp, "team=", s - envp + 1) == 0) { - team = *(s + 1); - if (!isdigit((unsigned char)team)) - team = ' '; - if ((s = strchr(envp, ',')) == NULL) { - *envp = '\0'; - break; - } - *s = '\0'; - envp = s + 1; - } /* must be last option */ - else if (strncmp(envp, "mapkey=", s - envp + 1) == 0) { - for (s = s + 1; *s != '\0'; s += 2) { - map_key[(unsigned int) *s] = *(s + 1); - if (*(s + 1) == '\0') { - break; - } - } - *envp = '\0'; - break; - } else { - *s = '\0'; - printf("unknown option %s\n", envp); - if ((s = strchr(envp, ',')) == NULL) { - *envp = '\0'; - break; - } - envp = s + 1; - } - } - if (*envp != '\0') { - if (envname == NULL) - strncpy(name, envp, NAMELEN); - else - printf("unknown option %s\n", envp); - } - } - return enter_status; -} - -void -fill_in_blanks() -{ - int i; - char *cp; - -again: - if (name[0] != '\0') { - printf("Entering as '%s'", name); - if (team != ' ') - printf(" on team %c.\n", team); - else - putchar('\n'); - } else { - printf("Enter your code name: "); - if (fgets(name, NAMELEN, stdin) == NULL) - exit(1); - } - rmnl(name); - if (name[0] == '\0') { - name[0] = '\0'; - printf("You have to have a code name!\n"); - goto again; - } - for (cp = name; *cp != '\0'; cp++) - if (!isprint((unsigned char)*cp)) { - name[0] = '\0'; - printf("Illegal character in your code name.\n"); - goto again; - } - if (team == ' ') { - printf("Enter your team (0-9 or nothing): "); - i = getchar(); - if (isdigit(i)) - team = i; - while (i != '\n' && i != EOF) - i = getchar(); - } -} diff --git a/otto.c b/otto.c deleted file mode 100644 index 352296e..0000000 --- a/otto.c +++ /dev/null @@ -1,629 +0,0 @@ -/* $NetBSD: otto.c,v 1.8 2004/11/05 21:30:32 dsl 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 - * met: - * - * + 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 - * 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 - * 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 - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * otto - a hunt otto-matic player - * - * This guy is buggy, unfair, stupid, and not extensible. - * Future versions of hunt will have a subroutine library for - * automatic players to link to. If you write your own "otto" - * please let us know what subroutines you would expect in the - * subroutine library. - * - * Id: otto.c,v 1.14 2003/04/16 06:11:54 gregc Exp - */ - -#include -#ifndef lint -__RCSID("$NetBSD: otto.c,v 1.8 2004/11/05 21:30:32 dsl Exp $"); -#endif /* not lint */ - -# include -# include -# include -# include -# include -# include -# include "hunt.h" -# include "./../patch.h" - -# undef WALL -# undef NORTH -# undef SOUTH -# undef WEST -# undef EAST -# undef FRONT -# undef LEFT -# undef BACK -# undef RIGHT - -# 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 DEBUG -# define STATIC static -# else -# define STATIC -# endif - -# define OPPONENT "{}i!" -# define PROPONENT "^v<>" -# define WALL "+\\/#*-|" -# define PUSHOVER " bg;*#&" -# define SHOTS "$@Oo:" - -/* number of "directions" */ -# define NUMDIRECTIONS 4 - -/* absolute directions (facings) - counterclockwise */ -# 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 ABSCHARS "NWSE" -# define RELCHARS "FLBR" -# define DIRKEYS "khjl" - -STATIC char command[BUFSIZ]; -STATIC int comlen; - -# 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 - -struct item { - char what; - int distance; - int flags; -}; - -STATIC struct item flbr[NUMDIRECTIONS]; - -# 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 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; - -STATIC SIGNAL_TYPE -nothing(dummy) - int dummy __attribute__((__unused__)); -{ -} - -void -otto(y, x, face) - int y, x; - char face; -{ - int i; - int old_mask; - -# ifdef DEBUG - if (debug == NULL) { - debug = fopen("bug", "w"); - setbuf(debug, NULL); - } - fprintf(debug, "\n%c(%d,%d)", face, y, x); -# endif - (void) signal(SIGALRM, nothing); - old_mask = sigblock(sigmask(SIGALRM)); - setitimer(ITIMER_REAL, &pause_time, NULL); - sigpause(old_mask); - sigsetmask(old_mask); - - /* 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(); - } - row = y; col = x; - been_there[row][col] |= 1 << facing; - - /* initially no commands to be sent */ - comlen = 0; - - /* find something to do */ - look_around(); - for (i = 0; i < NUMDIRECTIONS; i++) { - if (strchr(OPPONENT, flbr[i].what) != NULL) { - attack(i, &flbr[i]); - memset(been_there, 0, sizeof been_there); - goto done; - } - } - - if (strchr(SHOTS, bitem.what) != NULL && !(bitem.what & ON_SIDE)) { - duck(BACK); - memset(been_there, 0, sizeof been_there); -# 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 - } else if (go_for_ammo(GMINE)) - memset(been_there, 0, sizeof been_there); - else if (go_for_ammo(MINE)) - memset(been_there, 0, sizeof been_there); - else - wander(); - -done: - (void) write(Socket, command, comlen); - Otto_count += comlen; -# ifdef DEBUG - (void) fwrite(command, 1, comlen, debug); -# endif -} - -# define direction(abs,rel) (((abs) + (rel)) % NUMDIRECTIONS) - -STATIC int -stop_look(itemp, c, dist, side) - struct item *itemp; - char c; - int dist; - int side; -{ - switch (c) { - - case SPACE: - if (side) - itemp->flags &= ~DEADEND; - return 0; - - case MINE: - case GMINE: -# ifdef BOOTS - case BOOT: - case BOOT_PAIR: -# endif - if (itemp->distance == -1) { - itemp->distance = dist; - itemp->what = c; - if (side < 0) - itemp->flags |= ON_LEFT; - else if (side > 0) - itemp->flags |= ON_RIGHT; - } - return 0; - - case SHOT: - case GRENADE: - case SATCHEL: - case BOMB: -# ifdef OOZE - case SLIME: -# endif - if (itemp->distance == -1 || (!side - && (itemp->flags & ON_SIDE - || itemp->what == GMINE || itemp->what == MINE))) { - itemp->distance = dist; - itemp->what = c; - itemp->flags &= ~ON_SIDE; - if (side < 0) - itemp->flags |= ON_LEFT; - else if (side > 0) - itemp->flags |= ON_RIGHT; - } - return 0; - - case '{': - case '}': - case 'i': - case '!': - itemp->distance = dist; - itemp->what = c; - itemp->flags &= ~(ON_SIDE|DEADEND); - if (side < 0) - itemp->flags |= ON_LEFT; - else if (side > 0) - itemp->flags |= ON_RIGHT; - return 1; - - default: - /* a wall or unknown object */ - if (side) - return 0; - if (itemp->distance == -1) { - itemp->distance = dist; - itemp->what = c; - } - return 1; - } -} - -STATIC void -ottolook(rel_dir, itemp) - int rel_dir; - struct item *itemp; -{ - int r, c; - char ch; - - r = 0; - itemp->what = 0; - itemp->distance = -1; - itemp->flags = DEADEND|BEEN; /* true until proven false */ - - switch (direction(facing, rel_dir)) { - - case NORTH: - if (been_there[row - 1][col] & NORTH) - itemp->flags |= BEEN_SAME; - for (r = row - 1; r >= 0; r--) - for (c = col - 1; c < col + 2; c++) { - ch = SCREEN(r, c); - if (stop_look(itemp, ch, row - r, c - col)) - goto cont_north; - if (c == col && !been_there[r][c]) - itemp->flags &= ~BEEN; - } - cont_north: - if (itemp->flags & DEADEND) { - itemp->flags |= BEEN; - been_there[r][col] |= NORTH; - for (r = row - 1; r > row - itemp->distance; r--) - been_there[r][col] = ALLDIRS; - } - break; - - case SOUTH: - if (been_there[row + 1][col] & SOUTH) - itemp->flags |= BEEN_SAME; - for (r = row + 1; r < HEIGHT; r++) - for (c = col - 1; c < col + 2; c++) { - ch = SCREEN(r, c); - if (stop_look(itemp, ch, r - row, col - c)) - goto cont_south; - if (c == col && !been_there[r][c]) - itemp->flags &= ~BEEN; - } - cont_south: - if (itemp->flags & DEADEND) { - itemp->flags |= BEEN; - been_there[r][col] |= SOUTH; - for (r = row + 1; r < row + itemp->distance; r++) - been_there[r][col] = ALLDIRS; - } - break; - - case WEST: - if (been_there[row][col - 1] & WEST) - itemp->flags |= BEEN_SAME; - for (c = col - 1; c >= 0; c--) - for (r = row - 1; r < row + 2; r++) { - ch = SCREEN(r, c); - if (stop_look(itemp, ch, col - c, row - r)) - goto cont_west; - if (r == row && !been_there[r][c]) - itemp->flags &= ~BEEN; - } - cont_west: - if (itemp->flags & DEADEND) { - itemp->flags |= BEEN; - been_there[r][col] |= WEST; - for (c = col - 1; c > col - itemp->distance; c--) - been_there[row][c] = ALLDIRS; - } - break; - - case EAST: - if (been_there[row][col + 1] & EAST) - itemp->flags |= BEEN_SAME; - for (c = col + 1; c < WIDTH; c++) - for (r = row - 1; r < row + 2; r++) { - ch = SCREEN(r, c); - if (stop_look(itemp, ch, c - col, r - row)) - goto cont_east; - if (r == row && !been_there[r][c]) - itemp->flags &= ~BEEN; - } - cont_east: - if (itemp->flags & DEADEND) { - itemp->flags |= BEEN; - been_there[r][col] |= EAST; - for (c = col + 1; c < col + itemp->distance; c++) - been_there[row][c] = ALLDIRS; - } - break; - - default: - abort(); - } -} - -STATIC void -look_around() -{ - int i; - - for (i = 0; i < NUMDIRECTIONS; i++) { - ottolook(i, &flbr[i]); -# ifdef DEBUG - fprintf(debug, " ottolook(%c)=%c(%d)(0x%x)", - RELCHARS[i], flbr[i].what, flbr[i].distance, flbr[i].flags); -# endif - } -} - -/* - * as a side effect modifies facing and location (row, col) - */ - -STATIC void -face_and_move_direction(rel_dir, distance) - int rel_dir, distance; -{ - 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]; - - command[comlen++] = toupper((unsigned char)cmd); - if (distance == 0) { - /* rotate ottolook's to be in right position */ - for (i = 0; i < NUMDIRECTIONS; i++) - items[i] = - flbr[(i + old_facing) % NUMDIRECTIONS]; - memcpy(flbr, items, sizeof flbr); - } - } - while (distance--) { - command[comlen++] = cmd; - switch (facing) { - - case NORTH: row--; break; - case WEST: col--; break; - case SOUTH: row++; break; - case EAST: col++; break; - } - if (distance == 0) - look_around(); - } -} - -STATIC void -attack(rel_dir, itemp) - int rel_dir; - struct item *itemp; -{ - if (!(itemp->flags & ON_SIDE)) { - face_and_move_direction(rel_dir, 0); - command[comlen++] = 'o'; - command[comlen++] = 'o'; - duck(FRONT); - command[comlen++] = ' '; - } else if (itemp->distance > 1) { - face_and_move_direction(rel_dir, 2); - duck(FRONT); - } else { - face_and_move_direction(rel_dir, 1); - if (itemp->flags & ON_LEFT) - rel_dir = LEFT; - else - rel_dir = RIGHT; - (void) face_and_move_direction(rel_dir, 0); - command[comlen++] = 'f'; - command[comlen++] = 'f'; - duck(FRONT); - command[comlen++] = ' '; - } -} - -STATIC void -duck(rel_dir) - int rel_dir; -{ - int dir; - - switch (dir = direction(facing, rel_dir)) { - - case NORTH: - case SOUTH: - if (strchr(PUSHOVER, SCREEN(row, col - 1)) != NULL) - command[comlen++] = 'h'; - else if (strchr(PUSHOVER, SCREEN(row, col + 1)) != NULL) - command[comlen++] = 'l'; - else if (dir == NORTH - && strchr(PUSHOVER, SCREEN(row + 1, col)) != NULL) - command[comlen++] = 'j'; - else if (dir == SOUTH - && strchr(PUSHOVER, SCREEN(row - 1, col)) != NULL) - command[comlen++] = 'k'; - else if (dir == NORTH) - command[comlen++] = 'k'; - else - command[comlen++] = 'j'; - break; - - case WEST: - case EAST: - if (strchr(PUSHOVER, SCREEN(row - 1, col)) != NULL) - command[comlen++] = 'k'; - else if (strchr(PUSHOVER, SCREEN(row + 1, col)) != NULL) - command[comlen++] = 'j'; - else if (dir == WEST - && strchr(PUSHOVER, SCREEN(row, col + 1)) != NULL) - command[comlen++] = 'l'; - else if (dir == EAST - && strchr(PUSHOVER, SCREEN(row, col - 1)) != NULL) - command[comlen++] = 'h'; - else if (dir == WEST) - command[comlen++] = 'h'; - else - command[comlen++] = 'l'; - break; - } -} - -/* - * go for the closest mine if possible - */ - -STATIC int -go_for_ammo(mine) - char mine; -{ - int i, rel_dir, dist; - - rel_dir = -1; - dist = WIDTH; - for (i = 0; i < NUMDIRECTIONS; i++) { - if (flbr[i].what == mine && flbr[i].distance < dist) { - rel_dir = i; - dist = flbr[i].distance; - } - } - if (rel_dir == -1) - return FALSE; - - if (!(flbr[rel_dir].flags & ON_SIDE) - || flbr[rel_dir].distance > 1) { - if (dist > 4) - dist = 4; - face_and_move_direction(rel_dir, dist); - } else - return FALSE; /* until it's done right */ - return TRUE; -} - -STATIC void -wander() -{ - int i, j, rel_dir, dir_mask, dir_count; - - for (i = 0; i < NUMDIRECTIONS; i++) - if (!(flbr[i].flags & BEEN) || flbr[i].distance <= 1) - break; - if (i == NUMDIRECTIONS) - memset(been_there, 0, sizeof been_there); - dir_mask = dir_count = 0; - for (i = 0; i < NUMDIRECTIONS; i++) { - j = (RIGHT + i) % NUMDIRECTIONS; - if (flbr[j].distance <= 1 || flbr[j].flags & DEADEND) - continue; - if (!(flbr[j].flags & BEEN_SAME)) { - dir_mask = 1 << j; - dir_count = 1; - break; - } - if (j == FRONT - && num_turns > 4 + (random() % - ((flbr[FRONT].flags & BEEN) ? 7 : HEIGHT))) - continue; - dir_mask |= 1 << j; -# ifdef notdef - dir_count++; -# else - dir_count = 1; - break; -# endif - } - if (dir_count == 0) { - duck(random() % NUMDIRECTIONS); - num_turns = 0; - return; - } else if (dir_count == 1) - rel_dir = ffs(dir_mask) - 1; - else { - rel_dir = ffs(dir_mask) - 1; - dir_mask &= ~(1 << rel_dir); - while (dir_mask != 0) { - i = ffs(dir_mask) - 1; - if (random() % 5 == 0) - rel_dir = i; - dir_mask &= ~(1 << i); - } - } - if (rel_dir == FRONT) - num_turns++; - else - num_turns = 0; - -# ifdef DEBUG - fprintf(debug, " w(%c)", RELCHARS[rel_dir]); -# endif - face_and_move_direction(rel_dir, 1); -} - -# endif /* OTTO */ diff --git a/patch.c b/patch.c deleted file mode 100644 index 9c71089..0000000 --- a/patch.c +++ /dev/null @@ -1,106 +0,0 @@ -#include -#include -int __set_errno(int mask) -{ - errno = mask; - return -1; -} - -# define __sigmask(sig) (((__sigset_t) 1) << ((sig) - 1)) - -#define __sigemptyset(set) \ - (__extension__ ({ \ - *(set) = (__sigset_t) 0; \ - 0; \ - })) -#define __sigfillset(set) \ - (__extension__ ({ \ - *(set) = ~(__sigset_t) 0; \ - 0; \ - })) - -# define __sigisemptyset(set) \ - (*(set) == (__sigset_t) 0) - -# define __sigandset(dest, left, right) \ - (__extension__ ({ \ - *(dest) = *(left) & *(right); \ - 0; \ - })) - -# define __sigorset(dest, left, right) \ - (__extension__ ({ \ - *(dest) = *(left) | *(right); \ - 0; \ - })) - -# define __sigismember(set, sig) \ - (__extension__ ({ \ - __sigset_t __mask = __sigmask (sig); \ - *(set) & __mask ? 1 : 0; \ - })) - -# define __sigaddset(set, sig) \ - (__extension__ ({ \ - __sigset_t __mask = __sigmask (sig); \ - *(set) |= __mask; \ - 0; \ - })) - -# define __sigdelset(set, sig) \ - (__extension__ ({ \ - __sigset_t __mask = __sigmask (sig); \ - *(set) &= ~__mask; \ - 0; \ - })) - -static inline int __attribute__ ((unused)) -sigset_set_old_mask (sigset_t *set, int mask) -{ - if (sizeof (__sigset_t) == sizeof (unsigned int)) - *set = (unsigned int) mask; - else - { - unsigned int __sig; - - if (__sigemptyset (set) < 0) - return -1; - - for (__sig = 1; __sig < NSIG && __sig <= sizeof (mask) * 8; __sig++) - if (mask & sigmask (__sig)) - if (__sigaddset (set, __sig) < 0) - return -1; - } - return 0; -} -static inline int __attribute__ ((unused)) -sigset_get_old_mask (const sigset_t *set) -{ - if (sizeof (sigset_t) == sizeof (unsigned int)) - return (unsigned int) *set; - else - { - unsigned int mask = 0; - unsigned int sig; - - for (sig = 1; sig < NSIG && sig <= sizeof (mask) * 8; sig++) - if (__sigismember (set, sig)) - mask |= sigmask (sig); - - return mask; - } -} -int sigblock(int mask) -{ - sigset_t set, oset; - if (sigset_set_old_mask (&set, mask) < 0) return -1; - if (sigprocmask (SIG_BLOCK, &set, &oset) < 0) return -1; - return sigset_get_old_mask(&oset); -} -int sigsetmask(int mask) -{ - sigset_t set, oset; - if (sigset_set_old_mask (&set, mask) < 0) return -1; - if (sigprocmask (SIG_SETMASK, &set, &oset) < 0) return -1; - return sigset_get_old_mask (&oset); -} diff --git a/patch.h b/patch.h deleted file mode 100644 index 3c7c7d1..0000000 --- a/patch.h +++ /dev/null @@ -1,125 +0,0 @@ -#include - -/* sysdeps/generic/sigset-cvt-mask.h */ -static inline int __attribute__ ((unused)) - sigset_set_old_mask(sigset_t *, int); -static inline int __attribute__ ((unused)) - sigset_get_old_mask(const sigset_t *); -/* sysdeps/posix/sigblock.c */ -int __sigblock(int); -/* sysdeps/posix/sigsetmask.c */ -int __sigsetmask(int); - -/* include/libc-symbols.h */ -/* Define ALIASNAME as a weak alias for NAME. - If weak aliases are not available, this defines a strong alias. */ -# define weak_alias(name, aliasname) _weak_alias (name, aliasname) -# define _weak_alias(name, aliasname) \ - extern __typeof (name) aliasname __attribute__ ((weak, alias (#name))); - -/* signal/signal.h */ -/* Compute mask for signal SIG. */ -# define sigmask(sig) ((int)(1u << ((sig) - 1))) - -/* sysdeps/generic/sigsetops.h */ -#define __sigemptyset(set) \ - (__extension__ ({ \ - *(set) = (__sigset_t) 0; \ - 0; \ - })) - -/* These macros needn't check for a bogus signal number; - checking is done in the non-__ versions. */ -# define __sigismember(set, sig) \ - (__extension__ ({ \ - __sigset_t __mask = sigmask (sig); \ - (*(set) & __mask) ? 1 : 0; \ - })) - -# define __sigaddset(set, sig) \ - (__extension__ ({ \ - __sigset_t __mask = sigmask (sig); \ - *(set) |= __mask; \ - 0; \ - })) - -/* sysdeps/generic/sigset-cvt-mask.h */ -/* Convert between an old-style 32-bit signal mask and a POSIX sigset_t. */ - -/* Perform *SET = MASK. Unused bits of *SET are set to 0. - Returns zero for success or -1 for errors (from sigaddset/sigemptyset). */ -static inline int __attribute__ ((unused)) -sigset_set_old_mask (sigset_t *set, int mask) -{ - if (sizeof (__sigset_t) == sizeof (unsigned int)) - *set = (unsigned int) mask; - else - { - unsigned int __sig; - - if (__sigemptyset (set) < 0) - return -1; - - for (__sig = 1; __sig < NSIG && __sig <= sizeof (mask) * 8; __sig++) - if (mask & sigmask (__sig)) - if (__sigaddset (set, __sig) < 0) - return -1; - } - return 0; -} - -/* Return the sigmask corresponding to *SET. - Unused bits of *SET are thrown away. */ -static inline int __attribute__ ((unused)) -sigset_get_old_mask (const sigset_t *set) -{ - if (sizeof (sigset_t) == sizeof (unsigned int)) - return (unsigned int) *set; - else - { - unsigned int mask = 0; - unsigned int sig; - - for (sig = 1; sig < NSIG && sig <= sizeof (mask) * 8; sig++) - if (__sigismember (set, sig)) - mask |= sigmask (sig); - - return mask; - } -} - -/* sysdeps/posix/sigblock.c */ -/* Block signals in MASK, returning the old mask. */ -int -__sigblock (int mask) -{ - sigset_t set, oset; - - if (sigset_set_old_mask (&set, mask) < 0) - return -1; - - if (sigprocmask (SIG_BLOCK, &set, &oset) < 0) - return -1; - - return sigset_get_old_mask (&oset); -} - -weak_alias (__sigblock, sigblock) - -/* sysdeps/posix/sigsetmask.c */ -/* Set the mask of blocked signals to MASK, returning the old mask. */ -int -__sigsetmask (int mask) -{ - sigset_t set, oset; - - if (sigset_set_old_mask (&set, mask) < 0) - return -1; - - if (sigprocmask (SIG_SETMASK, &set, &oset) < 0) - return -1; - - return sigset_get_old_mask (&oset); -} - -weak_alias (__sigsetmask, sigsetmask) diff --git a/patch_file.patch b/patch_file.patch new file mode 100644 index 0000000..8fee17e --- /dev/null +++ b/patch_file.patch @@ -0,0 +1,161 @@ +diff -uNr orig/hunt/hunt.c hunt/hunt/hunt.c +--- orig/hunt/hunt.c 2018-04-13 18:10:32.939979900 +0800 ++++ hunt/hunt/hunt.c 2018-04-13 18:19:49.421020600 +0800 +@@ -394,7 +394,7 @@ + + vec_cnt = 0; + for (ip = ifp; ip; ip = ip->ifa_next) +- if (ip->ifa_addr && ++ if ((ip->ifa_broadaddr != NULL) && + (ip->ifa_addr->sa_family == AF_INET) && + (ip->ifa_flags & IFF_BROADCAST)) + vec_cnt++; +@@ -406,7 +406,7 @@ + + vec_cnt = 0; + for (ip = ifp; ip; ip = ip->ifa_next) +- if (ip->ifa_addr && ++ if ((ip->ifa_broadaddr != NULL) && + (ip->ifa_addr->sa_family == AF_INET) && + (ip->ifa_flags & IFF_BROADCAST)) + memcpy(&(*vector)[vec_cnt++], ip->ifa_broadaddr, +diff -uNr orig/hunt/otto.c hunt/hunt/otto.c +--- orig/hunt/otto.c 2018-04-13 18:10:32.939979900 +0800 ++++ hunt/hunt/otto.c 2018-04-13 18:28:05.353646500 +0800 +@@ -55,6 +55,7 @@ + # include + # include + # include "hunt.h" ++# include "../patch.h" + + # undef WALL + # undef NORTH +diff -uNr orig/patch.h hunt/patch.h +--- orig/patch.h 1970-01-01 08:00:00.000000000 +0800 ++++ hunt/patch.h 2018-04-13 18:19:49.406037800 +0800 +@@ -0,0 +1,125 @@ ++#include ++ ++/* sysdeps/generic/sigset-cvt-mask.h */ ++static inline int __attribute__ ((unused)) ++ sigset_set_old_mask(sigset_t *, int); ++static inline int __attribute__ ((unused)) ++ sigset_get_old_mask(const sigset_t *); ++/* sysdeps/posix/sigblock.c */ ++int __sigblock(int); ++/* sysdeps/posix/sigsetmask.c */ ++int __sigsetmask(int); ++ ++/* include/libc-symbols.h */ ++/* Define ALIASNAME as a weak alias for NAME. ++ If weak aliases are not available, this defines a strong alias. */ ++# define weak_alias(name, aliasname) _weak_alias (name, aliasname) ++# define _weak_alias(name, aliasname) \ ++ extern __typeof (name) aliasname __attribute__ ((weak, alias (#name))); ++ ++/* signal/signal.h */ ++/* Compute mask for signal SIG. */ ++# define sigmask(sig) ((int)(1u << ((sig) - 1))) ++ ++/* sysdeps/generic/sigsetops.h */ ++#define __sigemptyset(set) \ ++ (__extension__ ({ \ ++ *(set) = (__sigset_t) 0; \ ++ 0; \ ++ })) ++ ++/* These macros needn't check for a bogus signal number; ++ checking is done in the non-__ versions. */ ++# define __sigismember(set, sig) \ ++ (__extension__ ({ \ ++ __sigset_t __mask = sigmask (sig); \ ++ (*(set) & __mask) ? 1 : 0; \ ++ })) ++ ++# define __sigaddset(set, sig) \ ++ (__extension__ ({ \ ++ __sigset_t __mask = sigmask (sig); \ ++ *(set) |= __mask; \ ++ 0; \ ++ })) ++ ++/* sysdeps/generic/sigset-cvt-mask.h */ ++/* Convert between an old-style 32-bit signal mask and a POSIX sigset_t. */ ++ ++/* Perform *SET = MASK. Unused bits of *SET are set to 0. ++ Returns zero for success or -1 for errors (from sigaddset/sigemptyset). */ ++static inline int __attribute__ ((unused)) ++sigset_set_old_mask (sigset_t *set, int mask) ++{ ++ if (sizeof (__sigset_t) == sizeof (unsigned int)) ++ *set = (unsigned int) mask; ++ else ++ { ++ unsigned int __sig; ++ ++ if (__sigemptyset (set) < 0) ++ return -1; ++ ++ for (__sig = 1; __sig < NSIG && __sig <= sizeof (mask) * 8; __sig++) ++ if (mask & sigmask (__sig)) ++ if (__sigaddset (set, __sig) < 0) ++ return -1; ++ } ++ return 0; ++} ++ ++/* Return the sigmask corresponding to *SET. ++ Unused bits of *SET are thrown away. */ ++static inline int __attribute__ ((unused)) ++sigset_get_old_mask (const sigset_t *set) ++{ ++ if (sizeof (sigset_t) == sizeof (unsigned int)) ++ return (unsigned int) *set; ++ else ++ { ++ unsigned int mask = 0; ++ unsigned int sig; ++ ++ for (sig = 1; sig < NSIG && sig <= sizeof (mask) * 8; sig++) ++ if (__sigismember (set, sig)) ++ mask |= sigmask (sig); ++ ++ return mask; ++ } ++} ++ ++/* sysdeps/posix/sigblock.c */ ++/* Block signals in MASK, returning the old mask. */ ++int ++__sigblock (int mask) ++{ ++ sigset_t set, oset; ++ ++ if (sigset_set_old_mask (&set, mask) < 0) ++ return -1; ++ ++ if (sigprocmask (SIG_BLOCK, &set, &oset) < 0) ++ return -1; ++ ++ return sigset_get_old_mask (&oset); ++} ++ ++weak_alias (__sigblock, sigblock) ++ ++/* sysdeps/posix/sigsetmask.c */ ++/* Set the mask of blocked signals to MASK, returning the old mask. */ ++int ++__sigsetmask (int mask) ++{ ++ sigset_t set, oset; ++ ++ if (sigset_set_old_mask (&set, mask) < 0) ++ return -1; ++ ++ if (sigprocmask (SIG_SETMASK, &set, &oset) < 0) ++ return -1; ++ ++ return sigset_get_old_mask (&oset); ++} ++ ++weak_alias (__sigsetmask, sigsetmask)