/** * Constructor, opens the file * * @param filename the name of the inifile to open. */ INIFile::INIFile(const string& filename) { char line[1024]; char key[1024]; char value[1024]; char* str; VFile* inifile; string cursectionName; // INISection cursection; INISection newSection; IniEntry Entry; //int MAXLINELENGTH = 1024; //int MAXSTRINGLENGTH = 128; // Open the File inifile = VFSUtils::VFS_Open(filename.c_str()); if (inifile == 0) { string s = "Unable to open "; s += filename; Logger::getInstance()->Error(s); throw runtime_error(s); } cursectionName = ""; // parse the inifile and write data to inidata while (inifile->getLine(line, 1024) != 0) { str = line; while ((*str) == ' ' || (*str) == '\t') { str++; } if ((*str) == ';') { continue; } if (sscanf(str, "[%[^]]]", key) == 1) { if (cursectionName != "") { //inidata[cursectionName] = cursection; Inidata[cursectionName] = newSection; // cursection.clear(); newSection.clear(); } for (unsigned int i = 0; key[i] != '\0'; i++) { key[i] = toupper(key[i]); } cursectionName = key; } else if (cursectionName != "" && sscanf(str, "%[^=]=%[^\r\n;]", key, value) == 2) { for (unsigned int i = 0; key[i] != '\0'; i++) { key[i] = toupper(key[i]); } if (strlen(key) > 0) { str = key + strlen(key) - 1; while ((*str) == ' ' || (*str) == '\t') { (*str) = '\0'; if (str == key) { break; } str--; } } if (strlen(value) > 0) { str = value + strlen(value) - 1; while ((*str) == ' ' || (*str) == '\t') { (*str) = '\0'; if (str == value) { break; } str--; } } str = value; while ((*str) == ' ' || (*str) == '\t') { str++; } //cursection[(string)key] = (string)str; Entry.first = (string) key; Entry.second = (string) str; //newSection.push_back(Entry); // std::pair entry ((string)key, (string)str); // newSection.push_back (key, str); newSection[key] = str; } } if (cursectionName != "") { //inidata[cursectionName] = cursection; Inidata[cursectionName] = newSection; // cursection.clear(); newSection.clear(); } // Close the file VFSUtils::VFS_Close(inifile); }
/** * Constructor, opens the file * * files beginning with ";" are ignored, tabs & spaces at beginning are ignored * @param filename the name of the inifile to open. */ INIFile::INIFile(const char* filename) { char line[1024]; char key[1024]; char value[1024]; // Uint32 i; char* str; VFile* inifile; string cursectionName; // INISection cursection; INISection newSection; IniEntry Entry; //int MAXLINELENGTH = 1024; //int MAXSTRINGLENGTH = 128; // Open the File inifile = VFSUtils::VFS_Open(filename); if (inifile == 0) { string s = "Unable to open "; s += filename; logger->error("%s\n", s.c_str()); throw runtime_error(s); } cursectionName = ""; // parse the inifile and write data to inidata while (inifile->getLine(line, 1024) != 0) { str = line; while ((*str) == ' ' || (*str) == '\t') { str++; } if ((*str) == ';') { continue; } if (sscanf(str, "[%[^]]]", key) == 1) { if (cursectionName != "") { //inidata[cursectionName] = cursection; Inidata[cursectionName] = newSection; // cursection.clear(); newSection.clear(); } strUpper(key); cursectionName = key; } else if (cursectionName != "" && sscanf(str, "%[^=]=%[^\r\n;]", key, value) == 2) { strUpper(key); if (strlen(key) > 0) strStripWhiteSpace(key); if (strlen(value) > 0) strStripWhiteSpace(key); str = value; while ((*str) == ' ' || (*str) == '\t') { str++; } //cursection[(string)key] = (string)str; Entry.first = (string) key; Entry.second = (string) str; newSection.push_back(Entry); // std::pair entry ((string)key, (string)str); // newSection.push_back (key, str); } } if (cursectionName != "") { //inidata[cursectionName] = cursection; Inidata[cursectionName] = newSection; // cursection.clear(); newSection.clear(); } #ifdef _DEBUG this->filename = filename; #endif // Close the file VFSUtils::VFS_Close(inifile); }
/** Constructor, opens the file * @param the name of the inifile to open. */ INIFile::INIFile(const char* filename) { char line[1024]; char key[1024]; char value[1024]; Uint32 i; char* str; VFile* inifile; string cursectionName; INISection cursection; inifile = VFS_Open(filename); if (inifile == NULL) { string s = "Unable to open "; s += filename; throw runtime_error(s); } cursectionName = ""; // parse the inifile and write data to inidata while (inifile->getLine(line, 1024) != NULL) { str = line; while ((*str) == ' ' || (*str) == '\t') { str++; } if ((*str) == ';') { continue; } if (sscanf(str, "[%[^]]]", key) == 1) { if (cursectionName != "") { inidata[cursectionName] = cursection; cursection.clear(); } for (i = 0; key[i] != '\0'; i++) { key[i] = toupper(key[i]); } cursectionName = key; } else if (cursectionName != "" && sscanf(str, "%[^=]=%[^\r\n;]", key, value) == 2) { for (i = 0; key[i] != '\0'; i++) { key[i] = toupper(key[i]); } if (strlen(key) > 0) { str = key+strlen(key)-1; while ((*str) == ' ' || (*str) == '\t') { (*str) = '\0'; if (str == key) { break; } str--; } } if (strlen(value) > 0) { str = value+strlen(value)-1; while ((*str) == ' ' || (*str) == '\t') { (*str) = '\0'; if (str == value) { break; } str--; } } str = value; while ((*str) == ' ' || (*str) == '\t') { str++; } cursection[(string)key] = (string)str; } } if (cursectionName != "") { inidata[cursectionName] = cursection; cursection.clear(); } VFS_Close(inifile); }