2 * $Id: zoomtst6.c,v 1.2 2001-10-24 12:24:43 adam Exp $
4 * Asynchronous multi-target client doing two searches
9 #include <yaz/xmalloc.h>
13 static void display_records (const char *tname, Z3950_resultset r)
15 /* OK, no major errors. Look at the result count */
17 printf ("%s: %d hits\n", tname, Z3950_resultset_size(r));
18 /* go through all records at target */
19 for (pos = 0; pos < 20; pos++)
21 /* get database for record and record itself at pos */
22 const char *db = Z3950_resultset_get (r, pos, "database", 0);
24 const char *rec = Z3950_resultset_get (r, pos, "render", &len);
25 /* if rec is non-null, we got a record for display */
28 printf ("%d %s\n", pos+1, (db ? db : "unknown"));
30 fwrite (rec, 1, len, stdout);
36 int main(int argc, char **argv)
40 Z3950_connection z[500]; /* allow at most 500 connections */
41 Z3950_resultset r1[500]; /* and result sets .. */
42 Z3950_resultset r2[500]; /* and result sets .. */
46 o = Z3950_options_create ();
49 fprintf (stderr, "usage:\n%s target1 .. targetN query1 query2\n",
56 Z3950_options_set (o, "async", "1");
58 /* get 3 (at most) records from beginning */
59 Z3950_options_set (o, "count", "3");
61 Z3950_options_set (o, "preferredRecordSyntax", "sutrs");
62 Z3950_options_set (o, "elementSetName", "B");
65 s = Z3950_search_create ();
66 if (Z3950_search_prefix (s, argv[argc-2]))
68 printf ("bad PQF: %s\n", argv[argc-2]);
71 /* connect - and search all */
72 for (i = 0; i<no; i++)
74 z[i] = Z3950_connection_create (o);
75 Z3950_connection_connect (z[i], argv[i+1], 0);
76 r1[i] = Z3950_connection_search (z[i], s);
78 if (Z3950_search_prefix (s, argv[argc-1]))
80 printf ("bad sort spec: %s\n", argv[argc-1]);
83 /* queue second search */
84 for (i = 0; i<no; i++)
85 r2[i] = Z3950_connection_search (z[i], s);
88 while (Z3950_event (no, z))
92 for (i = 0; i<no; i++)
95 const char *errmsg, *addinfo;
96 if ((error = Z3950_connection_error(z[i], &errmsg, &addinfo)))
97 fprintf (stderr, "%s error: %s (%d) %s\n",
98 Z3950_connection_host(z[i]),
99 errmsg, error, addinfo);
102 display_records (Z3950_connection_host(z[i]), r1[i]);
103 display_records (Z3950_connection_host(z[i]), r2[i]);
106 /* destroy stuff and exit */
107 Z3950_search_destroy (s);
108 for (i = 0; i<no; i++)
110 Z3950_connection_destroy (z[i]);
111 Z3950_resultset_destroy (r1[i]);
112 Z3950_resultset_destroy (r2[i]);
114 Z3950_options_destroy(o);