-/* $NetBSD: hack.main.c,v 1.7 2002/05/26 00:12:12 wiz Exp $ */
+/* $NetBSD: hack.main.c,v 1.17 2011/08/06 20:42:43 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.main.c,v 1.7 2002/05/26 00:12:12 wiz Exp $");
+__RCSID("$NetBSD: hack.main.c,v 1.17 2011/08/06 20:42:43 dholland Exp $");
#endif /* not lint */
#include <signal.h>
#define gamename "hack"
#endif
-int (*afternmv) __P((void));
-int (*occupation) __P((void));
+int (*afternmv)(void);
+int (*occupation)(void);
const char *occtxt; /* defined when occupation != NULL */
int hackpid; /* current pid */
#endif
char SAVEF[PL_NSIZ + 11] = "save/"; /* save/99999player */
char *hname; /* name of the game (argv[0] of call) */
-char obuf[BUFSIZ]; /* BUFSIZ is defined in stdio.h */
-int main __P((int, char *[]));
-static void chdirx __P((const char *, boolean));
+static char obuf[BUFSIZ]; /* BUFSIZ is defined in stdio.h */
+
+int main(int, char *[]);
+static void chdirx(const char *, boolean);
int
-main(argc, argv)
- int argc;
- char *argv[];
+main(int argc, char *argv[])
{
int fd;
#ifdef CHDIR
cls();
u.uhp = 1; /* prevent RIP on early quits */
u.ux = FAR; /* prevent nscr() */
- (void) signal(SIGHUP, hangup);
+ (void) signal(SIGHUP, hang_up);
/*
* Find the creation date of this game,
}
*gp = 0;
} else
- (void) strcpy(genocided, sfoo);
+ (void) strlcpy(genocided, sfoo,
+ sizeof(genocided));
(void) strcpy(fut_geno, genocided);
}
}
#endif
setftty();
- (void) sprintf(SAVEF, "save/%d%s", getuid(), plname);
+ (void) snprintf(SAVEF, sizeof(SAVEF), "save/%d%s", getuid(), plname);
regularize(SAVEF + 5); /* avoid . or / in name */
if ((fd = open(SAVEF, O_RDONLY)) >= 0 &&
(uptodate(fd) || unlink(SAVEF) == 666)) {
}
if (multi < 0) {
if (!++multi) {
- pline(nomovemsg ? nomovemsg :
- "You can move again.");
+ if (nomovemsg)
+ pline("%s", nomovemsg);
+ else
+ pline("You can move again.");
nomovemsg = 0;
if (afternmv)
(*afternmv) ();
#ifdef MAIL
ckmailstatus();
#endif
- rhack((char *) 0);
+ rhack(NULL);
}
if (multi && multi % 7 == 0)
(void) fflush(stdout);
}
void
-glo(foo)
- int foo;
+glo(int foo)
{
/* construct the string xlock.n */
- char *tf;
+ size_t pos;
- tf = lock;
- while (*tf && *tf != '.')
- tf++;
- (void) sprintf(tf, ".%d", foo);
+ pos = 0;
+ while (lock[pos] && lock[pos] != '.')
+ pos++;
+ (void) snprintf(lock + pos, sizeof(lock) - pos, ".%d", foo);
}
/*
* It may still contain a suffix denoting pl_character.
*/
void
-askname()
+askname(void)
{
int c, ct;
printf("\nWho are you? ");
if (c != '-')
if (c < 'A' || (c > 'Z' && c < 'a') || c > 'z')
c = '_';
- if (ct < sizeof(plname) - 1)
+ if (ct < (int)sizeof(plname) - 1)
plname[ct++] = c;
}
plname[ct] = 0;
#ifdef CHDIR
static void
-chdirx(dir, wr)
- const char *dir;
- boolean wr;
+chdirx(const char *dir, boolean wr)
{
#ifdef SECURE
#endif
void
-stop_occupation()
+stop_occupation(void)
{
if (occupation) {
pline("You stop %s.", occtxt);