Move the code to use a nethack menu for restoring a saved game. It
was inline in tty_askname() but is now a separate routine, restore_menu()
in restore.c. There was no port-specific code and only a small amount of
tty-specific code; it should be useable by anyone (but Qt doesn't have to
switch over if it doesn't want to).
The original behaved strangely if there were exactly 26 saved chars;
the "start new game" menu entry ended up using "{" as selection character.
There wasn't any comparable problem at 52; it was limiting the menu to 51
games. Now it will allow 52 (with "start a new game" bumped into "#" if
there are that many), and adds an explicit quit entry (unless there are
52 or more games so that # is already used by new-game, then quit remains
implicit rather than resort to some other none-of-the-above character).
207 lines
4.1 KiB
C
207 lines
4.1 KiB
C
/* SCCS Id: @(#)version.c 3.5 2006/12/11 */
|
|
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
|
/* NetHack may be freely redistributed. See license for details. */
|
|
|
|
#include "hack.h"
|
|
#include "date.h"
|
|
/*
|
|
* All the references to the contents of patchlevel.h have been moved
|
|
* into makedefs....
|
|
*/
|
|
#ifdef SHORT_FILENAMES
|
|
#include "patchlev.h"
|
|
#else
|
|
#include "patchlevel.h"
|
|
#endif
|
|
|
|
/* #define BETA_INFO "" */
|
|
|
|
/* fill buffer with short version (so caller can avoid including date.h) */
|
|
char *
|
|
version_string(buf)
|
|
char *buf;
|
|
{
|
|
return strcpy(buf, VERSION_STRING);
|
|
}
|
|
|
|
/* fill and return the given buffer with the long nethack version string */
|
|
char *
|
|
getversionstring(buf)
|
|
char *buf;
|
|
{
|
|
Strcpy(buf, VERSION_ID);
|
|
#if defined(BETA) && defined(BETA_INFO)
|
|
Sprintf(eos(buf), " %s", BETA_INFO);
|
|
#endif
|
|
#if defined(RUNTIME_PORT_ID)
|
|
append_port_id(buf);
|
|
#endif
|
|
return buf;
|
|
}
|
|
|
|
int
|
|
doversion()
|
|
{
|
|
char buf[BUFSZ];
|
|
|
|
pline("%s", getversionstring(buf));
|
|
return 0;
|
|
}
|
|
|
|
int
|
|
doextversion()
|
|
{
|
|
display_file(OPTIONS_USED, TRUE);
|
|
return 0;
|
|
}
|
|
|
|
#ifdef MICRO
|
|
boolean
|
|
comp_times(filetime)
|
|
long filetime;
|
|
{
|
|
return((boolean)(filetime < BUILD_TIME));
|
|
}
|
|
#endif
|
|
|
|
boolean
|
|
check_version(version_data, filename, complain)
|
|
struct version_info *version_data;
|
|
const char *filename;
|
|
boolean complain;
|
|
{
|
|
if (
|
|
#ifdef VERSION_COMPATIBILITY
|
|
version_data->incarnation < VERSION_COMPATIBILITY ||
|
|
version_data->incarnation > VERSION_NUMBER
|
|
#else
|
|
version_data->incarnation != VERSION_NUMBER
|
|
#endif
|
|
) {
|
|
if (complain)
|
|
pline("Version mismatch for file \"%s\".", filename);
|
|
return FALSE;
|
|
} else if (
|
|
#ifndef IGNORED_FEATURES
|
|
version_data->feature_set != VERSION_FEATURES ||
|
|
#else
|
|
(version_data->feature_set & ~IGNORED_FEATURES) !=
|
|
(VERSION_FEATURES & ~IGNORED_FEATURES) ||
|
|
#endif
|
|
version_data->entity_count != VERSION_SANITY1 ||
|
|
version_data->struct_sizes1 != VERSION_SANITY2 ||
|
|
version_data->struct_sizes2 != VERSION_SANITY3) {
|
|
if (complain)
|
|
pline("Configuration incompatibility for file \"%s\".",
|
|
filename);
|
|
return FALSE;
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
/* this used to be based on file date and somewhat OS-dependant,
|
|
but now examines the initial part of the file's contents */
|
|
boolean
|
|
uptodate(fd, name)
|
|
int fd;
|
|
const char *name;
|
|
{
|
|
int rlen;
|
|
struct version_info vers_info;
|
|
boolean verbose = name ? TRUE : FALSE;
|
|
|
|
rlen = read(fd, (genericptr_t) &vers_info, sizeof vers_info);
|
|
minit(); /* ZEROCOMP */
|
|
if (rlen == 0) {
|
|
if (verbose) {
|
|
pline("File \"%s\" is empty?", name);
|
|
wait_synch();
|
|
}
|
|
return FALSE;
|
|
}
|
|
if (!check_version(&vers_info, name, verbose)) {
|
|
if (verbose) wait_synch();
|
|
return FALSE;
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
void
|
|
store_version(fd)
|
|
int fd;
|
|
{
|
|
static const struct version_info version_data = {
|
|
VERSION_NUMBER, VERSION_FEATURES,
|
|
VERSION_SANITY1, VERSION_SANITY2, VERSION_SANITY3
|
|
};
|
|
|
|
bufoff(fd);
|
|
/* bwrite() before bufon() uses plain write() */
|
|
bwrite(fd,(genericptr_t)&version_data,(unsigned)(sizeof version_data));
|
|
bufon(fd);
|
|
return;
|
|
}
|
|
|
|
#ifdef AMIGA
|
|
const char amiga_version_string[] = AMIGA_VERSION_STRING;
|
|
#endif
|
|
|
|
unsigned long
|
|
get_feature_notice_ver(str)
|
|
char *str;
|
|
{
|
|
char buf[BUFSZ];
|
|
int ver_maj, ver_min, patch;
|
|
char *istr[3];
|
|
int j = 0;
|
|
|
|
if (!str) return 0L;
|
|
str = strcpy(buf, str);
|
|
istr[j] = str;
|
|
while (*str) {
|
|
if (*str == '.') {
|
|
*str++ = '\0';
|
|
j++;
|
|
istr[j] = str;
|
|
if (j == 2) break;
|
|
} else if (index("0123456789", *str) != 0) {
|
|
str++;
|
|
} else
|
|
return 0L;
|
|
}
|
|
if (j != 2) return 0L;
|
|
ver_maj = atoi(istr[0]);
|
|
ver_min = atoi(istr[1]);
|
|
patch = atoi(istr[2]);
|
|
return FEATURE_NOTICE_VER(ver_maj,ver_min,patch);
|
|
/* macro from hack.h */
|
|
}
|
|
|
|
unsigned long
|
|
get_current_feature_ver()
|
|
{
|
|
return FEATURE_NOTICE_VER(VERSION_MAJOR,VERSION_MINOR,PATCHLEVEL);
|
|
}
|
|
|
|
/*ARGUSED*/
|
|
const char *
|
|
copyright_banner_line(indx)
|
|
int indx;
|
|
{
|
|
#ifdef COPYRIGHT_BANNER_A
|
|
if (indx == 1) return COPYRIGHT_BANNER_A;
|
|
#endif
|
|
#ifdef COPYRIGHT_BANNER_B
|
|
if (indx == 2) return COPYRIGHT_BANNER_B;
|
|
#endif
|
|
#ifdef COPYRIGHT_BANNER_C
|
|
if (indx == 3) return COPYRIGHT_BANNER_C;
|
|
#endif
|
|
#ifdef COPYRIGHT_BANNER_D
|
|
if (indx == 4) return COPYRIGHT_BANNER_D;
|
|
#endif
|
|
return "";
|
|
}
|
|
|
|
/*version.c*/
|