1 /* This file is part of the Zebra server.
2 Copyright (C) 1994-2011 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
27 #include <yaz/xmalloc.h>
28 #include <yaz/options.h>
31 char *prog = "testclient";
33 int main(int argc, char **argv)
38 const char *errmsg, *addinfo;
44 int retrieve_number = 0;
45 int retrieve_offset = 0;
51 while ((ret = options("d:n:o:f:c:", argv, argc, &arg)) != -2)
57 target = xstrdup(arg);
62 delay_sec = atoi(arg);
65 retrieve_number = atoi(arg);
68 retrieve_offset = atoi(arg);
71 format = xstrdup(arg);
74 check_count = atoi(arg);
77 printf ("%s: unknown option %s\n", prog, arg);
78 printf ("usage:\n%s [options] target query \n", prog);
79 printf (" eg. indexdata.dk/gils computer\n");
84 if (!target || !query)
86 printf ("%s: missing target/query\n", prog);
87 printf ("usage:\n%s [options] target query \n", prog);
88 printf (" eg. bagel.indexdata.dk/gils computer\n");
89 printf ("Options:\n");
90 printf (" -n num number of records to fetch. Default: 0.\n");
91 printf (" -o off offset for records - counting from 0.\n");
92 printf (" -f format set record syntax. Default: none\n");
93 printf (" -d sec delay a number of seconds before exit.\n");
94 printf (" -c count expect count hits, fail if not.\n");
97 z = ZOOM_connection_new (target, 0);
99 if ((error = ZOOM_connection_error(z, &errmsg, &addinfo)))
101 printf ("Error: %s (%d) %s\n", errmsg, error, addinfo);
105 r = ZOOM_connection_search_pqf (z, query);
106 if ((error = ZOOM_connection_error(z, &errmsg, &addinfo)))
108 printf ("Error: %s (%d) %s\n", errmsg, error, addinfo);
109 if (check_count != -1)
114 printf ("Result count: %ld\n", (long) ZOOM_resultset_size(r));
115 if (check_count != -1 && check_count != ZOOM_resultset_size(r))
117 printf("Wrong number of hits, expected %d, got %ld\n",
118 check_count, (long) ZOOM_resultset_size(r) );
123 ZOOM_resultset_option_set(r, "preferredRecordSyntax", format);
124 for (pos = 0; pos < retrieve_number; pos++)
129 ZOOM_resultset_record(r, pos + retrieve_offset),
133 fwrite (rec, 1, len, stdout);
137 ZOOM_resultset_destroy (r);
138 ZOOM_connection_destroy (z);
144 * c-file-style: "Stroustrup"
145 * indent-tabs-mode: nil
147 * vim: shiftwidth=4 tabstop=8 expandtab