X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/61a235f9c8a332df14e8fe40b7b1fcaa98ecc548..366256a208a1fe59bfb23c3e852701f35f8921da:/battlestar/init.c diff --git a/battlestar/init.c b/battlestar/init.c index a582545f..9670ea84 100644 --- a/battlestar/init.c +++ b/battlestar/init.c @@ -1,4 +1,4 @@ -/* $NetBSD: init.c,v 1.7 1997/10/11 02:07:25 lukem Exp $ */ +/* $NetBSD: init.c,v 1.12 2000/09/09 09:37:58 jsm Exp $ */ /* * Copyright (c) 1983, 1993 @@ -38,26 +38,31 @@ #if 0 static char sccsid[] = "@(#)init.c 8.4 (Berkeley) 4/30/95"; #else -__RCSID("$NetBSD: init.c,v 1.7 1997/10/11 02:07:25 lukem Exp $"); +__RCSID("$NetBSD: init.c,v 1.12 2000/09/09 09:37:58 jsm Exp $"); #endif #endif /* not lint */ #include "extern.h" +static int checkout __P((const char *)); +static const char *getutmp __P((void)); +static int wizard __P((const char *)); + void -initialize(startup) - char startup; +initialize(filename) + const char *filename; { - struct objs *p; + 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); + username = getutmp(); wordinit(); - if (startup) { + if (filename == NULL) { direction = NORTH; ourtime = 0; snooze = CYCLE * 1.5; @@ -67,23 +72,29 @@ initialize(startup) 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() { struct passwd *ptr; ptr = getpwuid(getuid()); - strcpy(uname, ptr ? ptr->pw_name : ""); + if (ptr == NULL) + return ""; + else + return strdup(ptr->pw_name); } -char *list[] = { /* hereditary wizards */ +/* Hereditary wizards. A configuration file might make more sense. */ +static const char *const list[] = { "riggle", "chris", "edward", @@ -94,16 +105,16 @@ char *list[] = { /* hereditary wizards */ 0 }; -char *badguys[] = { +static const char *const badguys[] = { "wnj", "root", "ted", 0 }; -int +static int wizard(uname) - char *uname; + const char *uname; { int flag; @@ -112,11 +123,11 @@ wizard(uname) return flag; } -int +static int checkout(uname) - char *uname; + const char *uname; { - char **ptr; + const char *const *ptr; for (ptr = list; *ptr; ptr++) if (strcmp(*ptr, uname) == 0)