-/* $NetBSD: main.c,v 1.19 2008/01/28 03:39:31 dholland Exp $ */
+/* $NetBSD: main.c,v 1.26 2019/02/03 03:19:25 mrg Exp $ */
/* main.c */
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: main.c,v 1.19 2008/01/28 03:39:31 dholland Exp $");
+__RCSID("$NetBSD: main.c,v 1.26 2019/02/03 03:19:25 mrg Exp $");
#endif /* not lint */
#include <sys/types.h>
#include "header.h"
#include "extern.h"
+static void showstr(void);
+static void t_setup(int);
+static void t_endup(int);
+static void showwear(void);
+static void showwield(void);
+static void showread(void);
+static void showeat(void);
+static void showquaff(void);
+static void show1(int, const char *[]);
+static void randmonst(void);
+static void parse(void);
+static void run(int);
+static void wield(void);
+static void ydhi(int);
+static void ycwi(int);
+static void wear(void);
+static void dropobj(void);
+static void readscr(void);
+static void eatcookie(void);
+static void quaff(void);
+static int whatitem(const char *);
+
static char copyright[] = "\nLarn is copyrighted 1986 by Noah Morgan.\n";
int srcount = 0; /* line counter for showstr() */
int dropflag = 0; /* if 1 then don't lookforobject() next round */
int rmst = 80; /* random monster creation counter */
int userid; /* the players login user id number */
-uid_t uid, euid; /* used for security */
+gid_t gid, egid; /* used for security */
u_char nowelcome = 0, nomove = 0; /* if (nomove) then don't
* count next iteration as a
* move */
************
*/
int
-main(argc, argv)
- int argc;
- char **argv;
+main(int argc, char **argv)
{
int i;
int hard;
struct passwd *pwe;
i = 0;
- euid = geteuid();
- uid = getuid();
- seteuid(uid); /* give up "games" if we have it */
+ egid = getegid();
+ gid = getgid();
+ setegid(gid); /* give up "games" if we have it */
/*
* first task is to identify the player
*/
show character's inventory
*/
-void
-showstr()
+static void
+showstr(void)
{
int i, number;
for (number = 3, i = 0; i < 26; i++)
}
void
-qshowstr()
+qshowstr(void)
{
int i, j, k, sigsav;
srcount = 0;
/*
* subroutine to clear screen depending on # lines to display
*/
-void
-t_setup(count)
- int count;
+static void
+t_setup(int count)
{
if (count < 20) { /* how do we clear the screen? */
cl_up(79, count);
/*
* subroutine to restore normal display screen depending on t_setup()
*/
-void
-t_endup(count)
- int count;
+static void
+t_endup(int count)
{
if (count < 18) /* how did we clear the screen? */
draws(0, MAXX, 0, (count > MAXY) ? MAXY : count);
/*
function to show the things player is wearing only
*/
-void
-showwear()
+static void
+showwear(void)
{
int i, j, sigsav, count;
sigsav = nosignal;
/*
function to show the things player can wield only
*/
-void
-showwield()
+static void
+showwield(void)
{
int i, j, sigsav, count;
sigsav = nosignal;
/*
* function to show the things player can read only
*/
-void
-showread()
+static void
+showread(void)
{
int i, j, sigsav, count;
sigsav = nosignal;
/*
* function to show the things player can eat only
*/
-void
-showeat()
+static void
+showeat(void)
{
int i, j, sigsav, count;
sigsav = nosignal;
/*
function to show the things player can quaff only
*/
-void
-showquaff()
+static void
+showquaff(void)
{
int i, j, sigsav, count;
sigsav = nosignal;
t_endup(count);
}
-void
-show1(idx, str2)
- int idx;
- char *str2[];
+static void
+show1(int idx, const char *str2[])
{
lprintf("\n%c) %s", idx + 'a', objectname[iven[idx]]);
if (str2 != 0 && str2[ivenarg[idx]][0] != 0)
}
void
-show3(index)
- int index;
+show3(int indx)
{
- switch (iven[index]) {
+ switch (iven[indx]) {
case OPOTION:
- show1(index, potionname);
+ show1(indx, potionname);
break;
case OSCROLL:
- show1(index, scrollname);
+ show1(indx, scrollname);
break;
case OLARNEYE:
case OCOOKIE:
case OSAPPHIRE:
case ONOTHEFT:
- show1(index, (char **) 0);
+ show1(indx, NULL);
break;
default:
- lprintf("\n%c) %s", index + 'a', objectname[iven[index]]);
- if (ivenarg[index] > 0)
- lprintf(" + %ld", (long) ivenarg[index]);
- else if (ivenarg[index] < 0)
- lprintf(" %ld", (long) ivenarg[index]);
+ lprintf("\n%c) %s", indx + 'a', objectname[iven[indx]]);
+ if (ivenarg[indx] > 0)
+ lprintf(" + %ld", (long) ivenarg[indx]);
+ else if (ivenarg[indx] < 0)
+ lprintf(" %ld", (long) ivenarg[indx]);
break;
}
- if (c[WIELD] == index)
+ if (c[WIELD] == indx)
lprcat(" (weapon in hand)");
- if ((c[WEAR] == index) || (c[SHIELD] == index))
+ if ((c[WEAR] == indx) || (c[SHIELD] == indx))
lprcat(" (being worn)");
if (++srcount >= 22) {
srcount = 0;
/*
subroutine to randomly create monsters if needed
*/
-void
-randmonst()
+static void
+randmonst(void)
{
if (c[TIMESTOP])
return; /* don't make monsters if time is stopped */
get and execute a command
*/
-void
-parse()
+static void
+parse(void)
{
int i, j, k, flag;
while (1) {
savegame(savefilename);
wizard = 1;
died(-257); /* save the game - doesn't return */
+ __unreachable();
case 'Z':
yrepcount = 0;
case 'g':
cursors();
lprintf("\nThe stuff you are carrying presently weighs %ld pounds", (long) packweight());
+ /* FALLTHROUGH */
case ' ':
yrepcount = 0;
nomove = 1;
}
void
-parse2()
+parse2(void)
{
if (c[HASTEMONST])
movemonst();
regen();
}
-void
-run(dir)
- int dir;
+static void
+run(int dir)
{
int i;
i = 1;
/*
function to wield a weapon
*/
-void
-wield()
+static void
+wield(void)
{
int i;
while (1) {
/*
common routine to say you don't have an item
*/
-void
-ydhi(x)
- int x;
+static void
+ydhi(int x)
{
cursors();
lprintf("\nYou don't have item %c!", x);
}
-void
-ycwi(x)
- int x;
+static void
+ycwi(int x)
{
cursors();
lprintf("\nYou can't wield item %c!", x);
/*
function to wear armor
*/
-void
-wear()
+static void
+wear(void)
{
int i;
while (1) {
/*
function to drop an object
*/
-void
-dropobj()
+static void
+dropobj(void)
{
int i;
- char *p;
+ unsigned char *p;
long amt;
p = &item[playerx][playery];
while (1) {
/*
* readscr() Subroutine to read a scroll one is carrying
*/
-void
-readscr()
+static void
+readscr(void)
{
int i;
while (1) {
/*
* subroutine to eat a cookie one is carrying
*/
-void
-eatcookie()
+static void
+eatcookie(void)
{
- int i;
- char *p;
+ const char *p;
+ int i;
+
while (1) {
if ((i = whatitem("eat")) == '\33')
return;
/*
* subroutine to quaff a potion one is carrying
*/
-void
-quaff()
+static void
+quaff(void)
{
int i;
while (1) {
/*
function to ask what player wants to do
*/
-int
-whatitem(str)
- char *str;
+static int
+whatitem(const char *str)
{
int i;
cursors();
lprintf("\nWhat do you want to %s [* for all] ? ", str);
i = 0;
while (i > 'z' || (i < 'a' && i != '*' && i != '\33' && i != '.'))
- i = lgetchar();
+ i = ttgetch();
if (i == '\33')
lprcat(" aborted");
return (i);
and allow * to mean return amt, else return the number entered
*/
unsigned long
-readnum(mx)
- long mx;
+readnum(long mx)
{
int i;
unsigned long amt = 0;
sncbr();
- if ((i = lgetchar()) == '*')
+ if ((i = ttgetch()) == '*')
amt = mx; /* allow him to say * for all gold */
else
while (i != '\n') {
}
if ((i <= '9') && (i >= '0') && (amt < 99999999))
amt = amt * 10 + i - '0';
- i = lgetchar();
+ i = ttgetch();
}
scbr();
return (amt);