]> git.cameronkatri.com Git - bsdgames-darwin.git/blobdiff - battlestar/init.c
From OpenBSD: in kiss(), "take" the bathing goddess if required, and
[bsdgames-darwin.git] / battlestar / init.c
index 6627984d0ffe0a43eeca5a5a64457cace781079a..9670ea84941bbb5d1f46254f4d8c9e2c73fd32ce 100644 (file)
@@ -1,4 +1,4 @@
-/*     $NetBSD: init.c,v 1.6 1997/10/10 11:40:01 lukem Exp $   */
+/*     $NetBSD: init.c,v 1.12 2000/09/09 09:37:58 jsm Exp $    */
 
 /*
  * Copyright (c) 1983, 1993
 #if 0
 static char sccsid[] = "@(#)init.c     8.4 (Berkeley) 4/30/95";
 #else
-__RCSID("$NetBSD: init.c,v 1.6 1997/10/10 11:40:01 lukem Exp $");
+__RCSID("$NetBSD: init.c,v 1.12 2000/09/09 09:37:58 jsm Exp $");
 #endif
-#endif /* not lint */
+#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,29 +105,29 @@ 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;
+       int     flag;
 
        if ((flag = checkout(uname)) != 0)
                printf("You are the Great wizard %s.\n", 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)
@@ -124,7 +135,7 @@ checkout(uname)
        for (ptr = badguys; *ptr; ptr++)
                if (strcmp(*ptr, uname) == 0) {
                        printf("You are the Poor anti-wizard %s.  Good Luck!\n",
-                               uname);
+                           uname);
                        CUMBER = 3;
                        WEIGHT = 9;     /* that'll get him! */
                        ourclock = 10;