X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/8218dc5ff267a1066f10d1dc24a259770c7e1257..e5c17e55df9ac3ba0cc4e6836b1296ca4e09c863:/phantasia/main.c diff --git a/phantasia/main.c b/phantasia/main.c index 996622ed..bd17453e 100644 --- a/phantasia/main.c +++ b/phantasia/main.c @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.17 2008/08/08 16:10:47 drochner Exp $ */ +/* $NetBSD: main.c,v 1.23 2009/08/31 08:27:16 dholland Exp $ */ /* * Phantasia 3.3.2 -- Interterminal fantasy game @@ -27,9 +27,25 @@ * AT&T is in no way connected with this game. */ -#include #include +#include +#include +#include #include +#include +#include +#include +#include +#include + +#include "macros.h" +#include "phantdefs.h" +#include "phantstruct.h" +#include "phantglobs.h" +#include "pathnames.h" + +#undef bool +#include /* * The program allocates as much file space as it needs to store characters, @@ -56,16 +72,19 @@ * main.c Main routines for Phantasia */ -#include "include.h" -#undef bool -#include +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 **); int -main(argc, argv) - int argc; - char **argv; +main(int argc, char **argv) { bool noheader = FALSE; /* set if don't want header */ bool headeronly = FALSE; /* set if only want header */ @@ -163,7 +182,7 @@ main(argc, 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; @@ -269,10 +288,11 @@ main(argc, argv) } } -void -initialstate() +static void +initialstate(void) { struct stat sb; + struct passwd *pw; Beyond = FALSE; Marsh = FALSE; @@ -285,8 +305,13 @@ initialstate() 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) @@ -320,8 +345,8 @@ initialstate() srandom((unsigned) time(NULL)); /* prime random numbers */ } -long -rollnewplayer() +static long +rollnewplayer(void) { int chartype; /* character type */ int ch; /* input */ @@ -410,8 +435,8 @@ rollnewplayer() return (allocrecord()); } -void -procmain() +static void +procmain(void) { int ch; /* input */ double x; /* desired new x coordinate */ @@ -620,8 +645,8 @@ procmain() } } -void -titlelist() +static void +titlelist(void) { FILE *fp; /* used for opening various files */ bool councilfound = FALSE; /* set if we find a member of the @@ -649,7 +674,8 @@ titlelist() Other.p_status != S_NOTUSED) /* found the king */ { - sprintf(Databuf, "The present ruler is %s Level:%.0f", + snprintf(Databuf, SZ_DATABUF, + "The present ruler is %s Level:%.0f", Other.p_name, Other.p_level); mvaddstr(4, 40 - strlen(Databuf) / 2, Databuf); kingfound = TRUE; @@ -664,7 +690,9 @@ titlelist() if (Other.p_specialtype == SC_VALAR && Other.p_status != S_NOTUSED) /* found the valar */ { - sprintf(Databuf, "The Valar is %s Login: %s", Other.p_name, Other.p_login); + snprintf(Databuf, SZ_DATABUF, + "The Valar is %s Login: %s", + Other.p_name, Other.p_login); mvaddstr(6, 40 - strlen(Databuf) / 2, Databuf); break; } @@ -680,7 +708,8 @@ titlelist() councilfound = TRUE; } /* This assumes a finite (<=5) number of C.O.W.: */ - sprintf(Databuf, "%s Login: %s", Other.p_name, Other.p_login); + snprintf(Databuf, SZ_DATABUF, + "%s Login: %s", Other.p_name, Other.p_login); mvaddstr(Lines++, 40 - strlen(Databuf) / 2, Databuf); } /* search for the two highest players */ @@ -710,7 +739,8 @@ titlelist() strcpy(nxtname, Other.p_name); } mvaddstr(15, 28, "Highest characters are:"); - sprintf(Databuf, "%s Level:%.0f and %s Level:%.0f", + snprintf(Databuf, SZ_DATABUF, + "%s Level:%.0f and %s Level:%.0f", hiname, hilvl, nxtname, nxtlvl); mvaddstr(17, 40 - strlen(Databuf) / 2, Databuf); @@ -725,8 +755,8 @@ titlelist() refresh(); } -long -recallplayer() +static long +recallplayer(void) { long loc = 0L; /* location in player file */ int loop; /* loop counter */ @@ -784,8 +814,8 @@ recallplayer() return (-1L); } -void -neatstuff() +static void +neatstuff(void) { double temp; /* for temporary calculations */ int ch; /* input */ @@ -886,9 +916,8 @@ neatstuff() } } -void -genchar(type) - int type; +static void +genchar(int type) { int subscript; /* used for subscripting into Stattable */ const struct charstats *statptr; /* for pointing into Stattable */ @@ -923,8 +952,8 @@ genchar(type) Player.p_experience = ROLL(600.0, 200.0); } -void -playinit() +static void +playinit(void) { /* catch/ingnore signals */ @@ -1007,8 +1036,7 @@ playinit() } void -cleanup(doexit) - int doexit; +cleanup(int doexit) { if (Windows) { move(LINES - 2, 0);