]> rtime.felk.cvut.cz Git - frescor/forb.git/blob - forb-idl/forb-idl-backend.c
0bbf6ec92ad76966d8c4733bb5db85299b7d473b
[frescor/forb.git] / forb-idl / forb-idl-backend.c
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 "forb-idl-backend.h"
28 #include "forb-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/forb-2.0/idl-backends", NULL));
48
49         g_strfreev (strv);
50
51         return paths;
52 }
53
54 #if 0
55 static ForbIDLBackendFunc
56 load_language_backend (const char *path,
57                        const char *language)
58 {
59         ForbIDLBackendFunc  retval = NULL;
60         GModule             *module;
61         char                *modname;
62         char                *modpath;
63
64         modname = g_strconcat ("forb-idl-backend-", language, NULL);
65         modpath = g_module_build_path (path, modname);
66         g_free (modname);
67
68         if (!(module = g_module_open (modpath, G_MODULE_BIND_LAZY))) {
69                 g_free (modpath);
70                 return NULL;
71         }
72
73         if (!g_module_symbol (module, "forb_idl_backend_func", (gpointer *) &retval))
74                 g_warning ("backend %s has no \"forb_idl_backend_func\" defined", modpath);
75
76         g_free (modpath);
77
78         return retval;
79 }
80
81 gboolean
82 forb_idl_backend_output (OIDL_Run_Info *rinfo,
83                           IDL_tree       tree)
84 {
85         ForbIDLBackendFunc     func = NULL;
86         ForbIDLBackendContext  context;
87         GSList                 *paths = NULL;
88         GSList                 *l;
89
90         paths = prepend_from_env_var (paths, "GNOME2_PATH");
91         paths = prepend_from_env_var (paths, "FORB_BACKENDS_PATH");
92
93         paths = g_slist_prepend (paths, g_strdup (FORB_BACKENDS_DIR));
94
95         if (rinfo->backend_directory)
96                 paths = g_slist_prepend (paths, g_strdup (rinfo->backend_directory));
97
98         for (l = paths; l; l = l->next) {
99                 func = load_language_backend (l->data, rinfo->output_language);
100
101                 g_free (l->data);
102
103                 if (func)
104                         break;
105         }
106
107         g_slist_free (paths);
108
109         if (!func) {
110                 g_warning("idl-compiler backend not found.");
111                 return FALSE;
112         }
113
114         context.tree      = tree;
115         context.filename  = rinfo->input_filename;
116         context.do_stubs  = (rinfo->enabled_passes & OUTPUT_STUBS ? 1 : 0);
117         context.do_skels  = (rinfo->enabled_passes & OUTPUT_SKELS ? 1 : 0);
118         context.do_common = (rinfo->enabled_passes & OUTPUT_COMMON ? 1 : 0);
119
120         return func (&context);
121 }
122 #endif