-/* $NetBSD: init.c,v 1.8 1999/02/10 01:36:50 hubertf Exp $ */
+/* $NetBSD: init.c,v 1.16 2014/03/22 23:33:33 dholland Exp $ */
/*
* Copyright (c) 1983, 1993
* 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. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
#if 0
static char sccsid[] = "@(#)init.c 8.4 (Berkeley) 4/30/95";
#else
-__RCSID("$NetBSD: init.c,v 1.8 1999/02/10 01:36:50 hubertf Exp $");
+__RCSID("$NetBSD: init.c,v 1.16 2014/03/22 23:33:33 dholland Exp $");
#endif
#endif /* not lint */
#include "extern.h"
+static int checkout(const char *);
+static const char *getutmp(void);
+static int wizard(const char *);
+
void
-initialize(startup)
- char startup;
+initialize(const char *filename)
{
const struct objs *p;
+ char *savefile;
puts("Version 4.2, fall 1984.");
puts("First Adventure game written by His Lordship, the honorable");
puts("Admiral D.W. Riggle\n");
location = dayfile;
- srand(getpid());
- getutmp(uname);
+ srandom(time(NULL));
+ username = getutmp();
wordinit();
- if (startup) {
+ if (filename == NULL) {
direction = NORTH;
ourtime = 0;
snooze = CYCLE * 1.5;
torps = TORPEDOES;
for (p = dayobjs; p->room != 0; p++)
setbit(location[p->room].objects, p->obj);
- } else
- restore();
- wiz = wizard(uname);
+ } else {
+ savefile = save_file_name(filename, strlen(filename));
+ restore(savefile);
+ free(savefile);
+ }
+ wiz = wizard(username);
signal(SIGINT, diesig);
}
-void
-getutmp(uname)
- char *uname;
+static const char *
+getutmp(void)
{
struct passwd *ptr;
ptr = getpwuid(getuid());
- strcpy(uname, ptr ? ptr->pw_name : "");
+ if (ptr == NULL)
+ return "";
+ else
+ return strdup(ptr->pw_name);
}
-const char *const list[] = { /* hereditary wizards */
+/* Hereditary wizards. A configuration file might make more sense. */
+static const char *const list[] = {
"riggle",
"chris",
"edward",
0
};
-const char *const badguys[] = {
+static const char *const badguys[] = {
"wnj",
"root",
"ted",
0
};
-int
-wizard(uname)
- const char *uname;
+static int
+wizard(const char *uname)
{
int flag;
return flag;
}
-int
-checkout(uname)
- const char *uname;
+static int
+checkout(const char *uname)
{
const char *const *ptr;