# HG changeset patch # User John "Elwin" Edwards # Date 1486675785 18000 # Node ID 096d3cfd9afd1b1e7cb29b81475a5f66ebe0f37c # Parent 2908dc47f9e21e8ccda384d6715887786687eebc UltraRogue: add the -n option. diff -r 2908dc47f9e2 -r 096d3cfd9afd urogue/main.c --- 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 #include #include +#include #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); diff -r 2908dc47f9e2 -r 096d3cfd9afd urogue/rogue.h --- a/urogue/rogue.h Wed Feb 08 19:50:36 2017 -0500 +++ b/urogue/rogue.h Thu Feb 09 16:29:45 2017 -0500 @@ -1686,6 +1686,7 @@ extern int canwizard; /* Will be permitted to do this */ extern int askme; /* Ask about unidentified things */ extern int moving; /* move using 'm' command */ +extern int use_savedir; /* Savefile is in system savedir */ extern int inv_type; /* Inven style. Bool so options works */ extern char take; /* Thing the rogue is taking */ @@ -1809,6 +1810,7 @@ long md_random(void); void md_srandom(long seed); int md_readchar(WINDOW *win); +int md_getuid(void); #define NOOP(x) (x += 0) #define CCHAR(x) ( (char) (x & A_CHARTEXT) ) diff -r 2908dc47f9e2 -r 096d3cfd9afd urogue/save.c --- a/urogue/save.c Wed Feb 08 19:50:36 2017 -0500 +++ b/urogue/save.c Thu Feb 09 16:29:45 2017 -0500 @@ -90,6 +90,8 @@ if ((infd = fopen(file, "r")) == NULL) { + if (use_savedir && errno == ENOENT) + return TRUE; perror(file); return(FALSE); } diff -r 2908dc47f9e2 -r 096d3cfd9afd urogue/state.c --- a/urogue/state.c Wed Feb 08 19:50:36 2017 -0500 +++ b/urogue/state.c Thu Feb 09 16:29:45 2017 -0500 @@ -138,6 +138,7 @@ int wizard = FALSE; int wiz_verbose = TRUE; int moving = FALSE; +int use_savedir = FALSE; coord delta; /* Change indicated to get_dir() */ LEVTYPE levtype; /* type of level i'm on */ long purse = 0;