yaz_use_attribute_create based on get_attributeList DRY
[yaz-moved-to-github.git] / zoom / zoomtst8.c
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) Index Data
3  * See the file LICENSE for details.
4  */
5
6 #include <stdio.h>
7 #include <string.h>
8
9 #include <yaz/nmem.h>
10 #include <yaz/xmalloc.h>
11 #include <yaz/zoom.h>
12
13 int main(int argc, char **argv)
14 {
15     int i;
16     int no = argc-2;
17     ZOOM_connection z[500]; /* allow at most 500 connections */
18     ZOOM_scanset s[500];  /* and scan sets .. */
19     ZOOM_options o = ZOOM_options_create ();
20
21     if (argc < 3)
22     {
23         fprintf (stderr, "usage:\n%s target1 target2 ... targetN scan\n",
24                  *argv);
25         exit (1);
26     }
27     if (no > 500)
28         no = 500;
29
30     /* async mode */
31     ZOOM_options_set (o, "async", "1");
32
33     /* connect to all */
34     for (i = 0; i<no; i++)
35     {
36         /* create connection - pass options (they are the same for all) */
37         z[i] = ZOOM_connection_create (o);
38
39         /* connect and init */
40         ZOOM_connection_connect (z[i], argv[1+i], 0);
41
42     }
43     /* scan all */
44     for (i = 0; i<no; i++)
45     {
46         /* set number of scan terms to be returned. */
47         ZOOM_connection_option_set (z[i], "number", "7");
48         /* and perform scan */
49         s[i] = ZOOM_connection_scan(z[i], argv[argc-1]);
50     }
51
52     /* network I/O. pass number of connections and array of connections */
53     while (ZOOM_event (no, z))
54         ;
55
56     for (i = 0; i<no; i++)
57     {
58         int error;
59         const char *errmsg, *addinfo;
60         if ((error = ZOOM_connection_error(z[i], &errmsg, &addinfo)))
61             fprintf (stderr, "%s error: %s (%d) %s\n",
62                      ZOOM_connection_option_get(z[i], "host"),
63                      errmsg, error, addinfo);
64         else
65         {
66             int j;
67             printf ("%s\n", ZOOM_connection_option_get(z[i], "host"));
68             for (j = 0; j < (int) ZOOM_scanset_size (s[i]); j++)
69             {
70                 size_t occur, len;
71                 const char *term;
72                 term = ZOOM_scanset_term (s[i], j, &occur, &len);
73                 if (term)
74                     printf ("%d %.*s %d\n", j, (int) len, term, (int) occur);
75             }
76         }
77     }
78
79     /* destroy and exit */
80     for (i = 0; i<no; i++)
81     {
82         ZOOM_scanset_destroy (s[i]);
83         ZOOM_connection_destroy (z[i]);
84     }
85     ZOOM_options_destroy(o);
86     exit (0);
87 }
88 /*
89  * Local variables:
90  * c-basic-offset: 4
91  * c-file-style: "Stroustrup"
92  * indent-tabs-mode: nil
93  * End:
94  * vim: shiftwidth=4 tabstop=8 expandtab
95  */
96