]> git.cameronkatri.com Git - bsdgames-darwin.git/blobdiff - hunt/huntd/driver.c
avoid unnecessary floating point ops
[bsdgames-darwin.git] / hunt / huntd / driver.c
index fa8e89309bf840eeb229dc347d5fbee0bf1028c2..ff5411d9f393355000d05a9b198308e434f288a5 100644 (file)
@@ -1,4 +1,4 @@
-/*     $NetBSD: driver.c,v 1.14 2009/06/28 21:12:35 dholland Exp $     */
+/*     $NetBSD: driver.c,v 1.22 2013/10/19 17:23:08 christos Exp $     */
 /*
  * Copyright (c) 1983-2003, Regents of the University of California.
  * All rights reserved.
 /*
  * Copyright (c) 1983-2003, Regents of the University of California.
  * All rights reserved.
 
 #include <sys/cdefs.h>
 #ifndef lint
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: driver.c,v 1.14 2009/06/28 21:12:35 dholland Exp $");
+__RCSID("$NetBSD: driver.c,v 1.22 2013/10/19 17:23:08 christos Exp $");
 #endif /* not lint */
 
 #endif /* not lint */
 
-# include      <sys/ioctl.h>
-# include      <sys/stat.h>
-# include      <sys/time.h>
-# include      <err.h>
-# include      <errno.h>
-# include      <signal.h>
-# include      <stdlib.h>
-# include      <unistd.h>
-# include      "hunt.h"
-
-# ifndef pdp11
-# define       RN      (((Seed = Seed * 11109 + 13849) >> 16) & 0xffff)
-# else
-# define       RN      ((Seed = Seed * 11109 + 13849) & 0x7fff)
-# endif
-
-int    Seed = 0;
-
-
-SOCKET Daemon;
-char   *First_arg;             /* pointer to argv[0] */
-char   *Last_arg;              /* pointer to end of argv/environ */
-# ifdef        INTERNET
-int    Test_socket;            /* test socket to answer datagrams */
-FLAG   inetd_spawned;          /* invoked via inetd */
-FLAG   standard_port = TRUE;   /* true if listening on standard port */
-u_short        sock_port;              /* port # of tcp listen socket */
-u_short        stat_port;              /* port # of statistics tcp socket */
-# define       DAEMON_SIZE     (sizeof Daemon)
-# else
-# define       DAEMON_SIZE     (sizeof Daemon - 1)
-# endif
-
-static void    clear_scores(void);
-static int     havechar(PLAYER *, int);
-static void    init(void);
-       int     main(int, char *[], char *[]);
-static void    makeboots(void);
-static void    send_stats(void);
-static void    zap(PLAYER *, FLAG, int);
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <err.h>
+#include <errno.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include"hunt.h"
+
+#ifndef pdp11
+#define RN     (((Seed = Seed * 11109 + 13849) >> 16) & 0xffff)
+#else
+#define RN     ((Seed = Seed * 11109 + 13849) & 0x7fff)
+#endif
+
+static int Seed = 0;
+
+
+static SOCKET Daemon;
+static char *First_arg;                        /* pointer to argv[0] */
+static char *Last_arg;                 /* pointer to end of argv/environ */
+
+#ifdef INTERNET
+static int Test_socket;                        /* test socket to answer datagrams */
+static FLAG inetd_spawned;             /* invoked via inetd */
+static FLAG standard_port = TRUE;      /* true if listening on standard port */
+static u_short sock_port;              /* port # of tcp listen socket */
+static u_short stat_port;              /* port # of statistics tcp socket */
+#define DAEMON_SIZE    (sizeof Daemon)
+#else
+#define DAEMON_SIZE    (sizeof Daemon - 1)
+#endif
+
+static void clear_scores(void);
+static int havechar(PLAYER *, int);
+static void init(void);
+int main(int, char *[], char *[]);
+static void makeboots(void);
+static void send_stats(void);
+static void zap(PLAYER *, FLAG, int);
 
 
 /*
 
 
 /*
@@ -82,21 +83,19 @@ static      void    zap(PLAYER *, FLAG, int);
  *     The main program.
  */
 int
  *     The main program.
  */
 int
-main(ac, av, ep)
-       int     ac;
-       char    **av, **ep;
+main(int ac, char **av, char **ep)
 {
 {
-       PLAYER  *pp;
-# ifdef INTERNET
-       u_short msg;
-       short   port_num, reply;
-       socklen_t       namelen;
-       SOCKET  test;
-# endif
-       static FLAG     first = TRUE;
-       static FLAG     server = FALSE;
-       int             c, i;
-       const int       linger = 90 * 1000;
+       PLAYER *pp;
+#ifdef INTERNET
+       u_short msg;
+       short reply;
+       socklen_t namelen;
+       SOCKET test;
+#endif
+       static FLAG first = TRUE;
+       static FLAG server = FALSE;
+       int c, i;
+       const int linger = 90 * 1000;
 
        First_arg = av[0];
        if (ep == NULL || *ep == NULL)
 
        First_arg = av[0];
        if (ep == NULL || *ep == NULL)
@@ -110,12 +109,12 @@ main(ac, av, ep)
                  case 's':
                        server = TRUE;
                        break;
                  case 's':
                        server = TRUE;
                        break;
-# ifdef INTERNET
+#ifdef INTERNET
                  case 'p':
                        standard_port = FALSE;
                        Test_port = atoi(optarg);
                        break;
                  case 'p':
                        standard_port = FALSE;
                        Test_port = atoi(optarg);
                        break;
-# endif
+#endif
                  default:
 erred:
                        fprintf(stderr, "Usage: %s [-s] [-p port]\n", av[0]);
                  default:
 erred:
                        fprintf(stderr, "Usage: %s [-s] [-p port]\n", av[0]);
@@ -134,31 +133,30 @@ again:
                while (poll(fdset, 3+MAXPL+MAXMON, INFTIM) < 0)
                {
                        if (errno != EINTR)
                while (poll(fdset, 3+MAXPL+MAXMON, INFTIM) < 0)
                {
                        if (errno != EINTR)
-# ifdef LOG
+#ifdef LOG
                                syslog(LOG_WARNING, "poll: %m");
                                syslog(LOG_WARNING, "poll: %m");
-# else
+#else
                                warn("poll");
                                warn("poll");
-# endif
+#endif
                        errno = 0;
                }
                        errno = 0;
                }
-# ifdef INTERNET
+#ifdef INTERNET
                if (fdset[2].revents & POLLIN) {
                        namelen = DAEMON_SIZE;
                if (fdset[2].revents & POLLIN) {
                        namelen = DAEMON_SIZE;
-                       port_num = htons(sock_port);
-                       (void) recvfrom(Test_socket, (char *) &msg, sizeof msg,
+                       (void) recvfrom(Test_socket, &msg, sizeof msg,
                                0, (struct sockaddr *) &test, &namelen);
                        switch (ntohs(msg)) {
                          case C_MESSAGE:
                                if (Nplayer <= 0)
                                        break;
                                reply = htons((u_short) Nplayer);
                                0, (struct sockaddr *) &test, &namelen);
                        switch (ntohs(msg)) {
                          case C_MESSAGE:
                                if (Nplayer <= 0)
                                        break;
                                reply = htons((u_short) Nplayer);
-                               (void) sendto(Test_socket, (char *) &reply,
+                               (void) sendto(Test_socket, &reply,
                                        sizeof reply, 0,
                                        (struct sockaddr *) &test, DAEMON_SIZE);
                                break;
                          case C_SCORES:
                                reply = htons(stat_port);
                                        sizeof reply, 0,
                                        (struct sockaddr *) &test, DAEMON_SIZE);
                                break;
                          case C_SCORES:
                                reply = htons(stat_port);
-                               (void) sendto(Test_socket, (char *) &reply,
+                               (void) sendto(Test_socket, &reply,
                                        sizeof reply, 0,
                                        (struct sockaddr *) &test, DAEMON_SIZE);
                                break;
                                        sizeof reply, 0,
                                        (struct sockaddr *) &test, DAEMON_SIZE);
                                break;
@@ -167,46 +165,46 @@ again:
                                if (msg == C_MONITOR && Nplayer <= 0)
                                        break;
                                reply = htons(sock_port);
                                if (msg == C_MONITOR && Nplayer <= 0)
                                        break;
                                reply = htons(sock_port);
-                               (void) sendto(Test_socket, (char *) &reply,
+                               (void) sendto(Test_socket, &reply,
                                        sizeof reply, 0,
                                        (struct sockaddr *) &test, DAEMON_SIZE);
                                break;
                        }
                }
                                        sizeof reply, 0,
                                        (struct sockaddr *) &test, DAEMON_SIZE);
                                break;
                        }
                }
-# endif
+#endif
                {
                        for (pp = Player, i = 0; pp < End_player; pp++, i++)
                                if (havechar(pp, i + 3)) {
                                        execute(pp);
                                        pp->p_nexec++;
                                }
                {
                        for (pp = Player, i = 0; pp < End_player; pp++, i++)
                                if (havechar(pp, i + 3)) {
                                        execute(pp);
                                        pp->p_nexec++;
                                }
-# ifdef MONITOR
+#ifdef MONITOR
                        for (pp = Monitor, i = 0; pp < End_monitor; pp++, i++)
                                if (havechar(pp, i + MAXPL + 3)) {
                                        mon_execute(pp);
                                        pp->p_nexec++;
                                }
                        for (pp = Monitor, i = 0; pp < End_monitor; pp++, i++)
                                if (havechar(pp, i + MAXPL + 3)) {
                                        mon_execute(pp);
                                        pp->p_nexec++;
                                }
-# endif
+#endif
                        moveshots();
                        for (pp = Player, i = 0; pp < End_player; )
                                if (pp->p_death[0] != '\0')
                                        zap(pp, TRUE, i + 3);
                                else
                                        pp++, i++;
                        moveshots();
                        for (pp = Player, i = 0; pp < End_player; )
                                if (pp->p_death[0] != '\0')
                                        zap(pp, TRUE, i + 3);
                                else
                                        pp++, i++;
-# ifdef MONITOR
+#ifdef MONITOR
                        for (pp = Monitor, i = 0; pp < End_monitor; )
                                if (pp->p_death[0] != '\0')
                                        zap(pp, FALSE, i + MAXPL + 3);
                                else
                                        pp++, i++;
                        for (pp = Monitor, i = 0; pp < End_monitor; )
                                if (pp->p_death[0] != '\0')
                                        zap(pp, FALSE, i + MAXPL + 3);
                                else
                                        pp++, i++;
-# endif
+#endif
                }
                if (fdset[0].revents & POLLIN)
                        if (answer()) {
                }
                if (fdset[0].revents & POLLIN)
                        if (answer()) {
-# ifdef INTERNET
+#ifdef INTERNET
                                if (first && standard_port)
                                        faketalk();
                                if (first && standard_port)
                                        faketalk();
-# endif
+#endif
                                first = FALSE;
                        }
                if (fdset[1].revents & POLLIN)
                                first = FALSE;
                        }
                if (fdset[1].revents & POLLIN)
@@ -217,14 +215,14 @@ again:
                        pp->p_nexec = 0;
                        (void) fflush(pp->p_output);
                }
                        pp->p_nexec = 0;
                        (void) fflush(pp->p_output);
                }
-# ifdef MONITOR
+#ifdef MONITOR
                for (pp = Monitor, i = 0; pp < End_monitor; pp++, i++) {
                        if (fdset[i + MAXPL + 3].revents & POLLIN)
                                sendcom(pp, READY, pp->p_nexec);
                        pp->p_nexec = 0;
                        (void) fflush(pp->p_output);
                }
                for (pp = Monitor, i = 0; pp < End_monitor; pp++, i++) {
                        if (fdset[i + MAXPL + 3].revents & POLLIN)
                                sendcom(pp, READY, pp->p_nexec);
                        pp->p_nexec = 0;
                        (void) fflush(pp->p_output);
                }
-# endif
+#endif
        } while (Nplayer > 0);
 
        if (poll(fdset, 3+MAXPL+MAXMON, linger) > 0) {
        } while (Nplayer > 0);
 
        if (poll(fdset, 3+MAXPL+MAXMON, linger) > 0) {
@@ -234,17 +232,17 @@ again:
                clear_scores();
                makemaze();
                clearwalls();
                clear_scores();
                makemaze();
                clearwalls();
-# ifdef BOOTS
+#ifdef BOOTS
                makeboots();
                makeboots();
-# endif
+#endif
                first = TRUE;
                goto again;
        }
 
                first = TRUE;
                goto again;
        }
 
-# ifdef MONITOR
+#ifdef MONITOR
        for (pp = Monitor, i = 0; pp < End_monitor; i++)
                zap(pp, FALSE, i + MAXPL + 3);
        for (pp = Monitor, i = 0; pp < End_monitor; i++)
                zap(pp, FALSE, i + MAXPL + 3);
-# endif
+#endif
        cleanup(0);
        /* NOTREACHED */
        return(0);
        cleanup(0);
        /* NOTREACHED */
        return(0);
@@ -255,127 +253,122 @@ again:
  *     Initialize the global parameters.
  */
 static void
  *     Initialize the global parameters.
  */
 static void
-init()
+init(void)
 {
 {
-       int     i;
-# ifdef        INTERNET
-       SOCKET  test_port;
-       int     msg;
-       socklen_t       len;
-# endif
-
-# ifndef DEBUG
-# ifdef TIOCNOTTY
+       int i;
+#ifdef INTERNET
+       SOCKET test_port;
+       int msg;
+       socklen_t len;
+#endif
+
+#ifndef DEBUG
+#ifdef TIOCNOTTY
        (void) ioctl(fileno(stdout), TIOCNOTTY, NULL);
        (void) ioctl(fileno(stdout), TIOCNOTTY, NULL);
-# endif
+#endif
        (void) setpgrp(getpid(), getpid());
        (void) signal(SIGHUP, SIG_IGN);
        (void) signal(SIGINT, SIG_IGN);
        (void) signal(SIGQUIT, SIG_IGN);
        (void) signal(SIGTERM, cleanup);
        (void) setpgrp(getpid(), getpid());
        (void) signal(SIGHUP, SIG_IGN);
        (void) signal(SIGINT, SIG_IGN);
        (void) signal(SIGQUIT, SIG_IGN);
        (void) signal(SIGTERM, cleanup);
-# endif
+#endif
 
        (void) chdir("/var/tmp");       /* just in case it core dumps */
        (void) umask(0);                /* No privacy at all! */
        (void) signal(SIGPIPE, SIG_IGN);
 
 
        (void) chdir("/var/tmp");       /* just in case it core dumps */
        (void) umask(0);                /* No privacy at all! */
        (void) signal(SIGPIPE, SIG_IGN);
 
-# ifdef LOG
-# ifdef        SYSLOG_43
+#ifdef LOG
        openlog("huntd", LOG_PID, LOG_DAEMON);
        openlog("huntd", LOG_PID, LOG_DAEMON);
-# endif
-# ifdef        SYSLOG_42
-       openlog("huntd", LOG_PID);
-# endif
-# endif
+#endif
 
        /*
         * Initialize statistics socket
         */
 
        /*
         * Initialize statistics socket
         */
-# ifdef        INTERNET
+#ifdef INTERNET
        Daemon.sin_family = SOCK_FAMILY;
        Daemon.sin_addr.s_addr = INADDR_ANY;
        Daemon.sin_port = 0;
        Daemon.sin_family = SOCK_FAMILY;
        Daemon.sin_addr.s_addr = INADDR_ANY;
        Daemon.sin_port = 0;
-# else
+#else
        Daemon.sun_family = SOCK_FAMILY;
        (void) strcpy(Daemon.sun_path, Stat_name);
        Daemon.sun_family = SOCK_FAMILY;
        (void) strcpy(Daemon.sun_path, Stat_name);
-# endif
+#endif
 
        Status = socket(SOCK_FAMILY, SOCK_STREAM, 0);
        if (bind(Status, (struct sockaddr *) &Daemon, DAEMON_SIZE) < 0) {
                if (errno == EADDRINUSE)
                        exit(0);
                else {
 
        Status = socket(SOCK_FAMILY, SOCK_STREAM, 0);
        if (bind(Status, (struct sockaddr *) &Daemon, DAEMON_SIZE) < 0) {
                if (errno == EADDRINUSE)
                        exit(0);
                else {
-# ifdef LOG
+#ifdef LOG
                        syslog(LOG_ERR, "bind: %m");
                        syslog(LOG_ERR, "bind: %m");
-# else
+#else
                        warn("bind");
                        warn("bind");
-# endif
+#endif
                        cleanup(1);
                }
        }
        (void) listen(Status, 5);
 
                        cleanup(1);
                }
        }
        (void) listen(Status, 5);
 
-# ifdef INTERNET
+#ifdef INTERNET
        len = sizeof (SOCKET);
        if (getsockname(Status, (struct sockaddr *) &Daemon, &len) < 0)  {
        len = sizeof (SOCKET);
        if (getsockname(Status, (struct sockaddr *) &Daemon, &len) < 0)  {
-# ifdef LOG
+#ifdef LOG
                syslog(LOG_ERR, "getsockname: %m");
                syslog(LOG_ERR, "getsockname: %m");
-# else
+#else
                warn("getsockname");
                warn("getsockname");
-# endif
+#endif
                exit(1);
        }
        stat_port = ntohs(Daemon.sin_port);
                exit(1);
        }
        stat_port = ntohs(Daemon.sin_port);
-# endif
+#endif
 
        /*
         * Initialize main socket
         */
 
        /*
         * Initialize main socket
         */
-# ifdef        INTERNET
+#ifdef INTERNET
        Daemon.sin_family = SOCK_FAMILY;
        Daemon.sin_addr.s_addr = INADDR_ANY;
        Daemon.sin_port = 0;
        Daemon.sin_family = SOCK_FAMILY;
        Daemon.sin_addr.s_addr = INADDR_ANY;
        Daemon.sin_port = 0;
-# else
+#else
        Daemon.sun_family = SOCK_FAMILY;
        (void) strcpy(Daemon.sun_path, Sock_name);
        Daemon.sun_family = SOCK_FAMILY;
        (void) strcpy(Daemon.sun_path, Sock_name);
-# endif
+#endif
 
        Socket = socket(SOCK_FAMILY, SOCK_STREAM, 0);
 
        Socket = socket(SOCK_FAMILY, SOCK_STREAM, 0);
-# if defined(INTERNET)
+#if defined(INTERNET)
        msg = 1;
        if (setsockopt(Socket, SOL_SOCKET, SO_USELOOPBACK, &msg, sizeof msg)<0)
        msg = 1;
        if (setsockopt(Socket, SOL_SOCKET, SO_USELOOPBACK, &msg, sizeof msg)<0)
-# ifdef LOG
+#ifdef LOG
                syslog(LOG_WARNING, "setsockopt loopback %m");
                syslog(LOG_WARNING, "setsockopt loopback %m");
-# else
+#else
                warn("setsockopt loopback");
                warn("setsockopt loopback");
-# endif
-# endif
+#endif
+#endif
        if (bind(Socket, (struct sockaddr *) &Daemon, DAEMON_SIZE) < 0) {
                if (errno == EADDRINUSE)
                        exit(0);
                else {
        if (bind(Socket, (struct sockaddr *) &Daemon, DAEMON_SIZE) < 0) {
                if (errno == EADDRINUSE)
                        exit(0);
                else {
-# ifdef LOG
+#ifdef LOG
                        syslog(LOG_ERR, "bind: %m");
                        syslog(LOG_ERR, "bind: %m");
-# else
+#else
                        warn("bind");
                        warn("bind");
-# endif
+#endif
                        cleanup(1);
                }
        }
        (void) listen(Socket, 5);
 
                        cleanup(1);
                }
        }
        (void) listen(Socket, 5);
 
-# ifdef INTERNET
+#ifdef INTERNET
        len = sizeof (SOCKET);
        if (getsockname(Socket, (struct sockaddr *) &Daemon, &len) < 0)  {
        len = sizeof (SOCKET);
        if (getsockname(Socket, (struct sockaddr *) &Daemon, &len) < 0)  {
-# ifdef LOG
+#ifdef LOG
                syslog(LOG_ERR, "getsockname: %m");
                syslog(LOG_ERR, "getsockname: %m");
-# else
+#else
                warn("getsockname");
                warn("getsockname");
-# endif
+#endif
                exit(1);
        }
        sock_port = ntohs(Daemon.sin_port);
                exit(1);
        }
        sock_port = ntohs(Daemon.sin_port);
-# endif
+#endif
 
        /*
         * Initialize minimal poll mask
 
        /*
         * Initialize minimal poll mask
@@ -385,7 +378,7 @@ init()
        fdset[1].fd = Status;
        fdset[1].events = POLLIN;
 
        fdset[1].fd = Status;
        fdset[1].events = POLLIN;
 
-# ifdef INTERNET
+#ifdef INTERNET
        len = sizeof (SOCKET);
        if (getsockname(0, (struct sockaddr *) &test_port, &len) >= 0
        && test_port.sin_family == AF_INET) {
        len = sizeof (SOCKET);
        if (getsockname(0, (struct sockaddr *) &test_port, &len) >= 0
        && test_port.sin_family == AF_INET) {
@@ -402,11 +395,11 @@ init()
                Test_socket = socket(SOCK_FAMILY, SOCK_DGRAM, 0);
                if (bind(Test_socket, (struct sockaddr *) &test_port,
                    DAEMON_SIZE) < 0) {
                Test_socket = socket(SOCK_FAMILY, SOCK_DGRAM, 0);
                if (bind(Test_socket, (struct sockaddr *) &test_port,
                    DAEMON_SIZE) < 0) {
-# ifdef LOG
+#ifdef LOG
                        syslog(LOG_ERR, "bind: %m");
                        syslog(LOG_ERR, "bind: %m");
-# else
+#else
                        warn("bind");
                        warn("bind");
-# endif
+#endif
                        exit(1);
                }
                (void) listen(Test_socket, 5);
                        exit(1);
                }
                (void) listen(Test_socket, 5);
@@ -414,15 +407,15 @@ init()
 
        fdset[2].fd = Test_socket;
        fdset[2].events = POLLIN;
 
        fdset[2].fd = Test_socket;
        fdset[2].events = POLLIN;
-# else
+#else
        fdset[2].fd = -1;
        fdset[2].fd = -1;
-# endif
+#endif
 
 
-       Seed = getpid() + time((time_t *) NULL);
+       Seed = getpid() + time(NULL);
        makemaze();
        makemaze();
-# ifdef BOOTS
+#ifdef BOOTS
        makeboots();
        makeboots();
-# endif
+#endif
 
        for (i = 0; i < NASCII; i++)
                See_over[i] = TRUE;
 
        for (i = 0; i < NASCII; i++)
                See_over[i] = TRUE;
@@ -430,23 +423,23 @@ init()
        See_over[WALL1] = FALSE;
        See_over[WALL2] = FALSE;
        See_over[WALL3] = FALSE;
        See_over[WALL1] = FALSE;
        See_over[WALL2] = FALSE;
        See_over[WALL3] = FALSE;
-# ifdef REFLECT
+#ifdef REFLECT
        See_over[WALL4] = FALSE;
        See_over[WALL5] = FALSE;
        See_over[WALL4] = FALSE;
        See_over[WALL5] = FALSE;
-# endif
+#endif
 
 }
 
 
 }
 
-# ifdef BOOTS
+#ifdef BOOTS
 /*
  * makeboots:
  *     Put the boots in the maze
  */
 static void
 /*
  * makeboots:
  *     Put the boots in the maze
  */
 static void
-makeboots()
+makeboots(void)
 {
 {
-       int     x, y;
-       PLAYER  *pp;
+       int x, y;
+       PLAYER *pp;
 
        do {
                x = rand_num(WIDTH - 1) + 1;
 
        do {
                x = rand_num(WIDTH - 1) + 1;
@@ -456,7 +449,7 @@ makeboots()
        for (pp = Boot; pp < &Boot[NBOOTS]; pp++)
                pp->p_flying = -1;
 }
        for (pp = Boot; pp < &Boot[NBOOTS]; pp++)
                pp->p_flying = -1;
 }
-# endif
+#endif
 
 
 /*
 
 
 /*
@@ -464,17 +457,14 @@ makeboots()
  *     Check the damage to the given player, and see if s/he is killed
  */
 void
  *     Check the damage to the given player, and see if s/he is killed
  */
 void
-checkdam(ouch, gotcha, credit, amt, this_shot_type)
-       PLAYER  *ouch, *gotcha;
-       IDENT   *credit;
-       int     amt;
-       char    this_shot_type;
+checkdam(PLAYER *ouch, PLAYER *gotcha, IDENT *credit, int amt,
+        char this_shot_type)
 {
 {
-       const char      *cp;
+       const char *cp;
 
        if (ouch->p_death[0] != '\0')
                return;
 
        if (ouch->p_death[0] != '\0')
                return;
-# ifdef BOOTS
+#ifdef BOOTS
        if (this_shot_type == SLIME)
                switch (ouch->p_nboots) {
                  default:
        if (this_shot_type == SLIME)
                switch (ouch->p_nboots) {
                  default:
@@ -487,7 +477,7 @@ checkdam(ouch, gotcha, credit, amt, this_shot_type)
                                message(gotcha, "He has boots on!");
                        return;
                }
                                message(gotcha, "He has boots on!");
                        return;
                }
-# endif
+#endif
        ouch->p_damage += amt;
        if (ouch->p_damage <= ouch->p_damcap) {
                (void) snprintf(Buf, sizeof(Buf), "%2d", ouch->p_damage);
        ouch->p_damage += amt;
        if (ouch->p_damage <= ouch->p_damcap) {
                (void) snprintf(Buf, sizeof(Buf), "%2d", ouch->p_damage);
@@ -501,11 +491,11 @@ checkdam(ouch, gotcha, credit, amt, this_shot_type)
          default:
                cp = "Killed";
                break;
          default:
                cp = "Killed";
                break;
-# ifdef FLY
+#ifdef FLY
          case FALL:
                cp = "Killed on impact";
                break;
          case FALL:
                cp = "Killed on impact";
                break;
-# endif
+#endif
          case KNIFE:
                cp = "Stabbed to death";
                ouch->p_ammo = 0;               /* No exploding */
          case KNIFE:
                cp = "Stabbed to death";
                ouch->p_ammo = 0;               /* No exploding */
@@ -522,23 +512,23 @@ checkdam(ouch, gotcha, credit, amt, this_shot_type)
          case GMINE:
                cp = "Blown apart";
                break;
          case GMINE:
                cp = "Blown apart";
                break;
-# ifdef        OOZE
+#ifdef OOZE
          case SLIME:
                cp = "Slimed";
                if (credit != NULL)
                        credit->i_slime++;
                break;
          case SLIME:
                cp = "Slimed";
                if (credit != NULL)
                        credit->i_slime++;
                break;
-# endif
-# ifdef        VOLCANO
+#endif
+#ifdef VOLCANO
          case LAVA:
                cp = "Baked";
                break;
          case LAVA:
                cp = "Baked";
                break;
-# endif
-# ifdef DRONE
+#endif
+#ifdef DRONE
          case DSHOT:
                cp = "Eliminated";
                break;
          case DSHOT:
                cp = "Eliminated";
                break;
-# endif
+#endif
        }
        if (credit == NULL) {
                (void) snprintf(ouch->p_death, sizeof(ouch->p_death),
        }
        if (credit == NULL) {
                (void) snprintf(ouch->p_death, sizeof(ouch->p_death),
@@ -588,13 +578,13 @@ checkdam(ouch, gotcha, credit, amt, this_shot_type)
                        STAT_NAME_COL);
                outstr(ouch, Buf, 5);
        }
                        STAT_NAME_COL);
                outstr(ouch, Buf, 5);
        }
-# ifdef MONITOR
+#ifdef MONITOR
        for (ouch = Monitor; ouch < End_monitor; ouch++) {
                cgoto(ouch, STAT_PLAY_ROW + 1 + (gotcha - Player),
                        STAT_NAME_COL);
                outstr(ouch, Buf, 5);
        }
        for (ouch = Monitor; ouch < End_monitor; ouch++) {
                cgoto(ouch, STAT_PLAY_ROW + 1 + (gotcha - Player),
                        STAT_NAME_COL);
                outstr(ouch, Buf, 5);
        }
-# endif
+#endif
 }
 
 /*
 }
 
 /*
@@ -602,16 +592,12 @@ checkdam(ouch, gotcha, credit, amt, this_shot_type)
  *     Kill off a player and take him out of the game.
  */
 static void
  *     Kill off a player and take him out of the game.
  */
 static void
-zap(pp, was_player, i)
-       PLAYER  *pp;
-       FLAG    was_player;
-       int     i;
+zap(PLAYER *pp, FLAG was_player, int i)
 {
 {
-       int     n, len;
-       BULLET  *bp;
-       PLAYER  *np;
-       int     x, y;
-       int     savefd;
+       int n, len;
+       BULLET *bp;
+       PLAYER *np;
+       int x, y;
 
        if (was_player) {
                if (pp->p_undershot)
 
        if (was_player) {
                if (pp->p_undershot)
@@ -634,11 +620,9 @@ zap(pp, was_player, i)
        outstr(pp, pp->p_death, len);
        cgoto(pp, HEIGHT, 0);
 
        outstr(pp, pp->p_death, len);
        cgoto(pp, HEIGHT, 0);
 
-       savefd = pp->p_fd;
-
-# ifdef MONITOR
+#ifdef MONITOR
        if (was_player) {
        if (was_player) {
-# endif
+#endif
                for (bp = Bullets; bp != NULL; bp = bp->b_next) {
                        if (bp->b_owner == pp)
                                bp->b_owner = NULL;
                for (bp = Bullets; bp != NULL; bp = bp->b_next) {
                        if (bp->b_owner == pp)
                                bp->b_owner = NULL;
@@ -674,16 +658,16 @@ zap(pp, was_player, i)
                }
                if (x > 0) {
                        (void) add_shot(len, pp->p_y, pp->p_x, pp->p_face, x,
                }
                if (x > 0) {
                        (void) add_shot(len, pp->p_y, pp->p_x, pp->p_face, x,
-                               (PLAYER *) NULL, TRUE, SPACE);
+                               NULL, TRUE, SPACE);
                        (void) snprintf(Buf, sizeof(Buf), "%s detonated.",
                                pp->p_ident->i_name);
                        for (np = Player; np < End_player; np++)
                                message(np, Buf);
                        (void) snprintf(Buf, sizeof(Buf), "%s detonated.",
                                pp->p_ident->i_name);
                        for (np = Player; np < End_player; np++)
                                message(np, Buf);
-# ifdef MONITOR
+#ifdef MONITOR
                        for (np = Monitor; np < End_monitor; np++)
                                message(np, Buf);
                        for (np = Monitor; np < End_monitor; np++)
                                message(np, Buf);
-# endif
-# ifdef BOOTS
+#endif
+#ifdef BOOTS
                        while (pp->p_nboots-- > 0) {
                                for (np = Boot; np < &Boot[NBOOTS]; np++)
                                        if (np->p_flying < 0)
                        while (pp->p_nboots-- > 0) {
                                for (np = Boot; np < &Boot[NBOOTS]; np++)
                                        if (np->p_flying < 0)
@@ -700,9 +684,9 @@ zap(pp, was_player, i)
                                np->p_face = BOOT;
                                showexpl(np->p_y, np->p_x, BOOT);
                        }
                                np->p_face = BOOT;
                                showexpl(np->p_y, np->p_x, BOOT);
                        }
-# endif
+#endif
                }
                }
-# ifdef BOOTS
+#ifdef BOOTS
                else if (pp->p_nboots > 0) {
                        if (pp->p_nboots == 2)
                                Maze[pp->p_y][pp->p_x] = BOOT_PAIR;
                else if (pp->p_nboots > 0) {
                        if (pp->p_nboots == 2)
                                Maze[pp->p_y][pp->p_x] = BOOT_PAIR;
@@ -712,9 +696,9 @@ zap(pp, was_player, i)
                                fixshots(pp->p_y, pp->p_x,
                                        Maze[pp->p_y][pp->p_x]);
                }
                                fixshots(pp->p_y, pp->p_x,
                                        Maze[pp->p_y][pp->p_x]);
                }
-# endif
+#endif
 
 
-# ifdef VOLCANO
+#ifdef VOLCANO
                volcano += pp->p_ammo - x;
                if (rand_num(100) < volcano / 50) {
                        do {
                volcano += pp->p_ammo - x;
                if (rand_num(100) < volcano / 50) {
                        do {
@@ -722,14 +706,14 @@ zap(pp, was_player, i)
                                y = rand_num(HEIGHT / 2) + HEIGHT / 4;
                        } while (Maze[y][x] != SPACE);
                        (void) add_shot(LAVA, y, x, LEFTS, volcano,
                                y = rand_num(HEIGHT / 2) + HEIGHT / 4;
                        } while (Maze[y][x] != SPACE);
                        (void) add_shot(LAVA, y, x, LEFTS, volcano,
-                               (PLAYER *) NULL, TRUE, SPACE);
+                               NULL, TRUE, SPACE);
                        for (np = Player; np < End_player; np++)
                                message(np, "Volcano eruption.");
                        volcano = 0;
                }
                        for (np = Player; np < End_player; np++)
                                message(np, "Volcano eruption.");
                        volcano = 0;
                }
-# endif
+#endif
 
 
-# ifdef        DRONE
+#ifdef DRONE
                if (rand_num(100) < 2) {
                        do {
                                x = rand_num(WIDTH / 2) + WIDTH / 4;
                if (rand_num(100) < 2) {
                        do {
                                x = rand_num(WIDTH / 2) + WIDTH / 4;
@@ -738,9 +722,9 @@ zap(pp, was_player, i)
                        add_shot(DSHOT, y, x, rand_dir(),
                                shot_req[MINDSHOT +
                                rand_num(MAXBOMB - MINDSHOT)],
                        add_shot(DSHOT, y, x, rand_dir(),
                                shot_req[MINDSHOT +
                                rand_num(MAXBOMB - MINDSHOT)],
-                               (PLAYER *) NULL, FALSE, SPACE);
+                               NULL, FALSE, SPACE);
                }
                }
-# endif
+#endif
 
                sendcom(pp, ENDWIN);
                (void) putc(' ', pp->p_output);
 
                sendcom(pp, ENDWIN);
                (void) putc(' ', pp->p_output);
@@ -759,12 +743,12 @@ zap(pp, was_player, i)
                                cgoto(np, n, STAT_NAME_COL);
                                outstr(np, Buf, STAT_NAME_LEN);
                        }
                                cgoto(np, n, STAT_NAME_COL);
                                outstr(np, Buf, STAT_NAME_LEN);
                        }
-# ifdef MONITOR
+#ifdef MONITOR
                        for (np = Monitor; np < End_monitor; np++) {
                                cgoto(np, n, STAT_NAME_COL);
                                outstr(np, Buf, STAT_NAME_LEN);
                        }
                        for (np = Monitor; np < End_monitor; np++) {
                                cgoto(np, n, STAT_NAME_COL);
                                outstr(np, Buf, STAT_NAME_LEN);
                        }
-# endif
+#endif
                } else
                        fdset[i].fd = -1;
 
                } else
                        fdset[i].fd = -1;
 
@@ -774,7 +758,7 @@ zap(pp, was_player, i)
                        cgoto(np, n, STAT_NAME_COL);
                        ce(np);
                }
                        cgoto(np, n, STAT_NAME_COL);
                        ce(np);
                }
-# ifdef MONITOR
+#ifdef MONITOR
                for (np = Monitor; np < End_monitor; np++) {
                        cgoto(np, n, STAT_NAME_COL);
                        ce(np);
                for (np = Monitor; np < End_monitor; np++) {
                        cgoto(np, n, STAT_NAME_COL);
                        ce(np);
@@ -816,7 +800,7 @@ zap(pp, was_player, i)
                        ce(np);
                }
        }
                        ce(np);
                }
        }
-# endif
+#endif
 }
 
 /*
 }
 
 /*
@@ -824,8 +808,7 @@ zap(pp, was_player, i)
  *     Return a random number in a given range.
  */
 int
  *     Return a random number in a given range.
  */
 int
-rand_num(range)
-       int     range;
+rand_num(int range)
 {
        return (range == 0 ? 0 : RN % range);
 }
 {
        return (range == 0 ? 0 : RN % range);
 }
@@ -837,9 +820,7 @@ rand_num(range)
  *     FALSE.
  */
 static int
  *     FALSE.
  */
 static int
-havechar(pp, i)
-       PLAYER  *pp;
-       int     i;
+havechar(PLAYER *pp, int i)
 {
 
        if (pp->p_ncount < pp->p_nchar)
 {
 
        if (pp->p_ncount < pp->p_nchar)
@@ -862,11 +843,10 @@ check_again:
  * cleanup:
  *     Exit with the given value, cleaning up any droppings lying around
  */
  * cleanup:
  *     Exit with the given value, cleaning up any droppings lying around
  */
-SIGNAL_TYPE
-cleanup(eval)
-       int     eval;
+void
+cleanup(int eval)
 {
 {
-       PLAYER  *pp;
+       PLAYER *pp;
 
        for (pp = Player; pp < End_player; pp++) {
                cgoto(pp, HEIGHT, 0);
 
        for (pp = Player; pp < End_player; pp++) {
                cgoto(pp, HEIGHT, 0);
@@ -874,18 +854,18 @@ cleanup(eval)
                (void) putc(LAST_PLAYER, pp->p_output);
                (void) fclose(pp->p_output);
        }
                (void) putc(LAST_PLAYER, pp->p_output);
                (void) fclose(pp->p_output);
        }
-# ifdef MONITOR
+#ifdef MONITOR
        for (pp = Monitor; pp < End_monitor; pp++) {
                cgoto(pp, HEIGHT, 0);
                sendcom(pp, ENDWIN);
                (void) putc(LAST_PLAYER, pp->p_output);
                (void) fclose(pp->p_output);
        }
        for (pp = Monitor; pp < End_monitor; pp++) {
                cgoto(pp, HEIGHT, 0);
                sendcom(pp, ENDWIN);
                (void) putc(LAST_PLAYER, pp->p_output);
                (void) fclose(pp->p_output);
        }
-# endif
+#endif
        (void) close(Socket);
        (void) close(Socket);
-# ifdef AF_UNIX_HACK
+#ifdef AF_UNIX_HACK
        (void) unlink(Sock_name);
        (void) unlink(Sock_name);
-# endif
+#endif
 
        exit(eval);
 }
 
        exit(eval);
 }
@@ -895,40 +875,40 @@ cleanup(eval)
  *     Print stats to requestor
  */
 static void
  *     Print stats to requestor
  */
 static void
-send_stats()
+send_stats(void)
 {
 {
-       IDENT   *ip;
-       FILE    *fp;
-       int     s;
-       SOCKET  sockstruct;
-       socklen_t       socklen;
+       IDENT *ip;
+       FILE *fp;
+       int s;
+       SOCKET sockstruct;
+       socklen_t socklen;
 
        /*
         * Get the output stream ready
         */
 
        /*
         * Get the output stream ready
         */
-# ifdef INTERNET
+#ifdef INTERNET
        socklen = sizeof sockstruct;
        socklen = sizeof sockstruct;
-# else
+#else
        socklen = sizeof sockstruct - 1;
        socklen = sizeof sockstruct - 1;
-# endif
+#endif
        s = accept(Status, (struct sockaddr *) &sockstruct, &socklen);
        if (s < 0) {
                if (errno == EINTR)
                        return;
        s = accept(Status, (struct sockaddr *) &sockstruct, &socklen);
        if (s < 0) {
                if (errno == EINTR)
                        return;
-# ifdef LOG
+#ifdef LOG
                syslog(LOG_WARNING, "accept: %m");
                syslog(LOG_WARNING, "accept: %m");
-# else
+#else
                warn("accept");
                warn("accept");
-# endif
+#endif
                return;
        }
        fp = fdopen(s, "w");
        if (fp == NULL) {
                return;
        }
        fp = fdopen(s, "w");
        if (fp == NULL) {
-# ifdef LOG
+#ifdef LOG
                syslog(LOG_WARNING, "fdopen: %m");
                syslog(LOG_WARNING, "fdopen: %m");
-# else
+#else
                warn("fdopen");
                warn("fdopen");
-# endif
+#endif
                (void) close(s);
                return;
        }
                (void) close(s);
                return;
        }
@@ -971,13 +951,13 @@ send_stats()
  *     Clear out the scores so the next session start clean
  */
 static void
  *     Clear out the scores so the next session start clean
  */
 static void
-clear_scores()
+clear_scores(void)
 {
 {
-       IDENT   *ip, *nextip;
+       IDENT *ip, *nextip;
 
        for (ip = Scores; ip != NULL; ip = nextip) {
                nextip = ip->i_next;
 
        for (ip = Scores; ip != NULL; ip = nextip) {
                nextip = ip->i_next;
-               (void) free((char *) ip);
+               (void) free(ip);
        }
        Scores = NULL;
 }
        }
        Scores = NULL;
 }