30 #ifndef GRAPHCHI_CONFIGFILE_DEF
31 #define GRAPHCHI_CONFIGFILE_DEF
43 const std::string whiteSpaces(
" \f\n\r\t\v" );
46 static void trimRight( std::string &str,
47 const std::string& trimChars )
49 std::string::size_type pos = str.find_last_not_of( trimChars );
54 static void trimLeft( std::string &str,
55 const std::string& trimChars )
57 std::string::size_type pos = str.find_first_not_of( trimChars );
62 static std::string trim( std::string str)
64 std::string trimChars =
" \f\n\r\t\v";
65 trimRight( str, trimChars );
66 trimLeft( str, trimChars );
72 static void _FIXLINE(
char * s) {
73 int len = (int)strlen(s)-1;
74 if(s[len] ==
'\n') s[len] = 0;
82 static std::map<std::string, std::string> loadconfig(std::string filename) {
83 FILE * f = fopen(filename.c_str(),
"r");
85 std::cout <<
"ERROR: Could not read configuration file: " << filename << std::endl;
86 std::cout <<
"Please define environment variable GRAPHCHI_ROOT or run the program from that directory." << std::endl;
91 std::map<std::string, std::string> conf;
94 while(fgets(s, 4096, f) != NULL) {
96 if (s[0] ==
'#')
continue;
97 if (s[0] ==
'%')
continue;
101 t = strtok(s, delims);
102 const char * ckey = t;
103 t = strtok(NULL, delims);
104 const char * cval = t;
106 if (ckey != NULL && cval != NULL) {
107 std::string key = trim(std::string(ckey));
108 std::string val = trim(std::string(cval));