• R/O
  • SSH
  • HTTPS

comatz: Commit


Commit MetaInfo

Revisão10 (tree)
Hora2007-04-04 17:07:32
Autorkous

Mensagem de Log

* ./: make skeleton.

Mudança Sumário

Diff

--- comatz/trunk/configure.ac (revision 9)
+++ comatz/trunk/configure.ac (revision 10)
@@ -254,9 +254,10 @@
254254 COMATZ_CFLAGS="$COMATZ_CFLAGS \$(GLIB_CFLAGS)"
255255 COMATZ_CFLAGS="$COMATZ_CFLAGS -DCONFDIR=\\\"\"\$(confdir)\"\\\""
256256 COMATZ_CFLAGS="$COMATZ_CFLAGS -DDATADIR=\\\"\"\$(pkgdatadir)\"\\\""
257-COMATZ_CFLAGS="$COMATZ_CFLAGS -DDICT_DATADIR=\\\"\"\$(dict_datadir)\"\\\""
257+COMATZ_CFLAGS="$COMATZ_CFLAGS -DCM_MODULES_DIR=\\\"\"\$(modulesdir)\"\\\""
258258 COMATZ_CFLAGS="$COMATZ_CFLAGS -I\$(srcdir)"
259259 COMATZ_CFLAGS="$COMATZ_CFLAGS -I\$(top_srcdir)"
260+COMATZ_CFLAGS="$COMATZ_CFLAGS -I\$(top_srcdir)/comatz"
260261 AC_SUBST(COMATZ_CFLAGS)
261262
262263 COMATZ_LIBS='$(GLIB_LIBS)'
--- comatz/trunk/module/anthy/cm-anthy-dict.c (nonexistent)
+++ comatz/trunk/module/anthy/cm-anthy-dict.c (revision 10)
@@ -0,0 +1,155 @@
1+/* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2+
3+/*
4+ * Copyright (C) 2007 Kouhei Sutou <kou@cozmixng.org>
5+ *
6+ * This library is free software; you can redistribute it and/or
7+ * modify it under the terms of the GNU Lesser 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
14+ * GNU Lesser General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU Lesser General Public
17+ * License along with this program; if not, write to the
18+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
19+ * Boston, MA 02111-1307 USA
20+ */
21+
22+#ifdef HAVE_CONFIG_H
23+# include "config.h"
24+#endif /* HAVE_CONFIG_H */
25+
26+#include "cm-dict.h"
27+#include "cm-module.h"
28+#include "cm-module-impl.h"
29+
30+#define CM_TYPE_ANTHY_DICT (cm_type_anthy_dict)
31+#define CM_ANTHY_DICT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CM_TYPE_ANTHY_DICT, CmAnthyDict))
32+#define CM_IS_ANTHY_DICT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CM_TYPE_ANTHY_DICT))
33+#define CM_ANTHY_DICT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CM_TYPE_ANTHY_DICT, CmAnthyDictClass))
34+#define CM_IS_ANTHY_DICT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CM_TYPE_ANTHY_DICT))
35+#define CM_ANTHY_DICT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CM_TYPE_ANTHY_DICT, CmAnthyDictClass))
36+
37+typedef struct _CmAnthyDict CmAnthyDict;
38+
39+struct _CmAnthyDict
40+{
41+ GObject parent;
42+};
43+
44+typedef struct _CmAnthyDictClass CmAnthyDictClass;
45+struct _CmAnthyDictClass
46+{
47+ GObjectClass parent_class;
48+};
49+
50+
51+/* CmAnthyDict Class */
52+static void cm_anthy_dict_class_init (CmAnthyDictClass *klass);
53+static void cm_anthy_dict_init (CmAnthyDict *dict);
54+
55+/* GObject Class */
56+static void dispose (GObject *object);
57+
58+/* CmDictIFace */
59+static void cm_anthy_dict_iface_init (CmDictIFace *iface);
60+
61+static GObjectClass *parent_class;
62+static GType cm_type_anthy_dict = 0;
63+
64+static void
65+cm_anthy_dict_register_type (GTypeModule *module)
66+{
67+ static const GTypeInfo cm_anthy_dict_info =
68+ {
69+ sizeof (CmAnthyDictClass),
70+ NULL, /* base_init */
71+ NULL, /* base_finalize */
72+ (GClassInitFunc)cm_anthy_dict_class_init,
73+ NULL, /* class_finalize */
74+ NULL, /* class_data */
75+ sizeof (CmAnthyDict),
76+ 0, /* n_preallocs */
77+ (GInstanceInitFunc)cm_anthy_dict_init,
78+ };
79+
80+ const GInterfaceInfo cm_dict_info =
81+ {
82+ (GInterfaceInitFunc)cm_anthy_dict_iface_init,
83+ NULL,
84+ NULL
85+ };
86+
87+ cm_type_anthy_dict =
88+ g_type_module_register_type(module,
89+ G_TYPE_OBJECT,
90+ "CmAnthyDict",
91+ &cm_anthy_dict_info, 0);
92+
93+ g_type_module_add_interface(module,
94+ CM_TYPE_ANTHY_DICT,
95+ CM_TYPE_DICT,
96+ &cm_dict_info);
97+}
98+
99+G_MODULE_EXPORT void
100+CM_MODULE_IMPL_INIT (GTypeModule *module)
101+{
102+ cm_anthy_dict_register_type(module);
103+}
104+
105+G_MODULE_EXPORT void
106+CM_MODULE_IMPL_EXIT (void)
107+{
108+}
109+
110+G_MODULE_EXPORT GObject *
111+CM_MODULE_IMPL_INSTANTIATE (const gchar *first_property,
112+ va_list var_args)
113+{
114+ return g_object_new_valist(CM_TYPE_ANTHY_DICT,
115+ first_property, var_args);
116+}
117+
118+G_MODULE_EXPORT const gchar *
119+CM_MODULE_IMPL_GET_NAME (void)
120+{
121+ return _("Anthy");
122+}
123+
124+
125+static void
126+cm_anthy_dict_class_init (CmAnthyDictClass *klass)
127+{
128+ GObjectClass *object_class;
129+
130+ parent_class = g_type_class_peek_parent (klass);
131+ object_class = (GObjectClass *) klass;
132+
133+ object_class->dispose = dispose;
134+}
135+
136+static void
137+cm_anthy_dict_iface_init (CmDictIFace *iface)
138+{
139+}
140+
141+static void
142+cm_anthy_dict_init (CmAnthyDict *dict)
143+{
144+}
145+
146+static void
147+dispose (GObject *object)
148+{
149+ if (G_OBJECT_CLASS(parent_class)->dispose)
150+ G_OBJECT_CLASS(parent_class)->dispose(object);
151+}
152+
153+/*
154+vi:ts=4:nowrap:ai:expandtab
155+*/
--- comatz/trunk/module/anthy/Makefile.am (revision 9)
+++ comatz/trunk/module/anthy/Makefile.am (revision 10)
@@ -9,6 +9,7 @@
99 anthy_la_CPPFLAGS = \
1010 -DG_LOG_DOMAIN=\"coMatz-Anthy\" \
1111 -DG_DISABLE_DEPRECATED=1 \
12+ $(INCLUDES) \
1213 $(NULL)
1314
1415 anthy_la_LDFLAGS = \
@@ -16,7 +17,8 @@
1617 -module \
1718 $(NULL)
1819
19-anthy_la_SOURCES =
20+anthy_la_SOURCES = \
21+ cm-anthy-dict.c
2022
2123 anthy_la_LIBADD = \
2224 $(COMATZ_LIBS) \
--- comatz/trunk/ChangeLog (revision 9)
+++ comatz/trunk/ChangeLog (revision 10)
@@ -1,5 +1,7 @@
11 2007-04-04 Kouhei Sutou <kou@cozmixng.org>
22
3+ * ./: make skeleton.
4+
35 * autogen.sh: added --copy prefix.
46
57 2007-04-03 Hiroyuki Ikezoe <poincare@ikezoe.net>
--- comatz/trunk/comatz/cm-dict.c (nonexistent)
+++ comatz/trunk/comatz/cm-dict.c (revision 10)
@@ -0,0 +1,162 @@
1+/* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2+
3+/*
4+ * Copyright (C) 2007 Kouhei Sutou <kou@cozmixng.org>
5+ *
6+ * This library is free software; you can redistribute it and/or
7+ * modify it under the terms of the GNU Lesser 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
14+ * GNU Lesser General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU Lesser General Public
17+ * License along with this program; if not, write to the
18+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
19+ * Boston, MA 02111-1307 USA
20+ */
21+
22+#ifdef HAVE_CONFIG_H
23+# include "config.h"
24+#endif /* HAVE_CONFIG_H */
25+
26+#include "cm-dict.h"
27+#include "cm-module.h"
28+
29+static GList *dicts = NULL;
30+
31+static const gchar *
32+_cm_dict_module_dir (void)
33+{
34+ const gchar *base_dir;
35+ base_dir = g_getenv("CM_MODULES_DIR");
36+ if (base_dir)
37+ return base_dir;
38+ return CM_MODULES_DIR;
39+}
40+
41+void
42+cm_dict_load (const gchar *base_dir)
43+{
44+ if (!base_dir)
45+ base_dir = _cm_dict_module_dir();
46+
47+ dicts = g_list_concat(cm_module_load_modules(base_dir), dicts);
48+}
49+
50+void
51+cm_dict_unload (void)
52+{
53+ g_list_foreach(dicts, (GFunc)cm_module_unload, NULL);
54+ g_list_free(dicts);
55+ dicts = NULL;
56+}
57+
58+void
59+cm_dict_exit (void)
60+{
61+ g_list_foreach(dicts, (GFunc)cm_module_exit, NULL);
62+}
63+
64+GList *
65+cm_dict_engine_names (void)
66+{
67+ GList *node;
68+ GList *result = NULL;
69+
70+ if (!dicts)
71+ cm_dict_load(NULL);
72+
73+ for (node = dicts; node; node = g_list_next(node)) {
74+ CmModule *module = node->data;
75+ result = g_list_append(result,
76+ g_strdup(cm_module_get_name(module)));
77+ }
78+
79+ return result;
80+}
81+
82+GList *
83+cm_dict_engine_ids (void)
84+{
85+ GList *node;
86+ GList *result = NULL;
87+
88+ if (!dicts)
89+ cm_dict_load(NULL);
90+
91+ for (node = dicts; node; node = g_list_next(node))
92+ {
93+ CmModule *module = node->data;
94+ result = g_list_append(result,
95+ g_strdup(G_TYPE_MODULE(module)->name));
96+ }
97+
98+ return result;
99+}
100+
101+static CmDict *
102+_cm_dict_new (CmModule *module, const gchar *name,
103+ const gchar *first_property, ...)
104+{
105+ GObject *dict;
106+ va_list var_args;
107+
108+ va_start(var_args, first_property);
109+ dict = cm_module_instantiate(module, first_property, var_args);
110+ va_end(var_args);
111+
112+ return CM_DICT(dict);
113+}
114+
115+CmDict *
116+cm_dict_new (const gchar *name)
117+{
118+ CmModule *module;
119+
120+ if (!dicts)
121+ cm_dict_load(NULL);
122+
123+ module = cm_module_find(dicts, name);
124+ if (!module)
125+ {
126+ module = cm_module_load_module(_cm_dict_module_dir(), name);
127+ if (!module)
128+ return NULL;
129+ dicts = g_list_prepend(dicts, module);
130+ }
131+
132+ return _cm_dict_new(module, name, NULL);
133+}
134+
135+
136+GType
137+cm_dict_get_type (void)
138+{
139+ static GType type = 0;
140+ if (!type)
141+ {
142+ static const GTypeInfo info = {
143+ sizeof(CmDictIFace),
144+ NULL, /* base_init */
145+ NULL, /* base_finalize */
146+ NULL, /* class_init */
147+ NULL, /* class_finalize */
148+ NULL, /* class_data */
149+ 0,
150+ 0, /* n_preallocs */
151+ NULL, /* instance_init */
152+ };
153+ type = g_type_register_static(G_TYPE_INTERFACE, "CmDict",
154+ &info, 0);
155+ g_type_interface_add_prerequisite(type, G_TYPE_OBJECT);
156+ }
157+ return type;
158+}
159+
160+/*
161+vi:ts=4:nowrap:ai:expandtab
162+*/
--- comatz/trunk/comatz/comatz.h (revision 9)
+++ comatz/trunk/comatz/comatz.h (revision 10)
@@ -1,4 +1,4 @@
1-/* -*- mode: c; c-file-style: "gnu"; indent-tabs-mode: nil -*- */
1+/* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
22
33 /*
44 * Copyright (C) 2007 Kouhei Sutou <kou@cozmixng.org>
@@ -36,3 +36,7 @@
3636 G_END_DECLS
3737
3838 #endif /* __COMATZ_H__ */
39+
40+/*
41+vi:ts=4:nowrap:ai:expandtab
42+*/
--- comatz/trunk/comatz/cm-module.c (nonexistent)
+++ comatz/trunk/comatz/cm-module.c (revision 10)
@@ -0,0 +1,389 @@
1+/* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2+
3+/*
4+ * Copyright (C) 2007 Kouhei Sutou <kou@cozmixng.org>
5+ *
6+ * This library is free software; you can redistribute it and/or
7+ * modify it under the terms of the GNU Lesser 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
14+ * GNU Lesser General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU Lesser General Public
17+ * License along with this program; if not, write to the
18+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
19+ * Boston, MA 02111-1307 USA
20+ */
21+
22+#ifdef HAVE_CONFIG_H
23+# include "config.h"
24+#endif /* HAVE_CONFIG_H */
25+
26+#include <string.h>
27+
28+#include <gmodule.h>
29+
30+#include "cm-module.h"
31+#include "cm-module-impl.h"
32+
33+#define CM_MODULE_GET_PRIVATE(obj) \
34+ (G_TYPE_INSTANCE_GET_PRIVATE ((obj), CM_TYPE_MODULE, CmModulePrivate))
35+
36+typedef struct _CmModulePrivate CmModulePrivate;
37+struct _CmModulePrivate
38+{
39+ GModule *library;
40+ gchar *mod_path;
41+ GList *registered_types;
42+ gboolean exited;
43+
44+ CmModuleInitFunc init;
45+ CmModuleExitFunc exit;
46+ CmModuleInstantiateFunc instantiate;
47+ CmModuleGetNameFunc get_name;
48+};
49+
50+G_DEFINE_TYPE (CmModule, cm_module, G_TYPE_TYPE_MODULE)
51+
52+static void finalize (GObject *object);
53+static gboolean load (GTypeModule *module);
54+static void unload (GTypeModule *module);
55+
56+static void _cm_module_show_error (GModule *module);
57+static GModule *_cm_module_open (const gchar *mod_path);
58+static void _cm_module_close (GModule *module);
59+static gboolean _cm_module_load_func (GModule *module,
60+ const gchar *func_name,
61+ gpointer *symbol);
62+static gboolean _cm_module_match_name (const gchar *mod_path,
63+ const gchar *name);
64+
65+static void
66+cm_module_class_init (CmModuleClass *klass)
67+{
68+ GObjectClass *gobject_class;
69+ GTypeModuleClass *type_module_class;
70+
71+ gobject_class = G_OBJECT_CLASS(klass);
72+ gobject_class->finalize = finalize;
73+
74+ type_module_class = G_TYPE_MODULE_CLASS(klass);
75+ type_module_class->load = load;
76+ type_module_class->unload = unload;
77+
78+ g_type_class_add_private(gobject_class, sizeof(CmModulePrivate));
79+}
80+
81+static void
82+cm_module_init (CmModule *module)
83+{
84+ CmModulePrivate *priv = CM_MODULE_GET_PRIVATE(module);
85+
86+ priv->library = NULL;
87+ priv->mod_path = NULL;
88+ priv->registered_types = NULL;
89+ priv->exited = FALSE;
90+}
91+
92+static void
93+finalize (GObject *object)
94+{
95+ CmModulePrivate *priv = CM_MODULE_GET_PRIVATE(object);
96+
97+ g_free(priv->mod_path);
98+ priv->mod_path = NULL;
99+ g_list_free(priv->registered_types);
100+ priv->registered_types = NULL;
101+
102+ G_OBJECT_CLASS(cm_module_parent_class)->finalize(object);
103+}
104+
105+static gboolean
106+load (GTypeModule *module)
107+{
108+ CmModulePrivate *priv = CM_MODULE_GET_PRIVATE(module);
109+
110+ priv->library = _cm_module_open(priv->mod_path);
111+ if (!priv->library)
112+ return FALSE;
113+
114+ if (!_cm_module_load_func(priv->library,
115+ G_STRINGIFY(CM_MODULE_IMPL_INIT),
116+ (gpointer)&priv->init) ||
117+ !_cm_module_load_func(priv->library,
118+ G_STRINGIFY(CM_MODULE_IMPL_EXIT),
119+ (gpointer)&priv->exit) ||
120+ !_cm_module_load_func(priv->library,
121+ G_STRINGIFY(CM_MODULE_IMPL_INSTANTIATE),
122+ (gpointer)&priv->instantiate)) {
123+ _cm_module_close(priv->library);
124+ priv->library = NULL;
125+ return FALSE;
126+ }
127+
128+ _cm_module_load_func(priv->library,
129+ G_STRINGIFY(CM_MODULE_IMPL_GET_NAME),
130+ (gpointer)&priv->get_name);
131+
132+ priv->exited = FALSE;
133+
134+ priv->init(module);
135+
136+ return TRUE;
137+}
138+
139+static void
140+unload (GTypeModule *module)
141+{
142+ CmModulePrivate *priv = CM_MODULE_GET_PRIVATE(module);
143+
144+ if (!priv->exited)
145+ {
146+ priv->exit();
147+ priv->exited = TRUE;
148+ }
149+
150+ _cm_module_close(priv->library);
151+ priv->library = NULL;
152+
153+ priv->init = NULL;
154+ priv->exit = NULL;
155+ priv->instantiate = NULL;
156+ priv->get_name = NULL;
157+}
158+
159+
160+static void
161+_cm_module_show_error (GModule *module)
162+{
163+ gchar *message;
164+
165+ if (!g_module_error()) return;
166+ message = g_locale_to_utf8(g_module_error(), -1, NULL, NULL, NULL);
167+
168+ if (module) {
169+ gchar *name;
170+ name = g_strdup(g_module_name(module));
171+ g_warning("%s: %s", name, message);
172+ g_free(name);
173+ } else {
174+ g_warning("%s", message);
175+ }
176+
177+ g_free(message);
178+}
179+
180+CmModule *
181+cm_module_find (GList *modules, const gchar *name)
182+{
183+ GList *node;
184+
185+ for (node = modules; node; node = g_list_next(node)) {
186+ CmModule *module = node->data;
187+ CmModulePrivate *priv;
188+
189+ priv = CM_MODULE_GET_PRIVATE(module);
190+ if (_cm_module_match_name(priv->mod_path, name))
191+ return module;
192+ }
193+
194+ return NULL;
195+}
196+
197+GObject *
198+cm_module_instantiate (CmModule *module,
199+ const gchar *first_property, va_list var_args)
200+{
201+ GObject *object = NULL;
202+ CmModulePrivate *priv;
203+
204+ priv = CM_MODULE_GET_PRIVATE(module);
205+ if (g_type_module_use(G_TYPE_MODULE(module)))
206+ {
207+ object = priv->instantiate(first_property, var_args);
208+ g_type_module_unuse(G_TYPE_MODULE(module));
209+ }
210+
211+ return object;
212+}
213+
214+const gchar *
215+cm_module_get_name (CmModule *module)
216+{
217+ CmModulePrivate *priv;
218+ const gchar *name = NULL;
219+
220+ priv = CM_MODULE_GET_PRIVATE(module);
221+ if (priv->get_name && g_type_module_use(G_TYPE_MODULE(module)))
222+ {
223+ name = priv->get_name();
224+ g_type_module_unuse(G_TYPE_MODULE(module));
225+ }
226+
227+ if (!name)
228+ name = G_TYPE_MODULE(module)->name;
229+
230+ return name;
231+}
232+
233+static GModule *
234+_cm_module_open (const gchar *mod_path)
235+{
236+ GModule *module;
237+
238+ module = g_module_open(mod_path, G_MODULE_BIND_LAZY);
239+ if (!module) {
240+ _cm_module_show_error(NULL);
241+ }
242+
243+ return module;
244+}
245+
246+static void
247+_cm_module_close (GModule *module)
248+{
249+ if (!module)
250+ return;
251+
252+ if (!g_module_close(module))
253+ _cm_module_show_error(module);
254+}
255+
256+static gchar *
257+_cm_module_module_file_name (const gchar *name)
258+{
259+ return g_strconcat(name, "." G_MODULE_SUFFIX, NULL);
260+}
261+
262+static gboolean
263+_cm_module_load_func (GModule *module, const gchar *func_name,
264+ gpointer *symbol)
265+{
266+ g_return_val_if_fail(module, FALSE);
267+
268+ if (g_module_symbol(module, func_name, symbol)) {
269+ return TRUE;
270+ } else {
271+ _cm_module_show_error(module);
272+ return FALSE;
273+ }
274+}
275+
276+CmModule *
277+cm_module_load_module (const gchar *base_dir, const gchar *name)
278+{
279+ gchar *mod_base_name, *mod_path;
280+ CmModule *module = NULL;
281+
282+ mod_base_name = g_build_filename(base_dir, name, NULL);
283+ if (g_str_has_suffix(mod_base_name, G_MODULE_SUFFIX)) {
284+ mod_path = mod_base_name;
285+ } else {
286+ mod_path = _cm_module_module_file_name(mod_base_name);
287+ g_free(mod_base_name);
288+ }
289+
290+ if (g_file_test(mod_path, G_FILE_TEST_EXISTS)) {
291+ CmModulePrivate *priv;
292+ gchar *mod_name;
293+
294+ module = g_object_new(CM_TYPE_MODULE, NULL);
295+ priv = CM_MODULE_GET_PRIVATE(module);
296+ priv->mod_path = g_strdup(mod_path);
297+
298+ mod_name = g_strdup(name);
299+ if (g_str_has_suffix(mod_name, "."G_MODULE_SUFFIX)) {
300+ guint last_index;
301+ last_index =
302+ strlen(mod_name) - strlen("."G_MODULE_SUFFIX);
303+ mod_name[last_index] = '\0';
304+ }
305+ g_type_module_set_name(G_TYPE_MODULE(module), mod_name);
306+ g_free(mod_name);
307+ }
308+ g_free(mod_path);
309+
310+ return module;
311+}
312+
313+GList *
314+cm_module_load_modules (const gchar *base_dir)
315+{
316+ GDir *dir;
317+ GList *modules = NULL;
318+
319+ dir = g_dir_open(base_dir, 0, NULL);
320+ if (dir) {
321+ const gchar *entry;
322+
323+ while ((entry = g_dir_read_name(dir))) {
324+ CmModule *module;
325+ module = cm_module_load_module(base_dir, entry);
326+ if (module)
327+ modules = g_list_prepend(modules, module);
328+ }
329+
330+ g_dir_close(dir);
331+ }
332+
333+ return modules;
334+}
335+
336+static gboolean
337+_cm_module_match_name (const gchar *mod_path, const gchar *name)
338+{
339+ gboolean matched;
340+ gchar *module_base_name, *normalized_matched_name;
341+
342+ module_base_name = g_path_get_basename(mod_path);
343+ normalized_matched_name = _cm_module_module_file_name(name);
344+
345+ matched = (0 == strcmp(module_base_name, normalized_matched_name));
346+
347+ g_free(module_base_name);
348+ g_free(normalized_matched_name);
349+
350+ return matched;
351+}
352+
353+void
354+cm_module_exit (CmModule *module)
355+{
356+ CmModulePrivate *priv;
357+
358+ g_return_if_fail(CM_IS_MODULE(module));
359+
360+ priv = CM_MODULE_GET_PRIVATE(module);
361+ if (priv->exited)
362+ return;
363+
364+ if (g_type_module_use(G_TYPE_MODULE(module))) {
365+ priv->exit();
366+ priv->exited = TRUE;
367+ g_type_module_unuse(G_TYPE_MODULE(module));
368+ }
369+
370+ g_type_module_unuse(G_TYPE_MODULE(module));
371+}
372+
373+void
374+cm_module_unload (CmModule *module)
375+{
376+ GTypeModule *type_module;
377+
378+ g_return_if_fail(CM_IS_MODULE(module));
379+
380+ type_module = G_TYPE_MODULE(module);
381+ if (type_module->type_infos || type_module->interface_infos)
382+ return;
383+
384+ g_object_unref(module);
385+}
386+
387+/*
388+vi:ts=4:nowrap:ai:expandtab
389+*/
--- comatz/trunk/comatz/cm-dict.h (revision 9)
+++ comatz/trunk/comatz/cm-dict.h (revision 10)
@@ -1,4 +1,4 @@
1-/* -*- mode: c; c-file-style: "gnu"; indent-tabs-mode: nil -*- */
1+/* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
22
33 /*
44 * Copyright (C) 2007 Kouhei Sutou <kou@cozmixng.org>
@@ -22,10 +22,37 @@
2222 #ifndef __CM_DICT_H__
2323 #define __CM_DICT_H__
2424
25-#include <glib.h>
25+#include <glib-object.h>
2626
2727 G_BEGIN_DECLS
2828
29+#define CM_TYPE_DICT (cm_dict_get_type())
30+#define CM_DICT(o) (G_TYPE_CHECK_INSTANCE_CAST((o), CM_TYPE_DICT, CmDict))
31+#define CM_IS_DICT(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), CM_TYPE_DICT))
32+#define CM_DICT_GET_IFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE((o), CM_TYPE_DICT, CmDictIFace))
33+
34+typedef struct _CmDict CmDict;
35+typedef struct _CmDictIFace CmDictIFace;
36+
37+struct _CmDictIFace
38+{
39+ GTypeInterface g_iface;
40+};
41+
42+GType cm_dict_get_type (void) G_GNUC_CONST;
43+
44+void cm_dict_load (const gchar *base_dir);
45+void cm_dict_unload (void);
46+void cm_dict_exit (void);
47+GList *cm_dict_engine_names (void);
48+GList *cm_dict_engine_ids (void);
49+
50+CmDict *cm_dict_new (const gchar *name);
51+
2952 G_END_DECLS
3053
3154 #endif /* __CM_DICT_H__ */
55+
56+/*
57+vi:ts=4:nowrap:ai:expandtab
58+*/
--- comatz/trunk/comatz/cm-module-impl.h (nonexistent)
+++ comatz/trunk/comatz/cm-module-impl.h (revision 10)
@@ -0,0 +1,57 @@
1+/* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2+
3+/*
4+ * Copyright (C) 2007 Kouhei Sutou <kou@cozmixng.org>
5+ *
6+ * This library is free software; you can redistribute it and/or
7+ * modify it under the terms of the GNU Lesser 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
14+ * GNU Lesser General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU Lesser General Public
17+ * License along with this program; if not, write to the
18+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
19+ * Boston, MA 02111-1307 USA
20+ */
21+
22+#ifndef __CM_MODULE_IMPL_H__
23+#define __CM_MODULE_IMPL_H__
24+
25+#include <glib-object.h>
26+#include <gmodule.h>
27+#include <glib/gi18n.h>
28+
29+#include "cm-module.h"
30+
31+G_BEGIN_DECLS
32+
33+typedef void (*CmModuleInitFunc) (GTypeModule *module);
34+typedef void (*CmModuleExitFunc) (void);
35+typedef GObject *(*CmModuleInstantiateFunc) (const gchar *first_property,
36+ va_list var_args);
37+typedef const gchar *(*CmModuleGetNameFunc) (void);
38+
39+#define CM_MODULE_IMPL_INIT cm_module_impl_init
40+#define CM_MODULE_IMPL_EXIT cm_module_impl_exit
41+#define CM_MODULE_IMPL_INSTANTIATE cm_module_impl_instantiate
42+#define CM_MODULE_IMPL_GET_NAME cm_module_impl_get_name
43+
44+
45+void CM_MODULE_IMPL_INIT (GTypeModule *module);
46+void CM_MODULE_IMPL_EXIT (void);
47+GObject *CM_MODULE_IMPL_INSTANTIATE (const gchar *first_property,
48+ va_list var_args);
49+const gchar *CM_MODULE_IMPL_GET_NAME (void);
50+
51+G_END_DECLS
52+
53+#endif /* __CM_MODULE_IMPL_H__ */
54+
55+/*
56+vi:ts=4:nowrap:ai:expandtab
57+*/
--- comatz/trunk/comatz/cm-module.h (nonexistent)
+++ comatz/trunk/comatz/cm-module.h (revision 10)
@@ -0,0 +1,73 @@
1+/* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2+
3+/*
4+ * Copyright (C) 2007 Kouhei Sutou <kou@cozmixng.org>
5+ *
6+ * This library is free software; you can redistribute it and/or
7+ * modify it under the terms of the GNU Lesser 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
14+ * GNU Lesser General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU Lesser General Public
17+ * License along with this program; if not, write to the
18+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
19+ * Boston, MA 02111-1307 USA
20+ */
21+
22+#ifndef __CM_MODULE_H__
23+#define __CM_MODULE_H__
24+
25+#include <glib-object.h>
26+
27+G_BEGIN_DECLS
28+
29+#define CM_TYPE_MODULE (cm_module_get_type ())
30+#define CM_MODULE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CM_TYPE_MODULE, CmModule))
31+#define CM_MODULE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CM_TYPE_MODULE, CmModuleClass))
32+#define CM_IS_MODULE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CM_TYPE_MODULE))
33+#define CM_IS_MODULE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CM_TYPE_MODULE))
34+#define CM_MODULE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), CM_TYPE_MODULE, CmModuleClass))
35+
36+typedef struct _CmModule CmModule;
37+typedef struct _CmModuleClass CmModuleClass;
38+
39+struct _CmModule
40+{
41+ GTypeModule object;
42+};
43+
44+struct _CmModuleClass
45+{
46+ GTypeModuleClass parent_class;
47+};
48+
49+GType cm_module_get_type (void) G_GNUC_CONST;
50+
51+
52+CmModule *cm_module_load_module (const gchar *base_dir,
53+ const gchar *name);
54+GList *cm_module_load_modules (const gchar *base_dir);
55+
56+CmModule *cm_module_find (GList *modules,
57+ const gchar *name);
58+
59+GObject *cm_module_instantiate (CmModule *module,
60+ const gchar *first_property,
61+ va_list var_args);
62+const gchar *cm_module_get_name (CmModule *module);
63+
64+void cm_module_exit (CmModule *module);
65+void cm_module_unload (CmModule *module);
66+
67+G_END_DECLS
68+
69+#endif /* __CM_MODULE_H__ */
70+
71+/*
72+vi:ts=4:nowrap:ai:expandtab
73+*/
--- comatz/trunk/comatz/Makefile.am (revision 9)
+++ comatz/trunk/comatz/Makefile.am (revision 10)
@@ -24,7 +24,9 @@
2424 INCLUDES = $(COMATZ_CFLAGS)
2525
2626 comatz_public_h_sources = \
27- cm-dict.h
27+ cm-dict.h \
28+ cm-module.h \
29+ cm-module-impl.h
2830
2931 enum_types_c = $(enum_types_prefix).c
3032 enum_types_h = $(enum_types_prefix).h
@@ -49,11 +51,14 @@
4951
5052 libcomatz_la_SOURCES = \
5153 comatz.c \
54+ cm-module.c \
55+ cm-dict.c \
5256 @enum_types_prefix@.c
5357
54-libcomatz_la_LDFLAGS = \
55- -version-info $(LT_VERSION_INFO) \
56- -export-dynamic $(no_undefined) $(LIBTOOL_EXPORT_OPTIONS)
58+libcomatz_la_LDFLAGS = \
59+ -version-info $(LT_VERSION_INFO) \
60+ -export-dynamic $(no_undefined) \
61+ $(LIBTOOL_EXPORT_OPTIONS)
5762
5863 libcomatz_la_LD_ADD =
5964
--- comatz/trunk/comatz/comatz.c (revision 9)
+++ comatz/trunk/comatz/comatz.c (revision 10)
@@ -1,4 +1,4 @@
1-/* -*- mode: c; c-file-style: "gnu"; indent-tabs-mode: nil -*- */
1+/* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
22
33 /*
44 * Copyright (C) 2007 Kouhei Sutou <kou@cozmixng.org>
@@ -30,3 +30,7 @@
3030 cm_quit (void)
3131 {
3232 }
33+
34+/*
35+vi:ts=4:nowrap:ai:expandtab
36+*/
--- comatz/trunk/po/ja.po (nonexistent)
+++ comatz/trunk/po/ja.po (revision 10)
@@ -0,0 +1,21 @@
1+# coMatz.
2+# Copyright (C) 2007 Kouhei Sutou <kou@cozmixng.org>
3+# This file is distributed under the same license as the coMatz package.
4+# Kouhei Sutou <kou@cozmixng.org>, 2007.
5+#
6+msgid ""
7+msgstr ""
8+"Project-Id-Version: coMatzh 0.0.1\n"
9+"Report-Msgid-Bugs-To: \n"
10+"POT-Creation-Date: 2007-04-04 16:59+0900\n"
11+"PO-Revision-Date: 2007-04-04 17:02+0900\n"
12+"Last-Translator: Kouhei Sutou <kou@cozmixng.org>\n"
13+"Language-Team: Kouhei Sutou <kou@cozmixng.org>\n"
14+"MIME-Version: 1.0\n"
15+"Content-Type: text/plain; charset=UTF-8\n"
16+"Content-Transfer-Encoding: 8bit\n"
17+"Plural-Forms: nplurals=1; plural=0;"
18+
19+#: ../module/anthy/cm-anthy-dict.c:121
20+msgid "Anthy"
21+msgstr ""
--- comatz/trunk/po/POTFILES.in (revision 9)
+++ comatz/trunk/po/POTFILES.in (revision 10)
@@ -1 +1,4 @@
11 comatz/comatz.c
2+comatz/cm-dict.c
3+comatz/cm-module.c
4+module/anthy/cm-anthy-dict.c
Show on old repository browser