X-Git-Url: http://lists.indexdata.com/cgi-bin?a=blobdiff_plain;f=src%2Fmetaproxy_prog.cpp;h=f9ee154fc3a10309585c0a080f531f3e47079064;hb=e1a663095b0b1ac8b605a3b5a1e3cbac6d3d6eed;hp=9151d0b2e2dba50bf62d470a7bcbf8a9c96cf124;hpb=79100c2ae2dac4bdde4f4d46b69e147562b4ec6c;p=metaproxy-moved-to-github.git diff --git a/src/metaproxy_prog.cpp b/src/metaproxy_prog.cpp index 9151d0b..f9ee154 100644 --- a/src/metaproxy_prog.cpp +++ b/src/metaproxy_prog.cpp @@ -1,16 +1,31 @@ -/* $Id: metaproxy_prog.cpp,v 1.1 2006-03-16 10:40:59 adam Exp $ - Copyright (c) 2005-2006, Index Data. +/* $Id: metaproxy_prog.cpp,v 1.12 2008-02-20 10:49:49 adam Exp $ + Copyright (c) 2005-2008, Index Data. -%LICENSE% +This file is part of Metaproxy. + +Metaproxy is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2, or (at your option) any later +version. + +Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Metaproxy; see the file LICENSE. If not, write to the +Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA +02111-1307, USA. */ #include "config.hpp" -#include -namespace po = boost::program_options; +#include #include #include +#include #include "filter.hpp" #include "package.hpp" @@ -23,63 +38,64 @@ int main(int argc, char **argv) { try { - po::options_description desc("Allowed options"); - desc.add_options() - ("help", "produce help message") - ("config", po::value< std::vector >(), "xml config") - ; - - po::positional_options_description p; - p.add("config", -1); - - po::variables_map vm; - po::store(po::command_line_parser(argc, argv). - options(desc).positional(p).run(), vm); - po::notify(vm); - - if (vm.count("help")) { - std::cout << desc << "\n"; - return 1; - } - - xmlDocPtr doc = 0; - if (vm.count("config")) + const char *fname = 0; + int ret; + char *arg; + while ((ret = options("h{help}V{version}c{config}:", + argv, argc, &arg)) != -2) { - std::vector config_fnames = - vm["config"].as< std::vector >(); - - if (config_fnames.size() != 1) + switch (ret) { - std::cerr << "Only one configuration must be given\n"; - std::exit(1); - } - - doc = xmlParseFile(config_fnames[0].c_str()); - if (!doc) - { - std::cerr << "xmlParseFile failed\n"; + case 'h': + std::cerr << "metaproxy\n" + " -h|--help help\n" + " -V|--version version\n" + " -c|--config config filename\n" + << std::endl; + break; + case 'V': + std::cout << "Metaproxy " VERSION "\n"; + break; + case 'c': + fname = arg; + break; + case -1: + std::cerr << "bad option: " << arg << std::endl; std::exit(1); } } - else + if (!fname) { std::cerr << "No configuration given\n"; std::exit(1); } - if (doc) + xmlDocPtr doc = xmlReadFile(fname, + NULL, + XML_PARSE_XINCLUDE + XML_PARSE_NOBLANKS + + XML_PARSE_NSCLEAN + XML_PARSE_NONET ); + + if (!doc) { - try { - mp::FactoryStatic factory; - mp::RouterFleXML router(doc, factory); - mp::Package pack; - pack.router(router).move(); - } - catch (std::runtime_error &e) { - std::cout << "std::runtime error: " << e.what() << "\n"; - exit(1); - } - xmlFreeDoc(doc); + std::cerr << "XML parsing failed\n"; + std::exit(1); } + // and perform Xinclude then + if (xmlXIncludeProcess(doc) > 0) { + std::cerr << "processing XInclude directive\n"; + } + mp::FactoryStatic factory; + mp::RouterFleXML router(doc, factory); + mp::Package pack; + pack.router(router).move(); + xmlFreeDoc(doc); + } + catch (std::logic_error &e) { + std::cerr << "std::logic error: " << e.what() << "\n"; + std::exit(1); + } + catch (std::runtime_error &e) { + std::cerr << "std::runtime error: " << e.what() << "\n"; + std::exit(1); } catch ( ... ) { std::cerr << "Unknown Exception" << std::endl;