moving some non-portable code to stlplus
[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 <stlplus/portability/file_system.hpp>
13
14 #include "log.hh"
15 #include "settings.hh"
16
17
18 namespace moof {
19
20
21 settings::settings(int argc, char* argv[], const std::string& path)
22 {
23 script_.import_base_library();
24 log::import(script_);
25
26 parse_args(argc, argv);
27 load_files(path);
28 }
29
30 settings::~settings()
31 {
32 save();
33 }
34
35
36 void settings::parse_args(int argc, char* argv[])
37 {
38 for (int i = 1; i < argc; ++i)
39 {
40 if (script_.do_string(argv[i]) != script::success)
41 {
42 std::string str;
43 script_[-1].get(str);
44 log_warning("invalid option", argv[i], "returned", str);
45 script_.clear_stack();
46 }
47 }
48 }
49
50
51 void settings::load_files(const std::string& path)
52 {
53 std::vector<std::string> paths;
54 boost::split(paths, path, boost::is_any_of(":"));
55
56 load_files(paths);
57 }
58
59 void settings::load_files(const std::vector<std::string>& path)
60 {
61 std::string home = stlplus::folder_home();
62
63 std::vector<std::string>::iterator it;
64 std::vector<std::string> copy(path);
65 for (it = copy.begin(); it != copy.end(); ++it)
66 {
67 if (!home.empty())
68 {
69 boost::replace_all(*it, "$HOME", home);
70
71 //logDebug("Copying global settings...");
72 //mUserFile = *it;
73 //mGlobals.push_copy();
74 //script_.set("globals", script::registry_index);
75 }
76
77 if (script_.do_file(*it) != script::success)
78 {
79 std::string str;
80 script_[-1].get(str);
81 log_warning(str);
82 script_.clear_stack();
83 }
84 }
85 }
86
87
88 void settings::clear()
89 {
90 script_.reset();
91 }
92
93
94 void settings::save_as(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 moof
107
This page took 0.033548 seconds and 4 git commands to generate.