Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5936 in orxonox.OLD


Ignore:
Timestamp:
Dec 6, 2005, 2:12:18 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: some fixes, but still some strange seg-faults in the IniParser/GuiExec-combination :(

Location:
trunk/src/lib
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/event/key_mapper.cc

    r5915 r5936  
    132132  int* index;
    133133
    134   iniParser->getFirstVar();
     134  iniParser->firstVar();
    135135  while(iniParser->getCurrentName())
    136136  {
     
    151151  }
    152152
    153   iniParser->getFirstVar();
     153  iniParser->firstVar();
    154154  while(iniParser->getCurrentName())
    155155  {
  • trunk/src/lib/gui/gtk_gui/gui_exec.cc

    r5241 r5936  
    254254
    255255/**
    256  * Reads in Configuration Data.
     256 * @brief Reads in Configuration Data.
    257257 * @param widget from which Widget on should be saved.
    258258*/
     
    265265    return;
    266266
    267   iniParser.getFirstSection();
     267  iniParser.firstSection();
    268268  Widget* groupWidget = widget;
    269269  const char* groupName;
     
    272272  while (groupName = iniParser.getCurrentSection())
    273273  {
     274    printf("GROUP:::%s\n", groupName);
    274275    if((groupWidget = locateGroup(widget, groupName, 1))==NULL)
    275276    {
     
    281282      PRINT(0)("Group %s located.\n", static_cast<Packer*>(groupWidget)->groupName);
    282283
    283     iniParser.getFirstVar();
    284     while(iniParser.getCurrentName())
    285     {
    286       varInfo.variableName = iniParser.getCurrentName();
     284    const char* entryName;
     285    iniParser.firstVar();
     286    while(entryName = iniParser.getCurrentName())
     287    {
     288      printf("ENTRY:::%s = %s\n", entryName, iniParser.getCurrentValue());
     289      varInfo.variableName = entryName;
    287290      varInfo.variableValue = iniParser.getCurrentValue();
    288291      groupWidget->walkThrough(this->readFileText, &varInfo, 0);
  • trunk/src/lib/util/ini_parser.cc

    r5935 r5936  
    6363  while(!this->sections.empty())
    6464  {
    65    
    66     IniSection section = this->sections.front();
     65     IniSection section = this->sections.front();
    6766   
    6867    // in all entries of the sections
     
    7978    this->sections.pop_front();
    8079  }
     80  this->currentSection = this->sections.end();
    8181  this->setFileName(NULL);
    8282}
     
    196196 * @return true on success false otherwise
    197197 */
    198 bool IniParser::writeFile(const char* fileName)
     198bool IniParser::writeFile(const char* fileName) const
    199199{
    200200  FILE*    stream;           //!< The stream we use to read the file.
     
    209209  else
    210210  {
    211     std::list<IniSection>::iterator section;
     211    std::list<IniSection>::const_iterator section;
    212212    for (section = this->sections.begin(); section != this->sections.end(); section++)
    213213      {
    214214        fprintf(stream, "\n [%s]\n", (*section).name);
    215215       
    216         std::list<IniEntry>::iterator entry;
     216        std::list<IniEntry>::const_iterator entry;
    217217        for (entry = (*section).entries.begin(); entry != (*section).entries.end(); entry++)
    218218          fprintf(stream, "   %s = %s\n", (*entry).name, (*entry).value);
     
    238238  this->currentSection = --this->sections.end();
    239239  if (!this->sections.empty())
    240     this->currentEntry = (*this->currentSection).entries.begin();
     240      this->currentEntry = (*this->currentSection).entries.begin();
    241241  PRINTF(5)("Added Section %s\n", sectionName);
    242242  return true;
     
    248248 * @param sectionName: the name of the section to set the cursor to
    249249 * @return true on success or false if the section could not be found
    250 */
    251 bool IniParser::getSection( const char* sectionName)
     250 */
     251bool IniParser::getSection(const char* sectionName)
    252252{
    253253  std::list<IniSection>::iterator section;
     
    259259        return true;
    260260      }
    261 
    262261  return false;
    263262}
     
    267266 * @brief moves to the first section
    268267 */
    269 void IniParser::getFirstSection()
     268void IniParser::firstSection()
    270269{
    271270  this->currentSection = this->sections.begin();
     
    283282  if (this->currentSection == this->sections.end())
    284283    return NULL;
    285   else
    286   {
    287     this->currentSection++;
    288   }
    289     if (this->currentSection == this->sections.end())
    290       return NULL;
     284
     285  this->currentSection++;
    291286
    292287  if (this->currentSection != this->sections.end())
     
    303298 * @brief moves to the first Variable of the current Section
    304299 */
    305 void IniParser::getFirstVar()
    306 {
    307   if (this->currentSection != this->sections.end())
     300void IniParser::firstVar()
     301{
     302  if (!this->sections.empty() &&
     303      this->currentSection != this->sections.end())
    308304    this->currentEntry = (*this->currentSection).entries.begin();
    309305}
     
    342338{
    343339  std::list<IniSection>::iterator section;
    344 
     340 
    345341  if (sectionName != NULL)
    346342  {
     
    351347  else
    352348    section = this->currentSection;
     349  if (section == this->sections.end())
     350    return false;
    353351
    354352  if (section == this->sections.end())
     
    364362    (*section).entries.back().value = new char[strlen(value)+1];
    365363    strcpy((*section).entries.back().value, value);
    366     PRINTF(5)("Added Entry %s with Value '%s' to Section %s\n", entryName, value, (*section).name);
     364    PRINTF(5)("Added Entry %s with Value '%s' to Section %s\n",
     365              (*section).entries.back().name,
     366              (*section).entries.back().value,
     367              (*section).name);
    367368    return true;
    368369  }
     
    387388    if (sectionName != NULL)
    388389      {
    389 
    390390        for (section = this->sections.begin(); section != this->sections.end(); section++)
    391391          {
     
    399399    else
    400400      section = this->currentSection;
     401   
     402   if (section == this->sections.end())
     403     return (defaultValue);
    401404
    402405    std::list<IniEntry>::const_iterator entry;
     
    420423const char* IniParser::getCurrentSection() const
    421424{
    422  return (this->currentSection!=NULL) ?
    423    this->currentSection->name :
    424    NULL;
     425  if (!this->sections.empty() &&
     426      this->currentSection != this->sections.end())
     427    return this->currentSection->name;
     428  else
     429    return NULL;
    425430 }
    426431
     
    432437{
    433438 if (!this->sections.empty() &&
     439     this->currentSection != this->sections.end() &&
    434440     this->currentEntry != (*this->currentSection).entries.end())
    435441   return (*this->currentEntry).name;
     
    443449const char* IniParser::getCurrentValue() const
    444450{
    445   if (!this->sections.empty()
    446       && this->currentEntry != (*this->currentSection).entries.end())
     451  if (!this->sections.empty() &&
     452      this->currentSection != this->sections.end() &&
     453      this->currentEntry != (*this->currentSection).entries.end())
    447454    return (*this->currentEntry).value;
    448455  else
  • trunk/src/lib/util/ini_parser.h

    r5935 r5936  
    4343
    4444    bool readFile(const char* fileName);
    45     bool writeFile(const char* fileName);
     45    bool writeFile(const char* fileName) const;
    4646
    4747    bool addSection(const char* sectionName);
     
    5151    bool isOpen() const { return (this->fileName != NULL)? true : false; };
    5252
    53     void getFirstSection();
     53    void firstSection();
    5454    const char* nextSection();
    5555
     
    6060    const char* getVar(const char* entryName, const char* sectionName, const char* defaultValue = "") const;
    6161
    62     void getFirstVar();
     62    void firstVar();
    6363    bool nextVar();
    6464
Note: See TracChangeset for help on using the changeset viewer.