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;
 
