5
#include <arc/StringConv.h>
8
#include "../misc/escaped.h"
9
#include "environment.h"
11
bool config_open(std::ifstream &cfile,const GMEnvironment& env) {
12
return config_open(cfile,env.nordugrid_config_loc());
15
bool config_open(std::ifstream &cfile,const std::string &name) {
16
cfile.open(name.c_str(),std::ifstream::in);
17
return cfile.is_open();
20
bool config_close(std::ifstream &cfile) {
21
if(cfile.is_open()) cfile.close();
25
std::string config_read_line(std::istream &cfile,std::string &rest,char separator) {
26
rest = config_read_line(cfile);
27
return config_next_arg(rest,separator);
30
std::string config_read_line(std::istream &cfile) {
33
if(cfile.eof() || cfile.fail()) { rest=""; return rest; };
34
std::getline(cfile,rest);
35
Arc::trim(rest," \t\r\n");
36
if(rest.empty()) continue; /* empty string - skip */
37
if(rest[0] == '#') continue; /* comment - skip */
43
std::string config_next_arg(std::string &rest,char separator) {
46
n=input_escaped_string(rest.c_str(),arg,separator);
51
config_file_type config_detect(std::istream& in) {
53
if (!in.good()) return config_file_unknown;
55
inchar = (char)(in.get());
56
if(isspace(inchar)) continue;
58
// XML starts from < even if it is comment
60
return config_file_XML;
62
if((inchar == '#') || (inchar = '[')) {
63
// INI file starts from comment or section
65
return config_file_INI;
69
return config_file_unknown;
73
bool elementtobool(Arc::XMLNode pnode,const char* ename,bool& val,Arc::Logger* logger) {
74
std::string v = ename?pnode[ename]:pnode;
75
if(v.empty()) return true; // default
76
if((v == "true") || (v == "1")) {
80
if((v == "false") || (v == "0")) {
84
if(logger && ename) logger->msg(Arc::ERROR,"wrong boolean in %s: %s",ename,v.c_str());
88
bool elementtoint(Arc::XMLNode pnode,const char* ename,unsigned int& val,Arc::Logger* logger) {
89
std::string v = ename?pnode[ename]:pnode;
90
if(v.empty()) return true; // default
91
if(Arc::stringto(v,val)) return true;
92
if(logger && ename) logger->msg(Arc::ERROR,"wrong number in %s: %s",ename,v.c_str());
96
bool elementtoint(Arc::XMLNode pnode,const char* ename,int& val,Arc::Logger* logger) {
97
std::string v = ename?pnode[ename]:pnode;
98
if(v.empty()) return true; // default
99
if(Arc::stringto(v,val)) return true;
100
if(logger && ename) logger->msg(Arc::ERROR,"wrong number in %s: %s",ename,v.c_str());
104
bool elementtoenum(Arc::XMLNode pnode,const char* ename,int& val,const char* const opts[],Arc::Logger* logger) {
105
std::string v = ename?pnode[ename]:pnode;
106
if(v.empty()) return true; // default
107
for(int n = 0;opts[n];++n) {
108
if(v == opts[n]) { val = n; return true; };