]> git.cameronkatri.com Git - bsdgames-darwin.git/blobdiff - hunt/huntd/driver.c
ANSIfy function declarations.
[bsdgames-darwin.git] / hunt / huntd / driver.c
index f7f0c9d601f9a2e95837d4d2d2eb5e94a3be99cc..d06c22dc671cd1826a2f89e634ac1b718c5db2d4 100644 (file)
@@ -1,14 +1,49 @@
+/*     $NetBSD: driver.c,v 1.16 2009/07/04 02:37:20 dholland Exp $     */
 /*
- *  Hunt
- *  Copyright (c) 1985 Conrad C. Huang, Gregory S. Couch, Kenneth C.R.C. Arnold
- *  San Francisco, California
+ * 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      "hunt.h"
-# include      <signal.h>
-# include      <errno.h>
+#include <sys/cdefs.h>
+#ifndef lint
+__RCSID("$NetBSD: driver.c,v 1.16 2009/07/04 02:37:20 dholland Exp $");
+#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)
@@ -33,32 +68,33 @@ u_short     stat_port;              /* port # of statistics tcp socket */
 # define       DAEMON_SIZE     (sizeof Daemon - 1)
 # endif
 
-extern SIGNAL_TYPE     cleanup();
+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);
+
 
 /*
  * main:
  *     The main program.
  */
-main(ac, av, ep)
-int    ac;
-char   **av, **ep;
+int
+main(int ac, char **av, char **ep)
 {
-       register PLAYER *pp;
-       register int    had_char;
+       PLAYER  *pp;
 # ifdef INTERNET
-       register long   test_mask;
-       u_short         msg;
-       short           port_num, reply;
-       int             namelen;
-       SOCKET          test;
+       u_short msg;
+       short   port_num, reply;
+       socklen_t       namelen;
+       SOCKET  test;
 # endif
-       static long     read_fds;
        static FLAG     first = TRUE;
        static FLAG     server = FALSE;
-       extern int      optind;
-       extern char     *optarg;
-       int             c;
-       static struct timeval   linger = {      90, 0   };
+       int             c, i;
+       const int       linger = 90 * 1000;
 
        First_arg = av[0];
        if (ep == NULL || *ep == NULL)
@@ -67,7 +103,7 @@ char **av, **ep;
                ep++;
        Last_arg = ep[-1] + strlen(ep[-1]);
 
-       while ((c = getopt(ac, av, "sp:")) != EOF) {
+       while ((c = getopt(ac, av, "sp:")) != -1) {
                switch (c) {
                  case 's':
                        server = TRUE;
@@ -88,47 +124,39 @@ erred:
                goto erred;
 
        init();
-       Sock_mask = (1 << Socket);
-       Stat_mask = (1 << Status);
-# ifdef INTERNET
-       test_mask = (1 << Test_socket);
-# endif
 
 
 again:
        do {
-               read_fds = Fds_mask;
                errno = 0;
-               while (select(Num_fds, &read_fds, (int *) NULL,
-                   (int *) NULL, (struct timeval *) NULL) < 0)
+               while (poll(fdset, 3+MAXPL+MAXMON, INFTIM) < 0)
                {
                        if (errno != EINTR)
 # ifdef LOG
-                               syslog(LOG_WARNING, "select: %m");
+                               syslog(LOG_WARNING, "poll: %m");
 # else
-                               perror("select");
+                               warn("poll");
 # endif
                        errno = 0;
                }
-               Have_inp = read_fds;
 # ifdef INTERNET
-               if (read_fds & test_mask) {
+               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);
-                               (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);
-                               (void) sendto(Test_socket, (char *) &reply,
+                               (void) sendto(Test_socket, &reply,
                                        sizeof reply, 0,
                                        (struct sockaddr *) &test, DAEMON_SIZE);
                                break;
@@ -137,46 +165,41 @@ again:
                                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;
                        }
                }
 # endif
-               for (;;) {
-                       had_char = FALSE;
-                       for (pp = Player; pp < End_player; pp++)
-                               if (havechar(pp)) {
+               {
+                       for (pp = Player, i = 0; pp < End_player; pp++, i++)
+                               if (havechar(pp, i + 3)) {
                                        execute(pp);
                                        pp->p_nexec++;
-                                       had_char++;
                                }
 # ifdef MONITOR
-                       for (pp = Monitor; pp < End_monitor; pp++)
-                               if (havechar(pp)) {
+                       for (pp = Monitor, i = 0; pp < End_monitor; pp++, i++)
+                               if (havechar(pp, i + MAXPL + 3)) {
                                        mon_execute(pp);
                                        pp->p_nexec++;
-                                       had_char++;
                                }
 # endif
-                       if (!had_char)
-                               break;
                        moveshots();
-                       for (pp = Player; pp < End_player; )
+                       for (pp = Player, i = 0; pp < End_player; )
                                if (pp->p_death[0] != '\0')
-                                       zap(pp, TRUE);
+                                       zap(pp, TRUE, i + 3);
                                else
-                                       pp++;
+                                       pp++, i++;
 # ifdef MONITOR
-                       for (pp = Monitor; pp < End_monitor; )
+                       for (pp = Monitor, i = 0; pp < End_monitor; )
                                if (pp->p_death[0] != '\0')
-                                       zap(pp, FALSE);
+                                       zap(pp, FALSE, i + MAXPL + 3);
                                else
-                                       pp++;
+                                       pp++, i++;
 # endif
                }
-               if (read_fds & Sock_mask)
+               if (fdset[0].revents & POLLIN)
                        if (answer()) {
 # ifdef INTERNET
                                if (first && standard_port)
@@ -184,17 +207,17 @@ again:
 # endif
                                first = FALSE;
                        }
-               if (read_fds & Stat_mask)
+               if (fdset[1].revents & POLLIN)
                        send_stats();
-               for (pp = Player; pp < End_player; pp++) {
-                       if (read_fds & pp->p_mask)
+               for (pp = Player, i = 0; pp < End_player; pp++, i++) {
+                       if (fdset[i + 3].revents & POLLIN)
                                sendcom(pp, READY, pp->p_nexec);
                        pp->p_nexec = 0;
                        (void) fflush(pp->p_output);
                }
 # ifdef MONITOR
-               for (pp = Monitor; pp < End_monitor; pp++) {
-                       if (read_fds & pp->p_mask)
+               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);
@@ -202,9 +225,7 @@ again:
 # endif
        } while (Nplayer > 0);
 
-       read_fds = Fds_mask;
-       if (select(Num_fds, &read_fds, (int *) NULL, (int *) NULL,
-                  &linger) > 0) {
+       if (poll(fdset, 3+MAXPL+MAXMON, linger) > 0) {
                goto again;
        }
        if (server) {
@@ -219,23 +240,26 @@ again:
        }
 
 # ifdef MONITOR
-       for (pp = Monitor; pp < End_monitor; )
-               zap(pp, FALSE);
+       for (pp = Monitor, i = 0; pp < End_monitor; i++)
+               zap(pp, FALSE, i + MAXPL + 3);
 # endif
        cleanup(0);
+       /* NOTREACHED */
+       return(0);
 }
 
 /*
  * init:
  *     Initialize the global parameters.
  */
-init()
+static void
+init(void)
 {
-       register int    i;
+       int     i;
 # ifdef        INTERNET
-       auto SOCKET     test_port;
-       auto int        msg;
-       auto int        len;
+       SOCKET  test_port;
+       int     msg;
+       socklen_t       len;
 # endif
 
 # ifndef DEBUG
@@ -249,16 +273,16 @@ init()
        (void) signal(SIGTERM, cleanup);
 # endif
 
-       (void) chdir("/usr/tmp");       /* just in case it core dumps */
+       (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
-       openlog("HUNT", LOG_PID, LOG_DAEMON);
+       openlog("huntd", LOG_PID, LOG_DAEMON);
 # endif
 # ifdef        SYSLOG_42
-       openlog("HUNT", LOG_PID);
+       openlog("huntd", LOG_PID);
 # endif
 # endif
 
@@ -282,7 +306,7 @@ init()
 # ifdef LOG
                        syslog(LOG_ERR, "bind: %m");
 # else
-                       perror("bind");
+                       warn("bind");
 # endif
                        cleanup(1);
                }
@@ -295,7 +319,7 @@ init()
 # ifdef LOG
                syslog(LOG_ERR, "getsockname: %m");
 # else
-               perror("getsockname");
+               warn("getsockname");
 # endif
                exit(1);
        }
@@ -321,7 +345,7 @@ init()
 # ifdef LOG
                syslog(LOG_WARNING, "setsockopt loopback %m");
 # else
-               perror("setsockopt loopback");
+               warn("setsockopt loopback");
 # endif
 # endif
        if (bind(Socket, (struct sockaddr *) &Daemon, DAEMON_SIZE) < 0) {
@@ -331,7 +355,7 @@ init()
 # ifdef LOG
                        syslog(LOG_ERR, "bind: %m");
 # else
-                       perror("bind");
+                       warn("bind");
 # endif
                        cleanup(1);
                }
@@ -344,7 +368,7 @@ init()
 # ifdef LOG
                syslog(LOG_ERR, "getsockname: %m");
 # else
-               perror("getsockname");
+               warn("getsockname");
 # endif
                exit(1);
        }
@@ -352,10 +376,12 @@ init()
 # endif
 
        /*
-        * Initialize minimal select mask
+        * Initialize minimal poll mask
         */
-       Fds_mask = (1 << Socket) | (1 << Status);
-       Num_fds = ((Socket > Status) ? Socket : Status) + 1;
+       fdset[0].fd = Socket;
+       fdset[0].events = POLLIN;
+       fdset[1].fd = Status;
+       fdset[1].events = POLLIN;
 
 # ifdef INTERNET
        len = sizeof (SOCKET);
@@ -377,16 +403,17 @@ init()
 # ifdef LOG
                        syslog(LOG_ERR, "bind: %m");
 # else
-                       perror("bind");
+                       warn("bind");
 # endif
                        exit(1);
                }
                (void) listen(Test_socket, 5);
        }
 
-       Fds_mask |= (1 << Test_socket);
-       if (Test_socket + 1 > Num_fds)
-               Num_fds = Test_socket + 1;
+       fdset[2].fd = Test_socket;
+       fdset[2].events = POLLIN;
+# else
+       fdset[2].fd = -1;
 # endif
 
        Seed = getpid() + time((time_t *) NULL);
@@ -413,10 +440,11 @@ init()
  * makeboots:
  *     Put the boots in the maze
  */
-makeboots()
+static void
+makeboots(void)
 {
-       register int    x, y;
-       register PLAYER *pp;
+       int     x, y;
+       PLAYER  *pp;
 
        do {
                x = rand_num(WIDTH - 1) + 1;
@@ -433,18 +461,16 @@ makeboots()
  * checkdam:
  *     Check the damage to the given player, and see if s/he is killed
  */
-checkdam(ouch, gotcha, credit, amt, shot_type)
-register PLAYER        *ouch, *gotcha;
-register IDENT *credit;
-int            amt;
-char           shot_type;
+void
+checkdam(PLAYER *ouch, PLAYER *gotcha, IDENT *credit, int amt,
+        char this_shot_type)
 {
-       register char   *cp;
+       const char      *cp;
 
        if (ouch->p_death[0] != '\0')
                return;
 # ifdef BOOTS
-       if (shot_type == SLIME)
+       if (this_shot_type == SLIME)
                switch (ouch->p_nboots) {
                  default:
                        break;
@@ -459,14 +485,14 @@ char              shot_type;
 # endif
        ouch->p_damage += amt;
        if (ouch->p_damage <= ouch->p_damcap) {
-               (void) sprintf(Buf, "%2d", ouch->p_damage);
+               (void) snprintf(Buf, sizeof(Buf), "%2d", ouch->p_damage);
                cgoto(ouch, STAT_DAM_ROW, STAT_VALUE_COL);
                outstr(ouch, Buf, 2);
                return;
        }
 
        /* Someone DIED */
-       switch (shot_type) {
+       switch (this_shot_type) {
          default:
                cp = "Killed";
                break;
@@ -510,13 +536,15 @@ char              shot_type;
 # endif
        }
        if (credit == NULL) {
-               (void) sprintf(ouch->p_death, "| %s by %s |", cp,
-                       (shot_type == MINE || shot_type == GMINE) ?
+               (void) snprintf(ouch->p_death, sizeof(ouch->p_death),
+                       "| %s by %s |", cp,
+                       (this_shot_type == MINE || this_shot_type == GMINE) ?
                        "a mine" : "act of God");
                return;
        }
 
-       (void) sprintf(ouch->p_death, "| %s by %s |", cp, credit->i_name);
+       (void) snprintf(ouch->p_death, sizeof(ouch->p_death),
+               "| %s by %s |", cp, credit->i_name);
 
        if (ouch == gotcha) {           /* No use killing yourself */
                credit->i_kills--;
@@ -541,13 +569,15 @@ char              shot_type;
        gotcha->p_damage -= STABDAM;
        if (gotcha->p_damage < 0)
                gotcha->p_damage = 0;
-       (void) sprintf(Buf, "%2d/%2d", gotcha->p_damage, gotcha->p_damcap);
+       (void) snprintf(Buf, sizeof(Buf), "%2d/%2d", gotcha->p_damage,
+                       gotcha->p_damcap);
        cgoto(gotcha, STAT_DAM_ROW, STAT_VALUE_COL);
        outstr(gotcha, Buf, 5);
-       (void) sprintf(Buf, "%3d", (gotcha->p_damcap - MAXDAM) / 2);
+       (void) snprintf(Buf, sizeof(Buf), "%3d",
+                       (gotcha->p_damcap - MAXDAM) / 2);
        cgoto(gotcha, STAT_KILL_ROW, STAT_VALUE_COL);
        outstr(gotcha, Buf, 3);
-       (void) sprintf(Buf, "%5.2f", gotcha->p_ident->i_score);
+       (void) snprintf(Buf, sizeof(Buf), "%5.2f", gotcha->p_ident->i_score);
        for (ouch = Player; ouch < End_player; ouch++) {
                cgoto(ouch, STAT_PLAY_ROW + 1 + (gotcha - Player),
                        STAT_NAME_COL);
@@ -566,15 +596,14 @@ char              shot_type;
  * zap:
  *     Kill off a player and take him out of the game.
  */
-zap(pp, was_player)
-register PLAYER        *pp;
-FLAG           was_player;
+static void
+zap(PLAYER *pp, FLAG was_player, int i)
 {
-       register int    i, len;
-       register BULLET *bp;
-       register PLAYER *np;
-       register int    x, y;
-       int             savefd, savemask;
+       int     n, len;
+       BULLET  *bp;
+       PLAYER  *np;
+       int     x, y;
+       int     savefd;
 
        if (was_player) {
                if (pp->p_undershot)
@@ -587,8 +616,8 @@ FLAG                was_player;
        x = (WIDTH - len) / 2;
        cgoto(pp, HEIGHT / 2, x);
        outstr(pp, pp->p_death, len);
-       for (i = 1; i < len; i++)
-               pp->p_death[i] = '-';
+       for (n = 1; n < len; n++)
+               pp->p_death[n] = '-';
        pp->p_death[0] = '+';
        pp->p_death[len - 1] = '+';
        cgoto(pp, HEIGHT / 2 - 1, x);
@@ -598,7 +627,6 @@ FLAG                was_player;
        cgoto(pp, HEIGHT, 0);
 
        savefd = pp->p_fd;
-       savemask = pp->p_mask;
 
 # ifdef MONITOR
        if (was_player) {
@@ -610,22 +638,22 @@ FLAG              was_player;
                                bp->b_over = SPACE;
                }
 
-               i = rand_num(pp->p_ammo);
+               n = rand_num(pp->p_ammo);
                x = rand_num(pp->p_ammo);
-               if (x > i)
-                       i = x;
+               if (x > n)
+                       n = x;
                if (pp->p_ammo == 0)
                        x = 0;
-               else if (i == pp->p_ammo - 1) {
+               else if (n == pp->p_ammo - 1) {
                        x = pp->p_ammo;
                        len = SLIME;
                }
                else {
                        for (x = MAXBOMB - 1; x > 0; x--)
-                               if (i >= shot_req[x])
+                               if (n >= shot_req[x])
                                        break;
                        for (y = MAXSLIME - 1; y > 0; y--)
-                               if (i >= slime_req[y])
+                               if (n >= slime_req[y])
                                        break;
                        if (y >= 0 && slime_req[y] > shot_req[x]) {
                                x = slime_req[y];
@@ -639,7 +667,7 @@ FLAG                was_player;
                if (x > 0) {
                        (void) add_shot(len, pp->p_y, pp->p_x, pp->p_face, x,
                                (PLAYER *) NULL, TRUE, SPACE);
-                       (void) sprintf(Buf, "%s detonated.",
+                       (void) snprintf(Buf, sizeof(Buf), "%s detonated.",
                                pp->p_ident->i_name);
                        for (np = Player; np < End_player; np++)
                                message(np, Buf);
@@ -653,7 +681,7 @@ FLAG                was_player;
                                        if (np->p_flying < 0)
                                                break;
                                if (np >= &Boot[NBOOTS])
-                                       abort(1, "Too many boots");
+                                       err(1, "Too many boots");
                                np->p_undershot = FALSE;
                                np->p_x = pp->p_x;
                                np->p_y = pp->p_y;
@@ -713,31 +741,34 @@ FLAG              was_player;
                End_player--;
                if (pp != End_player) {
                        memcpy(pp, End_player, sizeof (PLAYER));
-                       (void) sprintf(Buf, "%5.2f%c%-10.10s %c",
+                       fdset[i] = fdset[End_player - Player + 3];
+                       fdset[End_player - Player + 3].fd = -1;
+                       (void) snprintf(Buf, sizeof(Buf), "%5.2f%c%-10.10s %c",
                                pp->p_ident->i_score, stat_char(pp),
                                pp->p_ident->i_name, pp->p_ident->i_team);
-                       i = STAT_PLAY_ROW + 1 + (pp - Player);
+                       n = STAT_PLAY_ROW + 1 + (pp - Player);
                        for (np = Player; np < End_player; np++) {
-                               cgoto(np, i, STAT_NAME_COL);
+                               cgoto(np, n, STAT_NAME_COL);
                                outstr(np, Buf, STAT_NAME_LEN);
                        }
 # ifdef MONITOR
                        for (np = Monitor; np < End_monitor; np++) {
-                               cgoto(np, i, STAT_NAME_COL);
+                               cgoto(np, n, STAT_NAME_COL);
                                outstr(np, Buf, STAT_NAME_LEN);
                        }
 # endif
-               }
+               } else
+                       fdset[i].fd = -1;
 
                /* Erase the last player */
-               i = STAT_PLAY_ROW + 1 + Nplayer;
+               n = STAT_PLAY_ROW + 1 + Nplayer;
                for (np = Player; np < End_player; np++) {
-                       cgoto(np, i, STAT_NAME_COL);
+                       cgoto(np, n, STAT_NAME_COL);
                        ce(np);
                }
 # ifdef MONITOR
                for (np = Monitor; np < End_monitor; np++) {
-                       cgoto(np, i, STAT_NAME_COL);
+                       cgoto(np, n, STAT_NAME_COL);
                        ce(np);
                }
        }
@@ -749,58 +780,43 @@ FLAG              was_player;
                End_monitor--;
                if (pp != End_monitor) {
                        memcpy(pp, End_monitor, sizeof (PLAYER));
-                       (void) sprintf(Buf, "%5.5s %-10.10s %c", " ",
+                       fdset[i] = fdset[End_monitor - Monitor + MAXPL + 3];
+                       fdset[End_monitor - Monitor + MAXPL + 3].fd = -1;
+                       (void) snprintf(Buf, sizeof(Buf), "%5.5s %-10.10s %c",
+                               " ",
                                pp->p_ident->i_name, pp->p_ident->i_team);
-                       i = STAT_MON_ROW + 1 + (pp - Player);
+                       n = STAT_MON_ROW + 1 + (pp - Player);
                        for (np = Player; np < End_player; np++) {
-                               cgoto(np, i, STAT_NAME_COL);
+                               cgoto(np, n, STAT_NAME_COL);
                                outstr(np, Buf, STAT_NAME_LEN);
                        }
                        for (np = Monitor; np < End_monitor; np++) {
-                               cgoto(np, i, STAT_NAME_COL);
+                               cgoto(np, n, STAT_NAME_COL);
                                outstr(np, Buf, STAT_NAME_LEN);
                        }
-               }
+               } else
+                       fdset[i].fd = -1;
 
                /* Erase the last monitor */
-               i = STAT_MON_ROW + 1 + (End_monitor - Monitor);
+               n = STAT_MON_ROW + 1 + (End_monitor - Monitor);
                for (np = Player; np < End_player; np++) {
-                       cgoto(np, i, STAT_NAME_COL);
+                       cgoto(np, n, STAT_NAME_COL);
                        ce(np);
                }
                for (np = Monitor; np < End_monitor; np++) {
-                       cgoto(np, i, STAT_NAME_COL);
+                       cgoto(np, n, STAT_NAME_COL);
                        ce(np);
                }
-
        }
 # endif
-
-       Fds_mask &= ~savemask;
-       if (Num_fds == savefd + 1) {
-               Num_fds = Socket;
-# ifdef INTERNET
-               if (Test_socket > Socket)
-                       Num_fds = Test_socket;
-# endif
-               for (np = Player; np < End_player; np++)
-                       if (np->p_fd > Num_fds)
-                               Num_fds = np->p_fd;
-# ifdef MONITOR
-               for (np = Monitor; np < End_monitor; np++)
-                       if (np->p_fd > Num_fds)
-                               Num_fds = np->p_fd;
-# endif
-               Num_fds++;
-       }
 }
 
 /*
  * rand_num:
  *     Return a random number in a given range.
  */
-rand_num(range)
-int    range;
+int
+rand_num(int range)
 {
        return (range == 0 ? 0 : RN % range);
 }
@@ -811,16 +827,14 @@ int       range;
  *     we do, read them, stash them away, and return TRUE; else return
  *     FALSE.
  */
-havechar(pp)
-register PLAYER        *pp;
+static int
+havechar(PLAYER *pp, int i)
 {
-       extern int      errno;
 
        if (pp->p_ncount < pp->p_nchar)
                return TRUE;
-       if (!(Have_inp & pp->p_mask))
+       if (!(fdset[i].revents & POLLIN))
                return FALSE;
-       Have_inp &= ~pp->p_mask;
 check_again:
        errno = 0;
        if ((pp->p_nchar = read(pp->p_fd, pp->p_cbuf, sizeof pp->p_cbuf)) <= 0)
@@ -838,10 +852,9 @@ check_again:
  *     Exit with the given value, cleaning up any droppings lying around
  */
 SIGNAL_TYPE
-cleanup(eval)
-int    eval;
+cleanup(int eval)
 {
-       register PLAYER *pp;
+       PLAYER  *pp;
 
        for (pp = Player; pp < End_player; pp++) {
                cgoto(pp, HEIGHT, 0);
@@ -869,13 +882,14 @@ int       eval;
  * send_stats:
  *     Print stats to requestor
  */
-send_stats()
+static void
+send_stats(void)
 {
-       register IDENT  *ip;
-       register FILE   *fp;
-       int             s;
-       SOCKET          sockstruct;
-       int             socklen;
+       IDENT   *ip;
+       FILE    *fp;
+       int     s;
+       SOCKET  sockstruct;
+       socklen_t       socklen;
 
        /*
         * Get the output stream ready
@@ -890,18 +904,18 @@ send_stats()
                if (errno == EINTR)
                        return;
 # ifdef LOG
-               syslog(LOG_ERR, "accept: %m");
+               syslog(LOG_WARNING, "accept: %m");
 # else
-               perror("accept");
+               warn("accept");
 # endif
                return;
        }
        fp = fdopen(s, "w");
        if (fp == NULL) {
 # ifdef LOG
-               syslog(LOG_ERR, "fdopen: %m");
+               syslog(LOG_WARNING, "fdopen: %m");
 # else
-               perror("fdopen");
+               warn("fdopen");
 # endif
                (void) close(s);
                return;
@@ -944,13 +958,14 @@ send_stats()
  * clear_scores:
  *     Clear out the scores so the next session start clean
  */
-clear_scores()
+static void
+clear_scores(void)
 {
-       register IDENT  *ip, *nextip;
+       IDENT   *ip, *nextip;
 
        for (ip = Scores; ip != NULL; ip = nextip) {
                nextip = ip->i_next;
-               (void) free((char *) ip);
+               (void) free(ip);
        }
        Scores = NULL;
 }