From 1b04533b356dcfe27700a5a8d4731c7df762a467 Mon Sep 17 00:00:00 2001 From: PatR Date: Sun, 5 Nov 2023 17:16:02 -0800 Subject: [PATCH] fix #4027 - unix command line parsing bug 'nethack --show' is rejected, which is ok, but the feedback is 'prscore: bad arguments (2)' which is pretty confusing. Reject any --s unless it's the start of --scores or --showpath[s]. 'nethack --show' will be rejected as "Unknown option: --show." 'nethack -show' is still accepted and will report that it can't find any scores for how as it always has (assuming that there aren't any score entries for "how" :-). --- doc/fixes3-7-0.txt | 4 +++- sys/unix/unixmain.c | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/doc/fixes3-7-0.txt b/doc/fixes3-7-0.txt index 616badf09..4e308dda5 100644 --- a/doc/fixes3-7-0.txt +++ b/doc/fixes3-7-0.txt @@ -1,4 +1,4 @@ -$NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.1277 $ $NHDT-Date: 1698899752 2023/11/02 04:35:52 $ +$NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.1286 $ $NHDT-Date: 1699233285 2023/11/06 01:14:45 $ General Fixes and Modified Features ----------------------------------- @@ -1809,6 +1809,8 @@ tty: if a group accelerator matched a menu command ('^' in menu for '/') it wouldn't work to select, just to manipulate the menu Unix: after lua changes to Makefiles, 'make spotless' for dat subdirectory left some generated data files which should have been deleted +Unix: reject "--sX" on command line except if "X" is "cores" (so "--scores"); + single dash form still accepts "-sX" to lookup scores for "X" Windows: new tile additions in win/share did not trigger the creation of a new NetHackW.res file Windows: nhl_loadlua() was missing the RDBMODE argument on the [dlb_]fopen(), diff --git a/sys/unix/unixmain.c b/sys/unix/unixmain.c index 60eedcc23..2b041d0e8 100644 --- a/sys/unix/unixmain.c +++ b/sys/unix/unixmain.c @@ -1,4 +1,4 @@ -/* NetHack 3.7 unixmain.c $NHDT-Date: 1693359574 2023/08/30 01:39:34 $ $NHDT-Branch: keni-crashweb2 $:$NHDT-Revision: 1.117 $ */ +/* NetHack 3.7 unixmain.c $NHDT-Date: 1699233290 2023/11/06 01:14:50 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.118 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Robert Patrick Rankin, 2011. */ /* NetHack may be freely redistributed. See license for details. */ @@ -606,7 +606,8 @@ early_options(int *argc_p, char ***argv_p, char **hackdir_p) /* * 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). - * argcheck() doesn't mind, prscore() (via scores_only()) does. + * argcheck() doesn't mind, prscore() (via scores_only()) does (for the + * number of args it gets passed, not for the value of argv[0]). */ for (ndx = 1; ndx < *argc_p; ndx += (consumed ? 0 : 1)) { consumed = 0; @@ -687,8 +688,16 @@ early_options(int *argc_p, char ***argv_p, char **hackdir_p) /*NOTREACHED*/ } /* check for "-s" request to show scores */ - if (lopt(arg, - (ArgValDisallowed | ArgNamOneLetter | ArgErrComplain), + if (lopt(arg, ((ArgValDisallowed | ArgErrComplain) + /* only accept one-letter if there is just one + dash; reject "--s" because prscore() via + scores_only() doesn't understand it */ + | ((origarg[1] != '-') ? ArgNamOneLetter : 0)), + /* [ought to omit val-disallowed and accept + --scores=foo since -s foo and -sfoo are + allowed, but -s form can take more than one + space-separated argument and --scores=foo + isn't suited for that] */ "-scores", origarg, &argc, &argv)) { /* at this point, argv[0] contains "-scores" or a leading substring of it; prscore() (via scores_only()) expects