Bump copyright year
[yazpp-moved-to-github.git] / zoom / zclient.cpp
1 // Simple sample client
2
3 #include <stdlib.h>             // for atoi()
4 #include <iostream>
5 #include "zoom.h"
6
7
8 int main(int argc, char **argv)
9 {
10     if (argc != 5) {
11         std::cerr << "Usage: " <<
12             argv[0] << " <host> <port> <dbname> <@prefix-search>\n";
13         return 1;
14     }
15
16     using namespace ZOOM;
17     try {
18         connection conn(argv[1], atoi(argv[2]));
19         conn.option("databaseName", argv[3]);
20         conn.option("preferredRecordSyntax",
21                     record::syntax(record::syntax::XML));
22         prefixQuery pq(argv[4]);
23         resultSet rs(conn, pq);
24
25         size_t n = rs.size();
26         std::cout << "found " << n << " records:\n";
27         for (size_t i = 0; i < n; i++) {
28             const record rec(rs, i);
29             std::cout << "=== record " << i+1 <<
30                 " (record-syntax " << (std::string) rec.recsyn() << ")" <<
31                 " ===\n" << rec.render();
32         }
33
34     } catch(bib1Exception& err) {
35         std::cerr << argv[0] << ": bib1Exception " <<
36             err.errmsg() << " (" << err.addinfo() << ")\n";
37         return 2;
38
39     } catch(ZOOM::exception& err) {
40         std::cerr << argv[0] << ": exception " <<
41             err.errmsg() << "\n";
42         return 3;
43     }
44
45     return 0;
46 }
47 /*
48  * Local variables:
49  * c-basic-offset: 4
50  * c-file-style: "Stroustrup"
51  * indent-tabs-mode: nil
52  * End:
53  * vim: shiftwidth=4 tabstop=8 expandtab
54  */
55