2 * $Id: zoomtst5.c,v 1.1 2001-10-23 21:00:20 adam Exp $
4 * Asynchronous multi-target client doing search, sort and present
9 #include <yaz/xmalloc.h>
13 const char *my_callback (void *handle, const char *name)
15 if (!strcmp (name, "async"))
20 int main(int argc, char **argv)
24 Z3950_connection z[500]; /* allow at most 500 connections */
25 Z3950_resultset r[500]; /* and result sets .. */
31 o = Z3950_options_create ();
34 fprintf (stderr, "usage:\n%s target1 .. targetN query sort\n",
41 /* function my_callback called when reading options .. */
42 Z3950_options_set_callback (o, my_callback, 0);
44 /* get 20 (at most) records from beginning */
45 Z3950_options_set (o, "count", "20");
47 Z3950_options_set (o, "implementationName", "sortapp");
48 Z3950_options_set (o, "preferredRecordSyntax", "usmarc");
49 Z3950_options_set (o, "elementSetName", "B");
52 s = Z3950_search_create ();
53 if (Z3950_search_prefix (s, argv[argc-2]))
55 printf ("bad PQF: %s\n", argv[argc-2]);
58 if (Z3950_search_sortby (s, argv[argc-1]))
60 printf ("bad sort spec: %s\n", argv[argc-1]);
63 /* connect - and search all */
64 for (i = 0; i<no; i++)
66 z[i] = Z3950_connection_create (o);
67 Z3950_connection_connect (z[i], argv[i+1], 0);
68 r[i] = Z3950_connection_search (z[i], s);
72 while (Z3950_event (no, z))
76 for (i = 0; i<no; i++)
79 const char *errmsg, *addinfo;
80 if ((error = Z3950_connection_error(z[i], &errmsg, &addinfo)))
81 fprintf (stderr, "%s error: %s (%d) %s\n",
82 Z3950_connection_host(z[i]),
83 errmsg, error, addinfo);
86 /* OK, no major errors. Look at the result count */
88 printf ("%s: %d hits\n", Z3950_connection_host(z[i]),
89 Z3950_resultset_size(r[i]));
90 /* go through all records at target */
91 for (pos = 0; pos < 20; pos++)
94 const char *db, *syntax, *str;
97 rec = Z3950_resultset_record (r[i], pos);
98 /* get database for record and record itself at pos */
100 db = Z3950_record_get (rec, "database", 0);
101 str = Z3950_record_get (rec, "render", &len);
102 syntax = Z3950_record_get (rec, "syntax", &len);
103 /* if rec is non-null, we got a record for display */
106 printf ("%d %s %s\n", pos+1, syntax,
107 (db ? db : "unknown"));
109 fwrite (str, 1, len, stdout);
112 Z3950_record_destroy (rec);
117 /* destroy stuff and exit */
118 Z3950_search_destroy (s);
119 for (i = 0; i<no; i++)
121 Z3950_resultset_destroy (r[i]);
122 Z3950_connection_destroy (z[i]);
124 Z3950_options_destroy(o);