File: zoomtst2.c

package info (click to toggle)
yaz 2.1.18-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 11,988 kB
  • ctags: 11,045
  • sloc: xml: 109,719; ansic: 41,566; sh: 10,625; makefile: 1,115; tcl: 380; yacc: 288
file content (66 lines) | stat: -rw-r--r-- 1,696 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* $Id: zoomtst2.c,v 1.8 2006/04/21 10:28:08 adam Exp $  */

/** \file zoomtst2.c
    \brief Asynchronous single-target client performing search (no retrieval)
*/

#include <stdio.h>
#include <stdlib.h>

#include <yaz/zoom.h>

int main(int argc, char **argv)
{
    ZOOM_connection z;
    ZOOM_resultset r;
    int error;
    const char *errmsg, *addinfo, *diagset;

    if (argc < 3)
    {
        fprintf (stderr, "usage:\n%s target query\n", *argv);
        fprintf (stderr,
                 "Verify: asynchronous single-target client\n");
        exit (1);
    }

    /* create connection (don't connect yet) */
    z = ZOOM_connection_create(0);

    /* option: set sru/get operation (only applicable if http: is used) */
    ZOOM_connection_option_set (z, "sru", "post");

    /* option: set async operation */
    ZOOM_connection_option_set (z, "async", "1");

    /* connect to target and initialize */
    ZOOM_connection_connect (z, argv[1], 0);

    /* search using prefix query format */
    r = ZOOM_connection_search_pqf (z, argv[2]);

    /* block here: only one connection */
    while (ZOOM_event (1, &z))
        ;

    /* see if any error occurred */
    if ((error = ZOOM_connection_error_x(z, &errmsg, &addinfo, &diagset)))
    {
        fprintf (stderr, "Error: %s: %s (%d) %s\n", diagset, errmsg, error,
                         addinfo);
        exit (2);
    }
    else /* OK print hit count */
        printf ("Result count: %ld\n", (long) ZOOM_resultset_size(r));  
    ZOOM_resultset_destroy (r);
    ZOOM_connection_destroy (z);
    exit (0);
}
/*
 * Local variables:
 * c-basic-offset: 4
 * indent-tabs-mode: nil
 * End:
 * vim: shiftwidth=4 tabstop=8 expandtab
 */