diff options
-rw-r--r-- | ChangeLog | 2 | ||||
-rw-r--r-- | libxklavier/xklavier_config_iso.c | 93 | ||||
-rw-r--r-- | tests/test_config.c | 12 |
3 files changed, 75 insertions, 32 deletions
@@ -2,7 +2,7 @@ * libxklavier/xkl_config_registry.h, libxklavier/xklavier_config.c, libxklavier/xklavier_config_iso.c, libxklavier/xklavier_private.h, - tests/test_config.c: more ISO-related functionality + tests/test_config.c: finished ISO browsing functionality 2008-04-21 svu diff --git a/libxklavier/xklavier_config_iso.c b/libxklavier/xklavier_config_iso.c index 10a520a..b6efb26 100644 --- a/libxklavier/xklavier_config_iso.c +++ b/libxklavier/xklavier_config_iso.c @@ -300,42 +300,32 @@ xkl_config_registry_foreach_language(XklConfigRegistry * } void -xkl_config_registry_foreach_country_variant(XklConfigRegistry * - config, - const gchar * - country_code, - TwoConfigItemsProcessFunc - func, gpointer data) +xkl_config_registry_foreach_iso_variant(XklConfigRegistry * + config, + const gchar * + iso_code, + TwoConfigItemsProcessFunc + func, gpointer data, + const gchar * layout_xpath_exprs[], + const gchar * + variant_xpath_exprs[], + const gboolean + should_layout_id_be_lowered[]) { - const gchar *layout_xpath_exprs[] = { - XKBCR_LAYOUT_PATH "[configItem/name = '%s']", - XKBCR_LAYOUT_PATH - "[configItem/countryList/iso3166Id = '%s']", - NULL - }; - const gboolean are_low_ids[] = { TRUE, FALSE }; - - const gchar *variant_xpath_exprs[] = { - XKBCR_VARIANT_PATH - "[configItem/countryList/iso3166Id = '%s']", - NULL - }; - - xmlXPathObjectPtr xpath_obj; const gchar **xpath_expr; - const gboolean *is_low_id = are_low_ids; + const gboolean *is_low_id = should_layout_id_be_lowered; if (!xkl_config_registry_is_initialized(config)) return; for (xpath_expr = layout_xpath_exprs; *xpath_expr; xpath_expr++, is_low_id++) { - gchar *acc = *is_low_id ? g_ascii_strdown(country_code, + gchar *aic = *is_low_id ? g_ascii_strdown(iso_code, -1) : - g_strdup(country_code); - gchar *xpe = g_strdup_printf(*xpath_expr, acc); - g_free(acc); + g_strdup(iso_code); + gchar *xpe = g_strdup_printf(*xpath_expr, aic); + g_free(aic); xpath_obj = xmlXPathEval((unsigned char *) xpe, xkl_config_registry_priv(config, @@ -361,7 +351,7 @@ xkl_config_registry_foreach_country_variant(XklConfigRegistry * } for (xpath_expr = variant_xpath_exprs; *xpath_expr; xpath_expr++) { - gchar *xpe = g_strdup_printf(*xpath_expr, country_code); + gchar *xpe = g_strdup_printf(*xpath_expr, iso_code); xpath_obj = xmlXPathEval((unsigned char *) xpe, xkl_config_registry_priv(config, @@ -393,6 +383,36 @@ xkl_config_registry_foreach_country_variant(XklConfigRegistry * } void +xkl_config_registry_foreach_country_variant(XklConfigRegistry * + config, + const gchar * + country_code, + TwoConfigItemsProcessFunc + func, gpointer data) +{ + const gchar *layout_xpath_exprs[] = { + XKBCR_LAYOUT_PATH "[configItem/name = '%s']", + XKBCR_LAYOUT_PATH + "[configItem/countryList/iso3166Id = '%s']", + NULL + }; + const gboolean should_layout_id_be_lowered[] = { TRUE, FALSE }; + + const gchar *variant_xpath_exprs[] = { + XKBCR_VARIANT_PATH + "[configItem/countryList/iso3166Id = '%s']", + NULL + }; + + xkl_config_registry_foreach_iso_variant(config, + country_code, + func, data, + layout_xpath_exprs, + variant_xpath_exprs, + should_layout_id_be_lowered); +} + +void xkl_config_registry_foreach_language_variant(XklConfigRegistry * config, const gchar * @@ -400,4 +420,23 @@ xkl_config_registry_foreach_language_variant(XklConfigRegistry * TwoConfigItemsProcessFunc func, gpointer data) { + const gchar *layout_xpath_exprs[] = { + XKBCR_LAYOUT_PATH + "[configItem/languageList/iso639Id = '%s']", + NULL + }; + const gboolean should_layout_id_be_lowered[] = { FALSE }; + + const gchar *variant_xpath_exprs[] = { + XKBCR_VARIANT_PATH + "[configItem/languageList/iso639Id = '%s']", + NULL + }; + + xkl_config_registry_foreach_iso_variant(config, + language_code, + func, data, + layout_xpath_exprs, + variant_xpath_exprs, + should_layout_id_be_lowered); } diff --git a/tests/test_config.c b/tests/test_config.c index d27174d..8add3bb 100644 --- a/tests/test_config.c +++ b/tests/test_config.c @@ -132,9 +132,9 @@ print_layout(XklConfigRegistry * config, const XklConfigItem * item, } static void -print_country_variant(XklConfigRegistry * config, - const XklConfigItem * item, - const XklConfigItem * subitem, gpointer data) +print_iso_variant(XklConfigRegistry * config, + const XklConfigItem * item, + const XklConfigItem * subitem, gpointer data) { print_xci(config, item, 2); if (subitem) @@ -149,7 +149,7 @@ print_country(XklConfigRegistry * config, const XklConfigItem * item, print_xci(config, item, 0); xkl_config_registry_foreach_country_variant(config, item->name, - print_country_variant, + print_iso_variant, data); } @@ -159,6 +159,10 @@ print_language(XklConfigRegistry * config, const XklConfigItem * item, { printf("language:"); print_xci(config, item, 0); + + xkl_config_registry_foreach_language_variant(config, item->name, + print_iso_variant, + data); } int |