]> Dogcows Code - chaz/yoink/blob - src/Moof/Settings.cc
sockets documentation and cleanup
[chaz/yoink] / src / Moof / Settings.cc
1
2 /*] Copyright (c) 2009-2010, Charles McGarvey [**************************
3 **] All rights reserved.
4 *
5 * vi:ts=4 sw=4 tw=75
6 *
7 * Distributable under the terms and conditions of the 2-clause BSD license;
8 * see the file COPYING for a complete text of the license.
9 *
10 **************************************************************************/
11
12 #include <cstdlib> // getenv
13
14 #include "Settings.hh"
15
16
17 namespace Mf {
18
19
20 Settings::~Settings()
21 {
22 save();
23 }
24
25
26 void Settings::parseArgs(int argc, char* argv[])
27 {
28 for (int i = 1; i < argc; ++i)
29 {
30 if (mScript.doString(argv[i]) != Script::SUCCESS)
31 {
32 std::string str;
33 mScript[-1].get(str);
34 logWarning << "invalid option: " << argv[i]
35 << ": " << str << std::endl;
36 mScript.clearStack();
37 }
38 }
39 }
40
41
42 void Settings::loadFromFiles(const std::string& path)
43 {
44 std::vector<std::string> paths;
45 boost::split(paths, path, boost::is_any_of(":"));
46
47 loadFromFiles(paths);
48 }
49
50 void Settings::loadFromFiles(const std::vector<std::string>& path)
51 {
52 std::vector<std::string> copy(path);
53 std::vector<std::string>::iterator it;
54
55 #if defined(_WIN32)
56 char* homeDrive = getenv("HOMEDRIVE");
57 char* homePath = getenv("HOMEPATH");
58 std::string home(homeDrive ? homeDrive : "");
59 if (homePath) home += homePath;
60 #else
61 char *homePath = getenv("HOME");
62 std::string home(homePath ? homePath : "");
63 #endif
64
65 for (it = copy.begin(); it != copy.end(); ++it)
66 {
67 if (!home.empty())
68 {
69 boost::replace_all(*it, "$HOME", home);
70
71 //Mf::logDebug("Copying global settings...");
72 //mUserFile = *it;
73 //mGlobals.pushCopy();
74 //mScript.set("globals", Script::REGISTRY);
75 }
76
77 if (mScript.doFile(*it) != Script::SUCCESS)
78 {
79 std::string str;
80 mScript[-1].get(str);
81 logWarning(str);
82 mScript.clearStack();
83 }
84 }
85 }
86
87
88 void Settings::clear()
89 {
90 mScript.reset();
91 }
92
93
94 void Settings::saveAs(const std::string& path)
95 {
96 mUserFile = path;
97 save();
98 }
99
100 void Settings::save() const
101 {
102 // TODO saving settings not yet implemented
103 }
104
105
106 } // namepsace Mf
107
This page took 0.039641 seconds and 4 git commands to generate.