From e005fd551460aab9ccefb561e42c746cc58fd302 Mon Sep 17 00:00:00 2001 From: Marc Cromme Date: Wed, 24 Oct 2007 14:48:17 +0000 Subject: [PATCH] Isolated ICU locale out of XML config file. Locale is now the second argument to chain = icu_chain_xml_config(xml_node, (uint8_t *) "en", &status); --- include/yaz/icu_I18N.h | 5 +++-- src/icu_I18N.c | 30 +++++++++++------------------- test/tst_icu_I18N.c | 14 +++++++------- util/yaz-icu.c | 12 ++++++++++-- 4 files changed, 31 insertions(+), 30 deletions(-) diff --git a/include/yaz/icu_I18N.h b/include/yaz/icu_I18N.h index 7436b2e..e4f5c8c 100644 --- a/include/yaz/icu_I18N.h +++ b/include/yaz/icu_I18N.h @@ -243,12 +243,13 @@ struct icu_chain struct icu_chain_step * steps; }; -struct icu_chain * icu_chain_create(const uint8_t * identifier, +struct icu_chain * icu_chain_create( // const uint8_t * identifier, const uint8_t * locale); void icu_chain_destroy(struct icu_chain * chain); -struct icu_chain * icu_chain_xml_config(xmlNode *xml_node, +struct icu_chain * icu_chain_xml_config(xmlNode *xml_node, + const uint8_t * locale, UErrorCode * status); diff --git a/src/icu_I18N.c b/src/icu_I18N.c index c3b0680..230d59f 100644 --- a/src/icu_I18N.c +++ b/src/icu_I18N.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: icu_I18N.c,v 1.4 2007-10-24 13:23:34 marc Exp $ + * $Id: icu_I18N.c,v 1.5 2007-10-24 14:48:17 marc Exp $ */ #if HAVE_CONFIG_H @@ -858,15 +858,15 @@ void icu_chain_step_destroy(struct icu_chain_step * step){ -struct icu_chain * icu_chain_create(const uint8_t * identifier, +struct icu_chain * icu_chain_create( //const uint8_t * identifier, const uint8_t * locale) { struct icu_chain * chain = (struct icu_chain *) malloc(sizeof(struct icu_chain)); - strncpy((char *) chain->identifier, (const char *) identifier, 128); - chain->identifier[128 - 1] = '\0'; + //strncpy((char *) chain->identifier, (const char *) identifier, 128); + //chain->identifier[128 - 1] = '\0'; strncpy((char *) chain->locale, (const char *) locale, 16); chain->locale[16 - 1] = '\0'; @@ -901,6 +901,7 @@ void icu_chain_destroy(struct icu_chain * chain) struct icu_chain * icu_chain_xml_config(xmlNode *xml_node, + const uint8_t * locale, UErrorCode * status){ xmlNode *node = 0; @@ -908,26 +909,17 @@ struct icu_chain * icu_chain_xml_config(xmlNode *xml_node, if (!xml_node ||xml_node->type != XML_ELEMENT_NODE - || strcmp((const char *) xml_node->name, "icu_chain")) + // || strcmp((const char *) xml_node->name, "icu_chain") + ) return 0; - { - xmlChar *xml_id = xmlGetProp(xml_node, (xmlChar *) "id"); - xmlChar *xml_locale = xmlGetProp(xml_node, (xmlChar *) "locale"); - - if (!xml_id || !strlen((const char *) xml_id) - || !xml_locale || !strlen((const char *) xml_locale)) - return 0; - - chain = icu_chain_create((const uint8_t *) xml_id, - (const uint8_t *) xml_locale); - - xmlFree(xml_id); - xmlFree(xml_locale); - } + chain = icu_chain_create( // (const uint8_t *) xml_id, + locale); + if (!chain) return 0; + for (node = xml_node->children; node; node = node->next) { diff --git a/test/tst_icu_I18N.c b/test/tst_icu_I18N.c index 717e760..35b4c56 100644 --- a/test/tst_icu_I18N.c +++ b/test/tst_icu_I18N.c @@ -1,4 +1,4 @@ -/* $Id: tst_icu_I18N.c,v 1.5 2007-10-24 13:23:34 marc Exp $ +/* $Id: tst_icu_I18N.c,v 1.6 2007-10-24 14:48:17 marc Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -493,7 +493,7 @@ void test_icu_I18N_chain(int argc, char **argv) struct icu_chain * chain = 0; - const char * xml_str = "" + const char * xml_str = "" "" "" "" @@ -511,7 +511,7 @@ void test_icu_I18N_chain(int argc, char **argv) // printf("ICU chain:\ninput: '%s'\n", en_str); - chain = icu_chain_xml_config(xml_node, &status); + chain = icu_chain_xml_config(xml_node, (uint8_t *) "en", &status); #if 0 chain = icu_chain_create((uint8_t *) "en:word", (uint8_t *) "en"); @@ -584,7 +584,7 @@ void test_bug_1140(void) UErrorCode status = U_ZERO_ERROR; struct icu_chain * chain = 0; - const char * xml_str = "" + const char * xml_str = "" /* if the first rule is normalize instead. Then it works */ #if 0 @@ -603,7 +603,7 @@ void test_bug_1140(void) xmlNode *xml_node = xmlDocGetRootElement(doc); YAZ_CHECK(xml_node); - chain = icu_chain_xml_config(xml_node, &status); + chain = icu_chain_xml_config(xml_node, (uint8_t *) "en", &status); xmlFreeDoc(doc); YAZ_CHECK(chain); @@ -647,7 +647,7 @@ void test_chain_empty_token(void) UErrorCode status = U_ZERO_ERROR; struct icu_chain * chain = 0; - const char * xml_str = "" + const char * xml_str = "" "" "" "" @@ -657,7 +657,7 @@ void test_chain_empty_token(void) xmlNode *xml_node = xmlDocGetRootElement(doc); YAZ_CHECK(xml_node); - chain = icu_chain_xml_config(xml_node, &status); + chain = icu_chain_xml_config(xml_node, (uint8_t *) "en", &status); xmlFreeDoc(doc); YAZ_CHECK(chain); diff --git a/util/yaz-icu.c b/util/yaz-icu.c index d929229..a876186 100644 --- a/util/yaz-icu.c +++ b/util/yaz-icu.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: yaz-icu.c,v 1.2 2007-10-22 17:32:08 adam Exp $ + * $Id: yaz-icu.c,v 1.3 2007-10-24 14:48:18 marc Exp $ */ #if HAVE_CONFIG_H @@ -428,6 +428,7 @@ static void process_text_file(const struct config_t *p_config) xmlDoc *doc = xmlParseFile(config.conffile); xmlNode *xml_node = xmlDocGetRootElement(doc); + xmlChar *xml_locale = xmlGetProp(xml_node, (xmlChar *) "locale"); long unsigned int token_count = 0; long unsigned int line_count = 0; @@ -441,8 +442,13 @@ static void process_text_file(const struct config_t *p_config) exit (1); } + if (!xml_locale || !strlen((const char *) xml_locale)) + return; - config.chain = icu_chain_xml_config(xml_node, &status); + config.chain = icu_chain_xml_config(xml_node, (uint8_t *) "en", &status); + + xmlFree(xml_locale); + if (config.chain && U_SUCCESS(status)) success = 1; @@ -452,6 +458,8 @@ static void process_text_file(const struct config_t *p_config) exit (1); } + + if (p_config->xmloutput) fprintf(config.outfile, "\n" -- 1.7.10.4