]> git.cameronkatri.com Git - bsdgames-darwin.git/blobdiff - phantasia/main.c
Remove the smap.* files
[bsdgames-darwin.git] / phantasia / main.c
index 8e206d58b737d5622b53680b1586ba97b7453351..c8850da86a4eaf591a9bed9c4991efab21d353a8 100644 (file)
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.19 2009/05/25 23:14:33 dholland Exp $       */
+/*     $NetBSD: main.c,v 1.24 2019/02/03 03:19:25 mrg Exp $    */
 
 /*
  * Phantasia 3.3.2 -- Interterminal fantasy game
  * AT&T is in no way connected with this game.
  */
 
-#include <sys/stat.h>
 #include <sys/types.h>
+#include <sys/stat.h>
+#include <err.h>
+#include <math.h>
 #include <pwd.h>
+#include <setjmp.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "macros.h"
+#include "phantdefs.h"
+#include "phantstruct.h"
+#include "phantglobs.h"
+#include "pathnames.h"
+
+#undef bool
+#include <curses.h>
 
 /*
  * The program allocates as much file space as it needs to store characters,
  * main.c      Main routines for Phantasia
  */
 
-#include "include.h"
-#undef bool
-#include <curses.h>
+static void genchar(int);
+static void initialstate(void);
+static void neatstuff(void);
+static void playinit(void);
+static void procmain(void);
+static long recallplayer(void);
+static long rollnewplayer(void);
+static void titlelist(void);
 
 int    main(int, char **);
 
@@ -87,11 +108,13 @@ main(int argc, char **argv)
                case 'a':       /* all users */
                        activelist();
                        cleanup(TRUE);
+                       __unreachable();
                        /* NOTREACHED */
 
                case 'p':       /* purge old players */
                        purgeoldplayers();
                        cleanup(TRUE);
+                       __unreachable();
                        /* NOTREACHED */
 
                case 'S':       /* set 'Wizard' */
@@ -105,11 +128,13 @@ main(int argc, char **argv)
                case 'm':       /* monsters */
                        monstlist();
                        cleanup(TRUE);
+                       __unreachable();
                        /* NOTREACHED */
 
                case 'b':       /* scoreboard */
                        scorelist();
                        cleanup(TRUE);
+                       __unreachable();
                        /* NOTREACHED */
                }
 
@@ -122,15 +147,18 @@ main(int argc, char **argv)
        if (examine) {
                changestats(FALSE);
                cleanup(TRUE);
+               __unreachable();
                /* NOTREACHED */
        }
        if (!noheader) {
                titlelist();
                purgeoldplayers();      /* clean up old characters */
        }
-       if (headeronly)
+       if (headeronly) {
                cleanup(TRUE);
-       /* NOTREACHED */
+               __unreachable();
+               /* NOTREACHED */
+       }
 
        do
                /* get the player structure filled */
@@ -146,6 +174,7 @@ main(int argc, char **argv)
 
                case 'Q':
                        cleanup(TRUE);
+                       __unreachable();
                        /* NOTREACHED */
 
                default:
@@ -161,7 +190,7 @@ main(int argc, char **argv)
                Timeout = TRUE;
 
        /* update some important player statistics */
-       strcpy(Player.p_login, Login);
+       strlcpy(Player.p_login, Login, sizeof(Player.p_login));
        time(&seconds);
        Player.p_lastused = localtime(&seconds)->tm_yday;
        Player.p_status = S_PLAYING;
@@ -267,10 +296,11 @@ main(int argc, char **argv)
        }
 }
 
-void
+static void
 initialstate(void)
 {
        struct stat sb;
+       struct passwd *pw;
 
        Beyond = FALSE;
        Marsh = FALSE;
@@ -283,8 +313,13 @@ initialstate(void)
        Echo = TRUE;
 
        /* setup login name */
-       if ((Login = getlogin()) == NULL)
-               Login = getpwuid(getuid())->pw_name;
+       if ((Login = getlogin()) == NULL) {
+               pw = getpwuid(getuid());
+               if (pw == NULL) {
+                       errx(1, "Who are you?");
+               }
+               Login = pw->pw_name;
+       }
 
        /* open some files */
        if ((Playersfp = fopen(_PATH_PEOPLE, "r+")) == NULL)
@@ -318,7 +353,7 @@ initialstate(void)
        srandom((unsigned) time(NULL)); /* prime random numbers */
 }
 
-long
+static long
 rollnewplayer(void)
 {
        int     chartype;       /* character type */
@@ -408,7 +443,7 @@ rollnewplayer(void)
        return (allocrecord());
 }
 
-void
+static void
 procmain(void)
 {
        int     ch;             /* input */
@@ -517,6 +552,7 @@ procmain(void)
 
        case '5':               /* good-bye */
                leavegame();
+               __unreachable();
                /* NOTREACHED */
 
        case '6':               /* cloak */
@@ -618,7 +654,7 @@ procmain(void)
        }
 }
 
-void
+static void
 titlelist(void)
 {
        FILE   *fp;             /* used for opening various files */
@@ -728,7 +764,7 @@ titlelist(void)
        refresh();
 }
 
-long
+static long
 recallplayer(void)
 {
        long    loc = 0L;       /* location in player file */
@@ -787,7 +823,7 @@ recallplayer(void)
        return (-1L);
 }
 
-void
+static void
 neatstuff(void)
 {
        double  temp;           /* for temporary calculations */
@@ -889,7 +925,7 @@ neatstuff(void)
        }
 }
 
-void
+static void
 genchar(int type)
 {
        int     subscript;      /* used for subscripting into Stattable */
@@ -925,7 +961,7 @@ genchar(int type)
                Player.p_experience = ROLL(600.0, 200.0);
 }
 
-void
+static void
 playinit(void)
 {
        /* catch/ingnore signals */