Avoid mixed decl/stmt
[yaz-moved-to-github.git] / zoom / zoomtst2.c
1 /*
2  * $Id: zoomtst2.c,v 1.6 2005-06-25 15:46:08 adam Exp $
3  *
4  * Asynchronous single-target client performing search (no retrieval)
5  */
6
7 #include <stdio.h>
8 #include <stdlib.h>
9
10 #include <yaz/zoom.h>
11
12 int main(int argc, char **argv)
13 {
14     ZOOM_connection z;
15     ZOOM_resultset r;
16     int error;
17     const char *errmsg, *addinfo, *diagset;
18
19     if (argc < 3)
20     {
21         fprintf (stderr, "usage:\n%s target query\n", *argv);
22         fprintf (stderr,
23                  "Verify: asynchronous single-target client\n");
24         exit (1);
25     }
26
27     /* create connection (don't connect yet) */
28     z = ZOOM_connection_create(0);
29
30     /* option: set async operation */
31     ZOOM_connection_option_set (z, "async", "1");
32
33     /* connect to target and initialize */
34     ZOOM_connection_connect (z, argv[1], 0);
35
36     /* search using prefix query format */
37     r = ZOOM_connection_search_pqf (z, argv[2]);
38
39     /* block here: only one connection */
40     while (ZOOM_event (1, &z))
41         ;
42
43     /* see if any error occurred */
44     if ((error = ZOOM_connection_error_x(z, &errmsg, &addinfo, &diagset)))
45     {
46         fprintf (stderr, "Error: %s: %s (%d) %s\n", diagset, errmsg, error,
47                          addinfo);
48         exit (2);
49     }
50     else /* OK print hit count */
51         printf ("Result count: %d\n", ZOOM_resultset_size(r));  
52     ZOOM_resultset_destroy (r);
53     ZOOM_connection_destroy (z);
54     exit (0);
55 }
56 /*
57  * Local variables:
58  * c-basic-offset: 4
59  * indent-tabs-mode: nil
60  * End:
61  * vim: shiftwidth=4 tabstop=8 expandtab
62  */
63