1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2009 Index Data
3 * See the file LICENSE for details.
10 #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 ZOOM_connection z[500]; /* allow at most 500 connections */
25 ZOOM_resultset r[500]; /* and result sets .. */
29 o = ZOOM_options_create ();
32 fprintf (stderr, "usage:\n%s target1 .. targetN query sort\n",
39 /* function my_callback called when reading options .. */
40 ZOOM_options_set_callback (o, my_callback, 0);
42 /* get 20 (at most) records from beginning */
43 ZOOM_options_set (o, "count", "20");
45 ZOOM_options_set (o, "implementationName", "sortapp");
46 ZOOM_options_set (o, "preferredRecordSyntax", "usmarc");
47 ZOOM_options_set (o, "elementSetName", "B");
50 q = ZOOM_query_create ();
51 if (ZOOM_query_prefix (q, argv[argc-2]))
53 printf ("bad PQF: %s\n", argv[argc-2]);
56 if (ZOOM_query_sortby (q, argv[argc-1]))
58 printf ("bad sort spec: %s\n", argv[argc-1]);
61 /* connect - and search all */
62 for (i = 0; i<no; i++)
64 z[i] = ZOOM_connection_create (o);
65 ZOOM_connection_connect (z[i], argv[i+1], 0);
66 r[i] = ZOOM_connection_search (z[i], q);
70 while (ZOOM_event (no, z))
74 for (i = 0; i<no; i++)
77 const char *errmsg, *addinfo;
78 if ((error = ZOOM_connection_error(z[i], &errmsg, &addinfo)))
79 fprintf (stderr, "%s error: %s (%d) %s\n",
80 ZOOM_connection_option_get(z[i], "host"),
81 errmsg, error, addinfo);
84 /* OK, no major errors. Look at the result count */
86 printf ("%s: %ld hits\n", ZOOM_connection_option_get(z[i], "host"),
87 (long) ZOOM_resultset_size(r[i]));
88 /* go through first 20 records at target */
89 for (pos = 0; pos < 20; pos++)
92 const char *db, *syntax, *str;
95 rec = ZOOM_resultset_record (r[i], pos);
96 /* get database for record and record itself at pos */
98 db = ZOOM_record_get (rec, "database", 0);
99 str = ZOOM_record_get (rec, "xml", &len);
100 syntax = ZOOM_record_get (rec, "syntax", &len);
101 /* if rec is non-null, we got a record for display */
104 printf ("%d %s %s\n", pos+1, syntax,
105 (db ? db : "unknown"));
108 if (fwrite (str, 1, len, stdout) != (size_t) len)
109 printf("write to stdout failed\n");
117 /* destroy stuff and exit */
118 ZOOM_query_destroy (q);
119 for (i = 0; i<no; i++)
121 ZOOM_resultset_destroy (r[i]);
122 ZOOM_connection_destroy (z[i]);
124 ZOOM_options_destroy(o);
130 * indent-tabs-mode: nil
132 * vim: shiftwidth=4 tabstop=8 expandtab