From 5001e9066e1ea876b10c23dc0e0f2b1cb9cf7d1a Mon Sep 17 00:00:00 2001 From: Timo Korvola Date: Mon, 19 Feb 2018 23:02:53 +0200 Subject: [PATCH] Fix resource Blorb opening. 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 | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/curses/ux_blorb.c b/src/curses/ux_blorb.c index 5980fa3..0db0f02 100644 --- a/src/curses/ux_blorb.c +++ b/src/curses/ux_blorb.c @@ -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; } -- 2.34.1