From e37bcc53f1d145e10974fb0bb91802d735921fcd Mon Sep 17 00:00:00 2001 From: Daiki Ueno Date: Wed, 31 Aug 2011 11:44:46 +0900 Subject: [PATCH 1/6] Update the format of default.xml to allow override. This patch allows value inheritance from the previous matches. With the new format: * 0 FALSE m17n:ja:* 2 TRUE m17n:ja:anthy 1 We will get preedit-highlight == TRUE and rank == 1 for m17n:ja:anthy. --- src/Makefile.am | 3 +- src/default.xml.in.in | 221 +++++++++++++++++++------------------------------ src/engine.c | 2 + src/m17nutil.c | 68 +++++++--------- src/m17nutil.h | 1 + src/test.c | 66 +++++++++++++++ 6 files changed, 186 insertions(+), 175 deletions(-) create mode 100644 src/test.c diff --git a/src/Makefile.am b/src/Makefile.am index 282128a..e354149 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -40,11 +40,10 @@ TESTS = \ test_m17n_SOURCES = \ - m17nutil.c \ + test.c \ $(NULL) test_m17n_CFLAGS = \ $(AM_CFLAGS) \ - -DDEBUG \ $(NULL) test_m17n_LDADD = \ libm17ncommon.a \ diff --git a/src/default.xml.in.in b/src/default.xml.in.in index 5c5d67d..dc93fd3 100644 --- a/src/default.xml.in.in +++ b/src/default.xml.in.in @@ -1,246 +1,197 @@ - + engine. A "name" element in an "engine" element allows + wildcard patterns. "engine" elements are evaluated in + first-to-last order and the latter match may override the + existing default. --> + + + m17n:* + 0 + FALSE + + + + m17n:as:* + 1 + + + m17n:bn:* + 1 + + + m17n:gu:* + 1 + + + m17n:hi:* + 1 + + + m17n:kn:* + 1 + + + m17n:ks:* + 1 + + + m17n:mai:* + 1 + + + m17n:ml:* + 1 + + + m17n:mr:* + 1 + + + m17n:ne:* + 1 + + + m17n:or:* + 1 + + + m17n:pa:* + 1 + + + m17n:sa:* + 1 + + + m17n:sd:* + 1 + + + m17n:si:* + 1 + + + m17n:ta:* + 1 + + + m17n:te:* + 1 + + m17n:as:phonetic 2 - FALSE m17n:bn:inscript 2 - FALSE m17n:gu:inscript 2 - FALSE m17n:hi:inscript 2 - FALSE m17n:kn:kgp 2 - FALSE m17n:ks:kbd 2 - FALSE m17n:mai:inscript 2 - FALSE m17n:ml:inscript 2 - FALSE m17n:mr:inscript 2 - FALSE m17n:ne:rom 2 - FALSE m17n:or:inscript 2 - FALSE m17n:pa:inscript 2 - FALSE m17n:sa:harvard-kyoto 2 - FALSE m17n:sd:inscript 2 - FALSE m17n:si:wijesekera 2 - FALSE m17n:ta:tamil99 2 - FALSE m17n:te:inscript 2 - FALSE - + m17n:si:samanala 0 - FALSE - - - - m17n:ja:anthy - 0 - TRUE + m17n:zh:cangjie - 0 TRUE m17n:zh:py-b5 - 0 TRUE m17n:zh:py-gb - 0 TRUE m17n:zh:py - 0 TRUE m17n:zh:quick - 0 TRUE m17n:zh:tonepy-b5 - 0 TRUE m17n:zh:tonepy-gb - 0 TRUE m17n:zh:tonepy - 0 TRUE - m17n:zh:util - 0 + m17n:ja:anthy TRUE - - - m17n:as:* - 1 - FALSE - - - m17n:bn:* - 1 - FALSE - - - m17n:gu:* - 1 - FALSE - - - m17n:hi:* - 1 - FALSE - - - m17n:kn:* - 1 - FALSE - - - m17n:ks:* - 1 - FALSE - - - m17n:mai:* - 1 - FALSE - - - m17n:ml:* - 1 - FALSE - - - m17n:mr:* - 1 - FALSE - - - m17n:ne:* - 1 - FALSE - - - m17n:or:* - 1 - FALSE - - - m17n:pa:* - 1 - FALSE - - - m17n:sa:* - 1 - FALSE - - - m17n:sd:* - 1 - FALSE - - - m17n:si:* - 1 - FALSE - - - m17n:ta:* - 1 - FALSE - - - m17n:te:* - 1 - FALSE - - - - m17n:* - 0 - FALSE - diff --git a/src/engine.c b/src/engine.c index cfb853c..dcff0c7 100644 --- a/src/engine.c +++ b/src/engine.c @@ -290,6 +290,8 @@ ibus_m17n_engine_class_init (IBusM17NEngineClass *klass) &klass->lookup_table_orientation)) klass->lookup_table_orientation = IBUS_ORIENTATION_SYSTEM; + ibus_m17n_engine_config_free (engine_config); + g_signal_connect (config, "value-changed", G_CALLBACK(ibus_m17n_config_value_changed), klass); diff --git a/src/m17nutil.c b/src/m17nutil.c index 42aa8f6..b06f71d 100644 --- a/src/m17nutil.c +++ b/src/m17nutil.c @@ -13,12 +13,18 @@ static MConverter *utf8_converter = NULL; #define DEFAULT_XML (SETUPDIR "/default.xml") -struct _IBusM17NEngineConfigNode { +typedef enum { + ENGINE_CONFIG_RANK_MASK = 1 << 0, + ENGINE_CONFIG_PREEDIT_HIGHLIGHT_MASK = 1 << 1 +} EngineConfigMask; + +struct _EngineConfigNode { gchar *name; + EngineConfigMask mask; IBusM17NEngineConfig config; }; -typedef struct _IBusM17NEngineConfigNode IBusM17NEngineConfigNode; +typedef struct _EngineConfigNode EngineConfigNode; static GSList *config_list = NULL; @@ -257,20 +263,31 @@ ibus_m17n_list_engines (void) IBusM17NEngineConfig * ibus_m17n_get_engine_config (const gchar *engine_name) { + IBusM17NEngineConfig *config = g_slice_new0 (IBusM17NEngineConfig); GSList *p; for (p = config_list; p != NULL; p = p->next) { - IBusM17NEngineConfigNode *cnode = p->data; + EngineConfigNode *cnode = p->data; - if (g_pattern_match_simple (cnode->name, engine_name)) - return &cnode->config; + if (g_pattern_match_simple (cnode->name, engine_name)) { + if (cnode->mask & ENGINE_CONFIG_RANK_MASK) + config->rank = cnode->config.rank; + if (cnode->mask & ENGINE_CONFIG_PREEDIT_HIGHLIGHT_MASK) + config->preedit_highlight = cnode->config.preedit_highlight; + } } - g_return_val_if_reached (NULL); + return config; +} + +void +ibus_m17n_engine_config_free (IBusM17NEngineConfig *config) +{ + g_slice_free (IBusM17NEngineConfig, config); } static gboolean -ibus_m17n_engine_config_parse_xml_node (IBusM17NEngineConfigNode *cnode, - XMLNode *node) +ibus_m17n_engine_config_parse_xml_node (EngineConfigNode *cnode, + XMLNode *node) { GList *p; @@ -284,6 +301,7 @@ ibus_m17n_engine_config_parse_xml_node (IBusM17NEngineConfigNode *cnode, } if (g_strcmp0 (sub_node->name , "rank") == 0) { cnode->config.rank = atoi (sub_node->text); + cnode->mask |= ENGINE_CONFIG_RANK_MASK; continue; } if (g_strcmp0 (sub_node->name , "preedit-highlight") == 0) { @@ -292,6 +310,7 @@ ibus_m17n_engine_config_parse_xml_node (IBusM17NEngineConfigNode *cnode, else if (g_ascii_strcasecmp ("FALSE", sub_node->text) != 0) g_warning ("<%s> element contains invalid boolean value %s", sub_node->name, sub_node->text); + cnode->mask |= ENGINE_CONFIG_PREEDIT_HIGHLIGHT_MASK; continue; } g_warning (" element contains invalid element <%s>", @@ -320,7 +339,7 @@ ibus_m17n_get_component (void) if (node && g_strcmp0 (node->name, "engines") == 0) { for (p = node->sub_nodes; p != NULL; p = p->next) { XMLNode *sub_node = p->data; - IBusM17NEngineConfigNode *cnode; + EngineConfigNode *cnode; if (g_strcmp0 (sub_node->name, "engine") != 0) { g_warning (" element contains invalid element <%s>", @@ -328,9 +347,9 @@ ibus_m17n_get_component (void) continue; } - cnode = g_slice_new0 (IBusM17NEngineConfigNode); + cnode = g_slice_new0 (EngineConfigNode); if (!ibus_m17n_engine_config_parse_xml_node (cnode, sub_node)) { - g_slice_free (IBusM17NEngineConfigNode, cnode); + g_slice_free (EngineConfigNode, cnode); continue; } config_list = g_slist_prepend (config_list, cnode); @@ -448,30 +467,3 @@ ibus_m17n_config_get_int (IBusConfig *config, return FALSE; #endif /* !IBUS_CHECK_VERSION(1,3,99) */ } - -#ifdef DEBUG -#include - -int main () -{ - IBusComponent *component; - GString *output; - - setlocale (LC_ALL, ""); - ibus_init (); - ibus_m17n_init_common (); - - component = ibus_m17n_get_component (); - - output = g_string_new (""); - - ibus_component_output (component, output, 1); - - g_debug ("\n%s", output->str); - - g_string_free (output, TRUE); - g_object_unref (component); - - return 0; -} -#endif diff --git a/src/m17nutil.h b/src/m17nutil.h index f083194..313e7bc 100644 --- a/src/m17nutil.h +++ b/src/m17nutil.h @@ -30,6 +30,7 @@ gunichar *ibus_m17n_mtext_to_ucs4 (MText *text, guint ibus_m17n_parse_color (const gchar *hex); IBusM17NEngineConfig *ibus_m17n_get_engine_config (const gchar *engine_name); +void ibus_m17n_engine_config_free (IBusM17NEngineConfig *config); void ibus_m17n_config_set_string (IBusConfig *config, const gchar *section, const gchar *name, diff --git a/src/test.c b/src/test.c new file mode 100644 index 0000000..0908818 --- /dev/null +++ b/src/test.c @@ -0,0 +1,66 @@ +/* vim:set et sts=4: */ +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include "m17nutil.h" + +static void +test_output_component (void) +{ + IBusComponent *component; + GString *output; + + component = ibus_m17n_get_component (); + + output = g_string_new (""); + + ibus_component_output (component, output, 1); + + g_debug ("\n%s", output->str); + + g_string_free (output, TRUE); + g_object_unref (component); +} + +static void +test_engine_config (void) +{ + IBusM17NEngineConfig *config; + + config = ibus_m17n_get_engine_config ("m17n:non:exsistent"); + g_assert_cmpint (config->rank, ==, 0); + g_assert_cmpint (config->preedit_highlight, ==, 0); + ibus_m17n_engine_config_free (config); + + config = ibus_m17n_get_engine_config ("m17n:si:wijesekera"); + g_assert_cmpint (config->rank, ==, 2); + g_assert_cmpint (config->preedit_highlight, ==, 0); + ibus_m17n_engine_config_free (config); + + config = ibus_m17n_get_engine_config ("m17n:si:phonetic-dynamic"); + g_assert_cmpint (config->rank, ==, 1); + g_assert_cmpint (config->preedit_highlight, ==, 0); + ibus_m17n_engine_config_free (config); + + config = ibus_m17n_get_engine_config ("m17n:si:samanala"); + g_assert_cmpint (config->rank, ==, 0); + g_assert_cmpint (config->preedit_highlight, ==, 0); + ibus_m17n_engine_config_free (config); +} + +int main (int argc, char **argv) +{ + setlocale (LC_ALL, ""); + ibus_init (); + ibus_m17n_init_common (); + + g_test_init (&argc, &argv, NULL); + + g_test_add_func ("/test-m17n/output-component", test_output_component); + g_test_add_func ("/test-m17n/engine-config", test_engine_config); + + return g_test_run (); +} -- 1.7.6.2