arogue7: implement the -n option.
This commit is contained in:
parent
7da765d616
commit
7824f79164
4 changed files with 43 additions and 1 deletions
|
|
@ -31,6 +31,8 @@ extern struct uwdata wdata, oldwin;
|
|||
extern char oldtext[WTXTNUM][WTXTLEN];
|
||||
#endif
|
||||
|
||||
#define SAVEDIR "."
|
||||
|
||||
main(argc, argv, envp)
|
||||
char **argv;
|
||||
char **envp;
|
||||
|
|
@ -67,6 +69,22 @@ char **envp;
|
|||
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 @@ char **envp;
|
|||
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);
|
||||
|
|
|
|||
|
|
@ -132,6 +132,7 @@ bool firstmove = FALSE;
|
|||
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.";
|
||||
|
|
|
|||
|
|
@ -1271,6 +1271,7 @@ extern bool slow_invent; /* Inventory one line at a time */
|
|||
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 */
|
||||
|
|
|
|||
|
|
@ -63,7 +63,10 @@ save_game()
|
|||
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 @@ save_game()
|
|||
}
|
||||
}
|
||||
|
||||
if (use_savedir)
|
||||
{
|
||||
msg("");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
msg("File name: ");
|
||||
|
|
@ -90,7 +99,11 @@ save_game()
|
|||
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 @@ char **envp;
|
|||
file = file_name;
|
||||
if ((inf = open(file, 0)) < 0)
|
||||
{
|
||||
if (use_savedir && errno == ENOENT)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
perror(file);
|
||||
return FALSE;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue