Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5021 in orxonox.OLD for orxonox/trunk/src/lib


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

orxonox/trunk: writing, loading, and comments work

Location:
orxonox/trunk/src/lib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/lib/gui/gui_exec.cc

    r5016 r5021  
    202202void GuiExec::writeToFile(Widget* widget)
    203203{
    204   this->CONFIG_FILE = fopen(this->confFile, "w");
    205   if(this->CONFIG_FILE)
    206     this->writeFileText(widget, 0);
    207   fclose(this->CONFIG_FILE);
     204  IniParser iniParser;
     205  this->writeFileText(widget, &iniParser, 0);
     206  char* fileName = ResourceManager::homeDirCheck(confFile);
     207  iniParser.writeFile(fileName);
     208  delete fileName;
    208209}
    209210
     
    211212 *  Actually writes into the configuration file to the disk.
    212213 * @param widget from which Widget on should be saved.
     214 * @param parser the IniParser to write to.
    213215 * @param depth initially "0", and grows higher, while new Groups are bundeled.
    214216*/
    215 void GuiExec::writeFileText(Widget* widget, int depth)
    216 {
    217   int counter = 0;
    218   while(counter < depth &&((widget->optionType > GUI_NOTHING
    219                               &&(static_cast<Option*>(widget)->isSaveable()))
    220                              ||(widget->optionType < GUI_NOTHING
    221                                 && static_cast<Packer*>(widget)->getGroupName())))
    222     {
    223       fprintf(this->CONFIG_FILE, "  ", depth);
    224       counter++;
    225     }
     217void GuiExec::writeFileText(Widget* widget, IniParser* parser, int depth)
     218{
     219//   int counter = 0;
     220//   while(counter < depth &&((widget->optionType > GUI_NOTHING
     221//                               &&(static_cast<Option*>(widget)->isSaveable()))
     222//                              ||(widget->optionType < GUI_NOTHING
     223//                                 && static_cast<Packer*>(widget)->getGroupName())))
     224//     {
     225//       fprintf(this->CONFIG_FILE, "  ", depth);
     226//       counter++;
     227//     }
    226228
    227229  // check if it is a Packer, and if it is, check if it has a name and if there is something in it.
     
    230232      if(static_cast<Packer*>(widget)->getGroupName())
    231233        {
    232           fprintf(CONFIG_FILE, "[%s]\n", static_cast<Packer*>(widget)->getGroupName());
    233           this->writeFileText(static_cast<Packer*>(widget)->down, depth+1);
    234           fprintf(CONFIG_FILE, "\n");
     234          parser->addSection(static_cast<Packer*>(widget)->getGroupName());
     235          this->writeFileText(static_cast<Packer*>(widget)->down, parser, depth+1);
    235236        }
    236237      else
    237238        {
    238           this->writeFileText(static_cast<Packer*>(widget)->down, depth);
     239          this->writeFileText(static_cast<Packer*>(widget)->down, parser, depth);
    239240        }
    240241    }
     
    242243  if(widget->optionType > GUI_NOTHING)
    243244    if (static_cast<Option*>(widget)->isSaveable())
    244       fprintf(CONFIG_FILE, "%s = %s\n", static_cast<Option*>(widget)->title, static_cast<Option*>(widget)->save());
     245      parser->addVar(static_cast<Option*>(widget)->title, static_cast<Option*>(widget)->save());
    245246
    246247  if(widget->next != NULL)
    247     this->writeFileText(widget->next, depth);
     248    this->writeFileText(widget->next, parser, depth);
    248249}
    249250
  • orxonox/trunk/src/lib/gui/gui_exec.h

    r5015 r5021  
    1414class CheckButton;
    1515using namespace std;
     16class IniParser;
    1617
    1718//! Class that creates the execute-Options.
     
    4142  int shouldsave();
    4243  void writeToFile(Widget* widget);
    43   void writeFileText(Widget* widget, int depth);
     44  void writeFileText(Widget* widget, IniParser* parser, int depth);
    4445  void readFromFile(Widget* widget);
    4546  static void readFileText(Widget* widget, void* varInfo);
  • 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.