Do not depend on libboost-program-options-dev.
[metaproxy-moved-to-github.git] / src / metaproxy_prog.cpp
1 /* $Id: metaproxy_prog.cpp,v 1.12 2008-02-20 10:49:49 adam Exp $
2    Copyright (c) 2005-2008, Index Data.
3
4 This file is part of Metaproxy.
5
6 Metaproxy is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
9 version.
10
11 Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Metaproxy; see the file LICENSE.  If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA.
20  */
21
22 #include "config.hpp"
23
24 #include <yaz/options.h>
25
26 #include <iostream>
27 #include <stdexcept>
28 #include <libxml/xinclude.h>
29
30 #include "filter.hpp"
31 #include "package.hpp"
32 #include "router_flexml.hpp"
33 #include "factory_static.hpp"
34
35 namespace mp = metaproxy_1;
36
37 int main(int argc, char **argv)
38 {
39     try 
40     {
41         const char *fname = 0;
42         int ret;
43         char *arg;
44         while ((ret = options("h{help}V{version}c{config}:", 
45                               argv, argc, &arg)) != -2)
46         {
47             switch (ret)
48             {
49             case 'h':
50                 std::cerr << "metaproxy\n"
51                     " -h|--help     help\n"
52                     " -V|--version  version\n"
53                     " -c|--config   config filename\n"
54                           << std::endl;
55                 break;
56             case 'V':
57                 std::cout << "Metaproxy " VERSION "\n";
58                 break;
59             case 'c':
60                 fname = arg;
61                 break;
62             case -1:
63                 std::cerr << "bad option: " << arg << std::endl;
64                 std::exit(1);
65             }
66         }
67         if (!fname)
68         {
69             std::cerr << "No configuration given\n";
70             std::exit(1);
71         }
72         xmlDocPtr doc = xmlReadFile(fname,
73                                     NULL, 
74                                     XML_PARSE_XINCLUDE + XML_PARSE_NOBLANKS
75                                     + XML_PARSE_NSCLEAN + XML_PARSE_NONET );
76         
77         if (!doc)
78         {
79             std::cerr << "XML parsing failed\n";
80             std::exit(1);
81         }
82         // and perform Xinclude then
83         if (xmlXIncludeProcess(doc) > 0) {
84             std::cerr << "processing XInclude directive\n";
85         }
86         mp::FactoryStatic factory;
87         mp::RouterFleXML router(doc, factory);
88         mp::Package pack;
89         pack.router(router).move();
90         xmlFreeDoc(doc);
91     }
92     catch (std::logic_error &e) {
93         std::cerr << "std::logic error: " << e.what() << "\n";
94         std::exit(1);
95     }
96     catch (std::runtime_error &e) {
97         std::cerr << "std::runtime error: " << e.what() << "\n";
98         std::exit(1);
99     }
100     catch ( ... ) {
101         std::cerr << "Unknown Exception" << std::endl;
102         std::exit(1);
103     }
104     std::exit(0);
105 }
106
107
108 /*
109  * Local variables:
110  * c-basic-offset: 4
111  * indent-tabs-mode: nil
112  * c-file-style: "stroustrup"
113  * End:
114  * vim: shiftwidth=4 tabstop=8 expandtab
115  */