'nethack --usage' and '?' menu
Write up a description of how the command line works on UNIX and put that in new file dat/usagehlp. Add support for |nethack --usage | --help | -? | ? to display it and exit. Also add a menu entry for nethack's help command to show it during play. That can be suppressed by uncommenting new '#define HIDE_USAGE' in config.h since it won't be useful on servers that don't give players access to command lines. New genl_display_file() just writes to stdout. opt_usage(), which calls it, might need some suid/sgid handling to make sure the output is done as the player rather than as nethack. doc/nethack.6 is already out of date again.
This commit is contained in:
@@ -1191,7 +1191,7 @@ $(TARGETPFX)vision.o: vision.c $(HACK_H)
|
||||
$(TARGETPFX)weapon.o: weapon.c $(HACK_H)
|
||||
$(TARGETPFX)were.o: were.c $(HACK_H)
|
||||
$(TARGETPFX)wield.o: wield.c $(HACK_H)
|
||||
$(TARGETPFX)windows.o: windows.c $(HACK_H) ../include/wintty.h
|
||||
$(TARGETPFX)windows.o: windows.c $(HACK_H) ../include/dlb.h ../include/wintty.h
|
||||
$(TARGETPFX)wizard.o: wizard.c $(HACK_H)
|
||||
$(TARGETPFX)worm.o: worm.c $(HACK_H)
|
||||
$(TARGETPFX)worn.o: worn.c $(HACK_H)
|
||||
|
||||
@@ -91,7 +91,7 @@ LUA_VERSION = 5.4.4
|
||||
# end of configuration
|
||||
#
|
||||
|
||||
DATHELP = help hh cmdhelp keyhelp history opthelp optmenu wizhelp
|
||||
DATHELP = help hh cmdhelp keyhelp history opthelp optmenu usagehlp wizhelp
|
||||
|
||||
SPEC_LEVS = asmodeus.lua baalz.lua bigrm-*.lua castle.lua fakewiz?.lua \
|
||||
juiblex.lua knox.lua medusa-?.lua minend-?.lua minefill.lua \
|
||||
|
||||
@@ -36,6 +36,7 @@ static void consume_arg(int, int *, char ***);
|
||||
static void consume_two_args(int, int *, char ***);
|
||||
static void early_options(int *, char ***, char **);
|
||||
static void opt_terminate(void) NORETURN;
|
||||
static void opt_usage(const char *) NORETURN;
|
||||
static void opt_showpaths(const char *);
|
||||
static void scores_only(int, char **, const char *) NORETURN;
|
||||
|
||||
@@ -571,6 +572,12 @@ early_options(int *argc_p, char ***argv_p, char **hackdir_p)
|
||||
|
||||
config_error_init(FALSE, "command line", FALSE);
|
||||
|
||||
/* treat "nethack ?" as a request for usage info; due to shell
|
||||
processing, player likely has to use "nethack \?" or "nethack '?'"
|
||||
[won't work if used as "nethack -dpath ?" or "nethack -d path ?"] */
|
||||
if (*argc_p > 1 && !strcmp((*argv_p)[1], "?"))
|
||||
opt_usage(*hackdir_p); /* doesn't return */
|
||||
|
||||
/*
|
||||
* Both *argc_p and *argv_p account for the program name as (*argv_p)[0];
|
||||
* local argc and argv impicitly discard that (by starting 'ndx' at 1).
|
||||
@@ -617,6 +624,12 @@ early_options(int *argc_p, char ***argv_p, char **hackdir_p)
|
||||
#endif /* CHDIR */
|
||||
}
|
||||
break;
|
||||
case 'h':
|
||||
case '?':
|
||||
if (lopt(arg, ArgValDisallowed, "-help", origarg, &argc, &argv)
|
||||
|| lopt(arg, ArgValDisallowed, "-?", origarg, &argc, &argv))
|
||||
opt_usage(*hackdir_p); /* doesn't return */
|
||||
break;
|
||||
case 'n':
|
||||
oldargc = argc;
|
||||
if (!strcmp(arg, "-no-nethackrc")) /* no abbreviation allowed */
|
||||
@@ -653,6 +666,10 @@ early_options(int *argc_p, char ***argv_p, char **hackdir_p)
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
break;
|
||||
case 'u':
|
||||
if (lopt(arg, ArgValDisallowed, "-usage", origarg, &argc, &argv))
|
||||
opt_usage(*hackdir_p);
|
||||
break;
|
||||
case 'v':
|
||||
if (argcheck(argc, argv, ARG_VERSION) == 2) {
|
||||
opt_terminate();
|
||||
@@ -689,6 +706,20 @@ opt_terminate(void)
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
|
||||
static void
|
||||
opt_usage(const char *hackdir)
|
||||
{
|
||||
#ifdef CHDIR
|
||||
chdirx(hackdir, TRUE);
|
||||
#else
|
||||
nhUse(hackdir);
|
||||
#endif
|
||||
dlb_init();
|
||||
|
||||
genl_display_file(USAGEHELP, TRUE);
|
||||
opt_terminate();
|
||||
}
|
||||
|
||||
/* show the sysconf file name, playground directory, run-time configuration
|
||||
file name, dumplog file name if applicable, and some other things */
|
||||
static void
|
||||
|
||||
Reference in New Issue
Block a user