From 4f3c8f79cadad5dbd3911fd2fefea0beacd18092 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Sat, 21 Sep 2013 10:40:44 -0700 Subject: [PATCH] Plugin-loader handles .la files Instead of passing .libs/plugin.so to plugin-loader, you can now pass plugin.la and the correct file will be loaded. --- tests/plugin-loader.c | 50 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) 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(); -- 2.30.2