| 1 | /*
|
|---|
| 2 | * orbit-idl-backend.c:
|
|---|
| 3 | *
|
|---|
| 4 | * Copyright (C) 2002 Sun Microsystems, Inc.
|
|---|
| 5 | *
|
|---|
| 6 | * This library is free software; you can redistribute it and/or
|
|---|
| 7 | * modify it under the terms of the GNU Library General Public
|
|---|
| 8 | * License as published by the Free Software Foundation; either
|
|---|
| 9 | * version 2 of the License, or (at your option) any later version.
|
|---|
| 10 | *
|
|---|
| 11 | * This library is distributed in the hope that it will be useful,
|
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 14 | * Library General Public License for more details.
|
|---|
| 15 | *
|
|---|
| 16 | * You should have received a copy of the GNU Library General Public
|
|---|
| 17 | * License along with this library; if not, write to the
|
|---|
| 18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|---|
| 19 | * Boston, MA 02111-1307, USA.
|
|---|
| 20 | *
|
|---|
| 21 | * Authors:
|
|---|
| 22 | * Mark McLoughlin <mark@skynet.ie>
|
|---|
| 23 | */
|
|---|
| 24 |
|
|---|
| 25 | #include <config.h>
|
|---|
| 26 |
|
|---|
| 27 | #include "orbit-idl-backend.h"
|
|---|
| 28 | #include "orbit-idl2.h"
|
|---|
| 29 |
|
|---|
| 30 | #include <glib.h>
|
|---|
| 31 | #include <gmodule.h>
|
|---|
| 32 |
|
|---|
| 33 | static GSList *
|
|---|
| 34 | prepend_from_env_var (GSList *paths,
|
|---|
| 35 | const char *env_var)
|
|---|
| 36 | {
|
|---|
| 37 | char *val;
|
|---|
| 38 | char **strv;
|
|---|
| 39 | int i;
|
|---|
| 40 |
|
|---|
| 41 | if (!(val = getenv ("GNOME2_PATH")))
|
|---|
| 42 | return paths;
|
|---|
| 43 |
|
|---|
| 44 | strv = g_strsplit (val, ";", -1);
|
|---|
| 45 | for (i = 0; strv [i]; i++)
|
|---|
| 46 | paths = g_slist_prepend (
|
|---|
| 47 | paths, g_strconcat (strv [i], "/lib/orbit-2.0/idl-backends", NULL));
|
|---|
| 48 |
|
|---|
| 49 | g_strfreev (strv);
|
|---|
| 50 |
|
|---|
| 51 | return paths;
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 | static ORBitIDLBackendFunc
|
|---|
| 55 | load_language_backend (const char *path,
|
|---|
| 56 | const char *language)
|
|---|
| 57 | {
|
|---|
| 58 | ORBitIDLBackendFunc retval = NULL;
|
|---|
| 59 | GModule *module;
|
|---|
| 60 | char *modname;
|
|---|
| 61 | char *modpath;
|
|---|
| 62 |
|
|---|
| 63 | modname = g_strconcat ("ORBit-idl-backend-", language, NULL);
|
|---|
| 64 | modpath = g_module_build_path (path, modname);
|
|---|
| 65 | g_free (modname);
|
|---|
| 66 |
|
|---|
| 67 | if (!(module = g_module_open (modpath, G_MODULE_BIND_LAZY))) {
|
|---|
| 68 | g_free (modpath);
|
|---|
| 69 | return NULL;
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | if (!g_module_symbol (module, "orbit_idl_backend_func", (gpointer *) &retval))
|
|---|
| 73 | g_warning ("backend %s has no \"orbit_idl_backend_func\" defined", modpath);
|
|---|
| 74 |
|
|---|
| 75 | g_free (modpath);
|
|---|
| 76 |
|
|---|
| 77 | return retval;
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | gboolean
|
|---|
| 81 | orbit_idl_backend_output (OIDL_Run_Info *rinfo,
|
|---|
| 82 | IDL_tree tree)
|
|---|
| 83 | {
|
|---|
| 84 | ORBitIDLBackendFunc func = NULL;
|
|---|
| 85 | ORBitIDLBackendContext context;
|
|---|
| 86 | GSList *paths = NULL;
|
|---|
| 87 | GSList *l;
|
|---|
| 88 |
|
|---|
| 89 | paths = prepend_from_env_var (paths, "GNOME2_PATH");
|
|---|
| 90 | paths = prepend_from_env_var (paths, "ORBIT_BACKENDS_PATH");
|
|---|
| 91 |
|
|---|
| 92 | paths = g_slist_prepend (paths, g_strdup (ORBIT_BACKENDS_DIR));
|
|---|
| 93 |
|
|---|
| 94 | if (rinfo->backend_directory)
|
|---|
| 95 | paths = g_slist_prepend (paths, g_strdup (rinfo->backend_directory));
|
|---|
| 96 |
|
|---|
| 97 | for (l = paths; l; l = l->next) {
|
|---|
| 98 | func = load_language_backend (l->data, rinfo->output_language);
|
|---|
| 99 |
|
|---|
| 100 | g_free (l->data);
|
|---|
| 101 |
|
|---|
| 102 | if (func)
|
|---|
| 103 | break;
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | g_slist_free (paths);
|
|---|
| 107 |
|
|---|
| 108 | if (!func) {
|
|---|
| 109 | g_warning("idl-compiler backend not found.");
|
|---|
| 110 | return FALSE;
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | context.tree = tree;
|
|---|
| 114 | context.filename = rinfo->input_filename;
|
|---|
| 115 | context.do_stubs = (rinfo->enabled_passes & OUTPUT_STUBS ? 1 : 0);
|
|---|
| 116 | context.do_skels = (rinfo->enabled_passes & OUTPUT_SKELS ? 1 : 0);
|
|---|
| 117 | context.do_common = (rinfo->enabled_passes & OUTPUT_COMMON ? 1 : 0);
|
|---|
| 118 |
|
|---|
| 119 | return func (&context);
|
|---|
| 120 | }
|
|---|