]> Dogcows Code - chaz/yoink/blob - src/moof/settings.cc
remove some unused stlplus modules
[chaz/yoink] / src / moof / settings.cc
1
2 /*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
3 **] All rights reserved.
4 *
5 * Distributable under the terms and conditions of the 2-clause BSD license;
6 * see the file COPYING for a complete text of the license.
7 *
8 *****************************************************************************/
9
10 #include <stlplus/portability/file_system.hpp>
11
12 #include "log.hh"
13 #include "settings.hh"
14
15
16 namespace moof {
17
18
19 settings::settings(int argc, char* argv[], const std::string& path)
20 {
21 script_.import_base_library();
22 log::import(script_);
23
24 parse_args(argc, argv);
25 load_files(path);
26 }
27
28 settings::~settings()
29 {
30 save();
31 }
32
33 void settings::parse_args(int argc, char* argv[])
34 {
35 for (int i = 1; i < argc; ++i)
36 {
37 if (script_.do_string(argv[i]) != script::success)
38 {
39 std::string str;
40 script_[-1].get(str);
41 log_warning("invalid option", argv[i], "returned", str);
42 script_.clear_stack();
43 }
44 }
45 }
46
47 void settings::load_files(const std::string& path)
48 {
49 std::vector<std::string> paths;
50 boost::split(paths, path, boost::is_any_of(":"));
51 load_files(paths);
52 }
53
54 void settings::load_files(const std::vector<std::string>& path)
55 {
56 std::string home = stlplus::folder_home();
57
58 std::vector<std::string>::iterator it;
59 std::vector<std::string> copy(path);
60 for (it = copy.begin(); it != copy.end(); ++it)
61 {
62 if (!home.empty())
63 {
64 boost::replace_all(*it, "$HOME", home);
65
66 //logDebug("Copying global settings...");
67 //userfile_ = *it;
68 //mGlobals.push_copy();
69 //script_.set("globals", script::registry_index);
70 }
71 if (script_.do_file(*it) != script::success)
72 {
73 std::string str;
74 script_[-1].get(str);
75 log_warning(str);
76 script_.clear_stack();
77 }
78 }
79 }
80
81 void settings::clear()
82 {
83 script_.reset();
84 }
85
86 void settings::save_as(const std::string& path)
87 {
88 userfile_ = path;
89 save();
90 }
91
92 void settings::save() const
93 {
94 // TODO saving settings not yet implemented
95 }
96
97
98 } // namepsace moof
99
This page took 0.037584 seconds and 4 git commands to generate.