diff xrogue/main.c @ 136:1fbdefa82533

xrogue: initial support for the -n option. The scorefile location is also configurable now.
author John "Elwin" Edwards
date Wed, 22 Apr 2015 16:03:00 -0400
parents ce0cf824c192
children 0d151573bdb0
line wrap: on
line diff
--- a/xrogue/main.c	Tue Apr 21 10:34:01 2015 -0400
+++ b/xrogue/main.c	Wed Apr 22 16:03:00 2015 -0400
@@ -26,6 +26,9 @@
 #include "network.h"
 #include "rogue.h"
 
+#define SCOREFILE "xrogue.scr"
+#define SAVEDIR "."
+
 main(argc, argv, envp)
 char **argv;
 char **envp;
@@ -46,12 +49,33 @@
     strcat(file_name, "xrogue.sav");
 
     /* Get default score file */
+#ifdef SCOREFILE
+    strncpy(score_file, SCOREFILE, LINELEN);
+    score_file[LINELEN-1] = '\0';
+#else
     strcpy(score_file, md_getroguedir());
 
     if (*score_file)
         strcat(score_file,"/");
 
     strcat(score_file, "xrogue.scr");
+#endif
+
+#ifdef SAVEDIR
+    /* Check for common save location */
+    if (argc >= 3 && strcmp(argv[1], "-n") == 0)
+    {
+        strncpy(whoami, argv[2], 79);
+        whoami[79] = '\0';
+        use_savedir = TRUE;
+        if (LINELEN <= snprintf(file_name, LINELEN, "%s/%d-%s.xrsav", SAVEDIR, 
+                     md_getuid(), whoami))
+        {
+            strcpy(file_name, "xrogue.sav");
+            use_savedir = FALSE;
+        }
+    }
+#endif
 
     if ((env = getenv("ROGUEOPTS")) != NULL)
         parse_opts(env);
@@ -121,6 +145,12 @@
         exit_game(0);
     }
 
+    if (use_savedir)
+    {
+        /* restore() will return TRUE if a new game should be started. */
+        if (!restore(file_name, envp))
+            exit_game(0);
+    }
     if (argc == 2)
         if (!restore(argv[1], envp)) /* Note: restore will never return */
             exit_game(0);