UltraRogue: add the -n option.
This commit is contained in:
parent
ed27d7a24f
commit
403d9ec171
4 changed files with 35 additions and 6 deletions
|
|
@ -23,8 +23,11 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <errno.h>
|
||||||
#include "rogue.h"
|
#include "rogue.h"
|
||||||
|
|
||||||
|
#define SAVEDIR "."
|
||||||
|
|
||||||
FILE *fd_score = NULL;
|
FILE *fd_score = NULL;
|
||||||
|
|
||||||
/* Command line options */
|
/* Command line options */
|
||||||
|
|
@ -62,6 +65,21 @@ main(int argc, char *argv[])
|
||||||
rflag = TRUE;
|
rflag = TRUE;
|
||||||
break;
|
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:
|
default:
|
||||||
fprintf(stderr,"%s: Unknown option '%c'.\n",argv[0],argv[x][1]);
|
fprintf(stderr,"%s: Unknown option '%c'.\n",argv[0],argv[x][1]);
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
@ -86,12 +104,14 @@ main(int argc, char *argv[])
|
||||||
if ((env = getenv("OPTIONS")) != NULL)
|
if ((env = getenv("OPTIONS")) != NULL)
|
||||||
parse_opts(env);
|
parse_opts(env);
|
||||||
|
|
||||||
|
if (!use_savedir) {
|
||||||
nm = getenv("USER");
|
nm = getenv("USER");
|
||||||
|
|
||||||
if (nm != NULL)
|
if (nm != NULL)
|
||||||
strcpy(whoami,nm);
|
strcpy(whoami,nm);
|
||||||
else
|
else
|
||||||
strcpy(whoami,"anonymous");
|
strcpy(whoami,"anonymous");
|
||||||
|
}
|
||||||
|
|
||||||
lowtime = time(&now);
|
lowtime = time(&now);
|
||||||
|
|
||||||
|
|
@ -168,7 +188,11 @@ main(int argc, char *argv[])
|
||||||
mw = newwin(LINES, COLS, 0, 0);
|
mw = newwin(LINES, COLS, 0, 0);
|
||||||
hw = 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 */
|
/* Note: restore returns on error only */
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1686,6 +1686,7 @@ extern int waswizard; /* Was a wizard sometime */
|
||||||
extern int canwizard; /* Will be permitted to do this */
|
extern int canwizard; /* Will be permitted to do this */
|
||||||
extern int askme; /* Ask about unidentified things */
|
extern int askme; /* Ask about unidentified things */
|
||||||
extern int moving; /* move using 'm' command */
|
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 int inv_type; /* Inven style. Bool so options works */
|
||||||
extern char take; /* Thing the rogue is taking */
|
extern char take; /* Thing the rogue is taking */
|
||||||
|
|
@ -1809,6 +1810,7 @@ char *md_strdup(const char *s);
|
||||||
long md_random(void);
|
long md_random(void);
|
||||||
void md_srandom(long seed);
|
void md_srandom(long seed);
|
||||||
int md_readchar(WINDOW *win);
|
int md_readchar(WINDOW *win);
|
||||||
|
int md_getuid(void);
|
||||||
|
|
||||||
#define NOOP(x) (x += 0)
|
#define NOOP(x) (x += 0)
|
||||||
#define CCHAR(x) ( (char) (x & A_CHARTEXT) )
|
#define CCHAR(x) ( (char) (x & A_CHARTEXT) )
|
||||||
|
|
|
||||||
|
|
@ -90,6 +90,8 @@ restore(char *file)
|
||||||
|
|
||||||
if ((infd = fopen(file, "r")) == NULL)
|
if ((infd = fopen(file, "r")) == NULL)
|
||||||
{
|
{
|
||||||
|
if (use_savedir && errno == ENOENT)
|
||||||
|
return TRUE;
|
||||||
perror(file);
|
perror(file);
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -138,6 +138,7 @@ int fighting = FALSE;
|
||||||
int wizard = FALSE;
|
int wizard = FALSE;
|
||||||
int wiz_verbose = TRUE;
|
int wiz_verbose = TRUE;
|
||||||
int moving = FALSE;
|
int moving = FALSE;
|
||||||
|
int use_savedir = FALSE;
|
||||||
coord delta; /* Change indicated to get_dir() */
|
coord delta; /* Change indicated to get_dir() */
|
||||||
LEVTYPE levtype; /* type of level i'm on */
|
LEVTYPE levtype; /* type of level i'm on */
|
||||||
long purse = 0;
|
long purse = 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue