]> granicus.if.org Git - nethack/commitdiff
display of data.base entries
authorPatR <rankin@nethack.org>
Sat, 4 Jan 2020 11:35:11 +0000 (03:35 -0800)
committerPatR <rankin@nethack.org>
Sat, 4 Jan 2020 11:35:11 +0000 (03:35 -0800)
Make data.base display perform a couple of extra data integrity
checks and meet tabexpand()'s expectation about buffer size.

Also be a little more forgiving in case someone uses spaces instead
of a tab to indent new text lines.

src/pager.c

index ca88c364f0df43817dd3decc2e762cb2df08703a..24e0e278330857b4c7baba64e61d65e6e0a1d1da 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.6 pager.c $NHDT-Date: 1575830188 2019/12/08 18:36:28 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.175 $ */
+/* NetHack 3.6 pager.c $NHDT-Date: 1578137709 2020/01/04 11:35:09 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.179 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Robert Patrick Rankin, 2018. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -778,12 +778,35 @@ char *supplemental_name;
                     }
                     datawin = create_nhwindow(NHW_MENU);
                     for (i = 0; i < entry_count; i++) {
-                        if (!dlb_fgets(buf, BUFSZ, fp))
+                        /* room for 1-tab or 8-space prefix + BUFSZ-1 + \0 */
+                        char tabbuf[BUFSZ + 8], *tp;
+
+                        if (!dlb_fgets(tabbuf, BUFSZ, fp))
+                            goto bad_data_file;
+                        tp = tabbuf;
+                        if (!index(tp, '\n'))
                             goto bad_data_file;
-                        (void) strip_newline(buf);
-                        if (index(buf + 1, '\t') != 0)
-                            (void) tabexpand(buf + 1);
-                        putstr(datawin, 0, buf + 1);
+                        (void) strip_newline(tp);
+                        /* text in this file is indented with one tab but
+                           someone modifying it might use spaces instead */
+                        if (*tp == '\t') {
+                            ++tp;
+                        } else if (*tp == ' ') {
+                            /* remove up to 8 spaces (we expect 8-column
+                               tab stops but user might have them set at
+                               something else so we don't require it) */
+                            do {
+                                ++tp;
+                            } while (tp < &tabbuf[8] && *tp == ' ');
+                        } else {
+                            goto bad_data_file;
+                        }
+                        /* if a tab after the leading one is found,
+                           convert tabs into spaces; the attributions
+                           at the end of quotes typically have them */
+                        if (index(tp, '\t') != 0)
+                            (void) tabexpand(tp);
+                        putstr(datawin, 0, tp);
                     }
                     display_nhwindow(datawin, FALSE);
                     destroy_nhwindow(datawin), datawin = WIN_ERR;