Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5946 in orxonox.OLD for trunk/src


Ignore:
Timestamp:
Dec 7, 2005, 12:46:43 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: adding comments (simple)

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  
    144144    while( fgets (lineBuffer, PARSELINELENGHT, stream))
    145145    {
    146 //      if (lineCount == 0)
    147 
    148146      lineBegin = lineBuffer;
    149147      // remove newline char, and \0-terminate
     
    153151      while((*lineBegin == ' ' || *lineBegin == '\t') && lineBegin < lineBuffer + strlen(lineBuffer))
    154152        ++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
    157169      // check for section identifyer
    158170      else if( sscanf (lineBegin, "[%s", buffer) == 1)
     
    162174          *ptr = 0;
    163175          this->addSection(buffer);
     176          this->setSectionComment();
    164177        }
    165178      }
     
    170183        {
    171184          PRINTF(2)("Not in a Section yet for %s\n", lineBegin);
     185          lineCount++;
    172186          continue;
    173187        }
    174         if( ptr == lineBegin)
     188        if( ptr == lineBegin) {
     189          lineCount++;
    175190          continue;
     191        }
    176192        char* valueBegin = ptr+1;
    177193        while ((*valueBegin == ' ' || *valueBegin == '\t') && valueBegin <= lineBegin + strlen(lineBegin))
     
    187203
    188204        this->addVar(lineBegin, valueBegin);
     205        this->setEntryComment();
    189206
    190207        lineCount++;
     
    234251void IniParser::setFileComment(const char* fileComment)
    235252{
    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;
    237263}
    238264
     
    247273{
    248274  this->sections.push_back(IniSection());
    249 
     275  this->sections.back().comment = NULL;
    250276  this->sections.back().name = new char[strlen(sectionName)+1];
    251277  strcpy(this->sections.back().name, sectionName);
     
    355381  {
    356382    (*section).entries.push_back(IniEntry());
     383    (*section).entries.back().comment = NULL;
    357384    (*section).entries.back().name = new char[strlen(entryName)+1];
    358385    strcpy((*section).entries.back().name, entryName);
     
    363390              (*section).entries.back().value,
    364391              (*section).name);
     392    this->currentEntry = --(*section).entries.end();
    365393    return true;
    366394  }
     
    520548
    521549
     550void 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
     578void 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
     606void 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
    522636/**
    523637 * @brief output the whole tree in a nice and easy way.
     
    526640{
    527641  PRINTF(0)("Iniparser %s - debug\n", this->fileName);
     642  if (this->comment != NULL)
     643    PRINTF(0)("FileComment:\n %s\n\n", this->comment);
     644
    528645  if (this->fileName != NULL)
    529646  {
     
    531648    for (section = this->sections.begin(); section != this->sections.end(); section++)
    532649    {
     650      if ((*section).comment != NULL)
     651        PRINTF(0)(" %s\n", (*section).comment);
    533652      PRINTF(0)(" [%s]\n", (*section).name);
    534653
    535654      std::list<IniEntry>::const_iterator entry;
    536655      for (entry = (*section).entries.begin(); entry != (*section).entries.end(); entry++)
     656      {
     657        if ((*entry).comment != NULL)
     658          PRINTF(0)(" %s\n", (*entry).comment);
    537659        PRINTF(0)("   '%s' -> '%s'\n", (*entry).name, (*entry).value);
     660      }
    538661    }
    539662  }
     
    542665}
    543666
    544 
  • trunk/src/lib/parser/ini_parser/ini_parser.h

    r5945 r5946  
    9090    void setFileName(const char* fileName);
    9191
     92    void setFileComment();
     93    void setSectionComment();
     94    void setEntryComment();
     95
    9296    std::list<IniSection>::const_iterator getSectionIT(const char* sectionName) const;
    9397    std::list<IniEntry>::const_iterator getEntryIT(const char* entryName, const char* sectionName = NULL) const;
Note: See TracChangeset for help on using the changeset viewer.