Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5021 in orxonox.OLD for orxonox/trunk/src/lib/util/ini_parser.cc


Ignore:
Timestamp:
Aug 15, 2005, 12:10:07 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: writing, loading, and comments work

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/lib/util/ini_parser.cc

    r5020 r5021  
    116116    char lineBuffer[PARSELINELENGHT];
    117117    char buffer[PARSELINELENGHT];
     118    const char* lineBegin;
    118119    char* ptr;
    119120
     
    122123      // get next line
    123124      fgets (lineBuffer, PARSELINELENGHT, stream);
     125      lineBegin = lineBuffer;
    124126      // remove newline char, and \0-terminate
    125127      if( (ptr = strchr( lineBuffer, '\n')) != NULL)
    126128        *ptr = 0;
     129      // cut up to the beginning of the line.
     130      while((*lineBegin == ' ' || *lineBegin == '\t') && lineBegin < lineBuffer + strlen(lineBuffer))
     131        ++lineBegin;
     132      if (strlen(lineBegin) <= 1 || *lineBegin == '#' || *lineBegin == ';')
     133        continue;//printf("empty Line\n");
    127134      // check for section identifyer
    128       if (strlen(lineBuffer) <= 1)
    129         ;//printf("empty Line\n");
    130       else if( sscanf (lineBuffer, "[%s", buffer) == 1)
     135      else if( sscanf (lineBegin, "[%s", buffer) == 1)
    131136      {
    132137        if( (ptr = strchr( buffer, ']')) != NULL)
     
    137142      }
    138143      // check for Entry identifier (Entry = Value)
    139       else if( (ptr = strchr( lineBuffer, '=')) != NULL)
     144      else if( (ptr = strchr( lineBegin, '=')) != NULL)
    140145      {
    141146        if (currentSection == NULL)
    142147        {
    143           PRINTF(2)("Not in a Section yet for %s\n", lineBuffer);
     148          PRINTF(2)("Not in a Section yet for %s\n", lineBegin);
    144149          continue;
    145150        }
    146         if( ptr == lineBuffer)
     151        if( ptr == lineBegin)
    147152          continue;
    148153        char* valueBegin = ptr+1;
    149         while ((*valueBegin == ' ' || *valueBegin == '\t') && valueBegin <= lineBuffer + strlen(lineBuffer))
     154        while ((*valueBegin == ' ' || *valueBegin == '\t') && valueBegin <= lineBegin + strlen(lineBegin))
    150155          ++valueBegin;
    151         char* nameBegin = lineBuffer;
    152         while ((*nameBegin == ' ' || *nameBegin == '\t') && nameBegin < ptr)
    153           ++nameBegin;
    154156        char* nameEnd = ptr-1;
    155         while ((*nameEnd == ' ' || *nameEnd == '\t' ) && nameEnd >= nameBegin)
     157        while ((*nameEnd == ' ' || *nameEnd == '\t' ) && nameEnd >= lineBegin)
    156158          --nameEnd;
    157159        nameEnd[1] = '\0';
    158160
    159         this->addVar(nameBegin, valueBegin);
     161        this->addVar(lineBegin, valueBegin);
    160162      }
    161163    }
     
    173175{
    174176  FILE*    stream;           //!< The stream we use to read the file.
    175   if (sections != NULL)
    176     deleteSections();
    177177  if( fileName == NULL)
    178178    return false;
     
    191191      while (sectionEnum)
    192192      {
    193         fprintf(stream, " [%s]\n", sectionEnum->name);
     193        fprintf(stream, "\n [%s]\n", sectionEnum->name);
    194194
    195195        tIterator<IniEntry>* entryIt = sectionEnum->entries->getIterator();
     
    197197        while (entryEnum)
    198198        {
    199           fprintf(stream, " %s = %s\n", entryEnum->name, entryEnum->value);
     199          fprintf(stream, "   %s = %s\n", entryEnum->name, entryEnum->value);
    200200
    201201          entryEnum = entryIt->nextElement();
     
    213213}
    214214
     215/**
     216 * adds a section to the list of Sections,
     217 * if no Section list is availiable, it will create it
     218 * @param sectionName the Name of the section to add
     219 * @return true on success... there is only success or segfault :)
     220 */
    215221bool IniParser::addSection(const char* sectionName)
    216222{
     
    224230  this->currentSection = newSection;
    225231  this->sections->add(newSection);
     232  PRINTF(0)("Added Section %s\n", sectionName);
     233  return true;
    226234}
    227235
Note: See TracChangeset for help on using the changeset viewer.