Changeset 5946 in orxonox.OLD for trunk/src/lib
- Timestamp:
- Dec 7, 2005, 12:46:43 AM (19 years ago)
- Location:
- trunk/src/lib/parser/ini_parser
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/parser/ini_parser/ini_parser.cc
r5945 r5946 144 144 while( fgets (lineBuffer, PARSELINELENGHT, stream)) 145 145 { 146 // if (lineCount == 0)147 148 146 lineBegin = lineBuffer; 149 147 // remove newline char, and \0-terminate … … 153 151 while((*lineBegin == ' ' || *lineBegin == '\t') && lineBegin < lineBuffer + strlen(lineBuffer)) 154 152 ++lineBegin; 155 if (strlen(lineBegin) <= 1 || *lineBegin == '#' || *lineBegin == ';') 156 continue;//printf("empty Line\n"); 153 154 // check if we have a FileComment 155 if ( (*lineBegin == '#' || *lineBegin == ';')) 156 { 157 printf("___________%d_____%s\n", lineCount,lineBegin); 158 char* newCommenLine = new char[strlen(lineBegin)+1]; 159 strcpy(newCommenLine, lineBegin); 160 this->commentList.push_back(newCommenLine); 161 continue; 162 } 163 if (lineCount == 0 && !this->commentList.empty()) 164 { 165 this->setFileComment(); 166 lineCount++; 167 } 168 157 169 // check for section identifyer 158 170 else if( sscanf (lineBegin, "[%s", buffer) == 1) … … 162 174 *ptr = 0; 163 175 this->addSection(buffer); 176 this->setSectionComment(); 164 177 } 165 178 } … … 170 183 { 171 184 PRINTF(2)("Not in a Section yet for %s\n", lineBegin); 185 lineCount++; 172 186 continue; 173 187 } 174 if( ptr == lineBegin) 188 if( ptr == lineBegin) { 189 lineCount++; 175 190 continue; 191 } 176 192 char* valueBegin = ptr+1; 177 193 while ((*valueBegin == ' ' || *valueBegin == '\t') && valueBegin <= lineBegin + strlen(lineBegin)) … … 187 203 188 204 this->addVar(lineBegin, valueBegin); 205 this->setEntryComment(); 189 206 190 207 lineCount++; … … 234 251 void IniParser::setFileComment(const char* fileComment) 235 252 { 236 253 if (this->comment != NULL) 254 delete this->comment; 255 256 if (fileComment != NULL) 257 { 258 this->comment = new char[strlen(fileComment)+1]; 259 strcpy(this->comment, fileComment); 260 } 261 else 262 this->comment = NULL; 237 263 } 238 264 … … 247 273 { 248 274 this->sections.push_back(IniSection()); 249 275 this->sections.back().comment = NULL; 250 276 this->sections.back().name = new char[strlen(sectionName)+1]; 251 277 strcpy(this->sections.back().name, sectionName); … … 355 381 { 356 382 (*section).entries.push_back(IniEntry()); 383 (*section).entries.back().comment = NULL; 357 384 (*section).entries.back().name = new char[strlen(entryName)+1]; 358 385 strcpy((*section).entries.back().name, entryName); … … 363 390 (*section).entries.back().value, 364 391 (*section).name); 392 this->currentEntry = --(*section).entries.end(); 365 393 return true; 366 394 } … … 520 548 521 549 550 void IniParser::setFileComment() 551 { 552 if (this->comment != NULL) 553 delete[] this->comment; 554 555 if (this->commentList.empty()) { 556 this->comment = NULL; 557 return; 558 } 559 560 unsigned int stringLength = 1; 561 std::list<char*>::iterator comment; 562 for (comment = this->commentList.begin(); comment != this->commentList.end(); comment++) 563 stringLength += strlen((*comment)) +1; 564 565 this->comment = new char[stringLength]; 566 this->comment[0] = '\0'; 567 while (!this->commentList.empty()) 568 { 569 if (*this->comment != '\0') 570 strcat(this->comment, "\n"); 571 strcat(this->comment, this->commentList.front()); 572 delete[] this->commentList.front(); 573 this->commentList.pop_front(); 574 printf("this->comment:: %s\n", this->comment); 575 } 576 } 577 578 void IniParser::setSectionComment() 579 { 580 if ((*this->currentSection).comment != NULL) 581 delete[] (*this->currentSection).comment; 582 583 if (this->commentList.empty()) { 584 (*this->currentSection).comment = NULL; 585 return; 586 } 587 588 unsigned int stringLength = 1; 589 std::list<char*>::iterator comment; 590 for (comment = this->commentList.begin(); comment != this->commentList.end(); comment++) 591 stringLength += strlen((*comment)) +1; 592 593 (*this->currentSection).comment = new char[stringLength]; 594 (*this->currentSection).comment[0] = '\0'; 595 while (!this->commentList.empty()) 596 { 597 if (*(*this->currentSection).comment != '\0') 598 strcat((*this->currentSection).comment, "\n"); 599 strcat((*this->currentSection).comment, this->commentList.front()); 600 delete[] this->commentList.front(); 601 this->commentList.pop_front(); 602 printf("this->comment:: %s", (*this->currentSection).comment); 603 } 604 } 605 606 void IniParser::setEntryComment() 607 { 608 if ((*this->currentEntry).comment != NULL) 609 delete[] (*this->currentEntry).comment; 610 611 if (this->commentList.empty()) { 612 (*this->currentEntry).comment = NULL; 613 return; 614 } 615 616 unsigned int stringLength = 1; 617 std::list<char*>::iterator comment; 618 for (comment = this->commentList.begin(); comment != this->commentList.end(); comment++) 619 stringLength += strlen((*comment)) +1; 620 621 (*this->currentEntry).comment = new char[stringLength]; 622 (*this->currentEntry).comment[0] = '\0'; 623 while (!this->commentList.empty()) 624 { 625 if (*(*this->currentEntry).comment != '\0') 626 strcat((*this->currentEntry).comment, "\n"); 627 strcat((*this->currentEntry).comment, this->commentList.front()); 628 delete[] this->commentList.front(); 629 this->commentList.pop_front(); 630 printf("=======this->comment:: %s\n", (*this->currentEntry).comment); 631 } 632 633 } 634 635 522 636 /** 523 637 * @brief output the whole tree in a nice and easy way. … … 526 640 { 527 641 PRINTF(0)("Iniparser %s - debug\n", this->fileName); 642 if (this->comment != NULL) 643 PRINTF(0)("FileComment:\n %s\n\n", this->comment); 644 528 645 if (this->fileName != NULL) 529 646 { … … 531 648 for (section = this->sections.begin(); section != this->sections.end(); section++) 532 649 { 650 if ((*section).comment != NULL) 651 PRINTF(0)(" %s\n", (*section).comment); 533 652 PRINTF(0)(" [%s]\n", (*section).name); 534 653 535 654 std::list<IniEntry>::const_iterator entry; 536 655 for (entry = (*section).entries.begin(); entry != (*section).entries.end(); entry++) 656 { 657 if ((*entry).comment != NULL) 658 PRINTF(0)(" %s\n", (*entry).comment); 537 659 PRINTF(0)(" '%s' -> '%s'\n", (*entry).name, (*entry).value); 660 } 538 661 } 539 662 } … … 542 665 } 543 666 544 -
trunk/src/lib/parser/ini_parser/ini_parser.h
r5945 r5946 90 90 void setFileName(const char* fileName); 91 91 92 void setFileComment(); 93 void setSectionComment(); 94 void setEntryComment(); 95 92 96 std::list<IniSection>::const_iterator getSectionIT(const char* sectionName) const; 93 97 std::list<IniEntry>::const_iterator getEntryIT(const char* entryName, const char* sectionName = NULL) const;
Note: See TracChangeset
for help on using the changeset viewer.