From 941107ab62dc3972a050c569b7b4e657dcc582a5 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 5 Jul 2007 18:40:24 +0000 Subject: [PATCH] Reindent according to c-mode. Added GPL header --- src/client.c | 90 +++++--- src/icu_chain_test.c | 565 ++++++++++++++++++++++++++------------------------ 2 files changed, 351 insertions(+), 304 deletions(-) diff --git a/src/client.c b/src/client.c index 6d98253..b13a28f 100644 --- a/src/client.c +++ b/src/client.c @@ -1,4 +1,4 @@ -/* $Id: client.c,v 1.13 2007-07-03 11:21:48 adam Exp $ +/* $Id: client.c,v 1.14 2007-07-05 18:40:24 adam Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -284,26 +284,19 @@ static void client_show_raw_cancel(struct client *cl) } } -void client_send_raw_present(struct client *cl) +static void client_present_syntax(Z_APDU *a, const char *syntax) { - Z_APDU *a = zget_APDU(global_parameters.odr_out, Z_APDU_presentRequest); - int toget = 1; - int start = cl->show_raw->position; - - assert(cl->show_raw); - - yaz_log(YLOG_DEBUG, "%s: trying to present %d record(s) from %d", - client_get_url(cl), toget, start); - - a->u.presentRequest->resultSetStartPoint = &start; - a->u.presentRequest->numberOfRecordsRequested = &toget; - - if (cl->show_raw->syntax) // syntax is optional + // empty string for syntax OMITS preferredRecordSyntax (OPTIONAL) + if (syntax && *syntax) a->u.presentRequest->preferredRecordSyntax = yaz_string_to_oid_odr(yaz_oid_std(), - CLASS_RECSYN, cl->show_raw->syntax, + CLASS_RECSYN, syntax, global_parameters.odr_out); - if (cl->show_raw->esn) // element set is optional +} + +static void client_present_elements(Z_APDU *a, const char *elements) +{ + if (elements && *elements) // element set is optional { Z_ElementSetNames *elementSetNames = odr_malloc(global_parameters.odr_out, sizeof(*elementSetNames)); @@ -316,8 +309,39 @@ void client_send_raw_present(struct client *cl) elementSetNames->which = Z_ElementSetNames_generic; elementSetNames->u.generic = - odr_strdup(global_parameters.odr_out, cl->show_raw->esn); + odr_strdup(global_parameters.odr_out, elements); } +} + +void client_send_raw_present(struct client *cl) +{ + struct session_database *sdb = client_get_database(cl); + Z_APDU *a = zget_APDU(global_parameters.odr_out, Z_APDU_presentRequest); + int toget = 1; + int start = cl->show_raw->position; + const char *syntax = 0; + const char *elements = 0; + + assert(cl->show_raw); + + yaz_log(YLOG_DEBUG, "%s: trying to present %d record(s) from %d", + client_get_url(cl), toget, start); + + a->u.presentRequest->resultSetStartPoint = &start; + a->u.presentRequest->numberOfRecordsRequested = &toget; + + if (cl->show_raw->syntax) + syntax = cl->show_raw->syntax; + else + syntax = session_setting_oneval(sdb, PZ_REQUESTSYNTAX); + + client_present_syntax(a, syntax); + if (cl->show_raw->esn) + elements = cl->show_raw->esn; + else + elements = session_setting_oneval(sdb, PZ_ELEMENTS); + client_present_elements(a, elements); + if (send_apdu(cl, a) >= 0) { cl->show_raw->active = 1; @@ -337,7 +361,8 @@ void client_send_present(struct client *cl) Z_APDU *a = zget_APDU(global_parameters.odr_out, Z_APDU_presentRequest); int toget; int start = cl->records + 1; - char *recsyn; + const char *syntax = 0; + const char *elements = 0; toget = global_parameters.chunk; if (toget > global_parameters.toget - cl->records) @@ -351,13 +376,11 @@ void client_send_present(struct client *cl) a->u.presentRequest->resultSetStartPoint = &start; a->u.presentRequest->numberOfRecordsRequested = &toget; - if ((recsyn = session_setting_oneval(sdb, PZ_REQUESTSYNTAX))) - { - a->u.presentRequest->preferredRecordSyntax = - yaz_string_to_oid_odr(yaz_oid_std(), - CLASS_RECSYN, recsyn, - global_parameters.odr_out); - } + syntax = session_setting_oneval(sdb, PZ_REQUESTSYNTAX); + client_present_syntax(a, syntax); + + elements = session_setting_oneval(sdb, PZ_ELEMENTS); + client_present_elements(a, elements); if (send_apdu(cl, a) >= 0) cl->state = Client_Presenting; @@ -376,7 +399,6 @@ void client_send_search(struct client *cl) char **databaselist; Z_Query *zquery; int ssub = 0, lslb = 100000, mspn = 10; - char *recsyn = 0; char *piggyback = 0; char *queryenc = 0; yaz_iconv_t iconv = 0; @@ -413,13 +435,25 @@ void client_send_search(struct client *cl) if (!(piggyback = session_setting_oneval(sdb, PZ_PIGGYBACK)) || *piggyback == '1') { - if ((recsyn = session_setting_oneval(sdb, PZ_REQUESTSYNTAX))) + const char *elements = session_setting_oneval(sdb, PZ_ELEMENTS); + const char *recsyn = session_setting_oneval(sdb, PZ_REQUESTSYNTAX); + if (recsyn && *recsyn) { a->u.searchRequest->preferredRecordSyntax = yaz_string_to_oid_odr(yaz_oid_std(), CLASS_RECSYN, recsyn, global_parameters.odr_out); } + if (elements && *elements) + { + Z_ElementSetNames *esn = + odr_malloc(global_parameters.odr_out, sizeof(*esn)); + esn->which = Z_ElementSetNames_generic; + esn->u.generic = odr_strdup(global_parameters.odr_out, elements); + + a->u.searchRequest->smallSetElementSetNames = esn; + a->u.searchRequest->mediumSetElementSetNames = esn; + } a->u.searchRequest->smallSetUpperBound = &ssub; a->u.searchRequest->largeSetLowerBound = &lslb; a->u.searchRequest->mediumSetPresentNumber = &mspn; diff --git a/src/icu_chain_test.c b/src/icu_chain_test.c index aed6af2..192d28c 100644 --- a/src/icu_chain_test.c +++ b/src/icu_chain_test.c @@ -1,12 +1,28 @@ -/** - gcc -I/usr/include/libxml2 -lxml2 -o icu-xml-convert icu-xml-convert.c +/* $Id: icu_chain_test.c,v 1.6 2007-07-05 18:40:24 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. */ #if HAVE_CONFIG_H #include "cconfig.h" #endif -#define _GNU_SOURCE #include #include @@ -37,63 +53,60 @@ static struct config_t { void print_option_error(const struct config_t *p_config) { - fprintf(stderr, "Calling error, valid options are :\n"); - fprintf(stderr, "icu_chain_test\n" - " [-c (path/to/config/file.xml)]\n" - " [-p (a|c|l|t)] print ICU info \n" - " [-x] XML output\n" - "\n" - "Examples:\n" - "cat hugetextfile.txt | ./icu_chain_test -c config.xml \n" - "./icu_chain_test -p c\n" - "./icu_chain_test -p l -x\n" - "./icu_chain_test -p t -x\n" + fprintf(stderr, "Calling error, valid options are :\n"); + fprintf(stderr, "icu_chain_test\n" + " [-c (path/to/config/file.xml)]\n" + " [-p (a|c|l|t)] print ICU info \n" + " [-x] XML output\n" + "\n" + "Examples:\n" + "cat hugetextfile.txt | ./icu_chain_test -c config.xml \n" + "./icu_chain_test -p c\n" + "./icu_chain_test -p l -x\n" + "./icu_chain_test -p t -x\n" ); - exit(1); + exit(1); } -void read_params(int argc, char **argv, struct config_t *p_config){ - char *arg; - int ret; - - /* set default parameters */ - p_config->conffile[0] = 0; - p_config->print[0] = 0; - p_config->xmloutput = 0; - p_config->chain = 0; - p_config->infile = stdin; - p_config->outfile = stdout; - - /* set up command line parameters */ - - while ((ret = options("c:p:x", argv, argc, &arg)) != -2) +void read_params(int argc, char **argv, struct config_t *p_config) +{ + char *arg; + int ret; + + /* set default parameters */ + p_config->conffile[0] = 0; + p_config->print[0] = 0; + p_config->xmloutput = 0; + p_config->chain = 0; + p_config->infile = stdin; + p_config->outfile = stdout; + + /* set up command line parameters */ + + while ((ret = options("c:p:x", argv, argc, &arg)) != -2) { - switch (ret) + switch (ret) { case 'c': - strcpy(p_config->conffile, arg); - break; + strcpy(p_config->conffile, arg); + break; case 'p': - strcpy(p_config->print, arg); - break; + strcpy(p_config->print, arg); + break; case 'x': p_config->xmloutput = 1; - break; + break; default: - print_option_error(p_config); + print_option_error(p_config); } } - //p_config->infile = fopen("/etc/passwd", "r"); - - - - if ((!strlen(p_config->conffile) - && !strlen(p_config->print)) - || !config.infile - || !config.outfile) - - print_option_error(p_config); + if ((!strlen(p_config->conffile) + && !strlen(p_config->print)) + || !config.infile + || !config.outfile) + + print_option_error(p_config); }; @@ -123,7 +136,7 @@ static void print_icu_converters(const struct config_t *p_config) count = ucnv_countAvailable(); if (p_config->xmloutput) fprintf(config.outfile, "\n", - count, ucnv_getDefaultName()); + count, ucnv_getDefaultName()); else { fprintf(config.outfile, "Available ICU converters: %d\n", count); fprintf(config.outfile, "Default ICU Converter is: '%s'\n", ucnv_getDefaultName()); @@ -144,254 +157,254 @@ 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]; - - if (p_config->xmloutput) - fprintf(config.outfile, "\n", count); - else - fprintf(config.outfile, "Available ICU transliterators: %d\n", count); - - for(i=0;ixmloutput) + fprintf(config.outfile, "\n", count); + else + fprintf(config.outfile, "Available ICU transliterators: %d\n", count); + + for(i = 0; i xmloutput) - fprintf(config.outfile, "\n", buf); - else - fprintf(config.outfile, " %s", buf); + utrans_getAvailableID(i, buf, buf_cap); + if (p_config->xmloutput) + fprintf(config.outfile, "\n", buf); + else + fprintf(config.outfile, " %s", buf); } - - if (p_config->xmloutput){ - fprintf(config.outfile, "\n"); - } - else + + if (p_config->xmloutput){ + fprintf(config.outfile, "\n"); + } + else { - fprintf(config.outfile, "\n\nUnicode Set Patterns:\n" - " Pattern Description\n" - " Ranges [a-z] The lower case letters a through z\n" - " Named Chars [abc123] The six characters a,b,c,1,2 and 3\n" - " String [abc{def}] chars a, b and c, and string 'def'\n" - " Categories [\\p{Letter}] Perl General Category 'Letter'.\n" - " Categories [:Letter:] Posix General Category 'Letter'.\n" - "\n" - " Combination Example\n" - " Union [[:Greek:] [:letter:]]\n" - " Intersection [[:Greek:] & [:letter:]]\n" - " Set Complement [[:Greek:] - [:letter:]]\n" - " Complement [^[:Greek:] [:letter:]]\n" - "\n" + fprintf(config.outfile, "\n\nUnicode Set Patterns:\n" + " Pattern Description\n" + " Ranges [a-z] The lower case letters a through z\n" + " Named Chars [abc123] The six characters a,b,c,1,2 and 3\n" + " String [abc{def}] chars a, b and c, and string 'def'\n" + " Categories [\\p{Letter}] Perl General Category 'Letter'.\n" + " Categories [:Letter:] Posix General Category 'Letter'.\n" + "\n" + " Combination Example\n" + " Union [[:Greek:] [:letter:]]\n" + " Intersection [[:Greek:] & [:letter:]]\n" + " Set Complement [[:Greek:] - [:letter:]]\n" + " Complement [^[:Greek:] [:letter:]]\n" + "\n" "see: http://icu.sourceforge.net/userguide/unicodeSet.html\n" - "\n" - "Examples:\n" - " [:Punctuation:] Any-Remove\n" - " [:Cased-Letter:] Any-Upper\n" - " [:Control:] Any-Remove\n" - " [:Decimal_Number:] Any-Remove\n" - " [:Final_Punctuation:] Any-Remove\n" - " [:Georgian:] Any-Upper\n" - " [:Katakana:] Any-Remove\n" - " [:Arabic:] Any-Remove\n" - " [:Punctuation:] Remove\n" - " [[:Punctuation:]-[.,]] Remove\n" - " [:Line_Separator:] Any-Remove\n" - " [:Math_Symbol:] Any-Remove\n" - " Lower; [:^Letter:] Remove (word tokenization)\n" - " [:^Number:] Remove (numeric tokenization)\n" - " [:^Katagana:] Remove (remove everything except Katagana)\n" - " Lower;[[:WhiteSpace:][:Punctuation:]] Remove (word tokenization)\n" - " NFD; [:Nonspacing Mark:] Remove; NFC (removes accents from characters)\n" - " [A-Za-z]; Lower(); Latin-Katakana; Katakana-Hiragana (transforms latin and katagana to hiragana)\n" - " [[:separator:][:start punctuation:][:initial punctuation:]] Remove \n" - "\n" - "see http://icu.sourceforge.net/userguide/Transform.html\n" - " http://www.unicode.org/Public/UNIDATA/UCD.html\n" - " http://icu.sourceforge.net/userguide/Transform.html\n" - " http://icu.sourceforge.net/userguide/TransformRule.html\n" - ); - - - fprintf(config.outfile, "\n\n"); - + "\n" + "Examples:\n" + " [:Punctuation:] Any-Remove\n" + " [:Cased-Letter:] Any-Upper\n" + " [:Control:] Any-Remove\n" + " [:Decimal_Number:] Any-Remove\n" + " [:Final_Punctuation:] Any-Remove\n" + " [:Georgian:] Any-Upper\n" + " [:Katakana:] Any-Remove\n" + " [:Arabic:] Any-Remove\n" + " [:Punctuation:] Remove\n" + " [[:Punctuation:]-[.,]] Remove\n" + " [:Line_Separator:] Any-Remove\n" + " [:Math_Symbol:] Any-Remove\n" + " Lower; [:^Letter:] Remove (word tokenization)\n" + " [:^Number:] Remove (numeric tokenization)\n" + " [:^Katagana:] Remove (remove everything except Katagana)\n" + " Lower;[[:WhiteSpace:][:Punctuation:]] Remove (word tokenization)\n" + " NFD; [:Nonspacing Mark:] Remove; NFC (removes accents from characters)\n" + " [A-Za-z]; Lower(); Latin-Katakana; Katakana-Hiragana (transforms latin and katagana to hiragana)\n" + " [[:separator:][:start punctuation:][:initial punctuation:]] Remove \n" + "\n" + "see http://icu.sourceforge.net/userguide/Transform.html\n" + " http://www.unicode.org/Public/UNIDATA/UCD.html\n" + " http://icu.sourceforge.net/userguide/Transform.html\n" + " http://icu.sourceforge.net/userguide/TransformRule.html\n" + ); + + + fprintf(config.outfile, "\n\n"); + } } static void print_icu_xml_locales(const struct config_t *p_config) { - int32_t count; - int32_t i; - UErrorCode status = U_ZERO_ERROR; - - UChar keyword[64]; - int32_t keyword_len = 0; - char keyword_str[128]; - int32_t keyword_str_len = 0; - - UChar language[64]; - int32_t language_len = 0; - char lang_str[128]; - int32_t lang_str_len = 0; - - UChar script[64]; - int32_t script_len = 0; - char script_str[128]; - int32_t script_str_len = 0; - - UChar location[64]; - int32_t location_len = 0; - char location_str[128]; - int32_t location_str_len = 0; - - UChar variant[64]; - int32_t variant_len = 0; - char variant_str[128]; - int32_t variant_str_len = 0; - - UChar name[64]; - int32_t name_len = 0; - char name_str[128]; - int32_t name_str_len = 0; - - UChar localname[64]; - int32_t localname_len = 0; - char localname_str[128]; - int32_t localname_str_len = 0; - - count = uloc_countAvailable() ; - - if (p_config->xmloutput){ + int32_t count; + int32_t i; + UErrorCode status = U_ZERO_ERROR; - fprintf(config.outfile, "\n", - count, uloc_getDefault(), ucol_countAvailable()); - } + UChar keyword[64]; + int32_t keyword_len = 0; + char keyword_str[128]; + int32_t keyword_str_len = 0; + + UChar language[64]; + int32_t language_len = 0; + char lang_str[128]; + int32_t lang_str_len = 0; + + UChar script[64]; + int32_t script_len = 0; + char script_str[128]; + int32_t script_str_len = 0; + + UChar location[64]; + int32_t location_len = 0; + char location_str[128]; + int32_t location_str_len = 0; + + UChar variant[64]; + int32_t variant_len = 0; + char variant_str[128]; + int32_t variant_str_len = 0; + + UChar name[64]; + int32_t name_len = 0; + char name_str[128]; + int32_t name_str_len = 0; + + UChar localname[64]; + int32_t localname_len = 0; + char localname_str[128]; + int32_t localname_str_len = 0; + + count = uloc_countAvailable() ; + + if (p_config->xmloutput){ + + fprintf(config.outfile, "\n", + count, uloc_getDefault(), ucol_countAvailable()); + } - for(i=0;ixmloutput){ - fprintf(config.outfile, ""); - if (strlen(localname_str)) - fprintf(config.outfile, "%s", localname_str); - fprintf(config.outfile, "\n"); - } - else if (1 == p_config->xmloutput){ - fprintf(config.outfile, "%s", uloc_getAvailable(i)); - fprintf(config.outfile, " | "); - if (strlen(name_str)) - fprintf(config.outfile, "%s", name_str); - fprintf(config.outfile, " | "); - if (strlen(localname_str)) - fprintf(config.outfile, "%s", localname_str); - fprintf(config.outfile, "\n"); + language_len + = uloc_getDisplayLanguage(uloc_getAvailable(i), "en", + language, 64, + &status); + + u_strToUTF8(lang_str, 128, &lang_str_len, + language, language_len, + &status); + + + script_len + = uloc_getDisplayScript(uloc_getAvailable(i), "en", + script, 64, + &status); + + u_strToUTF8(script_str, 128, &script_str_len, + script, script_len, + &status); + + location_len + = uloc_getDisplayCountry(uloc_getAvailable(i), "en", + location, 64, + &status); + + u_strToUTF8(location_str, 128, &location_str_len, + location, location_len, + &status); + + variant_len + = uloc_getDisplayVariant(uloc_getAvailable(i), "en", + variant, 64, + &status); + + u_strToUTF8(variant_str, 128, &variant_str_len, + variant, variant_len, + &status); + + name_len + = uloc_getDisplayName(uloc_getAvailable(i), "en", + name, 64, + &status); + + u_strToUTF8(name_str, 128, &name_str_len, + name, name_len, + &status); + + localname_len + = uloc_getDisplayName(uloc_getAvailable(i), uloc_getAvailable(i), + localname, 64, + &status); + + u_strToUTF8(localname_str, 128, &localname_str_len, + localname, localname_len, + &status); + + + if (p_config->xmloutput){ + fprintf(config.outfile, ""); + if (strlen(localname_str)) + fprintf(config.outfile, "%s", localname_str); + fprintf(config.outfile, "\n"); + } + else if (1 == p_config->xmloutput){ + fprintf(config.outfile, "%s", uloc_getAvailable(i)); + fprintf(config.outfile, " | "); + if (strlen(name_str)) + fprintf(config.outfile, "%s", name_str); + fprintf(config.outfile, " | "); + if (strlen(localname_str)) + fprintf(config.outfile, "%s", localname_str); + fprintf(config.outfile, "\n"); + } + else + fprintf(config.outfile, "%s ", uloc_getAvailable(i)); } + if (p_config->xmloutput) + fprintf(config.outfile, "\n"); else - fprintf(config.outfile, "%s ", uloc_getAvailable(i)); - } - if (p_config->xmloutput) - fprintf(config.outfile, "\n"); - else - fprintf(config.outfile, "\n"); - - if(U_FAILURE(status)) { - fprintf(stderr, "ICU Error: %d %s\n", status, u_errorName(status)); - exit(status); - } + fprintf(config.outfile, "\n"); + + if(U_FAILURE(status)) { + fprintf(stderr, "ICU Error: %d %s\n", status, u_errorName(status)); + exit(status); + } } static void print_info(const struct config_t *p_config) { - if (p_config->xmloutput) - fprintf(config.outfile, "\n" - "\n"); + if (p_config->xmloutput) + fprintf(config.outfile, "\n" + "\n"); if ('c' == config.print[0]) print_icu_converters(&config); @@ -408,7 +421,7 @@ static void print_info(const struct config_t *p_config) if (p_config->xmloutput) fprintf(config.outfile, "\n"); - exit(0); + exit(0); }; @@ -469,7 +482,7 @@ static void process_text_file(const struct config_t *p_config) } - if (p_config->xmloutput) + if (p_config->xmloutput) fprintf(config.outfile, "\n" "\n"); -- 1.7.10.4