1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2010 Index Data
3 * See the file LICENSE for details.
11 #include <yaz/xmalloc.h>
15 int main(int argc, char **argv)
20 ZOOM_connection z[500]; /* allow at most 500 connections */
21 ZOOM_resultset r[500]; /* and result sets .. */
22 ZOOM_options o = ZOOM_options_create ();
26 fprintf (stderr, "usage:\n%s target1 target2 ... targetN query\n"
27 "%s number target query\n", *argv, *argv);
30 if (argc == 4 && isdigit(argv[1][0]) && !strchr(argv[1],'.'))
40 ZOOM_options_set (o, "async", "1");
42 /* get first 10 records of result set (using piggyback) */
43 ZOOM_options_set (o, "count", "10");
45 /* preferred record syntax */
46 ZOOM_options_set (o, "preferredRecordSyntax", "usmarc");
47 ZOOM_options_set (o, "elementSetName", "F");
50 for (i = 0; i<no; i++)
52 /* create connection - pass options (they are the same for all) */
53 z[i] = ZOOM_connection_create (o);
55 /* connect and init */
57 ZOOM_connection_connect (z[i], argv[2], 0);
59 ZOOM_connection_connect (z[i], argv[1+i], 0);
62 for (i = 0; i<no; i++)
63 r[i] = ZOOM_connection_search_pqf (z[i], argv[argc-1]);
65 /* network I/O. pass number of connections and array of connections */
66 while ((i = ZOOM_event (no, z)))
68 int peek = ZOOM_connection_peek_event(z[i-1]);
69 printf ("no = %d peek = %d event = %d\n", i-1,
71 ZOOM_connection_last_event(z[i-1]));
74 /* no more to be done. Inspect results */
75 for (i = 0; i<no; i++)
78 const char *errmsg, *addinfo;
79 const char *tname = (same_target ? argv[2] : argv[1+i]);
80 /* display errors if any */
81 if ((error = ZOOM_connection_error(z[i], &errmsg, &addinfo)))
82 fprintf (stderr, "%s error: %s (%d) %s\n", tname, errmsg,
86 /* OK, no major errors. Look at the result count */
88 printf ("%s: %ld hits\n", tname, (long) ZOOM_resultset_size(r[i]));
89 /* go through all records at target */
90 for (pos = 0; pos < 10; pos++)
92 int len; /* length of buffer rec */
95 ZOOM_resultset_record (r[i], pos), "render", &len);
96 /* if rec is non-null, we got a record for display */
98 printf ("%d\n%.*s\n", pos+1, len, rec);
102 /* destroy and exit */
103 for (i = 0; i<no; i++)
105 ZOOM_resultset_destroy (r[i]);
106 ZOOM_connection_destroy (z[i]);
108 ZOOM_options_destroy(o);
114 * c-file-style: "Stroustrup"
115 * indent-tabs-mode: nil
117 * vim: shiftwidth=4 tabstop=8 expandtab