*/
#include "arguments.hh"
#include <boost/algorithm/string.hpp>
+#include <boost/algorithm/string/predicate.hpp>
+#include <boost/filesystem.hpp>
+#include <boost/foreach.hpp>
#include "namespaces.hh"
+#include "logger.hh"
const ArgvMap::param_t::const_iterator ArgvMap::begin()
{
return true;
}
-
bool ArgvMap::file(const char *fname, bool lax)
+{
+ return file(fname,lax,false);
+}
+
+bool ArgvMap::file(const char *fname, bool lax, bool included)
{
ifstream f(fname);
if(!f) {
return false;
}
+ if (!included) // inject include-dir
+ set("include-dir","Directory to include configuration files from");
+
string line;
string pline;
string::size_type pos;
line="";
}
+ // handle include here (avoid re-include)
+ if (!included && parmIsset("include-dir")) {
+ // rerun parser for all files
+ boost::filesystem::path targetDir(params["include-dir"]);
+ if (!boost::filesystem::exists(targetDir)) {
+ L << Logger::Error << params["include-dir"] << " does not exist!" << std::endl;
+ throw ArgException(params["include-dir"] + " does not exist!");
+ }
+ boost::filesystem::directory_iterator bfd_it(targetDir), eod;
+ BOOST_FOREACH(boost::filesystem::path const &p, std::make_pair(bfd_it, eod)) {
+ if (boost::ends_with(p.native(),".conf") && is_regular_file(p)) file(p.c_str(), lax, true);
+ }
+ }
+
return true;
}
bool preParseFile(const char *fname, const string &arg, const string& theDefault=""); //!< use this to preparse a single var in configuration
bool file(const char *fname, bool lax=false); //!< Parses a file with parameters
+ bool file(const char *fname, bool lax, bool included);
bool laxFile(const char *fname)
{
return file(fname,true);