X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=util%2Fyaz-icu.c;h=dd972493866f57b166c76aa57e9e7b2eebc8a5cd;hb=fffad7b88b5fcc5ce744151034d1df379919d6d6;hp=4247f80ae9e923ec04bce1f0cdeacc81b2b980ad;hpb=0ffb25b0bf78f53399267664b71206c88980c4da;p=yaz-moved-to-github.git diff --git a/util/yaz-icu.c b/util/yaz-icu.c index 4247f80..dd97249 100644 --- a/util/yaz-icu.c +++ b/util/yaz-icu.c @@ -1,26 +1,12 @@ -/* $Id: yaz-icu.c,v 1.1 2007-10-22 12:21:40 adam Exp $ - Copyright (c) 2006-2007, Index Data. - -This file is part of Pazpar2. - -Pazpar2 is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2, or (at your option) any later -version. - -Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -for more details. - -You should have received a copy of the GNU General Public License -along with Pazpar2; see the file LICENSE. If not, write to the -Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA -02111-1307, USA. +/* + * Copyright (C) 1995-2007, Index Data ApS + * See the file LICENSE for details. + * + * $Id: yaz-icu.c,v 1.8 2007-11-07 09:50:24 adam Exp $ */ #if HAVE_CONFIG_H -#include "cconfig.h" +#include "config.h" #endif #include @@ -28,11 +14,10 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include -//#include #include -#ifdef HAVE_ICU +#if HAVE_ICU #include #include @@ -70,10 +55,7 @@ void print_option_error(const struct config_t *p_config) " \n" " \n" " \n" - " \n" " \n" - " \n" - " \n" "\n" ); exit(1); @@ -118,7 +100,7 @@ void read_params(int argc, char **argv, struct config_t *p_config) || !config.outfile) print_option_error(p_config); -}; +} /* UConverter *conv; */ @@ -170,13 +152,10 @@ static void print_icu_converters(const struct config_t *p_config) static void print_icu_transliterators(const struct config_t *p_config) { - int32_t count; - int32_t i; - - count = utrans_countAvailableIDs(); - int32_t buf_cap = 128; char buf[buf_cap]; + int32_t i; + int32_t count = utrans_countAvailableIDs(); if (p_config->xmloutput) fprintf(config.outfile, "\n", count); @@ -435,7 +414,7 @@ static void print_info(const struct config_t *p_config) fprintf(config.outfile, "\n"); exit(0); -}; +} @@ -446,6 +425,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; @@ -459,8 +439,14 @@ 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, (const char *) xml_locale, 0, + &status); + + xmlFree(xml_locale); + if (config.chain && U_SUCCESS(status)) success = 1; @@ -470,13 +456,15 @@ static void process_text_file(const struct config_t *p_config) exit (1); } + + if (p_config->xmloutput) fprintf(config.outfile, "\n" "\n" "\n"); - // read input lines for processing + /* read input lines for processing */ while ((line=fgets(linebuf, sizeof(linebuf)-1, config.infile))) { success = icu_chain_assign_cstr(config.chain, line, &status); @@ -493,14 +481,14 @@ static void process_text_file(const struct config_t *p_config) " norm=\"%s\" display=\"%s\"/>\n", token_count, line_count, - icu_chain_get_norm(config.chain), - icu_chain_get_display(config.chain)); + icu_chain_token_norm(config.chain), + icu_chain_token_display(config.chain)); else fprintf(config.outfile, "%lu %lu '%s' '%s'\n", token_count, line_count, - icu_chain_get_norm(config.chain), - icu_chain_get_display(config.chain)); + icu_chain_token_norm(config.chain), + icu_chain_token_display(config.chain)); } } @@ -515,15 +503,15 @@ static void process_text_file(const struct config_t *p_config) xmlFreeDoc(doc); if (line) free(line); -}; +} -#endif // HAVE_ICU +#endif /* HAVE_ICU */ int main(int argc, char **argv) { -#ifdef HAVE_ICU +#if HAVE_ICU read_params(argc, argv, &config); @@ -533,17 +521,17 @@ int main(int argc, char **argv) if (config.print && strlen(config.print)) print_info(&config); -#else // HAVE_ICU +#else /* HAVE_ICU */ printf("ICU not available on your system.\n" "Please install libicu36-dev and icu-doc or similar, " "re-configure and re-compile\n"); -#endif // HAVE_ICU +#endif /* HAVE_ICU */ return(0); -}; +} /*