#include <string.h>\r
#include "frotz.h"\r
#include "bcfrotz.h"\r
+#include "bcblorb.h"\r
\r
f_setup_t f_setup;\r
\r
int user_random_seed = -1;\r
int user_font = 1;\r
\r
+\r
+/* Blorb-related things */\r
+char *blorb_name;\r
+char *blorb_file;\r
+bool use_blorb;\r
+bool exec_in_blorb;\r
+\r
static byte old_video_mode = 0;\r
\r
static void interrupt (*oldvect) () = NULL;\r
\r
}/* hextoi */\r
\r
+/*\r
+ * basename\r
+ *\r
+ * A generic and spartan bit of code to extract the filename from a path.\r
+ * This one is so trivial that it's okay to steal.\r
+ */\r
+char *basename(const char *path)\r
+{\r
+ const char *s;\r
+ const char *p;\r
+ p = s = path;\r
+\r
+ while (*s) {\r
+ if (*s++ == '\\') {\r
+ p = s;\r
+ }\r
+ }\r
+ return (char *) p;\r
+} /* basename */\r
+\r
+\r
/*\r
* cleanup\r
*\r
\r
progname = argv[0];\r
\r
+ blorb_file = strdup(f_setup.story_name);\r
+ strcat(blorb_file, ".blb");\r
+\r
+ switch (dos_init_blorb()) {\r
+ case bb_err_Format:\r
+ printf("Blorb file loaded, but unable to build map.\n\n");\r
+ break;\r
+ default:\r
+ printf("Blorb error code %i\n\n");\r
+ }\r
}/* os_process_arguments */\r
\r
/*\r
return NULL;\r
}/* os_path_open */\r
\r
+/*\r
+ * os_load_story\r
+ *\r
+ * This is different from os_path_open() because we need to see if the\r
+ * story file is actually a chunk inside a blorb file. Right now we're\r
+ * looking only at the exact path we're given on the command line.\r
+ *\r
+ * Open a file in the current directory. If this fails, then search the\r
+ * directories in the ZCODE_PATH environmental variable. If that's not\r
+ * defined, search INFOCOM_PATH.\r
+ *\r
+ */\r
+\r
+FILE *os_load_story(void)\r
+{\r
+ FILE *fp;\r
+\r
+ /* Did we build a valid blorb map? */\r
+ if (exec_in_blorb) {\r
+ fp = fopen(blorb_file, "rb");\r
+ fseek(fp, blorb_res.data.startpos, SEEK_SET);\r
+ } else {\r
+ fp = fopen(f_setup.story_file, "rb");\r
+ }\r
+ return fp;\r
+}\r
+\r
+int dos_init_blorb(void)\r
+{\r
+ FILE *blorbfile;\r
+\r
+ /* If the filename given on the command line is the same as our\r
+ * computed blorb filename, then we will assume the executable\r
+ * is contained in the blorb file.\r
+ */\r
+\r
+ printf("blorb_file %s\n", blorb_file);\r
+ printf("story_file %s\n", f_setup.story_file);\r
+\r
+ if (strncmp((char *)basename(f_setup.story_file),\r
+ (char *)basename(blorb_file), 55) == 0) {\r
+ if ((blorbfile = fopen(blorb_file, "rb")) == NULL)\r
+ return bb_err_Read;\r
+ blorb_err = bb_create_map(blorbfile, &blorb_map);\r
+\r
+ if (blorb_err != bb_err_None) {\r
+ return blorb_err;\r
+ }\r
+\r
+ /* Now we need to locate the EXEC chunk within the blorb file\r
+ * and present it to the rest of the program as a file stream.\r
+ */\r
+\r
+ blorb_err = bb_load_chunk_by_type(blorb_map, bb_method_FilePos,\r
+ &blorb_res, bb_make_id('Z','C','O','D'), 0);\r
+\r
+ if (blorb_err == bb_err_None) {\r
+ exec_in_blorb = 1;\r
+ use_blorb = 1;\r
+ }\r
+ }\r
+ return 0;\r
+}\r
+\r