2 * $Id: zoomtst5.c,v 1.4 2001-11-15 08:58:29 adam Exp $
4 * Asynchronous multi-target client doing search, sort and present
11 #include <yaz/xmalloc.h>
14 const char *my_callback (void *handle, const char *name)
16 if (!strcmp (name, "async"))
21 int main(int argc, char **argv)
25 Z3950_connection z[500]; /* allow at most 500 connections */
26 Z3950_resultset r[500]; /* and result sets .. */
30 o = Z3950_options_create ();
33 fprintf (stderr, "usage:\n%s target1 .. targetN query sort\n",
40 /* function my_callback called when reading options .. */
41 Z3950_options_set_callback (o, my_callback, 0);
43 /* get 20 (at most) records from beginning */
44 Z3950_options_set (o, "count", "20");
46 Z3950_options_set (o, "implementationName", "sortapp");
47 Z3950_options_set (o, "preferredRecordSyntax", "usmarc");
48 Z3950_options_set (o, "elementSetName", "B");
51 q = Z3950_query_create ();
52 if (Z3950_query_prefix (q, argv[argc-2]))
54 printf ("bad PQF: %s\n", argv[argc-2]);
57 if (Z3950_query_sortby (q, argv[argc-1]))
59 printf ("bad sort spec: %s\n", argv[argc-1]);
62 /* connect - and search all */
63 for (i = 0; i<no; i++)
65 z[i] = Z3950_connection_create (o);
66 Z3950_connection_connect (z[i], argv[i+1], 0);
67 r[i] = Z3950_connection_search (z[i], q);
71 while (Z3950_event (no, z))
75 for (i = 0; i<no; i++)
78 const char *errmsg, *addinfo;
79 if ((error = Z3950_connection_error(z[i], &errmsg, &addinfo)))
80 fprintf (stderr, "%s error: %s (%d) %s\n",
81 Z3950_connection_host(z[i]),
82 errmsg, error, addinfo);
85 /* OK, no major errors. Look at the result count */
87 printf ("%s: %d hits\n", Z3950_connection_host(z[i]),
88 Z3950_resultset_size(r[i]));
89 /* go through all records at target */
90 for (pos = 0; pos < 20; pos++)
93 const char *db, *syntax, *str;
96 rec = Z3950_resultset_record (r[i], pos);
97 /* get database for record and record itself at pos */
99 db = Z3950_record_get (rec, "database", 0);
100 str = Z3950_record_get (rec, "render", &len);
101 syntax = Z3950_record_get (rec, "syntax", &len);
102 /* if rec is non-null, we got a record for display */
105 printf ("%d %s %s\n", pos+1, syntax,
106 (db ? db : "unknown"));
108 fwrite (str, 1, len, stdout);
115 /* destroy stuff and exit */
116 Z3950_query_destroy (q);
117 for (i = 0; i<no; i++)
119 Z3950_resultset_destroy (r[i]);
120 Z3950_connection_destroy (z[i]);
122 Z3950_options_destroy(o);