]> granicus.if.org Git - nethack/commitdiff
fix 'nethack --scores'
authorPatR <rankin@nethack.org>
Thu, 17 Nov 2022 07:41:07 +0000 (23:41 -0800)
committerPatR <rankin@nethack.org>
Thu, 17 Nov 2022 07:41:07 +0000 (23:41 -0800)
The command line parsing in unixmain.c accepted --scores as an
alternative to -s but prscore() in topten.c didn't.

doc/fixes3-7-0.txt
src/topten.c

index bc689a6440d984eecb8e17af742e648f1b4f8fd5..dccda09f28d0712919140188f31d092b60c81ad6 100644 (file)
@@ -1420,6 +1420,7 @@ if hero's steed got hit by knockback effect, impossible "no monster to remove"
        would occur (plus more warnings if 'sanity_check' was On)
 the #saveoptions command included options changed via doset_simple() but not
        ones changed via full doset()
+fix 'nethack --scores' as alias for 'nethack -s'
 
 curses: 'msg_window' option wasn't functional for curses unless the binary
        also included tty support
index b39f9ffe7c6e586f6198ff4d6beaca11cea5113a..0b89c06d147837cba72182309156fbd102c9cb6c 100644 (file)
@@ -1146,10 +1146,13 @@ prscore(int argc, char **argv)
     boolean match_found = FALSE;
     register int i;
     char pbuf[BUFSZ];
+    unsigned ln = 0;
     int uid = -1;
     const char *player0;
 
-    if (argc < 2 || strncmp(argv[1], "-s", 2)) {
+    if (argc < 2 || (ln = Strlen(argv[1])) < 2
+        || (strncmp(argv[1], "-s", 2)
+            && (ln < 4 || strncmp(argv[1], "--scores", ln)))) {
         raw_printf("prscore: bad arguments (%d)", argc);
         return;
     }
@@ -1177,11 +1180,12 @@ prscore(int argc, char **argv)
         init_done = TRUE;
     }
 
-    if (!argv[1][2]) { /* plain "-s" */
+    /* 'ln' is 2 for -s, longer for --scores */
+    if (!argv[1][ln]) { /* plain "-s" */
         argc--;
         argv++;
     } else
-        argv[1] += 2;
+        argv[1] += ln;
 
     if (argc > 1 && !strcmp(argv[1], "-v")) {
         current_ver = FALSE;