nethack --version:dump

Add the 'dump' argument to the existing '--version' command-line
option to display the magic numbers used when validating save and
bones files for compatibility.

Nothing exciting, just a line of 5 hex values.  I was going to also
list the values for however many save and bones files are specified
on the command line but it seems to need more effort than I care to
expend.  And I hadn't made up my mind whether that should be done by
nethack, recover, or some new standalone program.  [Single line of
relatively raw output is so that they could be compared more easily.]

nethack --version:bad-argument was writing a message to stdout and
then starting play--which immediately overwrites stdout.  Have it
quit instead.  Player wasn't trying to start a game and quitting is
what it does with --version:good-argument.
This commit is contained in:
PatR
2024-02-13 15:58:10 -08:00
parent d511944dda
commit bf8a634760
5 changed files with 72 additions and 23 deletions

View File

@@ -936,7 +936,7 @@ argcheck(int argc, char *argv[], enum earlyarg e_arg)
break;
}
if (idx >= SIZE(earlyopts) || argc < 1)
return FALSE;
return 0;
for (i = 0; i < argc; ++i) {
if (argv[i][0] != '-')
@@ -975,13 +975,21 @@ argcheck(int argc, char *argv[], enum earlyarg e_arg)
than next major version */
if (match_optname(extended_opt, "paste", 5, FALSE)) {
insert_into_pastebuf = TRUE;
} else if(match_optname(extended_opt, "copy", 4, FALSE)) {
} else if (match_optname(extended_opt, "copy", 4, FALSE)) {
insert_into_pastebuf = TRUE;
} else {
raw_printf(
"-%sversion can only be extended with -%sversion:copy.\n",
} else if (match_optname(extended_opt, "dump", 4, FALSE)) {
/* version number plus enabled features and sanity
values that the program compares against the same
thing recorded in save and bones files to check
whether they're being used compatibly */
dump_version_info();
return 2; /* done */
} else if (!match_optname(extended_opt, "show", 4, FALSE)) {
raw_printf("-%sversion can only be extended with"
" -%sversion:copy or :dump or :show.\n",
dashdash, dashdash);
return TRUE;
/* exit after we've reported bad command line argument */
return 2;
}
}
early_version_info(insert_into_pastebuf);
@@ -1016,7 +1024,7 @@ argcheck(int argc, char *argv[], enum earlyarg e_arg)
break;
}
};
return FALSE;
return 0;
}
/*

View File

@@ -485,4 +485,26 @@ copyright_banner_line(int indx)
return "";
}
/* called by argcheck(allmain.c) from early_options(sys/xxx/xxxmain.c) */
void
dump_version_info(void)
{
char buf[BUFSZ];
const char *hname = gh.hname ? gh.hname : "nethack";
if (strlen(hname) > 33)
hname = eos(nhStr(hname)) - 33; /* discard const for eos() */
runtime_info_init();
Snprintf(buf, sizeof buf, "%-12.33s %08lx %08lx %08lx %08lx %08lx",
hname,
nomakedefs.version_number,
(nomakedefs.version_features & ~nomakedefs.ignored_features),
nomakedefs.version_sanity1,
nomakedefs.version_sanity2,
nomakedefs.version_sanity3);
raw_print(buf);
release_runtime_info();
return;
}
/*version.c*/