/*] Copyright (c) 2009-2010, Charles McGarvey [************************** **] All rights reserved. * * vi:ts=4 sw=4 tw=75 * * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * **************************************************************************/ #include // getenv #include "Settings.hh" namespace Mf { Settings::~Settings() { save(); } void Settings::parseArgs(int argc, char* argv[]) { for (int i = 1; i < argc; ++i) { if (mScript.doString(argv[i]) != Script::SUCCESS) { std::string str; mScript[-1].get(str); logWarning << "invalid option: " << argv[i] << ": " << str << std::endl; mScript.clearStack(); } } } void Settings::loadFromFiles(const std::string& path) { std::vector paths; boost::split(paths, path, boost::is_any_of(":")); loadFromFiles(paths); } void Settings::loadFromFiles(const std::vector& path) { std::vector copy(path); std::vector::iterator it; #if defined(_WIN32) char* homeDrive = getenv("HOMEDRIVE"); char* homePath = getenv("HOMEPATH"); std::string home(homeDrive ? homeDrive : ""); if (homePath) home += homePath; #else char *homePath = getenv("HOME"); std::string home(homePath ? homePath : ""); #endif for (it = copy.begin(); it != copy.end(); ++it) { if (!home.empty()) { boost::replace_all(*it, "$HOME", home); //Mf::logDebug("Copying global settings..."); //mUserFile = *it; //mGlobals.pushCopy(); //mScript.set("globals", Script::REGISTRY); } if (mScript.doFile(*it) != Script::SUCCESS) { std::string str; mScript[-1].get(str); logWarning(str); mScript.clearStack(); } } } void Settings::clear() { mScript.reset(); } void Settings::saveAs(const std::string& path) { mUserFile = path; save(); } void Settings::save() const { // TODO saving settings not yet implemented } } // namepsace Mf