Index: /orxonox/trunk/src/lib/gui/gui_keys.cc
===================================================================
--- /orxonox/trunk/src/lib/gui/gui_keys.cc	(revision 5019)
+++ /orxonox/trunk/src/lib/gui/gui_keys.cc	(revision 5020)
@@ -1,3 +1,3 @@
-/* 
+/*
    orxonox - the future of 3D-vertical-scrollers
 
@@ -16,5 +16,5 @@
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software Foundation,
-   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
+   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 
@@ -38,5 +38,5 @@
   {
     Box* keysBox0;          //!< The Frame that holds the keyOptions.
-    
+
     //  keysFrame->setGroupName("Keyboard");
     keysBox0 = new Box('v');
@@ -47,12 +47,12 @@
       keysBox1 = new Box('h');
       {
-	PlayerKeys* player1;       //!< The first Player's keys.
-	PlayerKeys* player2;       //!< The seconds Player's keys.
-	
-	player1 = new PlayerKeys(CONFIG_SECTION_PLAYER "1");
-	player2 = new PlayerKeys(CONFIG_SECTION_PLAYER "2");
-	
-	keysBox1->fill(player1->getOpenButton());
-	keysBox1->fill(player2->getOpenButton());
+        PlayerKeys* player1;       //!< The first Player's keys.
+        PlayerKeys* player2;       //!< The seconds Player's keys.
+
+        player1 = new PlayerKeys(CONFIG_SECTION_PLAYER "1");
+        player2 = new PlayerKeys(CONFIG_SECTION_PLAYER "2");
+
+        keysBox1->fill(player1->getOpenButton());
+        keysBox1->fill(player2->getOpenButton());
       }
       keysBox0->fill(keysBox1);
@@ -63,5 +63,5 @@
     keysFrame->fill(keysBox0);
   }
-  
+
   // setting up the Input Windows that receives keystrokes.
   this->inputWindow = new Window("inputWindow");
@@ -72,5 +72,5 @@
 #endif /* HAVE_GTK2 */
   this->inputWindow->fill(inputButton);
-  
+
   this->setMainWidget(keysFrame);
 }
@@ -112,20 +112,20 @@
       pKeysBox = new Box('v');
       {
-	Button* closeButton;    //!< The CloseButton for this key-settings.
-
-	pKeysBox->setGroupName(player);
-	pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_UP, "UP"));
-	pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_DOWN, "DOWN"));
-	pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_LEFT, "LEFT"));
-	pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_RIGHT, "RIGHT"));
-	pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_FIRE, "SPACE"));
-	pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_NEXT_WEAPON, "m"));
-	pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_PREV_WEAPON, "n"));
-	closeButton = new Button("close");
-#ifdef HAVE_GTK2
-	closeButton->connectSignal("button_press_event", pKeyWindow, Window::windowClose);
-#endif /* HAVE_GTK2 */
-
-	pKeysBox->fill(closeButton);
+        Button* closeButton;    //!< The CloseButton for this key-settings.
+
+        pKeysBox->setGroupName(player);
+        pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_UP, "UP"));
+        pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_DOWN, "DOWN"));
+        pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_LEFT, "LEFT"));
+        pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_RIGHT, "RIGHT"));
+        pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_FIRE, "SPACE"));
+        pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_NEXT_WEAPON, "m"));
+        pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_PREV_WEAPON, "n"));
+        closeButton = new Button("close");
+#ifdef HAVE_GTK2
+        closeButton->connectSignal("button_press_event", pKeyWindow, Window::windowClose);
+#endif /* HAVE_GTK2 */
+
+        pKeysBox->fill(closeButton);
       }
       pKeyFrame->fill(pKeysBox);
@@ -139,5 +139,5 @@
   pKeyWindow->connectSignal("delete_event", pKeyWindow, Window::windowClose);
 #endif /* HAVE_GTK2 */
-  
+
   this->openButton = new Button(player);
 #ifdef HAVE_GTK2
@@ -174,24 +174,24 @@
       keysBox = new Box('v');
       {
-	Button* closeButton;    //!< The CloseButton for this key-settings.
-
-	keysBox->setGroupName(CONFIG_SECTION_MISC_KEYS);
-	keysBox->fill(addKey(CONFIG_NAME_QUIT , "ESCAPE"));
-	keysBox->fill(addKey(CONFIG_NAME_PAUSE, "PAUSE"));
-	keysBox->fill(addKey(CONFIG_NAME_NEXT_WORLD, "x"));
-	keysBox->fill(addKey(CONFIG_NAME_PREV_WORLD, "z"));
-	keysBox->fill(addKey(CONFIG_NAME_VIEW0, "1"));
-	keysBox->fill(addKey(CONFIG_NAME_VIEW1, "2"));
-	keysBox->fill(addKey(CONFIG_NAME_VIEW2, "3"));
-	keysBox->fill(addKey(CONFIG_NAME_VIEW3, "4"));
-	keysBox->fill(addKey(CONFIG_NAME_VIEW4, "5"));
-	keysBox->fill(addKey(CONFIG_NAME_VIEW5, "6"));
-
-	closeButton = new Button("close");
-#ifdef HAVE_GTK2
-	closeButton->connectSignal("button_press_event", keyWindow, Window::windowClose);
-#endif /* HAVE_GTK2 */
-
-	keysBox->fill(closeButton);
+        Button* closeButton;    //!< The CloseButton for this key-settings.
+
+        keysBox->setGroupName(CONFIG_SECTION_MISC_KEYS);
+        keysBox->fill(addKey(CONFIG_NAME_QUIT , "ESCAPE"));
+        keysBox->fill(addKey(CONFIG_NAME_PAUSE, "PAUSE"));
+        keysBox->fill(addKey(CONFIG_NAME_NEXT_WORLD, "x"));
+        keysBox->fill(addKey(CONFIG_NAME_PREV_WORLD, "z"));
+        keysBox->fill(addKey(CONFIG_NAME_VIEW0, "1"));
+        keysBox->fill(addKey(CONFIG_NAME_VIEW1, "2"));
+        keysBox->fill(addKey(CONFIG_NAME_VIEW2, "3"));
+        keysBox->fill(addKey(CONFIG_NAME_VIEW3, "4"));
+        keysBox->fill(addKey(CONFIG_NAME_VIEW4, "5"));
+        keysBox->fill(addKey(CONFIG_NAME_VIEW5, "6"));
+
+        closeButton = new Button("close");
+#ifdef HAVE_GTK2
+        closeButton->connectSignal("button_press_event", keyWindow, Window::windowClose);
+#endif /* HAVE_GTK2 */
+
+        keysBox->fill(closeButton);
       }
       keyFrame->fill(keysBox);
@@ -204,5 +204,5 @@
   keyWindow->connectSignal("delete_event", keyWindow, Window::windowClose);
 #endif /* HAVE_GTK2 */
-  
+
   this->openButton = new Button("misc");
 #ifdef HAVE_GTK2
@@ -254,5 +254,5 @@
   GuiKeys::inputWindow->open();
 }
-  
+
 /**
  *  Function which gets keystrokes
@@ -281,13 +281,13 @@
       strcpy(title, "RIGHT");
       break;
-      
+
     case GDK_space:
       strcpy(title, "SPACE");
       break;
-      
+
     case GDK_Return:
       strcpy(title, "RETURN");
       break;
-      
+
       // Special Keys //
     case GDK_BackSpace:
@@ -361,5 +361,5 @@
       strcpy(title, "INSERT");
       break;
-      
+
     case GDK_Escape:
       strcpy(title, "ESCAPE");
@@ -423,6 +423,6 @@
       strcpy(title, "F12");
       break;
-      
-      
+
+
     default:
       char* tmp;
Index: /orxonox/trunk/src/lib/util/ini_parser.cc
===================================================================
--- /orxonox/trunk/src/lib/util/ini_parser.cc	(revision 5019)
+++ /orxonox/trunk/src/lib/util/ini_parser.cc	(revision 5020)
@@ -34,5 +34,4 @@
 {
   this->setClassID(CL_INI_PARSER, "IniParser");
-  this->setName(fileName);
 
   this->currentEntry = NULL;
@@ -84,4 +83,5 @@
   this->currentSection = NULL;
   this->sections = NULL;
+  this->setName(NULL);
 }
 
@@ -98,6 +98,6 @@
   if( fileName == NULL)
     return false;
-
-  printf("1\n");
+  this->setName(fileName);
+
   if( (stream = fopen (fileName, "r")) == NULL)
   {
@@ -107,5 +107,4 @@
   else
   {
-    printf("2\n");
     this->currentEntry = NULL;
     this->currentSection = NULL;
@@ -134,10 +133,5 @@
         {
           *ptr = 0;
-          IniSection* newSection = new IniSection;
-          newSection->name = new char[strlen(buffer)+1];
-          strcpy(newSection->name, buffer);
-          newSection->entries = new tList<IniEntry>;
-          this->currentSection = newSection;
-          this->sections->add(newSection);
+          this->addSection(buffer);
         }
       }
@@ -163,11 +157,5 @@
         nameEnd[1] = '\0';
 
-        IniEntry* newEntry = new IniEntry;
-        newEntry->value = new char[strlen(valueBegin)+1];
-        strcpy(newEntry->value, valueBegin);
-        newEntry->name = new char[strlen (nameBegin)+1];
-        strcpy(newEntry->name, nameBegin);
-
-        this->currentSection->entries->add(newEntry);
+        this->addVar(nameBegin, valueBegin);
       }
     }
@@ -175,4 +163,65 @@
   fclose(stream);
   return true;
+}
+
+/**
+ * opens a file and writes to it
+ * @param fileName: path and name of the new file to write to
+ * @return true on success false otherwise
+ */
+bool IniParser::writeFile(const char* fileName)
+{
+  FILE*    stream;           //!< The stream we use to read the file.
+  if (sections != NULL)
+    deleteSections();
+  if( fileName == NULL)
+    return false;
+
+  if( (stream = fopen (fileName, "w")) == NULL)
+  {
+    PRINTF(1)("IniParser could not open %s\n", fileName);
+    return false;
+  }
+  else
+  {
+    if (this->sections)
+    {
+      tIterator<IniSection>* sectionIt = this->sections->getIterator();
+      IniSection* sectionEnum = sectionIt->nextElement();
+      while (sectionEnum)
+      {
+        fprintf(stream, " [%s]\n", sectionEnum->name);
+
+        tIterator<IniEntry>* entryIt = sectionEnum->entries->getIterator();
+        IniEntry* entryEnum = entryIt->nextElement();
+        while (entryEnum)
+        {
+          fprintf(stream, " %s = %s\n", entryEnum->name, entryEnum->value);
+
+          entryEnum = entryIt->nextElement();
+        }
+        delete entryIt;
+
+        sectionEnum = sectionIt->nextElement();
+      }
+      delete sectionIt;
+    }
+    else
+      PRINTF(1)("%s no sections defined yet\n", fileName);
+  }
+  fclose(stream);
+}
+
+bool IniParser::addSection(const char* sectionName)
+{
+  if (this->sections == NULL)
+    this->sections = new tList<IniSection>;
+
+  IniSection* newSection = new IniSection;
+  newSection->name = new char[strlen(sectionName)+1];
+  strcpy(newSection->name, sectionName);
+  newSection->entries = new tList<IniEntry>;
+  this->currentSection = newSection;
+  this->sections->add(newSection);
 }
 
@@ -269,4 +318,51 @@
   else
     return true;
+}
+
+/**
+ * adds a new Entry to either the currentSection or the section called by sectionName
+ * @param entryName the Name of the Entry to add
+ * @param value the value to assign to this entry
+ * @param sectionName if NULL then this entry will be set to the currentSection
+ * otherwise to the section refered to by sectionName.
+ * If both are NULL no entry will be added
+ * @return true if everything is ok false on error
+ */
+bool IniParser::addVar(const char* entryName, const char* value, const char* sectionName)
+{
+  IniSection* addSection = NULL;
+  if (sectionName != NULL)
+  {
+    tIterator<IniSection>* sectionIt = this->sections->getIterator();
+    IniSection* sectionEnum = sectionIt->nextElement();
+    while (sectionEnum)
+    {
+      if (!strcmp(sectionEnum->name, sectionName))
+      {
+        addSection = sectionEnum;
+        break;
+      }
+      sectionEnum = sectionIt->nextElement();
+    }
+    delete sectionIt;
+  }
+  else
+    addSection = this->currentSection;
+
+  if (addSection == NULL)
+  {
+    PRINTF(2)("section not found for value %s\n", entryName);
+    return false;
+  }
+  else
+  {
+    IniEntry* newEntry = new IniEntry;
+    newEntry->name = new char[strlen (entryName)+1];
+    strcpy(newEntry->name, entryName);
+    newEntry->value = new char[strlen(value)+1];
+    strcpy(newEntry->value, value);
+    this->currentSection->entries->add(newEntry);
+    return true;
+  }
 }
 
@@ -277,7 +373,7 @@
  * @param defaultValue: what should be returned in case the entry cannot be found
  * @return a pointer to a buffer conatining the value of the specified entry. This buffer will contain the data specified in defvalue in case the entry wasn't found
-
-   The returned pointer points to an internal buffer, so do not free it on your own. Do not give a NULL pointer to defvalue, this will certainly
-   lead to unwanted behaviour.
+ *
+ *  The returned pointer points to an internal buffer, so do not free it on your own. Do not give a NULL pointer to defvalue, this will certainly
+ * lead to unwanted behaviour.
 */
 const char* IniParser::getVar(const char* entryName, const char* sectionName, const char* defaultValue) const
Index: /orxonox/trunk/src/lib/util/ini_parser.h
===================================================================
--- /orxonox/trunk/src/lib/util/ini_parser.h	(revision 5019)
+++ /orxonox/trunk/src/lib/util/ini_parser.h	(revision 5020)
@@ -42,6 +42,8 @@
     ~IniParser ();
 
-    bool readFile(const char* name);
+    bool readFile(const char* fileName);
+    bool writeFile(const char* fileName);
 
+    bool addSection(const char* sectionName);
     bool getSection(const char* sectionName);
 
@@ -52,4 +54,5 @@
     bool isOpen() const { return (sections != NULL)?true:false; };
 
+    bool addVar(const char* entryName, const char* value, const char* sectionName = NULL);
     const char* getVar(const char* entryName, const char* sectionName, const char* defaultValue = "") const;
 
