-/* $NetBSD: hack.invent.c,v 1.6 1997/10/23 07:05:55 fair Exp $ */
+/* $NetBSD: hack.invent.c,v 1.18 2011/08/07 06:03:45 dholland Exp $ */
/*
- * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
+ * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
+ * Amsterdam
+ * 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 Stichting Centrum voor Wiskunde en
+ * Informatica, 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.
+ */
+
+/*
+ * Copyright (c) 1982 Jay Fenlason <hack@gnu.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``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 AUTHOR 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 <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: hack.invent.c,v 1.6 1997/10/23 07:05:55 fair Exp $");
+__RCSID("$NetBSD: hack.invent.c,v 1.18 2011/08/07 06:03:45 dholland Exp $");
#endif /* not lint */
+#include <assert.h>
#include <stdlib.h>
#include "hack.h"
#include "extern.h"
static int lastinvnr = 51; /* 0 ... 51 */
-static void assigninvlet __P((struct obj *));
-static char *xprname __P((struct obj *, char));
+static char *xprname(struct obj *, char);
+static void doinv(const char *);
+static int merged(struct obj *, struct obj *, int);
static void
-assigninvlet(otmp)
- struct obj *otmp;
+assigninvlet(struct obj *otmp)
{
boolean inuse[52];
int i;
}
struct obj *
-addinv(obj)
- struct obj *obj;
+addinv(struct obj *obj)
{
struct obj *otmp;
}
void
-useup(obj)
- struct obj *obj;
+useup(struct obj *obj)
{
if (obj->quan > 1) {
obj->quan--;
}
void
-freeinv(obj)
- struct obj *obj;
+freeinv(struct obj *obj)
{
struct obj *otmp;
/* destroy object in fobj chain (if unpaid, it remains on the bill) */
void
-delobj(obj)
- struct obj *obj;
+delobj(struct obj *obj)
{
freeobj(obj);
unpobj(obj);
/* unlink obj from chain starting with fobj */
void
-freeobj(obj)
- struct obj *obj;
+freeobj(struct obj *obj)
{
struct obj *otmp;
if (obj == fobj)
fobj = fobj->nobj;
else {
- for (otmp = fobj; otmp->nobj != obj; otmp = otmp->nobj)
- if (!otmp)
+ otmp = fobj;
+ while (otmp->nobj != obj) {
+ if (otmp->nobj == NULL)
panic("error in freeobj");
+ otmp = otmp->nobj;
+ }
otmp->nobj = obj->nobj;
}
}
/* Note: freegold throws away its argument! */
void
-freegold(gold)
- struct gold *gold;
+freegold(struct gold *gold)
{
struct gold *gtmp;
if (gold == fgold)
fgold = gold->ngold;
else {
- for (gtmp = fgold; gtmp->ngold != gold; gtmp = gtmp->ngold)
- if (!gtmp)
+ gtmp = fgold;
+ while (gtmp->ngold != gold) {
+ if (gtmp->ngold == NULL)
panic("error in freegold");
+ gtmp = gtmp->ngold;
+ }
gtmp->ngold = gold->ngold;
}
- free((char *) gold);
+ free(gold);
}
void
-deltrap(trap)
- struct trap *trap;
+deltrap(struct trap *trap)
{
struct trap *ttmp;
for (ttmp = ftrap; ttmp->ntrap != trap; ttmp = ttmp->ntrap);
ttmp->ntrap = trap->ntrap;
}
- free((char *) trap);
+ free(trap);
}
struct wseg *m_atseg;
struct monst *
-m_at(x, y)
- int x, y;
+m_at(int x, int y)
{
struct monst *mtmp;
#ifndef NOWORM
}
struct obj *
-o_at(x, y)
- int x, y;
+o_at(int x, int y)
{
struct obj *otmp;
}
struct obj *
-sobj_at(n, x, y)
- int n, x, y;
+sobj_at(int n, int x, int y)
{
struct obj *otmp;
}
int
-carried(obj)
- struct obj *obj;
+carried(struct obj *obj)
{
struct obj *otmp;
for (otmp = invent; otmp; otmp = otmp->nobj)
}
int
-carrying(type)
- int type;
+carrying(int type)
{
struct obj *otmp;
}
struct obj *
-o_on(id, objchn)
- unsigned int id;
- struct obj *objchn;
+o_on(unsigned int id, struct obj *objchn)
{
while (objchn) {
if (objchn->o_id == id)
}
struct trap *
-t_at(x, y)
- int x, y;
+t_at(int x, int y)
{
struct trap *trap = ftrap;
while (trap) {
}
struct gold *
-g_at(x, y)
- int x, y;
+g_at(int x, int y)
{
struct gold *gold = fgold;
while (gold) {
}
/* make dummy object structure containing gold - for temporary use only */
-struct obj *
-mkgoldobj(q)
- long q;
+static struct obj *
+mkgoldobj(long q)
{
struct obj *otmp;
* &zeroobj explicitly no object (as in w-).
*/
struct obj *
-getobj(let, word)
- char *let, *word;
+getobj(const char *let, const char *word)
{
struct obj *otmp;
char ilet, ilet1, ilet2;
continue;
/* he typed a letter (not a space) to more() */
} else if (ilet == '*') {
- doinv((char *) 0);
+ doinv(NULL);
if (!(ilet = morc))
continue;
/* ... */
return (otmp);
}
-int
-ckunpaid(otmp)
- struct obj *otmp;
+static int
+ckunpaid(struct obj *otmp)
{
return (otmp->unpaid);
}
/* interactive version of getobj - used for Drop and Identify */
/* return the number of times fn was called successfully */
int
-ggetobj(word, fn, max)
- char *word;
- int (*fn) __P((struct obj *));
- int max;
+ggetobj(const char *word, int (*fn)(struct obj *), int max)
{
char buf[BUFSZ];
char *ip;
char sym;
- int oletct = 0, iletct = 0;
+ unsigned oletct = 0, iletct = 0;
boolean allflag = FALSE;
char olets[20], ilets[20];
- int (*ckfn) __P((struct obj *)) =
- (int (*) __P((struct obj *))) 0;
+ int (*ckfn)(struct obj *) =
+ (int (*)(struct obj *)) 0;
xchar allowgold = (u.ugold && !strcmp(word, "drop")) ? 1 : 0; /* BAH */
if (!invent && !allowgold) {
pline("You have nothing to %s.", word);
if (invent)
ilets[iletct++] = 'a';
ilets[iletct] = 0;
+ assert(iletct < sizeof(ilets));
}
pline("What kinds of thing do you want to %s? [%s] ",
word, ilets);
olets[oletct++] = sym;
olets[oletct] = 0;
}
+ assert(oletct < sizeof(olets));
} else
pline("You don't have any %c's.", sym);
}
* objects to be treated. Return the number of objects treated.
*/
int
-askchain(objchn, olets, allflag, fn, ckfn, max)
- struct obj *objchn;
- char *olets;
- int allflag;
- int (*fn) __P((struct obj *));
- int (*ckfn) __P((struct obj *));
- int max;
+askchain(struct obj *objchn, char *olets, int allflag,
+ int (*fn)(struct obj *),
+ int (*ckfn)(struct obj *),
+ int max)
{
struct obj *otmp, *otmp2;
char sym, ilet;
if (ckfn && !(*ckfn) (otmp))
continue;
if (!allflag) {
- pline(xprname(otmp, ilet));
+ pline("%s", xprname(otmp, ilet));
addtopl(" [nyaq]? ");
sym = readchar();
} else
switch (sym) {
case 'a':
allflag = 1;
+ /* FALLTHROUGH */
case 'y':
cnt += (*fn) (otmp);
if (--max == 0)
goto ret;
+ break;
case 'n':
default:
break;
return (cnt);
}
-char
-obj_to_let(obj) /* should of course only be called for things
- * in invent */
- struct obj *obj;
+/* should of course only be called for things in invent */
+static char
+obj_to_let(struct obj *obj)
{
struct obj *otmp;
char ilet;
}
void
-prinv(obj)
- struct obj *obj;
+prinv(struct obj *obj)
{
- pline(xprname(obj, obj_to_let(obj)));
+ pline("%s", xprname(obj, obj_to_let(obj)));
}
-static char *
-xprname(obj, let)
- struct obj *obj;
- char let;
+static char *
+xprname(struct obj *obj, char let)
{
static char li[BUFSZ];
- (void) sprintf(li, "%c - %s.",
+ (void) snprintf(li, sizeof(li), "%c - %s.",
flags.invlet_constant ? obj->invlet : let,
doname(obj));
return (li);
}
int
-ddoinv()
+ddoinv(void)
{
- doinv((char *) 0);
+ doinv(NULL);
return (0);
}
/* called with 0 or "": all objects in inventory */
/* otherwise: all objects with (serial) letter in lets */
-void
-doinv(lets)
- char *lets;
+static void
+doinv(const char *lets)
{
struct obj *otmp;
char ilet;
- int ct = 0;
+ unsigned ct = 0;
char any[BUFSZ];
morc = 0; /* just to be sure */
pline("Not carrying anything.");
return;
}
- cornline(0, (char *) 0);
+ cornline(0, NULL);
ilet = 'a';
for (otmp = invent; otmp; otmp = otmp->nobj) {
if (flags.invlet_constant)
ilet = 'A';
}
any[ct] = 0;
+ assert(ct < sizeof(any));
cornline(2, any);
}
int
-dotypeinv()
+dotypeinv(void)
{ /* free after Robert Viduya */
/* Changed to one type only, so he doesnt have to type cr */
char c, ilet;
char stuff[BUFSZ];
- int stct;
+ unsigned stct;
struct obj *otmp;
boolean billx = inshop() && doinvbill(0);
boolean unpd = FALSE;
if (billx)
stuff[stct++] = 'x';
stuff[stct] = 0;
+ assert(stct < sizeof(stuff));
if (stct > 1) {
pline("What type of object [%s] do you want an inventory of? ",
ilet = 'A';
}
stuff[stct] = '\0';
+ assert(stct < sizeof(stuff));
+
if (stct == 0)
pline("You have no such objects.");
else
/* look at what is here */
int
-dolook()
+dolook(void)
{
struct obj *otmp = NULL, *otmp0 = NULL;
struct gold *gold = NULL;
- char *verb = Blind ? "feel" : "see";
+ const char *verb = Blind ? "feel" : "see";
int ct = 0;
if (!u.uswallow) {
if (gold) {
char gbuf[30];
- (void) sprintf(gbuf, "%ld gold piece%s",
+ (void) snprintf(gbuf, sizeof(gbuf), "%ld gold piece%s",
gold->amount, plur(gold->amount));
if (!ct++)
pline("You %s here %s.", verb, gbuf);
}
if (ct == 1 && !gold) {
pline("You %s here %s.", verb, doname(otmp0));
- cornline(3, (char *) 0);
+ cornline(3, NULL);
}
if (ct > 1)
- cornline(2, (char *) 0);
+ cornline(2, NULL);
return (!!Blind);
}
void
-stackobj(obj)
- struct obj *obj;
+stackobj(struct obj *obj)
{
struct obj *otmp = fobj;
for (otmp = fobj; otmp; otmp = otmp->nobj)
}
/* merge obj with otmp and delete obj if types agree */
-int
-merged(otmp, obj, lose)
- struct obj *otmp, *obj;
+static int
+merged(struct obj *otmp, struct obj *obj, int lose)
{
if (obj->otyp == otmp->otyp &&
obj->unpaid == otmp->unpaid &&
* it may take a while before you have counted it all.
* [Bug: d$ and pickup still tell you how much it was.]
*/
-int
-countgold()
+static int
+countgold(void)
{
if ((goldcounted += 100 * (u.ulevel + 1)) >= u.ugold) {
long eps = 0;
}
int
-doprgold()
+doprgold(void)
{
if (!u.ugold)
pline("You do not carry any gold.");
/* --- end of gold counting section --- */
int
-doprwep()
+doprwep(void)
{
if (!uwep)
pline("You are empty handed.");
}
int
-doprarm()
+doprarm(void)
{
if (!uarm && !uarmg && !uarms && !uarmh)
pline("You are not wearing any armor.");
}
int
-doprring()
+doprring(void)
{
if (!uleft && !uright)
pline("You are not wearing any rings.");
}
int
-digit(c)
- char c;
+digit(int c)
{
return (c >= '0' && c <= '9');
}