42#include "BESInternalFatalError.h"
47#define BES_INCLUDE_KEY "BES.Include"
55 const std::string &keys_file_name,
56 set<string> &loaded_kvp_files,
57 std::map<std::string, std::vector<std::string> > &keystore);
59 bool only_blanks(
const char *line) {
60 string my_line = line;
61 if (my_line.find_first_not_of(
" ") != string::npos)
76 bool break_pair(
const char *b,
string &key,
string &value,
bool &addto) {
79 if (b && (b[0] !=
'#') && (!only_blanks(b))) {
84 for (
size_t j = 0; j < l && !done; j++) {
89 if (pos !=
static_cast<int>(j - 1)) {
90 string s = string(
"BES: Invalid entry ") + b +
91 " in configuration file "
92 +
" '+' character found in variable name" +
" or attempting '+=' with space"
93 +
" between the characters.\n";
98 }
else if (b[j] ==
'+') {
104 string s = string(
"BES: Invalid entry ") + b +
" in configuration file "
105 +
" '=' character not found.\n";
110 key = s.substr(0, pos);
113 value = s.substr(pos + 2, s.size());
115 value = s.substr(pos + 1, s.size());
131 void load_include_file(
133 set<string> &loaded_kvp_files,
134 std::map<std::string, std::vector<std::string> > &keystore
139 set<string>::iterator it = loaded_kvp_files.find(file);
141 if (it == loaded_kvp_files.end()) {
143 loaded_kvp_files.insert(file);
144 load_keys(file, loaded_kvp_files, keystore);
160 void load_include_files(
161 const string ¤t_keys_file_name,
162 const string &file_expr,
163 set<string> &loaded_kvp_files,
164 std::map<std::string, std::vector<std::string> > &keystore
171 if (!file_expr.empty() && file_expr[0] ==
'/') {
172 newdir = allfiles.getDirName();
176 BESFSFile currfile(current_keys_file_name);
177 string currdir = currfile.getDirName();
179 string alldir = allfiles.getDirName();
181 if ((currdir ==
"./" || currdir ==
".") && (alldir ==
"./" || alldir ==
".")) {
184 if (alldir ==
"./" || alldir ==
".") {
187 newdir = currdir +
"/" + alldir;
194 BESFSDir fsd(newdir, allfiles.getFileName());
195 BESFSDir::fileIterator i = fsd.beginOfFileList();
196 BESFSDir::fileIterator e = fsd.endOfFileList();
197 for (; i != e; i++) {
198 string include_file = (*i).getFullPath();
199 load_include_file(include_file, loaded_kvp_files, keystore);
207 std::map<std::string, std::vector<std::string> > &keystore) {
208 map<string, vector<string> >::iterator i;
209 i = keystore.find(key);
210 if (i == keystore.end()) {
212 keystore[key] = vals;
214 if (!addto) keystore[key].clear();
216 keystore[key].push_back(val);
221 const string ¤t_keys_file_name,
222 std::ifstream &keys_file,
223 set<string> &loaded_kvp_files,
224 std::map<std::string, std::vector<std::string> > &keystore ) {
226 string key, value, line;
227 while (!keys_file.eof()) {
229 getline(keys_file, line);
230 if (break_pair(line.c_str(), key, value, addto)) {
231 if (key == BES_INCLUDE_KEY) {
235 set_key(key, value,
true, keystore);
237 load_include_files(current_keys_file_name, value, loaded_kvp_files, keystore );
239 set_key(key, value, addto, keystore);
246 const std::string &keys_file_name,
247 set<string> &loaded_kvp_files,
248 std::map<std::string, std::vector<std::string> > &keystore
250 std::ifstream keys_file(keys_file_name.c_str());
254 getcwd(path,
sizeof(path));
255 string s = string(
"Cannot open configuration file '") + keys_file_name +
"': ";
256 char *err = strerror(errno);
260 s +=
"Unknown error";
262 s += (string)
".\n" +
"The current working directory is " + path;
267 loaded_kvp_files.insert(keys_file_name);
268 load_keys(keys_file_name, keys_file, loaded_kvp_files, keystore);
276 catch (std::exception &e) {
278 string s = (string)
"Caught exception load keys from the BES configuration file '"
279 + keys_file_name +
"' message:" + e.what();
286 const std::string &keys_file_name,
287 std::map<std::string, std::vector<std::string> > &keystore
289 set<string> loaded_kvp_files;
290 load_keys(keys_file_name, loaded_kvp_files, keystore);
Base exception class for the BES with basic string message.
unsigned int get_line() const
get the line number where the exception was thrown
std::string get_file() const
get the file name where the exception was thrown
std::string get_message() const
get the error message for this exception
exception thrown if an internal error is found and is fatal to the BES
static void removeLeadingAndTrailingBlanks(std::string &key)