From 3be1ae1c3d42285d7ec44509096625fe89b0d764 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Sun, 15 Nov 2009 16:32:30 +0000 Subject: [PATCH] Wrote 'plugin-loader' for loading and executing a plugin. git-svn-id: http://lassie.dyndns-server.com/svn/gargoyle-gtk@165 ddfedd41-794f-dd11-ae45-00112f111e67 --- tests/plugin-loader.c | 109 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 tests/plugin-loader.c diff --git a/tests/plugin-loader.c b/tests/plugin-loader.c new file mode 100644 index 0000000..03ab746 --- /dev/null +++ b/tests/plugin-loader.c @@ -0,0 +1,109 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ +/* + * main.c + * Copyright (C) Philip en Marijn 2008 <> + * + * main.c is free software copyrighted by Philip en Marijn. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name ``Philip en Marijn'' nor the name of any other + * contributor may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * main.c IS PROVIDED BY Philip en Marijn ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL Philip en Marijn OR ANY OTHER CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +/* Global pointers to widgets */ +GtkWidget *window = NULL; +GtkWidget *glk = NULL; + +static gboolean +quit() +{ + gtk_main_quit(); + return TRUE; +} + +static void +create_window(void) +{ + window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_widget_set_size_request(window, 400, 400); + g_signal_connect(window, "delete-event", G_CALLBACK(quit), NULL); + glk = chimara_glk_new(); + g_object_set(glk, + "border-width", 6, + "spacing", 6, + NULL); + chimara_glk_set_default_font_string(CHIMARA_GLK(glk), "Serif 12"); + chimara_glk_set_monospace_font_string(CHIMARA_GLK(glk), "Monospace 12"); + gtk_container_add(GTK_CONTAINER(window), glk); +} + +int +main(int argc, char *argv[]) +{ + GError *error = NULL; + +#ifdef ENABLE_NLS + bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); + bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); + textdomain(GETTEXT_PACKAGE); +#endif + + if( !g_thread_supported() ) + g_thread_init(NULL); + gdk_threads_init(); + gtk_init(&argc, &argv); + + create_window(); + gtk_widget_show_all(window); + + if(argc < 2) { + g_printerr("Must provide a plugin\n"); + return 1; + } + + if( !chimara_glk_run(CHIMARA_GLK(glk), argv[1], argc - 1, argv + 1, &error) ) { + g_printerr("Error starting Glk library: %s\n", error->message); + return 1; + } + + gdk_threads_enter(); + gtk_main(); + gdk_threads_leave(); + + chimara_glk_stop(CHIMARA_GLK(glk)); + chimara_glk_wait(CHIMARA_GLK(glk)); + + return 0; +} -- 2.30.2