From 9f2bcb03606f31b1bcf0626b6b022f66576c5ca7 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Mon, 16 Jan 2006 11:22:56 +0000 Subject: [PATCH] Make yp2 program --- src/.cvsignore | 1 + src/Makefile.am | 5 ++- src/ex_router_flexml.cpp | 5 +-- src/yp2_prog.cpp | 95 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+), 6 deletions(-) create mode 100644 src/yp2_prog.cpp diff --git a/src/.cvsignore b/src/.cvsignore index dea9d51..6c55b8d 100644 --- a/src/.cvsignore +++ b/src/.cvsignore @@ -31,3 +31,4 @@ test_filter_virt_db test_router_flexml test_ses_map tstdl +yp2 diff --git a/src/Makefile.am b/src/Makefile.am index 275c69d..5fc6a02 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,4 @@ -## $Id: Makefile.am,v 1.43 2006-01-15 20:03:14 adam Exp $ +## $Id: Makefile.am,v 1.44 2006-01-16 11:22:56 adam Exp $ MAINTAINERCLEANFILES = Makefile.in config.in config.hpp @@ -36,12 +36,13 @@ libyp2_la_SOURCES = \ LDADD= libyp2.la $(YAZPPLALIB) $(XSLT_LIBS) -bin_PROGRAMS = +bin_PROGRAMS = yp2 noinst_PROGRAMS = ex_filter_frontend_net ex_router_flexml tstdl ex_filter_frontend_net_SOURCES = ex_filter_frontend_net.cpp ex_router_flexml_SOURCES = ex_router_flexml.cpp tstdl_SOURCES = tstdl.cpp +yp2_SOURCES = yp2_prog.cpp # Rules for dl programs pkglib_LTLIBRARIES = yp2_filter_dl.la diff --git a/src/ex_router_flexml.cpp b/src/ex_router_flexml.cpp index 3793ea2..3d77c98 100644 --- a/src/ex_router_flexml.cpp +++ b/src/ex_router_flexml.cpp @@ -1,4 +1,4 @@ -/* $Id: ex_router_flexml.cpp,v 1.6 2006-01-09 13:43:59 adam Exp $ +/* $Id: ex_router_flexml.cpp,v 1.7 2006-01-16 11:22:56 adam Exp $ Copyright (c) 2005, Index Data. %LICENSE% @@ -21,7 +21,6 @@ int main(int argc, char **argv) { try { - po::options_description desc("Allowed options"); desc.add_options() ("help", "produce help message") @@ -86,8 +85,6 @@ int main(int argc, char **argv) } - - /* * Local variables: * c-basic-offset: 4 diff --git a/src/yp2_prog.cpp b/src/yp2_prog.cpp new file mode 100644 index 0000000..244f3b0 --- /dev/null +++ b/src/yp2_prog.cpp @@ -0,0 +1,95 @@ +/* $Id: yp2_prog.cpp,v 1.1 2006-01-16 11:22:56 adam Exp $ + Copyright (c) 2005, Index Data. + +%LICENSE% + */ + +#include "config.hpp" + +#include +namespace po = boost::program_options; + +#include +#include + +#include "filter.hpp" +#include "package.hpp" +#include "router_flexml.hpp" +#include "factory_static.hpp" + +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")) + { + std::vector config_fnames = + vm["config"].as< std::vector >(); + + if (config_fnames.size() != 1) + { + 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"; + std::exit(1); + } + } + else + { + std::cerr << "No configuration given\n"; + std::exit(1); + } + if (doc) + { + yp2::FactoryStatic factory; + yp2::RouterFleXML router(doc, factory); + + yp2::Package pack; + + pack.router(router).move(); + + xmlFreeDoc(doc); + } + } + catch ( ... ) { + std::cerr << "Unknown Exception" << std::endl; + throw; + std::exit(1); + } + std::exit(0); +} + + +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * c-file-style: "stroustrup" + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ -- 1.7.10.4