diff urogue/main.c @ 259:096d3cfd9afd

UltraRogue: add the -n option.
author John "Elwin" Edwards
date Thu, 09 Feb 2017 16:29:45 -0500
parents c495a4f288c6
children 08057be02f47
line wrap: on
line diff
--- a/urogue/main.c	Wed Feb 08 19:50:36 2017 -0500
+++ b/urogue/main.c	Thu Feb 09 16:29:45 2017 -0500
@@ -23,8 +23,11 @@
 #include <string.h>
 #include <signal.h>
 #include <stdlib.h>
+#include <errno.h>
 #include "rogue.h"
 
+#define SAVEDIR "."
+
 FILE *fd_score = NULL;
 
 /* Command line options */
@@ -62,6 +65,21 @@
                 rflag = TRUE;
                 break;
 
+#ifdef SAVEDIR
+	    case 'n':
+		if (x + 1 < argc) {
+		    use_savedir = TRUE;
+		    x++;
+		    // Set rogue's name to the next argument
+		    strncpy(whoami, argv[x], 2*LINELEN);
+		    whoami[2*LINELEN - 1] = '\0';
+		    // And set up the savefile name
+		    snprintf(file_name, 2*LINELEN, "%s/%d-%.80s.ursav", SAVEDIR,
+				    md_getuid(), whoami);
+		}
+		break;
+#endif
+
             default:
                 fprintf(stderr,"%s: Unknown option '%c'.\n",argv[0],argv[x][1]);
                 exit(1);
@@ -86,12 +104,14 @@
     if ((env = getenv("OPTIONS")) != NULL)
         parse_opts(env);
 
-    nm = getenv("USER");
+    if (!use_savedir) {
+        nm = getenv("USER");
 
-    if (nm != NULL)
-        strcpy(whoami,nm);
-    else
-        strcpy(whoami,"anonymous");
+        if (nm != NULL)
+            strcpy(whoami,nm);
+        else
+            strcpy(whoami,"anonymous");
+    }
 		
 	lowtime = time(&now);
 	
@@ -168,7 +188,11 @@
     mw = newwin(LINES, COLS, 0, 0);
     hw = newwin(LINES, COLS, 0, 0);
 
-    if (argc == 2 && argv[1][0] != '\0' && !restore(argv[1]))
+    if (use_savedir) {
+        if (!restore(file_name))
+            exit(1);
+    }
+    else if (argc == 2 && argv[1][0] != '\0' && !restore(argv[1]))
         /* Note: restore returns on error only */
         exit(1);