]> Dogcows Code - chaz/yoink/blob - src/Moof/Settings.cc
cade lab fixes
[chaz/yoink] / src / Moof / Settings.cc
1
2 /*******************************************************************************
3
4 Copyright (c) 2009, Charles McGarvey
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9
10 * Redistributions of source code must retain the above copyright notice,
11 this list of conditions and the following disclaimer.
12 * Redistributions in binary form must reproduce the above copyright notice,
13 this list of conditions and the following disclaimer in the documentation
14 and/or other materials provided with the distribution.
15
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27 *******************************************************************************/
28
29 #include <cstdlib> // getenv
30
31 #include "Settings.hh"
32
33
34 namespace Mf {
35
36
37 Settings::~Settings()
38 {
39 save();
40 }
41
42 //Settings& Settings::getInstance()
43 //{
44 //static Settings settings;
45 //return settings;
46 //}
47
48
49 void Settings::parseArgs(int argc, char* argv[])
50 {
51 for (int i = 1; i < argc; ++i)
52 {
53 mScript.doString(argv[i]);
54 }
55 }
56
57
58 void Settings::loadFromFiles(const std::string& path)
59 {
60 std::vector<std::string> paths;
61 boost::split(paths, path, boost::is_any_of(":"));
62
63 loadFromFiles(paths);
64 }
65
66 void Settings::loadFromFiles(const std::vector<std::string>& path)
67 {
68 std::vector<std::string> copy(path);
69 std::vector<std::string>::iterator it;
70
71 #if defined(_WIN32) || defined(__WIN32__)
72 char* homeDrive = getenv("HOMEDRIVE");
73 char* homePath = getenv("HOMEPATH");
74 std::string home(homeDrive ? homeDrive : "");
75 if (homePath) home += homePath;
76 #else
77 char *homePath = getenv("HOME");
78 std::string home(homePath ? homePath : "");
79 #endif
80
81 for (it = copy.begin(); it != copy.end(); ++it)
82 {
83 if (!home.empty())
84 {
85 boost::replace_all(*it, "$HOME", home);
86
87 //Mf::logDebug("Copying global settings...");
88 //mUserFile = *it;
89 //mGlobals.pushCopy();
90 //mScript.set("globals", Script::REGISTRY);
91 }
92
93 if (mScript.doFile(*it) != Script::SUCCESS)
94 {
95 std::string str;
96 mScript[-1].get(str);
97 logWarning(str);
98 mScript.clear();
99 }
100 }
101 }
102
103
104 void Settings::clear()
105 {
106 mScript.reset();
107 }
108
109
110 void Settings::saveAs(const std::string& path)
111 {
112 mUserFile = path;
113 save();
114 }
115
116 void Settings::save() const
117 {
118 }
119
120
121 Settings settings;
122
123
124 } // namepsace Mf
125
126 /** vim: set ts=4 sw=4 tw=80: *************************************************/
127
This page took 0.039228 seconds and 4 git commands to generate.