1 /* This file is part of the Zebra server.
2 Copyright (C) Index Data
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 #include <yaz/xmalloc.h>
31 #include <yaz/options.h>
34 char *prog = "testclient";
36 int main(int argc, char **argv)
41 const char *errmsg, *addinfo;
47 int retrieve_number = 0;
48 int retrieve_offset = 0;
54 while ((ret = options("d:n:o:f:c:", argv, argc, &arg)) != -2)
60 target = xstrdup(arg);
65 delay_sec = atoi(arg);
68 retrieve_number = atoi(arg);
71 retrieve_offset = atoi(arg);
74 format = xstrdup(arg);
77 check_count = atoi(arg);
80 printf ("%s: unknown option %s\n", prog, arg);
81 printf ("usage:\n%s [options] target query \n", prog);
82 printf (" eg. indexdata.dk/gils computer\n");
87 if (!target || !query)
89 printf ("%s: missing target/query\n", prog);
90 printf ("usage:\n%s [options] target query \n", prog);
91 printf (" eg. bagel.indexdata.dk/gils computer\n");
92 printf ("Options:\n");
93 printf (" -n num number of records to fetch. Default: 0.\n");
94 printf (" -o off offset for records - counting from 0.\n");
95 printf (" -f format set record syntax. Default: none\n");
96 printf (" -d sec delay a number of seconds before exit.\n");
97 printf (" -c count expect count hits, fail if not.\n");
100 z = ZOOM_connection_new (target, 0);
102 if ((error = ZOOM_connection_error(z, &errmsg, &addinfo)))
104 printf ("Error: %s (%d) %s\n", errmsg, error, addinfo);
108 r = ZOOM_connection_search_pqf (z, query);
109 if ((error = ZOOM_connection_error(z, &errmsg, &addinfo)))
111 printf ("Error: %s (%d) %s\n", errmsg, error, addinfo);
112 if (check_count != -1)
117 printf ("Result count: %ld\n", (long) ZOOM_resultset_size(r));
118 if (check_count != -1 && check_count != ZOOM_resultset_size(r))
120 printf("Wrong number of hits, expected %d, got %ld\n",
121 check_count, (long) ZOOM_resultset_size(r) );
126 ZOOM_resultset_option_set(r, "preferredRecordSyntax", format);
127 for (pos = 0; pos < retrieve_number; pos++)
132 ZOOM_resultset_record(r, pos + retrieve_offset),
136 fwrite (rec, 1, len, stdout);
140 ZOOM_resultset_destroy (r);
141 ZOOM_connection_destroy (z);
147 * c-file-style: "Stroustrup"
148 * indent-tabs-mode: nil
150 * vim: shiftwidth=4 tabstop=8 expandtab