Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5015 in orxonox.OLD for orxonox


Ignore:
Timestamp:
Aug 14, 2005, 5:25:53 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: robust IniParser

Location:
orxonox/trunk/src
Files:
8 edited

Legend:

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

    r5014 r5015  
    128128  int* index;
    129129
    130   while(iniParser->nextVar())
     130  iniParser->getFirstVar();
     131  while(iniParser->getCurrentName())
    131132  {
    132133    PRINTF(3)("Keys: Parsing %s, %s now.\n", iniParser->getCurrentName(), iniParser->getCurrentValue());
    133134    index = nameToIndex (iniParser->getCurrentValue());
    134135    this->mapKeys(iniParser->getCurrentName(), index[1]);
     136    iniParser->nextVar();
    135137  }
    136138
     
    143145  }
    144146
    145   while( iniParser->nextVar())
     147  iniParser->getFirstVar();
     148  while(iniParser->getCurrentName())
    146149  {
    147150    PRINTF(3)("MISC: Parsing %s, %s now.\n", iniParser->getCurrentName(), iniParser->getCurrentValue());
    148151    index = nameToIndex (iniParser->getCurrentValue());
    149152    this->mapKeys(iniParser->getCurrentName(), index[1]);
     153    iniParser->nextVar();
    150154  }
    151155}
  • orxonox/trunk/src/lib/gui/gui_exec.cc

    r5014 r5015  
    265265void GuiExec::readFromFile(Widget* widget)
    266266{
    267   IniParser iniParser(this->confFile);
     267
     268  char* fileName = ResourceManager::homeDirCheck(confFile);
     269  IniParser iniParser(fileName);
     270  delete fileName;
    268271  if (!iniParser.isOpen())
    269272    return;
    270273
    271 //   const char* name;
    272 //   while (name = iniParser.nextSection())
    273 //     printf("%s\n", name);
     274  iniParser.getFirstSection();
     275  Widget* groupWidget = widget;
     276  const char* groupName;
     277  const char* widgetName;
     278  VarInfo varInfo;
     279  while (groupName = iniParser.getCurrentSection())
     280  {
     281    if((groupWidget = locateGroup(widget, groupName, 1))==NULL)
     282    {
     283      PRINTF(2)("!!There is no group called %s in this GUI.\n First best Widget will get the Infos assigned.\n Config-File will be updated in next Save\n", groupName);
     284      groupWidget = widget;
     285      continue;
     286    }
     287    else
     288      PRINT(0)("Group %s located.\n", static_cast<Packer*>(groupWidget)->groupName);
     289
     290    iniParser.getFirstVar();
     291    while(iniParser.getCurrentName())
     292    {
     293      varInfo.variableName = iniParser.getCurrentName();
     294      varInfo.variableValue = iniParser.getCurrentValue();
     295      groupWidget->walkThrough(this->readFileText, &varInfo, 0);
     296      iniParser.nextVar();
     297    }
     298
     299    iniParser.nextSection();
     300  }
     301  widget->walkThrough(widget->setOptions, 0);
     302
    274303//
    275304//
     
    342371   @todo do this in gui-gtk.
    343372*/
    344 Widget* GuiExec::locateGroup(Widget* widget, char* groupName, int depth)
     373Widget* GuiExec::locateGroup(Widget* widget, const char* groupName, int depth)
    345374{
    346375  Widget* tmp;
    347 
    348   // removes the trailing and ending [ ].
    349   if(!strncmp(groupName, "[", 1))
    350     {
    351       groupName = groupName+1;
    352       groupName[strlen(groupName)-1] = '\0';
    353     }
    354376
    355377  if(widget->optionType < GUI_NOTHING)
  • orxonox/trunk/src/lib/gui/gui_exec.h

    r4746 r5015  
    2828  struct VarInfo
    2929  {
    30     char* variableName;        //!< The Name of this variable;
    31     char* variableValue;      //!< The Value this variable gets.
     30    const char* variableName;  //!< The Name of this variable;
     31    const char* variableValue; //!< The Value this variable gets.
    3232  };
    3333
     
    3535  GuiExec();
    3636  ~GuiExec();
    37  
     37
    3838  void setConfDir(const char* confDir);
    3939  void setConfFile(const char* confFile);
     
    4444  void readFromFile(Widget* widget);
    4545  static void readFileText(Widget* widget, void* varInfo);
    46   Widget* locateGroup(Widget* widget, char* groupName, int depth);
     46  Widget* locateGroup(Widget* widget, const char* groupName, int depth);
    4747
    4848#ifdef HAVE_GTK2
     
    5555};
    5656
    57 //! A simple hashtable 
     57//! A simple hashtable
    5858struct HashTable
    5959{
  • orxonox/trunk/src/lib/gui/gui_gtk.cc

    r4836 r5015  
    1 /* 
     1/*
    22   orxonox - the future of 3D-vertical-scrollers
    33
     
    1616   You should have received a copy of the GNU General Public License
    1717   along with this program; if not, write to the Free Software Foundation,
    18    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
     18   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    1919
    2020
     
    8282      PRINT(0)("  #############################\n");
    8383      Window::mainWindow->walkThrough(Widget::listOptionsAndGroups, 1);
    84      
     84
    8585      PRINT(0)("\nDo you want change any of the above values now? [Yn] ");
    8686      scanf("%s", ans);
    8787      if (ans[0] =='n' || ans[0]=='N')
    88         break;
    89      
     88        break;
     89
    9090      PRINT(0)("\n Listing all groups\n");
    9191      PRINT(0)("  #################\n");
    9292      int groupCount = 0;
    9393      Window::mainWindow->walkThrough(Widget::listGroups, &groupCount, 1);
    94      
     94
    9595      PRINT(0)("\nIn which Group? [1-%d] ", groupCount);
    9696      Packer* group;
    9797      while(true)
    98         {
    99           scanf("%s", ans);
    100           int ansIp = atoi(ans);
    101           if (ansIp <= groupCount)
    102             {
    103               group = static_cast<Packer*>(Window::mainWindow->findGroupByNumber(&ansIp, 1));
    104               break;
    105             }
    106           else
    107             PRINT(0)("\nChoose a smaller Number please: [1-%d] ", groupCount);
    108         }
     98        {
     99          scanf("%s", ans);
     100          int ansIp = atoi(ans);
     101          if (ansIp <= groupCount)
     102            {
     103              group = static_cast<Packer*>(Window::mainWindow->findGroupByNumber(&ansIp, 1));
     104              break;
     105            }
     106          else
     107            PRINT(0)("\nChoose a smaller Number please: [1-%d] ", groupCount);
     108        }
    109109      PRINT(0)("\n\nGroup: [%s]\n\n", group->groupName);
    110110      int optionCount = 0;
     
    113113      Option* option;
    114114      while(true)
    115         {
    116           scanf("%s", ans);
    117           int ansIp = atoi(ans);
    118           if (ansIp <= groupCount)
    119             {
    120               option = static_cast<Option*>(group->findOptionByNumber(&ansIp, 0));
    121               break;
    122             }
    123           else
    124             PRINT(0)("\nChoose a smaler Number please: [1-%d] ", optionCount);
    125         }
     115        {
     116          scanf("%s", ans);
     117          int ansIp = atoi(ans);
     118          if (ansIp <= groupCount)
     119            {
     120              option = static_cast<Option*>(group->findOptionByNumber(&ansIp, 0));
     121              break;
     122            }
     123          else
     124            PRINT(0)("\nChoose a smaler Number please: [1-%d] ", optionCount);
     125        }
    126126      PRINT(0)("\n\n:: %s ::\n", option->title);
    127127      option->changeOption();
    128      
     128
    129129      // here follows the rest.... this will be nasty.
    130130      //! @todo finish it.
     
    132132    }
    133133#endif /* HAVE_GTK2 */
    134  
     134
    135135}
    136136
     
    162162      delete []this->title;
    163163    }
    164  
     164
    165165  PRINTF(5)("deleting the Widget part.\n");
    166166
     
    232232      Widget* tmp = static_cast<Packer*>(this)->down->findWidgetByName(name, depth+1);
    233233      if (tmp)
    234         return tmp;
    235     }
    236  
     234        return tmp;
     235    }
     236
    237237  if (depth>0 && this->next)
    238238    return this->next->findWidgetByName(name, depth);
     
    243243/**
    244244 *  Moves through all the Widgets downwards from this and executes the function on them.
    245  * @param function must be of type void and takes a Widget* as an Input. 
     245 * @param function must be of type void and takes a Widget* as an Input.
    246246 * @param depth the current depth. if > 0 then the next Widget will also be walked through.
    247247*/
     
    252252    {
    253253      static_cast<Packer*>(this)->down->walkThrough(function, depth+1);
    254     } 
     254    }
    255255
    256256  if (this->next && depth != 0)
     
    275275}
    276276
    277 /** 
     277/**
    278278  *  This is for listing the options of "widget"
    279279  * @param widget specifies the widget that should be listed
     
    289289}
    290290
    291 /** 
     291/**
    292292  *  This is for listing the options of "widget"
    293293  * @param widget specifies the widget that should be listed
     
    299299}
    300300
    301 /** 
     301/**
    302302  *  This is for listing the options of "widget"
    303303  * @param widget specifies the widget that should be listed
     
    306306void Widget::listOptions(Widget* widget, void* data)
    307307{
    308  
     308
    309309  if (widget->optionType > GUI_NOTHING)
    310310    {
     
    312312      *count = *count +1;
    313313      PRINT(0)(" %d:%s is %s\n", *count,
    314                static_cast<Option*>(widget)->title,
    315                static_cast<Option*>(widget)->save());
    316     }
    317 }
    318 
    319 /** 
     314               static_cast<Option*>(widget)->title,
     315               static_cast<Option*>(widget)->save());
     316    }
     317}
     318
     319/**
    320320  *  This is for listing the options of "widget"
    321321  * @param widget specifies the widget that should be listed
     
    330330      Option* option = (Option*)widget;
    331331      if (option->flagName || option->flagNameShort)
    332         {
    333           PRINT(0)("  ");
    334           if (option->flagNameShort)
    335             {
    336               PRINT(0)("-%s", option->flagNameShort);
    337               helpLen += strlen(option->flagNameShort)+1;
    338             }
    339           if (option->flagName)
    340             {
    341               if (helpLen > 0)
    342                 {
    343                   PRINT(0)("|");
    344                   helpLen++;
    345                 }
    346               PRINT(0)("--%s:", option->flagName);
    347               helpLen += strlen(option->flagName)+2;
    348             }
    349           while ((helpLen ++) < 29)
    350             PRINT(0)(" ");
    351           if (option->shortDescription)
    352             PRINT(0)("%s\n", option->shortDescription);
    353           else
    354             PRINT(0)("\n");
    355         }
    356     }
    357 }
    358 
    359 /** 
     332        {
     333          PRINT(0)("  ");
     334          if (option->flagNameShort)
     335            {
     336              PRINT(0)("-%s", option->flagNameShort);
     337              helpLen += strlen(option->flagNameShort)+1;
     338            }
     339          if (option->flagName)
     340            {
     341              if (helpLen > 0)
     342                {
     343                  PRINT(0)("|");
     344                  helpLen++;
     345                }
     346              PRINT(0)("--%s:", option->flagName);
     347              helpLen += strlen(option->flagName)+2;
     348            }
     349          while ((helpLen ++) < 29)
     350            PRINT(0)(" ");
     351          if (option->shortDescription)
     352            PRINT(0)("%s\n", option->shortDescription);
     353          else
     354            PRINT(0)("\n");
     355        }
     356    }
     357}
     358
     359/**
    360360  *  Finds an Option by a given number(the n'th option found away from this Widget)
    361361  * @param number The Count of options to wait(by reference)
    362362  * @param depth The depth of the sarch. if 0 it will not search next pointer
    363    
     363
    364364    @todo should return Option* would be much sexier.
    365365*/
     
    370370      --*number;
    371371      if (*number <= 0)
    372         {
    373           return this;
    374         }
     372        {
     373          return this;
     374        }
    375375    }
    376376  if (this->optionType < GUI_NOTHING && static_cast<Packer*>(this)->down)
     
    378378      Widget* tmp = static_cast<Packer*>(this)->down->findOptionByNumber(number, depth+1);
    379379      if (tmp)
    380         return tmp;
     380        return tmp;
    381381    }
    382382  if (depth>0 && this->next)
     
    386386}
    387387
    388 /** 
     388/**
    389389  *  This is for listing the groups of "widget"
    390390  * @param widget specifies the widget that should be listed
     
    396396}
    397397
    398 /** 
     398/**
    399399  *  This is for listing the Groups of "widget". It also displays the n'th number found.
    400400  * @param widget specifies the widget that should be listed
     
    408408}
    409409
    410 /** 
     410/**
    411411  *  Finds a Group by a given number(the n'th Group found away from this Widget)
    412412  * @param number The Count of options to wait(by reference)
     
    419419      --*number;
    420420      if (*number <= 0)
    421         {
    422           return this;
    423         }
     421        {
     422          return this;
     423        }
    424424    }
    425425  if (this->optionType < GUI_NOTHING && static_cast<Packer*>(this)->down)
     
    427427      Widget* tmp = static_cast<Packer*>(this)->down->findGroupByNumber(number, depth+1);
    428428      if (tmp)
    429         return tmp;
     429        return tmp;
    430430    }
    431431  if (depth>0 && this->next)
     
    462462{
    463463  if (widget->optionType > GUI_NOTHING)
    464     {     
     464    {
    465465      Option* option =(Option*)widget;
    466466      char* name =(char*)flagName;
     
    469469      // check if long flag matches
    470470      if ((option->flagName && strlen(name) > 2 &&
    471            !strncmp(name+2, option->flagName, strlen(option->flagName)) &&
    472            (name[strlen(option->flagName)+2] == '\0' || name[strlen(option->flagName)+2] == '=') ))
    473         {
    474           found = true;
    475           if (name[strlen(option->flagName)+2] == '=')
    476             {
    477               value = name+strlen(option->flagName)+3;
    478             }
    479         }
     471           !strncmp(name+2, option->flagName, strlen(option->flagName)) &&
     472           (name[strlen(option->flagName)+2] == '\0' || name[strlen(option->flagName)+2] == '=') ))
     473        {
     474          found = true;
     475          if (name[strlen(option->flagName)+2] == '=')
     476            {
     477              value = name+strlen(option->flagName)+3;
     478            }
     479        }
    480480      // check if short flag matches
    481481      else if (option->flagNameShort && strlen(name)>1 &&
    482                !strncmp(name+1, option->flagNameShort, strlen(option->flagNameShort)) &&
    483                (name[strlen(option->flagNameShort)+1] == '\0' || name[strlen(option->flagNameShort)+1] == '='))
    484         {
    485           found = true;
    486           if (name[strlen(option->flagNameShort)+1] == '=')
    487             {
    488               value = name+strlen(option->flagNameShort)+2;
    489             }     
    490         }
     482               !strncmp(name+1, option->flagNameShort, strlen(option->flagNameShort)) &&
     483               (name[strlen(option->flagNameShort)+1] == '\0' || name[strlen(option->flagNameShort)+1] == '='))
     484        {
     485          found = true;
     486          if (name[strlen(option->flagNameShort)+1] == '=')
     487            {
     488              value = name+strlen(option->flagNameShort)+2;
     489            }
     490        }
    491491
    492492      if (found)
    493         {
    494           PRINT(4)("found matching Flag %s\n", name);
    495           if (value)
    496             {
    497               PRINT(4)("with Value %s\n", value);
    498               option->value = atoi(value);
    499             }
    500           else
    501             {
    502               option->value = !option->defaultValue;
    503             }
    504           option->redraw();
    505         }
    506 
    507     }
    508 }
    509 
    510 #ifdef HAVE_GTK2
    511 /** 
     493        {
     494          PRINT(4)("found matching Flag %s\n", name);
     495          if (value)
     496            {
     497              PRINT(4)("with Value %s\n", value);
     498              option->value = atoi(value);
     499            }
     500          else
     501            {
     502              option->value = !option->defaultValue;
     503            }
     504          option->redraw();
     505        }
     506
     507    }
     508}
     509
     510#ifdef HAVE_GTK2
     511/**
    512512  *  Connect any signal to any given Sub-widget
    513513*/
     
    581581*/
    582582Packer::~Packer()
    583 { 
     583{
    584584  PRINTF(5)("deleting the Packer part.\n");
    585585  if (this->groupName)
    586586    delete []this->groupName;
    587  
     587
    588588  //deleting recursively.
    589589  if (this->down)
     
    620620*/
    621621Container::~Container()
    622 { 
     622{
    623623  PRINTF(5)("deleting the Container part.\n");
    624624}
     
    663663 *  The main Window of Th Gui
    664664*/
    665 Window* Window::mainWindow = NULL;     
     665Window* Window::mainWindow = NULL;
    666666
    667667/**
     
    683683#if !defined(__WIN32__)
    684684  //  gtk_window_set_decorated(GTK_WINDOW(widget), FALSE);
    685 #endif 
     685#endif
    686686  gtk_container_set_border_width(GTK_CONTAINER(widget), 3);
    687687#endif /* HAVE_GTK2 */
     
    715715      Widget* tmpWindow = mainWindow;
    716716      while(tmpWindow->next)
    717         tmpWindow = tmpWindow->next;
     717        tmpWindow = tmpWindow->next;
    718718      tmpWindow->next = windowToAdd;
    719719      windowToAdd->isOpen = false;
     
    904904}
    905905
    906 /** 
     906/**
    907907  *  Fills a box with a given Widget.
    908908  * @param lowerWidget the next Widget that should be appendet to this Box
     
    922922      tmp = this->down;
    923923      while(tmp->next != NULL)
    924         tmp = tmp->next;
     924        tmp = tmp->next;
    925925      tmp->next = lowerWidget;
    926926    }
     
    939939  this->flagName = NULL;
    940940  this->flagNameShort = NULL;
    941  
     941
    942942  this->shortDescription = NULL;
    943943  this->longDescription = NULL;
     
    951951*/
    952952Option::~Option()
    953 { 
     953{
    954954  PRINTF(5)("deleting the Option Part.\n");
    955955  if (this->flagName)
     
    995995}
    996996
    997 /** 
     997/**
    998998  *  see Option::setFlagName(char* flagname, int defaultvalue)
    999999  * @param flagname the Name that will be displayed in the output
     
    10621062 * @param loadString the string from which to load the data from
    10631063*/
    1064 void Option::load(char* loadString)
     1064void Option::load(const char* loadString)
    10651065{
    10661066  this->value = atoi(loadString);
    1067   PRINT(5)("Loading %s: %s %d\n", this->title, loadString, value); 
     1067  PRINT(5)("Loading %s: %s %d\n", this->title, loadString, value);
    10681068  this->redraw();
    10691069}
     
    10781078
    10791079#ifdef HAVE_GTK2
    1080 /** 
     1080/**
    10811081  *  Signal OptionChange writes the Value from the Option to its Object-Database.
    10821082  * @param widget The widget(Option) that has a changed Value
     
    11561156/////////////////
    11571157/**
    1158  *  Creates a new CheckButton with an ame 
     1158 *  Creates a new CheckButton with an ame
    11591159 * @param buttonName The name the CheckButton should display.
    11601160*/
     
    11821182  if (this->title)
    11831183    PRINTF(5)("deleting the CheckButton: %s\n", this->title);
    1184   else 
     1184  else
    11851185    PRINTF(5)("deleting the CheckButton.\n");
    11861186}
     
    13341334  return value;
    13351335}
    1336 void Slider::load(char* loadString)
     1336void Slider::load(const char* loadString)
    13371337{
    13381338  this->fValue = atof(loadString);
    1339   PRINT(5)("Loading %s: %s %f\n", this->title, loadString, fValue); 
     1339  PRINT(5)("Loading %s: %s %f\n", this->title, loadString, fValue);
    13401340  this->redraw();
    13411341}
     
    13551355}
    13561356
    1357 /** 
     1357/**
    13581358  *  Creates a Menu-Item-list out of multiple input.
    13591359    !! Consider, that the last input argument has to be "lastItem" for this to work!!
     
    13891389      //! @todo destroy menu
    13901390      /*
    1391         #ifdef HAVE_GTK2
    1392         gtk_widget_destroy(this->currItem->item);
    1393         #endif /* HAVE_GTK2 */
     1391        #ifdef HAVE_GTK2
     1392        gtk_widget_destroy(this->currItem->item);
     1393        #endif /* HAVE_GTK2 */
    13941394      MenuItem* tmpItem = this->currItem;
    13951395      this->currItem = this->currItem->next;
     
    14321432      return tmpName;
    14331433    }
    1434   else 
     1434  else
    14351435    return NULL;
    14361436}
     
    14401440 * @param loadString the string from which to load the data from
    14411441*/
    1442 void Menu::load(char* loadString)
     1442void Menu::load(const char* loadString)
    14431443{
    14441444  MenuItem* tmpItem = firstItem;
     
    14471447    {
    14481448      if (!strcmp(loadString, tmpItem->name))
    1449         {foundItem = true; break;}
     1449        {foundItem = true; break;}
    14501450      tmpItem = tmpItem->next;
    14511451    }
     
    14571457      PRINTF(2)("%s has not been found in the Itemlist of %s\n", loadString, this->title);
    14581458    }
    1459   PRINTF(5)( "Loading %s: setting to %d\n", this->title, this->value); 
     1459  PRINTF(5)( "Loading %s: setting to %d\n", this->title, this->value);
    14601460  this->redraw();
    14611461}
     
    16011601 * @param loadString the string from which to load the data from
    16021602*/
    1603 void OptionLabel::load(char* loadString)
    1604 {
    1605   PRINTF(5)("Loading %s: setting to %s\n", this->title, loadString); 
     1603void OptionLabel::load(const char* loadString)
     1604{
     1605  PRINTF(5)("Loading %s: setting to %s\n", this->title, loadString);
    16061606  this->setValue(loadString);
    16071607}
     
    16171617{
    16181618  this->optionType = GUI_NOTHING;
    1619  
     1619
    16201620#ifdef HAVE_GTK2
    16211621  this->widget = gtk_label_new("");
    16221622  gtk_label_set_line_wrap(GTK_LABEL(this->widget), TRUE);
    16231623#endif /* HAVE_GTK2 */
    1624  
     1624
    16251625  if (text)
    16261626    this->setTitle(text);
     
    16581658}
    16591659
    1660 /** 
     1660/**
    16611661  *  appends some Text to a Label
    16621662  * @param textToAppend The text that will be appended to this Label
     
    16671667    {
    16681668      char* tmpTitle = new char[strlen(this->title)+strlen(textToAppend)+1];
    1669       strcpy(tmpTitle, title); 
     1669      strcpy(tmpTitle, title);
    16701670      strcat(tmpTitle, textToAppend);
    16711671      delete []this->title;
     
    16741674  else
    16751675    this->title = new char[strlen(textToAppend)];
    1676  
     1676
    16771677#ifdef HAVE_GTK2
    16781678  gtk_label_set_text(GTK_LABEL(this->widget), title);
     
    16801680}
    16811681
    1682 /** 
     1682/**
    16831683  *  Appends some integer to the Label
    16841684  * @param intToAppend The Int that will be added.
    1685    
     1685
    16861686    it does this by just converting the int into a char* and send it to appendText
    16871687*/
     
    18051805}
    18061806
    1807 /** 
     1807/**
    18081808  *  Initializes a new Image
    18091809  * @param name the name to set to the Image
     
    19191919#ifdef HAVE_GTK2
    19201920      if(this->okFunc((const char*)gtk_file_selection_get_filename(GTK_FILE_SELECTION(this->widget)), this->okObject))
    1921         this->close();
     1921        this->close();
    19221922#endif /* HAVE_GTK2 */
    19231923    }
  • orxonox/trunk/src/lib/gui/gui_gtk.h

    r4836 r5015  
    66#define _GUI_GTK_H
    77
    8 #if HAVE_CONFIG_H 
    9 #include <config.h> 
     8#if HAVE_CONFIG_H
     9#include <config.h>
    1010#endif
    1111
     
    3434// enumerator for different GuiOption-Types
    3535enum GUI_OPTION {GUI_BOX = -2,
    36                 GUI_CONTAINER = -1,
    37                 GUI_NOTHING = 0,
    38                 GUI_BOOL = 1,
    39                 GUI_INT = 2,
    40                 GUI_FLOAT = 3,
    41                 GUI_CHAR = 4,
    42                 GUI_CHAR_ARRAY = 5};
     36                GUI_CONTAINER = -1,
     37                GUI_NOTHING = 0,
     38                GUI_BOOL = 1,
     39                GUI_INT = 2,
     40                GUI_FLOAT = 3,
     41                GUI_CHAR = 4,
     42                GUI_CHAR_ARRAY = 5};
    4343
    4444extern char* executable;
     
    7777   static void redrawOptions(Widget* widget);
    7878   static void flagCheck(Widget* widget, void* flagName);
    79  
     79
    8080#ifdef HAVE_GTK2
    8181  // Connection - Functions
     
    140140  int borderwidth;          //!< The width of The Container Boarder.
    141141  int policy;               //!< The Update Policy of a Container.
    142  
     142
    143143 public:
    144144  Container();
     
    164164  Window(const char* windowName = NULL);
    165165  virtual ~Window();
    166  
     166
    167167  virtual void setTitle(const char* title);
    168168  void showall();
     
    216216  Box(char boxtype = 'h');
    217217  virtual ~Box();
    218  
     218
    219219  virtual void fill(Widget* lowerWidget);
    220220};
     
    228228 protected:
    229229  bool saveable;              //!< Options can be Saved.
    230  
     230
    231231 public:
    232232  Option();
     
    243243  void saveability(bool isSaveable = true);
    244244  virtual char* save();
    245   virtual void load(char* loadString);
     245  virtual void load(const char* loadString);
    246246
    247247  bool isSaveable();
     
    254254  virtual void changeOption() = 0; //!< What to do, if an Option is Changed. eacht option decides for itself.
    255255#ifdef HAVE_GTK2
    256     // Signals 
     256    // Signals
    257257  static gint OptionChange(GtkWidget* widget, Widget* option); //!< Signal for Options that change.
    258258#endif /* HAVE_GTK2 */
     
    263263 * Buttons are mainly there for executing some action like Starting the Programm, or Quiting it.
    264264 */
    265 class Button : public Option 
     265class Button : public Option
    266266{
    267267 public:
     
    310310
    311311  virtual char* save();
    312   virtual void load(char* loadString);
     312  virtual void load(const char* loadString);
    313313};
    314314
     
    334334  MenuItem* firstItem;                  //!< Pointer to the first Item.
    335335  MenuItem* currItem;                   //!< Pointer to the current Item.
    336  
     336
    337337 public:
    338338  Menu(const char* menuName);
     
    342342
    343343  virtual char* save();
    344   virtual void load(char* loadString);
    345  
     344  virtual void load(const char* loadString);
     345
    346346  void addItem(char* itemName);
    347347  virtual void redraw();
     
    355355  OptionLabel(const char* label, const char* value);
    356356  virtual ~OptionLabel();
    357  
     357
    358358  void setValue(const char* newValue);
    359359
    360360  virtual char* save();
    361   virtual void load(char* loadString);
     361  virtual void load(const char* loadString);
    362362
    363363  virtual void redraw();
     
    373373  EntryField(const char* name = NULL);
    374374  virtual ~EntryField();
    375  
     375
    376376  void setValue(const char* newValue);
    377377  virtual char* save();
    378   virtual void load(char* loadString);
    379  
     378  virtual void load(const char* loadString);
     379
    380380  virtual void redraw();
    381381  virtual void changeOption();
     
    388388  Label(const char* text = NULL);
    389389  virtual ~Label();
    390  
     390
    391391  virtual void setTitle(const char* text);
    392392  void ereaseText();
     
    415415};
    416416
    417 //! Image is the keeper of one Image 
    418 /** 
     417//! Image is the keeper of one Image
     418/**
    419419 * Images are mighty cool.
    420420 * Images can help you lighten up the Programming process, and will give everyone a better impression of the Software.
  • orxonox/trunk/src/lib/util/ini_parser.cc

    r5014 r5015  
    2323#include "list.h"
    2424#include "stdlibincl.h"
    25 
    26 #include "resource_manager.h"
    2725#include "debug.h"
    2826
     
    5351}
    5452
     53/**
     54 * removes all the sections. This is like delete, but even cooler :)
     55 */
    5556void IniParser::deleteSections()
    5657{
     
    8081  }
    8182  delete this->sections;
     83  this->currentEntry = NULL;
     84  this->currentSection = NULL;
    8285  this->sections = NULL;
    8386}
     
    8891 * @return true on success false otherwise;
    8992*/
    90 bool IniParser::openFile(const char* filename)
     93bool IniParser::openFile(const char* fileName)
    9194{
    9295  FILE*    stream;           //!< The stream we use to read the file.
    9396
    94 
    95   if( filename == NULL)
    96     return false;
    97   char* tmpName = ResourceManager::homeDirCheck(filename);
    9897
    9998  if (sections != NULL)
    10099    deleteSections();
    101 
    102   if( (stream = fopen (tmpName, "r")) == NULL)
    103   {
    104     PRINTF(1)("IniParser could not open %s\n", filename);
    105     delete tmpName;
     100  if( fileName == NULL)
     101    return false;
     102
     103  if( (stream = fopen (fileName, "r")) == NULL)
     104  {
     105    PRINTF(1)("IniParser could not open %s\n", fileName);
    106106    return false;
    107107  }
     
    189189    {
    190190      this->currentSection = sectionEnum;
     191      this->currentEntry = NULL;
    191192      delete sectionIt;
    192193      return true;
     
    200201
    201202/**
     203 * moves to the first section
     204 */
     205void IniParser::getFirstSection()
     206{
     207  if (this->sections)
     208    this->currentSection = this->sections->firstElement();
     209  else
     210    this->currentSection = NULL;
     211  this->currentEntry = NULL;
     212}
     213
     214/**
    202215 * searches the next section
    203216 * @returns the name of the section if found, NULL otherwise
     
    210223  {
    211224    if (this->sections)
    212       this->currentSection = sections->nextElement(this->currentSection);
    213   }
     225    {
     226      if (this->currentSection == this->sections->lastElement())
     227        this->currentSection = NULL;
     228      else
     229        this->currentSection = this->sections->nextElement(this->currentSection);
     230    }
     231  }
     232
    214233  if (this->currentSection != NULL)
    215234    return this->currentSection->name;
     
    219238
    220239/**
     240 * moves to the first Variable of the current Section
     241 */
     242void IniParser::getFirstVar()
     243{
     244  if (this->currentSection)
     245    this->currentEntry = this->currentSection->entries->firstElement();
     246  else
     247    this->currentEntry = NULL;
     248}
     249
     250/**
    221251 *  gets the next VarName=VarValue pair from the parsing stream
    222  * @param name: a pointer to the Name of the next Var
    223  * @param value: a pointer to the Value of the next Var
    224252 * @return true on success, false otherwise (in the latter case name and value will be NULL)
    225253 */
    226254bool IniParser::nextVar()
    227255{
    228   if (this->currentSection == NULL)
    229     return false;
    230   if(this->currentEntry == this->currentSection->entries->lastElement())
     256  if (this->currentSection == NULL
     257      || this->currentEntry == NULL
     258      || this->currentEntry == this->currentSection->entries->lastElement())
    231259  {
    232260    this->currentEntry = NULL;
    233261    return false;
    234262  }
    235   if (this->currentEntry == NULL)
    236     this->currentEntry = this->currentSection->entries->firstElement();
    237   else
    238     this->currentEntry = this->currentSection->entries->nextElement(this->currentEntry);
     263  this->currentEntry = this->currentSection->entries->nextElement(this->currentEntry);
    239264
    240265  if (this->currentEntry == NULL)
  • orxonox/trunk/src/lib/util/ini_parser.h

    r5014 r5015  
    4343    bool openFile(const char* name);
    4444
    45     bool getSection( const char* sectionName);
     45    bool getSection(const char* sectionName);
     46
     47    void getFirstSection();
    4648    const char* nextSection();
    4749
     50    /** @returns true if the file is opened, false otherwise*/
    4851    bool isOpen() const { return (sections != NULL)?true:false; };
    4952
    5053    const char* getVar(const char* entryName, const char* sectionName, const char* defaultValue = "") const;
     54
     55    void getFirstVar();
    5156    bool nextVar();
    5257
    53     const char* getCurrentName() const { return (currentEntry!=NULL)?currentEntry->name:NULL; };
    54     const char* getCurrentValue() const { return (currentEntry!=NULL)?currentEntry->value:NULL; };
     58    /** @returns the name of the Current selected Section */
     59    const char* getCurrentSection() const { return (this->currentSection!=NULL)?this->currentSection->name:NULL; };
     60    /** @returns the current entries Name, or NULL if we havn't selected a Entry */
     61    const char* getCurrentName() const { return (this->currentEntry!=NULL)?this->currentEntry->name:NULL; };
     62    /** @returns the current entries Value, or NULL if we havn't selected a Entry */
     63    const char* getCurrentValue() const { return (this->currentEntry!=NULL)?this->currentEntry->value:NULL; };
    5564
    5665    void debug() const;
  • orxonox/trunk/src/orxonox.cc

    r5014 r5015  
    124124const char* Orxonox::getConfigFile ()
    125125{
    126   this->configFileName = new char[strlen(DEFAULT_CONFIG_FILE)];
    127   strcpy (this->configFileName, DEFAULT_CONFIG_FILE);
     126  this->configFileName = ResourceManager::homeDirCheck(DEFAULT_CONFIG_FILE);
    128127  this->iniParser = new IniParser(this->configFileName);
    129128}
Note: See TracChangeset for help on using the changeset viewer.