File: zoomtst10.c

package info (click to toggle)
yaz 3.0.34-2
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 13,404 kB
  • ctags: 12,108
  • sloc: xml: 116,075; ansic: 52,205; sh: 9,746; tcl: 2,043; makefile: 1,141; yacc: 347
file content (65 lines) | stat: -rw-r--r-- 1,820 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
/* This file is part of the YAZ toolkit.
 * Copyright (C) 1995-2008 Index Data
 * See the file LICENSE for details.
 */

#include <stdlib.h>
#include <stdio.h>
#include <yaz/xmalloc.h>
#include <yaz/zoom.h>

int main(int argc, char **argv)
{
    ZOOM_connection z;
    ZOOM_resultset r;
    ZOOM_query q = ZOOM_query_create();
    int error;
    const char *errmsg, *addinfo;
    int ccl_error_code, ccl_error_pos;
    const char *ccl_error_string;

    if (argc != 3)
    {
        fprintf (stderr, "usage:\n%s target cclquery\n", *argv);
        fprintf (stderr, " eg.  bagel.indexdata.dk/gils \"ti=utah\"\n");
        exit (1);
    }

    if (ZOOM_query_ccl2rpn(q, argv[2], 
                           "term t=l,r s=al\n" "ti u=4 s=pw\n",
                           &ccl_error_code, &ccl_error_string, &ccl_error_pos))
    {
        printf("CCL Error %d: %s\n", ccl_error_code, ccl_error_string);
        if (ccl_error_pos >= 0)
            printf("%s\n%*s^\n", argv[2], ccl_error_pos, "");
        ZOOM_query_destroy(q);
    }
    else
    {
        z = ZOOM_connection_new (argv[1], 0);
        
        if ((error = ZOOM_connection_error(z, &errmsg, &addinfo)))
        {
            fprintf (stderr, "Error: %s (%d) %s\n", errmsg, error, addinfo);
            exit (2);
        }
        
        r = ZOOM_connection_search (z, q);
        ZOOM_query_destroy(q);
        if ((error = ZOOM_connection_error(z, &errmsg, &addinfo)))
            fprintf (stderr, "Error: %s (%d) %s\n", errmsg, error, addinfo);
        else
            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
 */