Fix resource Blorb opening.
authorTimo Korvola <tkorvola@iki.fi>
Mon, 19 Feb 2018 21:02:53 +0000 (23:02 +0200)
committerTimo Korvola <tkorvola@iki.fi>
Fri, 23 Feb 2018 07:22:10 +0000 (09:22 +0200)
ux_blorb_init may have worked for story Blorbs but handling of
separate resource Blorbs (accompanying a plain story file) was quite
broken.

dumb_blorb.c is basically a copy of ux_blorb.c.  Can't be bothered
to copy this fix there.  dfrotz should use the same code instead of
a copy.

src/curses/ux_blorb.c

index 5980fa3a896d6102efed0f9c5562e7c320cc6b76..0db0f023d772827fd852b305587133fbc3f36d7b 100644 (file)
@@ -81,8 +81,9 @@ bb_err_t ux_blorb_init(char *filename)
      */
     if (isblorb(fp)) {                 /* Now we know to look */
        f_setup.exec_in_blorb = 1;      /* for zcode in the blorb */
-        blorb_fp = fopen(filename, "rb");
+        blorb_fp = fp;
     } else {
+        fclose(fp);
        len1 = strlen(filename) + strlen(EXT_BLORB);
        len2 = strlen(filename) + strlen(EXT_BLORB3);
 
@@ -94,24 +95,23 @@ bb_err_t ux_blorb_init(char *filename)
 
         strncat(mystring, EXT_BLORB, len1 * sizeof(char));
 
-       /* Done monkeying with the initial file. */
-       fclose(fp);
-       fp = NULL;
-
        /* Check if foo.blb is there. */
-        if ((blorb_fp = fopen(mystring, "rb")) == NULL) {
+        if ((fp = fopen(mystring, "rb")) == NULL) {
            p = rindex(mystring, '.');
            if (p != NULL)
                *p = '\0';
             strncat(mystring, EXT_BLORB3, len2 * sizeof(char));
-           blorb_fp = fopen(mystring, "rb");
+           if (!(fp = fopen(mystring, "rb")))
+               return bb_err_NoBlorb;
        }
-
-       if (blorb_fp == NULL || !isblorb(fp))   /* No matching blorbs found. */
+       if (!isblorb(fp)) {
+           fclose(fp);
            return bb_err_NoBlorb;
+       }
 
        /* At this point we know that we're using a naked zcode file */
        /* with resources in a seperate Blorb file. */
+       blorb_fp = fp;
        f_setup.use_blorb = 1;
     }
 
@@ -119,7 +119,7 @@ bb_err_t ux_blorb_init(char *filename)
      * This will fail if the file is not a valid Blorb file.
      * From this map, we can now pick out any resource we need.
      */
-    blorb_err = bb_create_map(fp, &blorb_map);
+    blorb_err = bb_create_map(blorb_fp, &blorb_map);
     if (blorb_err != bb_err_None)
        return bb_err_Format;
 
@@ -132,7 +132,6 @@ bb_err_t ux_blorb_init(char *filename)
        f_setup.exec_in_blorb = 1;
     }
 
-    fclose(fp);
     return blorb_err;
 }