Provide blorb file to interpreter on command line
authorP. F. Chimento <philip.chimento@gmail.com>
Sun, 30 Jan 2011 17:49:53 +0000 (18:49 +0100)
committerP. F. Chimento <philip.chimento@gmail.com>
Sun, 30 Jan 2011 17:49:53 +0000 (18:49 +0100)
Apparently both interpreters have the undocumented command line option
of providing an extra file name on the command line, which is the Blorb
resource file. We now take advantage of this.

libchimara/chimara-glk-private.h
libchimara/chimara-glk.c
libchimara/chimara-if.c

index 24d79fa0bcf085517dce63b90557aa0592b4b2fa..67366707f92af252c0354a97e5dc08041a934ec7 100644 (file)
@@ -91,9 +91,6 @@ struct _ChimaraGlkPrivate {
        giblorb_map_t *resource_map;
        /* File stream pointing to the blorb used as current resource map */
        strid_t resource_file;
-       /* Information for opening external blorb file */
-       gboolean open_external_blorb;
-       gchar *external_blorb_pathname;
        /* Optional callback for loading resource data */
        ChimaraResourceLoadFunc resource_load_callback;
        gpointer resource_load_callback_data;
index aca2f212e8c47d6d02443ff899898c8ecd6cb045..ca01f44510d7c7dd86a0db2fa9698385cea1197b 100644 (file)
@@ -180,8 +180,6 @@ chimara_glk_init(ChimaraGlk *self)
        priv->line_input_queue = g_async_queue_new();
        /* Should be g_async_queue_new_full(g_free); but only in GTK >= 2.16 */
        priv->resource_map = NULL;
-       priv->open_external_blorb = FALSE;
-       priv->external_blorb_pathname = NULL;
        priv->resource_lock = g_mutex_new();
        priv->resource_loaded = g_cond_new();
        priv->resource_info_available = g_cond_new();
@@ -1172,18 +1170,6 @@ glk_enter(struct StartupData *startup)
                if(!result)
                        return NULL;
        }
-
-       /* Open external Blorb file if specified */
-       if(startup->glk_data->open_external_blorb) {
-               glkunix_set_base_file(startup->glk_data->external_blorb_pathname);
-               gchar *basename = g_path_get_basename(startup->glk_data->external_blorb_pathname);
-               frefid_t blorbref = glk_fileref_create_by_name(fileusage_BinaryMode | fileusage_Data, basename, 0);
-               g_free(basename);
-               strid_t blorbfile = glk_stream_open_file(blorbref, filemode_Read, 0);
-               giblorb_set_resource_map(blorbfile);
-               glk_fileref_destroy(blorbref);
-               g_printerr("Opening external blorb file\n");
-       }
        
        /* Run main function */
        glk_main_t glk_main = startup->glk_main;
index 76edcf645c6252d07da503fb4b9895d099c70a73..2048f95d8783ee7df28adf825ce05f72da824f18 100644 (file)
@@ -650,6 +650,24 @@ chimara_if_run_game(ChimaraIF *self, gchar *gamefile, GError **error)
                        ;
        }
 
+       /* Check if an external blorb file is present */
+       /* FIXME: hardcoded path */
+       if(format == CHIMARA_IF_FORMAT_Z5 || format == CHIMARA_IF_FORMAT_Z6 || format == CHIMARA_IF_FORMAT_Z8) {
+               gchar *path = g_path_get_dirname(gamefile);
+               gchar *scratch = g_path_get_basename(gamefile);
+               *(strrchr(scratch, '.')) = '\0';
+               gchar *blorbfile = g_strconcat(path, "/../Resources/", scratch, ".blb", NULL);
+               g_printerr("Looking for %s\n", blorbfile);
+               if(g_file_test(blorbfile, G_FILE_TEST_EXISTS)) {
+                       args = g_slist_prepend(args, blorbfile);
+                       g_printerr("Prepending graphics file to args\n");
+               } else {
+                       g_free(blorbfile);
+               }
+               g_free(path);
+               g_free(scratch);
+       }
+
        /* Allocate argv to hold the arguments */
        int argc = g_slist_length(args);
        args = g_slist_prepend(args, NULL);
@@ -668,26 +686,6 @@ chimara_if_run_game(ChimaraIF *self, gchar *gamefile, GError **error)
        CHIMARA_GLK_USE_PRIVATE(self, glk_priv);
        glk_priv->story_name = g_path_get_basename(gamefile);
        g_object_notify(G_OBJECT(self), "story-name");
-
-       /* Check if an external blorb file is present */
-       /* FIXME: hardcoded path */
-       if(format == CHIMARA_IF_FORMAT_Z5
-           || format == CHIMARA_IF_FORMAT_Z6
-           || format == CHIMARA_IF_FORMAT_Z8
-           || format == CHIMARA_IF_FORMAT_GLULX) {
-               gchar *path = g_path_get_dirname(gamefile);
-               gchar *scratch = g_path_get_basename(gamefile);
-               *(strrchr(scratch, '.')) = '\0';
-               gchar *blorbfile = g_strconcat(path, "/../Resources/", scratch, ".blb", NULL);
-               if(g_file_test(blorbfile, G_FILE_TEST_EXISTS)) {
-                       glk_priv->open_external_blorb = TRUE;
-                       glk_priv->external_blorb_pathname = blorbfile;
-               } else {
-                       g_free(blorbfile);
-               }
-               g_free(path);
-               g_free(scratch);
-       }
        
        gboolean retval = chimara_glk_run(CHIMARA_GLK(self), pluginpath, argc, argv, error);
        g_free(argv);