-/* $NetBSD: hack.do_name.c,v 1.5 2001/03/25 20:43:59 jsm Exp $ */
+/* $NetBSD: hack.do_name.c,v 1.13 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.do_name.c,v 1.5 2001/03/25 20:43:59 jsm Exp $");
+__RCSID("$NetBSD: hack.do_name.c,v 1.13 2011/08/07 06:03:45 dholland Exp $");
#endif /* not lint */
#include <stdlib.h>
#include "hack.h"
#include "extern.h"
+static void do_oname(struct obj *);
+static char *xmonnam(struct monst *, int);
+static char *lmonnam(struct monst *);
+static char *visctrl(int);
+
coord
-getpos(force, goal)
- int force;
- const char *goal;
+getpos(int force, const char *goal)
{
int cx, cy, i, c;
coord cc;
}
int
-do_mname()
+do_mname(void)
{
char buf[BUFSZ];
coord cc;
- int cx, cy, lth, i;
+ int cx, cy;
+ size_t lth;
+ unsigned i;
struct monst *mtmp, *mtmp2;
cc = getpos(0, "the monster you want to name");
cx = cc.x;
* when there might be pointers around in unknown places. For now: only
* when obj is in the inventory.
*/
-void
-do_oname(obj)
- struct obj *obj;
+static void
+do_oname(struct obj *obj)
{
struct obj *otmp, *otmp2;
- int lth;
+ size_t lth;
char buf[BUFSZ];
pline("What do you want to name %s? ", doname(obj));
getlin(buf);
#if 0
obfree(obj, otmp2); /* now unnecessary: no pointers on bill */
#endif
- free((char *) obj); /* let us hope nobody else saved a pointer */
+ free(obj); /* let us hope nobody else saved a pointer */
}
int
-ddocall()
+ddocall(void)
{
struct obj *obj;
}
void
-docall(obj)
- struct obj *obj;
+docall(struct obj *obj)
{
char buf[BUFSZ];
struct obj otemp;
*str1 = str;
}
-const char *const ghostnames[] = {/* these names should have length < PL_NSIZ */
+static const char *const ghostnames[] = {
+ /* these names should have length < PL_NSIZ */
"adri", "andries", "andreas", "bert", "david", "dirk", "emile",
"frans", "fred", "greg", "hether", "jay", "john", "jon", "kay",
"kenny", "maud", "michiel", "mike", "peter", "robert", "ron",
"tom", "wilmar"
};
-char *
-xmonnam(mtmp, vb)
- struct monst *mtmp;
- int vb;
+static char *
+xmonnam(struct monst *mtmp, int vb)
{
static char buf[BUFSZ]; /* %% */
if (mtmp->mnamelth && !vb) {
- (void) strcpy(buf, NAME(mtmp));
+ (void) strlcpy(buf, NAME(mtmp), sizeof(buf));
return (buf);
}
switch (mtmp->data->mlet) {
gn = ghostnames[rn2(SIZE(ghostnames))];
if (!rn2(2))
(void)
- strcpy((char *) mtmp->mextra, !rn2(5) ? plname : gn);
+ strlcpy((char *) mtmp->mextra, !rn2(5) ? plname : gn, mtmp->mxlth);
}
- (void) sprintf(buf, "%s's ghost", gn);
+ (void) snprintf(buf, sizeof(buf), "%s's ghost", gn);
}
break;
case '@':
if (mtmp->isshk) {
- (void) strcpy(buf, shkname(mtmp));
+ (void) strlcpy(buf, shkname(mtmp), sizeof(buf));
break;
}
- /* fall into next case */
+ /* FALLTHROUGH */
default:
- (void) sprintf(buf, "the %s%s",
+ (void) snprintf(buf, sizeof(buf), "the %s%s",
mtmp->minvis ? "invisible " : "",
mtmp->data->mname);
}
if (vb && mtmp->mnamelth) {
- (void) strcat(buf, " called ");
- (void) strcat(buf, NAME(mtmp));
+ (void) strlcat(buf, " called ", sizeof(buf));
+ (void) strlcat(buf, NAME(mtmp), sizeof(buf));
}
return (buf);
}
-char *
-lmonnam(mtmp)
- struct monst *mtmp;
+static char *
+lmonnam(struct monst *mtmp)
{
return (xmonnam(mtmp, 1));
}
char *
-monnam(mtmp)
- struct monst *mtmp;
+monnam(struct monst *mtmp)
{
return (xmonnam(mtmp, 0));
}
char *
-Monnam(mtmp)
- struct monst *mtmp;
+Monnam(struct monst *mtmp)
{
char *bp = monnam(mtmp);
if ('a' <= *bp && *bp <= 'z')
}
char *
-amonnam(mtmp, adj)
- struct monst *mtmp;
- const char *adj;
+amonnam(struct monst *mtmp, const char *adj)
{
char *bp = monnam(mtmp);
static char buf[BUFSZ]; /* %% */
if (!strncmp(bp, "the ", 4))
bp += 4;
- (void) sprintf(buf, "the %s %s", adj, bp);
+ (void) snprintf(buf, sizeof(buf), "the %s %s", adj, bp);
return (buf);
}
char *
-Amonnam(mtmp, adj)
- struct monst *mtmp;
- const char *adj;
+Amonnam(struct monst *mtmp, const char *adj)
{
char *bp = amonnam(mtmp, adj);
}
char *
-Xmonnam(mtmp)
- struct monst *mtmp;
+Xmonnam(struct monst *mtmp)
{
char *bp = Monnam(mtmp);
if (!strncmp(bp, "The ", 4)) {
return (bp);
}
-char *
-visctrl(c)
- char c;
+static char *
+visctrl(int c)
{
static char ccc[3];
if (c < 040) {