-/* $NetBSD: main.c,v 1.15 2000/05/22 12:42:46 blymn Exp $ */
+/* $NetBSD: main.c,v 1.27 2021/05/02 12:50:45 rillig Exp $ */
/* main.c */
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: main.c,v 1.15 2000/05/22 12:42:46 blymn Exp $");
+__RCSID("$NetBSD: main.c,v 1.27 2021/05/02 12:50:45 rillig 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 *);
+
+#define __unreachable() __builtin_unreachable()
+
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
*/
strcpy(savefilename, ptr);
strcat(savefilename, "/Larn.sav"); /* save file name in home
* directory */
- sprintf(optsfile, "%s/.larnopts", ptr); /* the .larnopts filename */
+ snprintf(optsfile, sizeof(optsfile), "%s/.larnopts", ptr);
+ /* the .larnopts filename */
/*
* now malloc the memory for the dungeon
break;
}
if (j) {
- lprcat("Sorry, Larn needs a VT100 family terminal for all it's features.\n");
+ lprcat("Sorry, Larn needs a VT100 family terminal for all its features.\n");
lflush();
exit(1);
}
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;
sigsav = nosignal;
nosignal = 1; /* don't allow ^c etc */
if (c[GOLD]) {
- lprintf(".) %d gold pieces", (long) c[GOLD]);
+ lprintf(".) %ld gold pieces", (long) c[GOLD]);
srcount++;
}
for (k = 26; k >= 0; k--)
show3(j);
k = 0;
}
- lprintf("\nElapsed time is %d. You have %d mobuls left", (long) ((gltime + 99) / 100 + 1), (long) ((TIMELIMIT - gltime) / 100));
+ lprintf("\nElapsed time is %ld. You have %ld mobuls left", (long) ((gltime + 99) / 100 + 1), (long) ((TIMELIMIT - gltime) / 100));
more();
nosignal = sigsav;
}
/*
* 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(" + %d", (long) ivenarg[index]);
- else if (ivenarg[index] < 0)
- lprintf(" %d", (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 ODARTRAP:
case OTRAPARROW:
case OTELEPORTER:
- lprcat("\nIts ");
+ lprcat("\nIt's ");
lprcat(objectname[item[i][j]]);
flag++;
};
case 'g':
cursors();
- lprintf("\nThe stuff you are carrying presently weighs %d pounds", (long) packweight());
+ lprintf("\nThe stuff you are carrying presently weighs %ld pounds", (long) packweight());
+ /* FALLTHROUGH */
case ' ':
yrepcount = 0;
nomove = 1;
case 'v':
yrepcount = 0;
cursors();
- lprintf("\nCaverns of Larn, Version %d.%d, Diff=%d", (long) VERSION, (long) SUBVERSION, (long) c[HARDGAME]);
+ lprintf("\nCaverns of Larn, Version %ld.%ld, Diff=%ld",
+ (long) VERSION, (long) SUBVERSION,
+ (long) c[HARDGAME]);
if (wizard)
lprcat(" Wizard");
nomove = 1;
case 'P':
cursors();
if (outstanding_taxes > 0)
- lprintf("\nYou presently owe %d gp in taxes.", (long) outstanding_taxes);
+ lprintf("\nYou presently owe %ld gp in taxes.",
+ (long) outstanding_taxes);
else
lprcat("\nYou do not owe any taxes.");
return;
}
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) {
amt = 32767000L;
}
c[GOLD] -= amt;
- lprintf("You drop %d gold pieces", (long) amt);
+ lprintf("You drop %ld gold pieces", (long)amt);
iarg[playerx][playery] = i;
bottomgold();
know[playerx][playery] = 0;
/*
* 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 = getchar();
+ i = ttgetch();
if (i == '\33')
lprcat(" aborted");
return (i);
subroutine to get a number from the player
and allow * to mean return amt, else return the number entered
*/
-unsigned long
-readnum(mx)
- long mx;
+unsigned long
+readnum(long mx)
{
int i;
unsigned long amt = 0;
sncbr();
- if ((i = getchar()) == '*')
+ 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 = getchar();
+ i = ttgetch();
}
scbr();
return (amt);