# HG changeset patch # User John "Elwin" Edwards # Date 1431377160 14400 # Node ID c697782a9b378998c9d4c7c56a5ddc2af7617ffb # Parent 8ae3ffd6c6e744282eedb66467919e6cc77fdf7e arogue7: implement the -n option. diff -r 8ae3ffd6c6e7 -r c697782a9b37 arogue7/main.c --- a/arogue7/main.c Mon May 11 13:36:36 2015 -0400 +++ b/arogue7/main.c Mon May 11 16:46:00 2015 -0400 @@ -31,6 +31,8 @@ extern char oldtext[WTXTNUM][WTXTLEN]; #endif +#define SAVEDIR "." + main(argc, argv, envp) char **argv; char **envp; @@ -67,6 +69,22 @@ strcat(score_file,"arogue77.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.ar7sav", SAVEDIR, + md_getuid(), whoami)) + { + strcpy(file_name, "xrogue.sav"); + use_savedir = FALSE; + } + } +#endif + if ((env = getenv("ROGUEOPTS")) != NULL) parse_opts(env); @@ -138,6 +156,11 @@ nice(19); /* nice the max amount */ #endif + if (use_savedir) + { + if (!restore(file_name, envp)) + exit(1); + } if (argc == 2) if (!restore(argv[1], envp)) /* Note: restore will never return */ exit(1); diff -r 8ae3ffd6c6e7 -r c697782a9b37 arogue7/rogue.c --- a/arogue7/rogue.c Mon May 11 13:36:36 2015 -0400 +++ b/arogue7/rogue.c Mon May 11 16:46:00 2015 -0400 @@ -132,6 +132,7 @@ bool askme = FALSE; bool in_shell = FALSE; bool daytime = TRUE; +bool use_savedir = FALSE; LEVTYPE levtype; /* type of level i'm on */ char *nothing = "Nothing seems to happen."; diff -r 8ae3ffd6c6e7 -r c697782a9b37 arogue7/rogue.h --- a/arogue7/rogue.h Mon May 11 13:36:36 2015 -0400 +++ b/arogue7/rogue.h Mon May 11 16:46:00 2015 -0400 @@ -1271,6 +1271,7 @@ extern bool firstmove; /* First move after setting door_stop */ extern bool waswizard; /* Was a wizard sometime */ extern bool askme; /* Ask about unidentified things */ +extern bool use_savedir; /* Are savefiles in SAVEDIR */ extern bool s_know[]; /* Does he know what a scroll does */ extern bool p_know[]; /* Does he know what a potion does */ extern bool r_know[]; /* Does he know what a ring does */ diff -r 8ae3ffd6c6e7 -r c697782a9b37 arogue7/save.c --- a/arogue7/save.c Mon May 11 13:36:36 2015 -0400 +++ b/arogue7/save.c Mon May 11 16:46:00 2015 -0400 @@ -63,7 +63,10 @@ mpos = 0; if (file_name[0] != '\0') { - msg("Save file (%s)? ", file_name); + if (use_savedir) + msg("Save game? "); + else + msg("Save file (%s)? ", file_name); do { c = readchar(); @@ -77,6 +80,12 @@ } } + if (use_savedir) + { + msg(""); + return FALSE; + } + do { msg("File name: "); @@ -90,7 +99,11 @@ strcpy(file_name, buf); gotfile: if ((savefd = open(file_name, O_WRONLY|O_CREAT|O_TRUNC,0666)) < 0) + { msg(strerror(errno)); /* fake perror() */ + if (use_savedir) + return FALSE; + } } while (savefd < 0); /* @@ -168,6 +181,10 @@ file = file_name; if ((inf = open(file, 0)) < 0) { + if (use_savedir && errno == ENOENT) + { + return TRUE; + } perror(file); return FALSE; }