static void read_inf(std::istream & in, PTree & node, Include * include, bool child) { std::string line, name; while (in.good()) { std::getline(in, line, '\n'); if (line.empty()) { continue; } size_t begin = line.find_first_not_of(" \t"); size_t end = line.find_first_of(";#"); if (begin >= end) { continue; } line = line.substr(begin, end); if (line[0] == '{' && name.length()) { // New node. read_inf(in, node.set(name, PTree()), include, true); continue; } if (line[0] == '}' && child) { break; } size_t next = line.find(" "); end = line.length(); name = line.substr(0, next); if (next < end) { // New property. std::string value = line.substr(next+1, end); // Include? if (include && name == "include") { (*include)(node, value); } else { node.set(name, value); } name.clear(); } } }
void read_inf(std::istream & in, PTree & p) { read_inf(in, p, false); }
void find_inf(void) { long ret; char path[128], *home = getenv("HOME"); if (home) { char myhome[128]; if (!strlen(home)) goto _nohome; strcpy(myhome,home); if (myhome[strlen(myhome)-1] != '\\') strcat(myhome,"\\"); strcpy(path,myhome); strcat(path,"defaults\\"); strcat(path,FILEINF); #ifdef DEBUG printf("%s (?)\n",path); #endif ret = Fopen(path,FO_READ); if (ret >= 0L) read_inf((int)ret); else { strcpy(path,myhome); strcat(path,FILEINF); #ifdef DEBUG printf("%s (?)\n",path); #endif ret = Fopen(path,FO_READ); if (ret < 0L) goto _nohome; read_inf((int)ret); } } else { _nohome: boot_device(path); strcat(path,FILEINF); #ifdef DEBUG printf("%s (?)\n",path); #endif ret = Fopen(path,FO_READ); if (ret >= 0L) read_inf((int)ret); else { strcpy(path,FILEINF); #ifdef DEBUG printf("%s (?)\n",path); #endif ret = Fopen(path,FO_READ); if (ret >= 0L) read_inf((int)ret); else { form_alert(1,MESSAGE_INFNOTFOUND); } } } #ifdef DEBUG printf("\n"); #endif }
void read_inf(std::istream & in, PTree & p, Include * inc) { read_inf(in, p, inc, false); }