Changeset 7234 in orxonox.OLD for branches/preferences/src/lib/parser/ini_parser
- Timestamp:
- Mar 21, 2006, 3:36:22 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/preferences/src/lib/parser/ini_parser/ini_parser.cc
r7221 r7234 392 392 } 393 393 394 /** 395 * @brief edits the entry speciefied by entryName in sectionName/currentSection or creates it if it doesn't exist 396 * @param entryName the Name of the Entry to add 397 * @param value the value to assign to this entry 398 * @param sectionName if NULL then this entry will be set to the currentSection 399 * otherwise to the section refered to by sectionName. 400 * If both are NULL no entry will be added 401 * @return true if everything is ok false on error 402 */ 403 bool IniParser::editVar(const char* entryName, const char* value, const char* sectionName) 404 { 405 std::list<IniSection>::iterator section; 406 407 if (sectionName != NULL) 408 { 409 for (section = this->sections.begin(); section != this->sections.end(); section++) 410 if (!strcmp((*section).name, sectionName)) 411 break; 412 } 413 else 414 section = this->currentSection; 415 416 if (section == this->sections.end()) 417 { 418 IniSection sec; 419 sec.comment = NULL; 420 sec.name = new char[strlen(sectionName)+1]; 421 strcpy(sec.name, sectionName); 422 section = this->sections.insert(this->sections.end(), sec); 423 } 424 425 if (section == this->sections.end()) 426 { 427 PRINTF(2)("section '%s' not found for value '%s'\n", sectionName, entryName); 428 return false; 429 } 430 else 431 { 432 //try find item 433 std::list<IniEntry>::iterator entry; 434 for (entry = section->entries.begin(); entry!=section->entries.end(); entry++) 435 if (!strcmp( entry->name, entryName )) 436 break; 437 438 //found it? 439 if ( entry != section->entries.end() ) 440 { 441 if ( entry->value != NULL ) 442 { 443 delete[] entry->value; 444 } 445 entry->value = new char[strlen(value)+1]; 446 strcpy(entry->value, value); 447 448 return true; 449 } 450 451 //not found -> create it 452 (*section).entries.push_back(IniEntry()); 453 (*section).entries.back().comment = NULL; 454 (*section).entries.back().name = new char[strlen(entryName)+1]; 455 strcpy((*section).entries.back().name, entryName); 456 (*section).entries.back().value = new char[strlen(value)+1]; 457 strcpy((*section).entries.back().value, value); 458 PRINTF(5)("Added Entry %s with Value '%s' to Section %s\n", 459 (*section).entries.back().name, 460 (*section).entries.back().value, 461 (*section).name); 462 this->currentEntry = --(*section).entries.end(); 463 return true; 464 } 465 } 466 394 467 395 468 /**
Note: See TracChangeset
for help on using the changeset viewer.