* Copyright (c) 1995-2002, Index Data
* See the file LICENSE for details.
*
- * $Id: client.c,v 1.146 2002-03-06 01:22:41 adam Exp $
+ * $Id: client.c,v 1.152 2002-05-18 09:52:37 oleg Exp $
*/
#include <stdio.h>
#include <yaz/marcdisp.h>
#include <yaz/diagbib1.h>
#include <yaz/otherinfo.h>
+#include <yaz/charneg.h>
#include <yaz/pquery.h>
#include <yaz/sortspec.h>
static char* esPackageName = 0;
static char* yazProxy = 0;
static int kilobytes = 1024;
+static char* yazCharset = 0;
+static char* yazLang = 0;
static char last_cmd[32] = "?";
static FILE *marcdump = 0;
static CCL_bibset bibset; /* CCL bibset handle */
#endif
+#if HAVE_READLINE_COMPLETION_OVER
+
+#else
+/* readline doesn't have this var. Define it ourselves. */
+int rl_attempted_completion_over = 0;
+#endif
/* set this one to 1, to avoid decode of unknown MARCs */
#define AVOID_MARC_DECODE 1
yaz_oi_set_string_oidval(&req->otherInfo, out, VAL_PROXY,
1, type_and_host);
+ if (yazCharset || yazLang) {
+ Z_OtherInformation **p;
+ Z_OtherInformationUnit *p0;
+
+ yaz_oi_APDU(apdu, &p);
+
+ if (p0=yaz_oi_update(p, out, NULL, 0, 0)) {
+ ODR_MASK_SET(req->options, Z_Options_negotiationModel);
+
+ p0->which = Z_OtherInfo_externallyDefinedInfo;
+ p0->information.externallyDefinedInfo =
+ yaz_set_charset_and_lang(out, CLASS_NEGOT, VAL_CHARNEG3,
+ (const char**)&yazCharset, (yazCharset)?1:0,
+ (const char**)&yazLang, (yazLang)?1:0);
+ }
+ }
+
send_apdu(apdu);
printf("Sent initrequest.\n");
}
return 2;
}
+/* display Query Expression as part of searchResult-1 */
+static void display_queryExpression (Z_QueryExpression *qe)
+{
+ if (!qe)
+ return;
+ if (qe->which == Z_QueryExpression_term)
+ {
+ if (qe->u.term->queryTerm)
+ {
+ Z_Term *term = qe->u.term->queryTerm;
+ if (term->which == Z_Term_general)
+ printf (" %.*s", term->u.general->len, term->u.general->buf);
+ }
+ }
+
+}
+
+/* see if we can find USR:SearchResult-1 */
+static void display_searchResult (Z_OtherInformation *o)
+{
+ int i;
+ if (!o)
+ return ;
+ for (i = 0; i < o->num_elements; i++)
+ {
+ if (o->list[i]->which == Z_OtherInfo_externallyDefinedInfo)
+ {
+ Z_External *ext = o->list[i]->information.externallyDefinedInfo;
+
+ if (ext->which == Z_External_searchResult1)
+ {
+ int j;
+ Z_SearchInfoReport *sr = ext->u.searchResult1;
+ printf ("SearchResult-1:");
+ for (j = 0; j < sr->num; j++)
+ {
+ if (!sr->elements[j]->subqueryExpression)
+ printf (" %d", j);
+ display_queryExpression (
+ sr->elements[j]->subqueryExpression);
+ display_queryExpression (
+ sr->elements[j]->subqueryInterpretation);
+ display_queryExpression (
+ sr->elements[j]->subqueryRecommendation);
+ if (sr->elements[j]->subqueryCount)
+ printf ("(%d)", *sr->elements[j]->subqueryCount);
+ }
+ printf ("\n");
+ }
+ }
+ }
+}
+
static int process_searchResponse(Z_SearchResponse *res)
{
printf ("Received SearchResponse.\n");
printf("Number of hits: %d", *res->resultCount);
if (setnumber >= 0)
printf (", setno %d", setnumber);
- printf("\nrecords returned: %d\n",
+ printf ("\n");
+ display_searchResult (res->additionalSearchInfo);
+ printf("records returned: %d\n",
*res->numberOfRecordsReturned);
setno += *res->numberOfRecordsReturned;
if (res->records)
int cmd_proxy(char* arg)
{
+ if (*arg == '\0') {
+ printf("Current proxy is `%s'\n", (yazCharset)?yazProxy:NULL);
+ return 1;
+ }
xfree (yazProxy);
yazProxy = NULL;
if (*arg)
return 1;
}
+int cmd_charset(char* arg)
+{
+ if (*arg == '\0') {
+ printf("Current character set is `%s'\n", (yazCharset)?yazCharset:NULL);
+ return 1;
+ }
+ xfree (yazCharset);
+ yazCharset = NULL;
+ if (*arg)
+ {
+ yazCharset = (char *) xmalloc (strlen(arg)+1);
+ strcpy (yazCharset, arg);
+ }
+ return 1;
+}
+
+int cmd_lang(char* arg)
+{
+ if (*arg == '\0') {
+ printf("Current language is `%s'\n", (yazLang)?yazLang:NULL);
+ return 1;
+ }
+ xfree (yazLang);
+ yazLang = NULL;
+ if (*arg)
+ {
+ yazLang = (char *) xmalloc (strlen(arg)+1);
+ strcpy (yazLang, arg);
+ }
+ return 1;
+}
+
int cmd_source(char* arg)
{
/* first should open the file and read one line at a time.. */
{"update", cmd_update, "<item>",NULL,0},
{"packagename", cmd_packagename, "<packagename>",NULL,0},
{"proxy", cmd_proxy, "[('tcp'|'ssl')]<host>[':'<port>]",NULL,0},
+ {"charset", cmd_charset, "<charset_name>",NULL,0},
+ {"lang", cmd_lang, "<language_code>",NULL,0},
{".", cmd_source, "<filename>",NULL,1},
{"!", cmd_subshell, "Subshell command",NULL,0},
{"set_apdufile", cmd_set_apdufile, "<filename>",NULL,0},
{
printf("Unknown command: %s.\n", word);
cmd_help ("");
-
+ res = 1;
}
if(apdu_file) fflush(apdu_file);
#if HAVE_READLINE_READLINE_H
if(start == 0) {
-#ifdef RL_READLINE_VERSION
+#if HAVE_READLINE_RL_COMPLETION_MATCHES
char** res=rl_completion_matches(text,
command_generator);
#else
if(!cmd[i].complete_filenames)
rl_attempted_completion_over = 1;
if(cmd[i].rl_completerfunction) {
-#ifdef RL_READLINE_VERSION
+#ifdef HAVE_READLINE_RL_COMPLETION_MATCHES
char** res=
rl_completion_matches(text,
cmd[i].rl_completerfunction);