X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=client%2Fclient.c;h=ed14f025f40c39d50989a91e3dbde91cd50ffd96;hp=6fa0c049b114a65e2b9f3e4a1ab37d333877c6f3;hb=0edfdd01ae95aa2770f2e122bdea25208494acbd;hpb=a2df70871ff2494610edf71f7c7c74b785a69cd6 diff --git a/client/client.c b/client/client.c index 6fa0c04..ed14f02 100644 --- a/client/client.c +++ b/client/client.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2002, Index Data * See the file LICENSE for details. * - * $Id: client.c,v 1.159 2002-06-17 14:57:34 ja7 Exp $ + * $Id: client.c,v 1.162 2002-07-25 12:52:53 adam Exp $ */ #include @@ -11,10 +11,7 @@ #include -#include -#ifdef USE_XTIMOSI -#include -#endif +#include #include #include @@ -31,6 +28,7 @@ #if HAVE_READLINE_READLINE_H #include +#include #endif #if HAVE_READLINE_HISTORY_H #include @@ -209,7 +207,7 @@ static void send_initRequest(const char* type_and_host) yaz_oi_APDU(apdu, &p); - if (p0=yaz_oi_update(p, out, NULL, 0, 0)) { + if ((p0=yaz_oi_update(p, out, NULL, 0, 0))) { ODR_MASK_SET(req->options, Z_Options_negotiationModel); p0->which = Z_OtherInfo_externallyDefinedInfo; @@ -308,10 +306,11 @@ static int process_initResponse(Z_InitResponse *res) char *charset=NULL, *lang=NULL; int selected; - yaz_get_response_charneg(session_mem, p, &charset, &lang, &selected); + yaz_get_response_charneg(session_mem, p, &charset, &lang, + &selected); - printf("Accepted character set : `%s'\n", charset); - printf("Accepted code language : `%s'\n", lang); + printf("Accepted character set : %s\n", charset); + printf("Accepted code language : %s\n", lang ? lang : "none"); printf("Accepted records in ...: %d\n", selected ); } } @@ -352,7 +351,6 @@ int cmd_open(char *arg) { void *add; char type_and_host[101], base[101]; - CS_TYPE t; if (conn) { @@ -366,23 +364,20 @@ int cmd_open(char *arg) session_mem = NULL; } } - if (strncmp (arg, "unix:", 5) == 0) - { + if (strncmp (arg, "unix:", 5) == 0) + { base[0] = '\0'; conn = cs_create_host(arg, 1, &add); - } - else - { - t = tcpip_type; - base[0] = '\0'; - if (sscanf (arg, "%100[^/]/%100s", type_and_host, base) < 1) - return 0; - - if(yazProxy) - conn = cs_create_host(yazProxy, 1, &add); - else - conn = cs_create_host(type_and_host, 1, &add); - + } + else + { + base[0] = '\0'; + if (sscanf (arg, "%100[^/]/%100s", type_and_host, base) < 1) + return 0; + if (yazProxy) + conn = cs_create_host(yazProxy, 1, &add); + else + conn = cs_create_host(type_and_host, 1, &add); } if (!conn) { @@ -602,17 +597,18 @@ static void display_record(Z_External *r) odr_perror(in, "Decoding constructed record."); fprintf(stderr, "[Near %d]\n", odr_offset(in)); fprintf(stderr, "Packet dump:\n---------\n"); - odr_dumpBER(stderr, (char*)r->u.octet_aligned->buf, - r->u.octet_aligned->len); + odr_dumpBER(stderr, (char*)r->u.octet_aligned->buf,r->u.octet_aligned->len); fprintf(stderr, "---------\n"); - exit(1); - } - /* - * Note: we throw away the original, BER-encoded record here. - * Do something else with it if you want to keep it. - */ - r->u.sutrs = (Z_SUTRS *) rr; /* we don't actually check the type here. */ - r->which = type->what; + + /* note just ignores the error ant print the bytes form the octet_aligned laiter */ + } else { + /* + * Note: we throw away the original, BER-encoded record here. + * Do something else with it if you want to keep it. + */ + r->u.sutrs = (Z_SUTRS *) rr; /* we don't actually check the type here. */ + r->which = type->what; + }; } } if (ent && ent->oclass != CLASS_RECSYN) @@ -906,11 +902,23 @@ static void display_queryExpression (Z_QueryExpression *qe) if (qe->u.term->queryTerm) { Z_Term *term = qe->u.term->queryTerm; - if (term->which == Z_Term_general) + switch (term->which) + { + case Z_Term_general: printf (" %.*s", term->u.general->len, term->u.general->buf); + break; + case Z_Term_characterString: + printf (" %s", term->u.characterString); + break; + case Z_Term_numeric: + printf (" %d", *term->u.numeric); + break; + case Z_Term_null: + printf (" null"); + break; + } } } - } /* see if we can find USR:SearchResult-1 */ @@ -1360,7 +1368,6 @@ static Z_External *create_ItemOrderExternal(const char *type, int itemno) (int *) odr_malloc(out, sizeof(int)); *r->u.itemOrder->u.esRequest->notToKeep->resultSetItem->item = itemno; -#if YAZ_MODULE_ill if (!strcmp (type, "item") || !strcmp(type, "2")) { printf ("using item-request\n"); @@ -1387,9 +1394,6 @@ static Z_External *create_ItemOrderExternal(const char *type, int itemno) else r->u.itemOrder->u.esRequest->notToKeep->itemRequest = 0; -#else - r->u.itemOrder->u.esRequest->notToKeep->itemRequest = 0; -#endif return r; } @@ -2123,17 +2127,24 @@ int cmd_proxy(char* arg) int cmd_charset(char* arg) { - if (*arg == '\0') { - printf("Current character set is `%s'\n", (yazCharset)?yazCharset:NULL); + char l1[30], l2[30]; + + *l1 = *l2 = 0; + if (sscanf(arg, "%29s %29s", l1, l2) < 1) + { + printf("Current character set is `%s'\n", (yazCharset) ? + yazCharset:NULL); return 1; } xfree (yazCharset); yazCharset = NULL; - if (*arg) + if (*l1) + yazCharset = xstrdup(l1); + if (*l2) { - yazCharset = (char *) xmalloc (strlen(arg)+1); - strcpy (yazCharset, arg); - } + odr_set_charset (out, l1, l2); + odr_set_charset (in, l2, l1); + } return 1; } @@ -2400,9 +2411,7 @@ void source_rcfile() static void initialize(void) { -#if YAZ_MODULE_ccl FILE *inf; -#endif if (!(out = odr_createmem(ODR_ENCODE)) || !(in = odr_createmem(ODR_DECODE)) || !(print = odr_createmem(ODR_PRINT))) @@ -2416,7 +2425,6 @@ static void initialize(void) if (apdu_file) odr_setprint(print, apdu_file); -#if YAZ_MODULE_ccl bibset = ccl_qual_mk (); inf = fopen (ccl_fields, "r"); if (inf) @@ -2424,7 +2432,6 @@ static void initialize(void) ccl_qual_file (bibset, inf); fclose (inf); } -#endif cmd_base("Default"); #if HAVE_READLINE_READLINE_H @@ -2551,6 +2558,33 @@ void wait_and_handle_responce() } +int cmd_cclparse(char* arg) { + int error, pos; + struct ccl_rpn_node *rpn=NULL; + + + rpn = ccl_find_str (bibset, arg, &error, &pos); + + if (error) { + printf ("%*s^ - ", 3+strlen(last_cmd)+1+pos, " "); + printf ("%s\n", ccl_err_msg (error)); + } + else + { + if (rpn) + { + ccl_pr_tree(rpn, stdout); + } + } + if (rpn) + ccl_rpn_delete(rpn); + + printf ("\n"); + + return 0; +}; + + static int cmd_help (char *line); typedef char *(*completerFunctionType)(const char *text, int state); @@ -2560,7 +2594,6 @@ static struct { int (*fun)(char *arg); char *ad; completerFunctionType rl_completerfunction; - //char *(*rl_completerfunction)(const char *text, int state); int complete_filenames; char **local_tabcompletes; } cmd[] = { @@ -2597,10 +2630,11 @@ static struct { {"!", cmd_subshell, "Subshell command",NULL,1,NULL}, {"set_apdufile", cmd_set_apdufile, "",NULL,1,NULL}, {"set_marcdump", cmd_set_marcdump," ",NULL,1,NULL}, - {"set_cclfiele", cmd_set_cclfields," ",NULL,1,NULL}, + {"set_cclfile", cmd_set_cclfields," ",NULL,1,NULL}, {"register_oid", cmd_register_oid," ",NULL,0,NULL}, {"push_command", cmd_push_command,"",command_generator,0,NULL}, {"register_tab", cmd_register_tab," ",command_generator,0,NULL}, + {"cclparse", cmd_cclparse,"",NULL,0,NULL}, /* Server Admin Functions */ {"adm-reindex", cmd_adm_reindex, "",NULL,0,NULL}, {"adm-truncate", cmd_adm_truncate, "('database'|'index')",NULL,0,NULL}, @@ -2658,7 +2692,7 @@ static int cmd_help (char *line) int cmd_register_tab(char* arg) { char command[101], tabargument[101]; - int i, res; + int i; int num_of_tabs; char** tabslist; @@ -2695,8 +2729,10 @@ int cmd_register_tab(char* arg) { tabslist=cmd[i].local_tabcompletes; tabslist[num_of_tabs]=strdup(tabargument); tabslist[num_of_tabs+1]=NULL; + return 1; } + void process_cmd_line(char* line) { int i,res; @@ -2914,19 +2950,19 @@ int main(int argc, char **argv) exit (1); } break; - case 'c': - strncpy (ccl_fields, arg, sizeof(ccl_fields)-1); - ccl_fields[sizeof(ccl_fields)-1] = '\0'; - break; + case 'c': + strncpy (ccl_fields, arg, sizeof(ccl_fields)-1); + ccl_fields[sizeof(ccl_fields)-1] = '\0'; + break; case 'a': if (!strcmp(arg, "-")) apdu_file=stderr; else apdu_file=fopen(arg, "a"); break; - case 'p': - yazProxy=strdup(arg); - break; + case 'p': + yazProxy=strdup(arg); + break; case 'u': if (!auth_command) {