+/*
+ * Copyright (C) 1995-2000, Index Data
+ * All rights reserved.
+ *
+ * $Header: /home/cvsroot/idis/index/Attic/apitest.c,v 1.10 2000-09-06 08:59:36 adam Exp $
+ */
#include <stdio.h>
-#include <log.h>
-#include <pquery.h>
+#include <yaz/log.h>
+#include <yaz/pquery.h>
#include "zebraapi.h"
/* Small routine to display GRS-1 record variants ... */
various functions */
ODR odr_input, odr_output;
- /* zh is our Zebra Handle - describes the server as a whole */
+ /* zs is our Zebra Service - decribes whole server */
+ ZebraService zs;
+
+ /* zh is our Zebra Handle - describes database session */
ZebraHandle zh;
/* the database we specify in our example */
nmem_init ();
+ yaz_log_init_file("apitest.log");
+
odr_input = odr_createmem (ODR_DECODE);
odr_output = odr_createmem (ODR_ENCODE);
- /* open Zebra */
- zh = zebra_open ("zebra.cfg");
+ zs = zebra_start ("zebra.cfg");
+ if (!zs)
+ {
+ printf ("zebra_start failed; missing zebra.cfg?\n");
+ exit (1);
+ }
+ /* open Zebra */
+ zh = zebra_open (zs);
if (!zh)
{
- printf ("Couldn't init zebra\n");
+ printf ("zebras_open failed\n");
exit (1);
}
-
- /* This call controls the logging facility in YAZ/Zebra */
-#if 0
- log_init(LOG_ALL, "", "out.log");
-#endif
-
/* Each argument to main will be a query */
for (argno = 1; argno < argc; argno++)
{
odr_reset (odr_input);
continue;
}
+ else
+ {
+ char out_str[100];
+ int r;
+#if 1
+ r = zebra_string_norm (zh, 'w',
+ argv[argno], strlen(argv[argno]),
+ out_str, sizeof(out_str));
+ if (r >= 0)
+ {
+ printf ("norm: '%s'\n", out_str);
+ }
+ else
+ {
+ printf ("norm fail: %d\n", r);
+ }
+#endif
+ }
/* result set name will be called 1,2, etc */
- sprintf (setname, "%d", i);
+ sprintf (setname, "%d", argno);
/* fire up the search */
zebra_search_rpn (zh, odr_input, odr_output, query, 1, &base, setname);
for (i = 0; i<noOfRecordsToFetch; i++)
records[i].position = i+1;
/* fetch them and request for GRS-1 records */
- zebra_records_retrieve (zh, odr_input, setname, NULL, VAL_GRS1,
+ zebra_records_retrieve (zh, odr_input, setname, NULL, VAL_SUTRS,
noOfRecordsToFetch, records);
/* status ... */
printf (" GRS-1\n");
display_grs1(grs_record, 0);
}
+ else if (records[i].format == VAL_SUTRS)
+ {
+ printf (" SUTRS\n");
+ printf ("%.*s", records[i].len, records[i].buf);
+ }
/* some other record we don't handle yet... */
else
{
odr_destroy (odr_input);
odr_destroy (odr_output);
zebra_close (zh);
+ zebra_stop (zs);
return 0;
}