X-Git-Url: https://git.stderr.nl/gitweb?p=projects%2Fchimara%2Fchimara.git;a=blobdiff_plain;f=tests%2Fplugin-loader.c;fp=tests%2Fplugin-loader.c;h=50a54268d4a2b34b2e09c884c64ec2b243e4dd52;hp=296a58f658ce5f741fbc1e9a4bf4f8d7abc40f29;hb=4f3c8f79cadad5dbd3911fd2fefea0beacd18092;hpb=fabc4f9b35b4d4e1bb3c3f67971e8e134889c453 diff --git a/tests/plugin-loader.c b/tests/plugin-loader.c index 296a58f..50a5426 100644 --- a/tests/plugin-loader.c +++ b/tests/plugin-loader.c @@ -40,6 +40,7 @@ #include #include +#include #include /* Global pointers to widgets */ @@ -77,6 +78,43 @@ resource_load(ChimaraResourceType usage, guint32 resnum) return g_strdup_printf("%s%d", resstr, resnum); } +static GFile * +libname_from_la_file(char *la_filename) +{ + GFile *la_file = g_file_new_for_commandline_arg(la_filename); + GFile *parentdir = g_file_get_parent(la_file); + GFile *objdir = g_file_get_child(parentdir, LT_OBJDIR); + g_object_unref(parentdir); + + GFileInputStream *istream = g_file_read(la_file, NULL, NULL); + if(istream == NULL) + return NULL; + GDataInputStream *stream = g_data_input_stream_new( G_INPUT_STREAM(istream) ); + + char *line; + char *dlname = NULL; + while( (line = g_data_input_stream_read_line(stream, NULL, NULL, NULL)) ) { + if( g_str_has_prefix(line, "dlname=") ) { + dlname = g_strdup( line + strlen("dlname='") ); + *(strrchr(dlname, '\'')) = '\0'; + g_free(line); + break; + } + g_free(line); + } + if(dlname == NULL) + return NULL; + + g_input_stream_close(G_INPUT_STREAM (stream), NULL, NULL); + + GFile *libfile = g_file_get_child(objdir, dlname); + g_free(dlname); + + g_object_unref(la_file); + g_object_unref(objdir); + return libfile; +} + int main(int argc, char *argv[]) { @@ -97,10 +135,18 @@ main(int argc, char *argv[]) if(argc < 2) g_error("Must provide a plugin\n"); + GFile *plugin_file; + if( g_str_has_suffix(argv[1], ".la") ) + plugin_file = libname_from_la_file(argv[1]); + else + plugin_file = g_file_new_for_commandline_arg(argv[1]); + chimara_glk_set_resource_load_callback(CHIMARA_GLK(glk), (ChimaraResourceLoadFunc)resource_load, NULL, NULL); - - if( !chimara_glk_run(CHIMARA_GLK(glk), argv[1], argc - 1, argv + 1, &error) ) + + if( !chimara_glk_run_file(CHIMARA_GLK(glk), plugin_file, + argc - 1, argv + 1, &error) ) g_error("Error starting Glk library: %s\n", error->message); + g_object_unref(plugin_file); gdk_threads_enter(); gtk_main();