selectsaved option (trunk only)
- always write plname into save file, no longer conditional
- add 'selectsaved' wincap option to control the display of
a menu of save files for ports/platforms that support it.
- add support for win32 tty using normal nethack menus.
- the win/tty/wintty code is generalized enough that any
tty port could support the option if the appropriate port-specific
code hooks for wildcard file lookups are added to src/file.c
specifically in the get_saved_games() routine. There is posix
code in there from Warwick already, and there is findfirst/findnext
code in there from win32. Warwick has the posix code only
enabled for Qt at present, but with wintty support, that could be expanded
to other Unix environments quite easily I would think.
Here is what the tty support looks like:
NetHack, Copyright 1985-2005
By Stichting Mathematisch Centrum and M. Stephenson.
See license for details.
Select one of your saved games
a - Bob
b - Fred
c - June
d - mine3
e - Sirius
f - Start a new character
(end)
The following files existed in the NetHack SAVEDIR directory
at the time:
ALLISONMI-Bob.NetHack-saved-game
ALLISONMI-Fred.NetHack-saved-game
ALLISONMI-June.NetHack-saved-game
ALLISONMI-mine3.NetHack-saved-game
ALLISONMI-Sirius.NetHack-saved-game
Note that despite the file names, the actual character name
is drawn from the savefile.
The WIN32CON support passes
USER-*.NetHack-saved-game
to findfirst/findnext where USER is your login name of course.
This commit is contained in:
73
src/files.c
73
src/files.c
@@ -148,6 +148,10 @@ extern char *sounddir;
|
||||
extern int n_dgns; /* from dungeon.c */
|
||||
|
||||
#if defined(UNIX) && defined(QT_GRAPHICS)
|
||||
#define SELECTSAVED
|
||||
#endif
|
||||
|
||||
#ifdef SELECTSAVED
|
||||
STATIC_DCL int FDECL(strcmp_wrap, (const void *, const void *));
|
||||
#endif
|
||||
STATIC_DCL char *FDECL(set_bonesfile_name, (char *,d_level*));
|
||||
@@ -543,13 +547,17 @@ clearlocks()
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(UNIX) && defined(QT_GRAPHICS)
|
||||
#if defined(SELECTSAVED)
|
||||
STATIC_OVL int
|
||||
strcmp_wrap(p, q)
|
||||
const void *p;
|
||||
const void *q;
|
||||
{
|
||||
#if defined(UNIX) && defined(QT_GRAPHICS)
|
||||
return strncasecmp(*(char **) p, *(char **) q, 16);
|
||||
# else
|
||||
return strncmpi(*(char **) p, *(char **) q, 16);
|
||||
# endif
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -954,25 +962,24 @@ restore_saved_game()
|
||||
return fd;
|
||||
}
|
||||
|
||||
#if defined(UNIX) && defined(QT_GRAPHICS)
|
||||
#if defined(SELECTSAVED)
|
||||
/*ARGSUSED*/
|
||||
static char*
|
||||
plname_from_file(filename)
|
||||
const char* filename;
|
||||
{
|
||||
#ifdef STORE_PLNAME_IN_FILE
|
||||
int fd;
|
||||
char* result = 0;
|
||||
|
||||
Strcpy(SAVEF,filename);
|
||||
#ifdef COMPRESS_EXTENSION
|
||||
# ifdef COMPRESS_EXTENSION
|
||||
SAVEF[strlen(SAVEF)-strlen(COMPRESS_EXTENSION)] = '\0';
|
||||
#endif
|
||||
# endif
|
||||
uncompress(SAVEF);
|
||||
if ((fd = open_savefile()) >= 0) {
|
||||
if (uptodate(fd, filename)) {
|
||||
char tplname[PL_NSIZ];
|
||||
mread(fd, (genericptr_t) tplname, PL_NSIZ);
|
||||
get_plname_from_file(fd, tplname);
|
||||
result = strdup(tplname);
|
||||
}
|
||||
(void) close(fd);
|
||||
@@ -980,19 +987,20 @@ const char* filename;
|
||||
compress(SAVEF);
|
||||
|
||||
return result;
|
||||
#else
|
||||
# if defined(UNIX) && defined(QT_GRAPHICS)
|
||||
# if 0
|
||||
/* --------- obsolete - used to be ifndef STORE_PLNAME_IN_FILE ----*/
|
||||
# if defined(UNIX) && defined(QT_GRAPHICS)
|
||||
/* Name not stored in save file, so we have to extract it from
|
||||
the filename, which loses information
|
||||
(eg. "/", "_", and "." characters are lost. */
|
||||
int k;
|
||||
int uid;
|
||||
char name[64]; /* more than PL_NSIZ */
|
||||
#ifdef COMPRESS_EXTENSION
|
||||
# ifdef COMPRESS_EXTENSION
|
||||
#define EXTSTR COMPRESS_EXTENSION
|
||||
#else
|
||||
# else
|
||||
#define EXTSTR ""
|
||||
#endif
|
||||
# endif
|
||||
if ( sscanf( filename, "%*[^/]/%d%63[^.]" EXTSTR, &uid, name ) == 2 ) {
|
||||
#undef EXTSTR
|
||||
/* "_" most likely means " ", which certainly looks nicer */
|
||||
@@ -1001,18 +1009,52 @@ const char* filename;
|
||||
name[k]=' ';
|
||||
return strdup(name);
|
||||
} else
|
||||
# endif
|
||||
# endif /* UNIX && QT_GRAPHICS */
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
/* --------- end of obsolete code ----*/
|
||||
# endif /* 0 - WAS STORE_PLNAME_IN_FILE*/
|
||||
}
|
||||
#endif /* defined(UNIX) && defined(QT_GRAPHICS) */
|
||||
#endif /* defined(SELECTSAVED) */
|
||||
|
||||
char**
|
||||
get_saved_games()
|
||||
{
|
||||
#if defined(UNIX) && defined(QT_GRAPHICS)
|
||||
#if defined(SELECTSAVED)
|
||||
int n, j;
|
||||
char **result;
|
||||
# ifdef WIN32CON
|
||||
char fnamebuf[BUFSZ], encodedfnamebuf[BUFSZ];
|
||||
char *foundfile;
|
||||
const char *fq_save;
|
||||
|
||||
Sprintf(fnamebuf, "%s-", get_username(0));
|
||||
(void)fname_encode("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-.",
|
||||
'%', fnamebuf, encodedfnamebuf, BUFSZ);
|
||||
Sprintf(SAVEF, "%s*.NetHack-saved-game", encodedfnamebuf);
|
||||
fq_save = fqname(SAVEF, SAVEPREFIX, 0);
|
||||
|
||||
foundfile = foundfile_buffer();
|
||||
if (findfirst((char *)fq_save)) {
|
||||
n = 0;
|
||||
do {
|
||||
++n;
|
||||
} while (findnext());
|
||||
}
|
||||
if (n > 0) {
|
||||
result = (char**)alloc((n+1)*sizeof(char*)); /* at most */
|
||||
if (findfirst((char *)fq_save)) {
|
||||
j = n = 0;
|
||||
do {
|
||||
char *r;
|
||||
r = plname_from_file(foundfile);
|
||||
if (r)
|
||||
result[j++] = r;
|
||||
++n;
|
||||
} while (findnext());
|
||||
# endif
|
||||
# if defined(UNIX) && defined(QT_GRAPHICS)
|
||||
/* posixly correct version */
|
||||
int myuid=getuid();
|
||||
DIR *dir;
|
||||
@@ -1045,6 +1087,7 @@ get_saved_games()
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
# endif
|
||||
qsort(result, j, sizeof(char *), strcmp_wrap);
|
||||
result[j++] = 0;
|
||||
return result;
|
||||
|
||||
@@ -171,6 +171,7 @@ static struct Bool_Opt
|
||||
#else
|
||||
{"sanity_check", (boolean *)0, FALSE, SET_IN_FILE},
|
||||
#endif
|
||||
{"selectsaved", &iflags.wc2_selectsaved, TRUE, DISP_IN_GAME}, /*WC*/
|
||||
#ifdef EXP_ON_BOTL
|
||||
{"showexp", &flags.showexp, FALSE, SET_IN_GAME},
|
||||
#else
|
||||
|
||||
@@ -573,11 +573,8 @@ register int fd;
|
||||
int rtmp;
|
||||
struct obj *otmp;
|
||||
|
||||
#ifdef STORE_PLNAME_IN_FILE
|
||||
mread(fd, (genericptr_t) plname, PL_NSIZ);
|
||||
#endif
|
||||
|
||||
restoring = TRUE;
|
||||
get_plname_from_file(fd, plname);
|
||||
getlev(fd, 0, (xchar)0, FALSE);
|
||||
if (!restgamestate(fd, &stuckid, &steedid)) {
|
||||
display_nhwindow(WIN_MESSAGE, TRUE);
|
||||
@@ -656,9 +653,8 @@ register int fd;
|
||||
(void) lseek(fd, (off_t)0, 0);
|
||||
#endif
|
||||
(void) uptodate(fd, (char *)0); /* skip version info */
|
||||
#ifdef STORE_PLNAME_IN_FILE
|
||||
mread(fd, (genericptr_t) plname, PL_NSIZ);
|
||||
#endif
|
||||
get_plname_from_file(fd, plname);
|
||||
|
||||
getlev(fd, 0, (xchar)0, FALSE);
|
||||
(void) close(fd);
|
||||
|
||||
@@ -931,6 +927,17 @@ boolean ghostly;
|
||||
clear_id_mapping();
|
||||
}
|
||||
|
||||
void
|
||||
get_plname_from_file(fd, plbuf)
|
||||
int fd;
|
||||
char *plbuf;
|
||||
{
|
||||
int rlen, pltmpsiz = 0;
|
||||
rlen = read(fd, (genericptr_t) &pltmpsiz, sizeof(pltmpsiz));
|
||||
rlen = read(fd, (genericptr_t) plbuf, pltmpsiz);
|
||||
return;
|
||||
}
|
||||
|
||||
STATIC_OVL void
|
||||
restore_msghistory(fd)
|
||||
register int fd;
|
||||
|
||||
22
src/save.c
22
src/save.c
@@ -209,9 +209,7 @@ dosave0()
|
||||
#endif /* MFLOPPY */
|
||||
|
||||
store_version(fd);
|
||||
#ifdef STORE_PLNAME_IN_FILE
|
||||
bwrite(fd, (genericptr_t) plname, PL_NSIZ);
|
||||
#endif
|
||||
store_plname_in_file(fd);
|
||||
ustuck_id = (u.ustuck ? u.ustuck->m_id : 0);
|
||||
#ifdef STEED
|
||||
usteed_id = (u.usteed ? u.usteed->m_id : 0);
|
||||
@@ -407,9 +405,8 @@ savestateinlock()
|
||||
(void) write(fd, (genericptr_t) &currlev, sizeof(currlev));
|
||||
save_savefile_name(fd);
|
||||
store_version(fd);
|
||||
#ifdef STORE_PLNAME_IN_FILE
|
||||
bwrite(fd, (genericptr_t) plname, PL_NSIZ);
|
||||
#endif
|
||||
store_plname_in_file(fd);
|
||||
|
||||
ustuck_id = (u.ustuck ? u.ustuck->m_id : 0);
|
||||
#ifdef STEED
|
||||
usteed_id = (u.usteed ? u.usteed->m_id : 0);
|
||||
@@ -1006,6 +1003,19 @@ register int fd, mode;
|
||||
ffruit = 0;
|
||||
}
|
||||
|
||||
void
|
||||
store_plname_in_file(fd)
|
||||
int fd;
|
||||
{
|
||||
int plsiztmp = PL_NSIZ;
|
||||
bufoff(fd);
|
||||
/* bwrite() before bufon() uses plain write() */
|
||||
bwrite(fd, (genericptr_t) &plsiztmp, sizeof(plsiztmp));
|
||||
bwrite(fd, (genericptr_t) plname, plsiztmp);
|
||||
bufon(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
STATIC_OVL void
|
||||
save_msghistory(fd, mode)
|
||||
register int fd, mode;
|
||||
|
||||
Reference in New Issue
Block a user