]> granicus.if.org Git - nethack/commitdiff
wizkit revisited
authornethack.rankin <nethack.rankin>
Wed, 19 Feb 2003 08:35:51 +0000 (08:35 +0000)
committernethack.rankin <nethack.rankin>
Wed, 19 Feb 2003 08:35:51 +0000 (08:35 +0000)
     The previous changed ended up discarding the begining portion of
excessively long lines and keeping the end.  It's unlikely that either
part is going to be valid, but reporting the ending portion as a failed
wish would make tracking down and fixing the situation trickier.

src/files.c

index 6322edf288e3e13ca782430df021fa003ad04e14..2c06e91e1bae5b080d4a74aadb58bff5eb1ccf6a 100644 (file)
@@ -1,4 +1,4 @@
-/*     SCCS Id: @(#)files.c    3.4     2002/08/18      */
+/*     SCCS Id: @(#)files.c    3.4     2003/02/18      */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -2067,22 +2067,30 @@ read_wizkit()
        FILE *fp;
        char *ep, buf[BUFSZ];
        struct obj *otmp;
-       boolean bad_items = FALSE;
+       boolean bad_items = FALSE, skip = FALSE;
 
        if (!wizard || !(fp = fopen_wizkit_file())) return;
 
-       while (fgets(buf, BUFSZ, fp)) {
-               if ((ep = index(buf, '\n'))) *ep = '\0';
-               if (ep && buf[0]) {
+       while (fgets(buf, (int)(sizeof buf), fp)) {
+           ep = index(buf, '\n');
+           if (skip) { /* in case previous line was too long */
+               if (ep) skip = FALSE; /* found newline; next line is normal */
+           } else {
+               if (!ep) skip = TRUE; /* newline missing; discard next fgets */
+               else *ep = '\0';                /* remove newline */
+
+               if (buf[0]) {
                        otmp = readobjnam(buf, (struct obj *)0, FALSE);
                        if (otmp) {
                            if (otmp != &zeroobj)
                                otmp = addinv(otmp);
                        } else {
-                           raw_printf("Bad wizkit item: \"%.50s\"", buf);
+                           /* .60 limits output line width to 79 chars */
+                           raw_printf("Bad wizkit item: \"%.60s\"", buf);
                            bad_items = TRUE;
                        }
                }
+           }
        }
        if (bad_items)
            wait_synch();