Index: /trunk/src/lib/shell/shell.cc
===================================================================
--- /trunk/src/lib/shell/shell.cc	(revision 5174)
+++ /trunk/src/lib/shell/shell.cc	(revision 5175)
@@ -18,4 +18,6 @@
 #include "shell.h"
 #include "shell_command.h"
+#include "shell_buffer.h"
+
 
 #include "text_engine.h"
@@ -43,16 +45,15 @@
   this->setName("Shell");
 
-
-  this->bActive = false;
-  this->bufferIterator = this->buffer->getIterator();
-
-  this->inputHistory = new tList<char>;
-  //this->commandList = new tList<ShellCommand>;
-
+  this->setAbsCoor2D(3, -400);
   this->textSize = 15;
   this->lineSpacing = 5;
-
-  //this->bufferSize = 0;
-  this->setAbsCoor2D(3, -400);
+  this->bActive = false;
+
+
+  // BUFFER
+  this->bufferText = NULL;
+  this->setBufferDisplaySize(10);
+
+  // INPUT LINE
   this->delayed = 0;
   this->setRepeatDelay(.3, .05);
@@ -62,4 +63,6 @@
   this->inputLine = new char[1];
   this->inputLine[0] = '\0';
+  this->inputHistory = new tList<char>;
+  //this->commandList = new tList<ShellCommand>;
 
   this->rebuildText();
@@ -89,16 +92,4 @@
   delete this->inputLine;
 
-  // delete all the Strings in the Buffers
-  char* charElem = this->bufferIterator->firstElement();
-  while (charElem != NULL)
-  {
-    delete charElem;
-    charElem = this->bufferIterator->nextElement();
-  }
-  delete this->bufferIterator;
-
-//  if (this->completionList != NULL)
-    //delete this->completionList;
-
   Shell::singletonRef = NULL;
 }
@@ -118,7 +109,7 @@
   this->setRelCoorSoft2D(0, 0, 1, 5);
 
-  this->bufferIterator->lastElement();
+  ShellBuffer::getInstance()->getBufferIterator()->lastElement();
   for (int i = 0; i < this->bufferDisplaySize; i++)
-    this->bufferText[i]->setText(this->bufferIterator->prevElement(), true);
+    this->bufferText[i]->setText(ShellBuffer::getInstance()->getBufferIterator()->prevElement(), true);
 }
 
@@ -135,7 +126,7 @@
   this->setRelCoorSoft2D(0, -400, 1, 5);
 
-  this->bufferIterator->lastElement();
+  ShellBuffer::getInstance()->getBufferIterator()->lastElement();
   for (int i = 0; i < this->bufferDisplaySize; i++)
-    this->bufferText[i]->setText(this->bufferIterator->prevElement(), false);
+    this->bufferText[i]->setText(ShellBuffer::getInstance()->getBufferIterator()->prevElement(), false);
 }
 
@@ -207,5 +198,5 @@
  * deletes all the Buffers
  */
-void Shell::flushBuffers()
+void Shell::flush()
 {
   // remove all chars from the BufferTexts.
@@ -216,102 +207,6 @@
     }
 
-  // delete all the Chars in the Buffers
-  tIterator<char>* charIterator = this->buffer->getIterator();
-  char* charElem = charIterator->firstElement();
-  while (charElem != NULL)
-  {
-    delete charElem;
-
-    charElem = charIterator->nextElement();
-  }
-  delete charIterator;
-  delete this->buffer;
-  this->buffer = new tList<char>;
-}
-
-/**
- * adds a new Line to the List of Buffers
- * @param line the Line as in the first argument in printf
- */
-bool Shell::addBufferLineStatic(const char* line, ...)
-{
-  va_list arguments;
-  va_start(arguments, line);
-
-#if DEBUG < 3
-  if (Shell::singletonRef == NULL)
-#endif
-
-  vprintf(line, arguments);
-#if DEBUG < 3
-  else
-#else
-  if (Shell::singletonRef != NULL)
-#endif
-    Shell::singletonRef->addBufferLine(line, arguments);
-  return true;
-}
-
-/**
- * add a Line to the List of Buffers
- * @param line
- * @param arguments
- *
- * This function Adds one line to the buffer.
- * and displays the line as the First Line of the display-buffer
- */
-void Shell::addBufferLine(const char* line, va_list arguments)
-{
-   vsprintf(this->bufferArray, line, arguments);
-
-   char* inputEnd;
-   char* newLineBegin;
-   char* newLineEnd;
-
-   // check if we have something left in the buffers
-   if (unlikely(this->keepBuffer))
-   {
-     strcat(this->keepBufferArray, this->bufferArray);
-     inputEnd = this->keepBufferArray + strlen(this->keepBufferArray);
-     newLineBegin = this->keepBufferArray;
-     this->keepBuffer = false;
-   }
-   else
-   {
-     inputEnd = this->bufferArray + strlen(this->bufferArray);
-     newLineBegin = this->bufferArray;
-   }
-
-   // adding all the new Lines
-   while (newLineBegin < inputEnd)
-   {
-     newLineEnd = strchr(newLineBegin, '\n');
-     if (newLineEnd != NULL && *newLineEnd == '\n')
-       *newLineEnd = '\0';
-     else
-     {
-//       newLineEnd = newLineBegin + strlen(newLineBegin);
-       strcpy(this->keepBufferArray, newLineBegin);
-       this->keepBuffer = true;
-       break;
-     }
-
-     char* addLine = new char[strlen(newLineBegin)+1];
-     strcpy(addLine, newLineBegin);
-
-     this->buffer->add(addLine);
-
-     if (this->buffer->getSize() > this->bufferSize)
-     {
-       delete this->buffer->firstElement();
-       this->buffer->remove(this->buffer->firstElement());
-     }
-
-     if (this->bActive)
-     {
-       this->printToDisplayBuffer(addLine);
-     }
-     newLineBegin = newLineEnd+1;
-   }
+
+    // BUFFER FLUSHING
 }
 
@@ -345,37 +240,4 @@
 
 /**
- * moves the buffer around lineCount lines upwards (negative values move down)
- * @param lineCount the Count of lines to move upwards
- *
- * @todo
- */
-void Shell::moveBuffer(unsigned int lineCount)
-{
-}
-
-/**
- * @param lineNumber the n-th line from the bottom
- * @returns the Buffer at Line lineNumber
- */
-const char* Shell::getBufferLine(unsigned int lineNumber)
-{
-  tIterator<char>* charIterator = this->buffer->getIterator();
-  char* charElem = charIterator->firstElement();
-
-  int i = 1;
-  while (charElem != NULL)
-  {
-    if (i++ < lineNumber)
-    {
-      delete charIterator;
-      return charElem;
-    }
-
-    charElem = charIterator->nextElement();
-  }
-  delete charIterator;
-}
-
-/**
  * deletes the InputLine
  */
@@ -446,5 +308,5 @@
 bool Shell::executeCommand()
 {
-  this->addBufferLineStatic("Execute Command: %s\n", this->inputLine);
+  ShellBuffer::addBufferLineStatic("Execute Command: %s\n", this->inputLine);
 
   char* newCommand = new char[strlen(this->inputLine)+1];
@@ -464,6 +326,6 @@
 void Shell::clear()
 {
-  this->flushBuffers();
-  this->addBufferLine("orxonox - shell\n ==================== \n", NULL);
+  this->flush();
+  ShellBuffer::addBufferLineStatic("orxonox - shell\n ==================== \n", NULL);
 }
 
@@ -858,9 +720,9 @@
 
 
-  char* tmpChar = this->bufferIterator->firstElement();
+  char* tmpChar = ShellBuffer::getInstance()->getBufferIterator()->firstElement();
   while(tmpChar != NULL)
   {
     printf(tmpChar);
-    tmpChar = this->bufferIterator->nextElement();
+    tmpChar = ShellBuffer::getInstance()->getBufferIterator()->nextElement();
   }
 }
Index: /trunk/src/lib/shell/shell.h
===================================================================
--- /trunk/src/lib/shell/shell.h	(revision 5174)
+++ /trunk/src/lib/shell/shell.h	(revision 5175)
@@ -39,4 +39,6 @@
     /** @returns a Pointer to the only object of this Class */
     inline static Shell* getInstance() { if (!Shell::singletonRef) Shell::singletonRef = new Shell();  return Shell::singletonRef; };
+    /** @returns true if this class is instanciated, false otherwise */
+    inline static bool isInstanciated() { return (Shell::singletonRef == NULL)?true:false; };
 
     void activate();
@@ -46,15 +48,8 @@
     void rebuildText();
 
-    // BUFFER //
-    /** @param bufferSize the new Buffer-Size */
-    void setBufferSize(unsigned int bufferSize) { this->bufferSize = bufferSize; };
+    // BUFFERS
     void setBufferDisplaySize(unsigned int bufferDisplaySize);
-    void flushBuffers();
-    static bool addBufferLineStatic(const char* line, ...);
-    void addBufferLine(const char* line, va_list arg);
+    void flush();
     void printToDisplayBuffer(const char* text);
-    void moveBuffer(unsigned int lineCount);
-//    void moveBufferTo(unsigned int lineNumber);
-    const char* getBufferLine(unsigned int lineNumber);
 
     // InputLine
@@ -103,7 +98,7 @@
     static Shell*            singletonRef;           //!< The singleton-reference to the only memeber of this class.
 
-    unsigned int             bufferSize;             //!< The Size of the buffer
     unsigned int             bufferDisplaySize;      //!< The Size of the Display-buffer, in lines (not in characters)
 
+    // HANDLING TEXT INPUT
     Text*                    inputLineText;          //!< The inputLine of the Shell
     char*                    inputLine;              //!< the Char-Array of the Buffer
@@ -112,7 +107,4 @@
     float                    delayed;                //!< how much of the delay is remaining.
     int                      pressedKey;             //!< the pressed key that will be repeated.
-
-    tList<char>*             buffer;                 //!< A list of stored char-arrays(strings) to store the history
-    tIterator<char>*         bufferIterator;         //!< An iterator for the Shells main buffer.
 
     tList<char>*             inputHistory;           //!< The history of given commands.
@@ -124,8 +116,4 @@
     bool                     bActive;                //!< if the shell is active;
 
-    char                     bufferArray[SHELL_BUFFER_SIZE];     //!< a BUFFER for fast writing
-    char                     keepBufferArray[SHELL_BUFFER_SIZE]; //!< a BUFFER to have multi-non-newLine commands be copied into the shell.
-    bool                     keepBuffer;             //!< if the keepbuffer contains unfinished lines.
-
     // completion
     tList<const char>*       completionList;          //!< A list of completions, that are io.
Index: /trunk/src/lib/shell/shell_buffer.cc
===================================================================
--- /trunk/src/lib/shell/shell_buffer.cc	(revision 5174)
+++ /trunk/src/lib/shell/shell_buffer.cc	(revision 5175)
@@ -19,4 +19,5 @@
 #include "debug.h"
 #include "list.h"
+#include "shell.h"
 
 #include "stdlibincl.h"
@@ -31,7 +32,11 @@
 ShellBuffer::ShellBuffer ()
 {
+  ShellBuffer::singletonRef = this;
+
+  this->lineCount = 0;
   this->keepBufferArray[0] = '\0';
   this->keepBuffer = false;
   this->buffer = new tList<char>;
+  this->bufferIterator = this->buffer->getIterator();
 
   this->setBufferSize(10);
@@ -45,5 +50,9 @@
 ShellBuffer::~ShellBuffer ()
 {
+  if (Shell::isInstanciated())
+    delete Shell::getInstance();
 
+  this->flushBuffers();
+  delete bufferIterator;
   delete buffer;
 
@@ -57,15 +66,15 @@
 {
   // delete all the Chars in the Buffers
-  tIterator<char>* charIterator = this->buffer->getIterator();
-  char* charElem = charIterator->firstElement();
+  char* charElem = bufferIterator->firstElement();
   while (charElem != NULL)
   {
     delete charElem;
 
-    charElem = charIterator->nextElement();
+    charElem = bufferIterator->nextElement();
   }
-  delete charIterator;
+  delete this->bufferIterator;
   delete this->buffer;
   this->buffer = new tList<char>;
+  this->bufferIterator = this->buffer->getIterator();
 }
 
@@ -141,4 +150,5 @@
 
     this->buffer->add(addLine);
+    this->lineCount++;
 
     if (this->buffer->getSize() > this->bufferSize)
Index: /trunk/src/lib/shell/shell_buffer.h
===================================================================
--- /trunk/src/lib/shell/shell_buffer.h	(revision 5174)
+++ /trunk/src/lib/shell/shell_buffer.h	(revision 5175)
@@ -14,4 +14,7 @@
 template<class T> class tList;
 template<class T> class tIterator;
+#ifndef NULL
+#define NULL 0            //!< a pointer to NULL
+#endif
 
 //! A class for ...
@@ -22,4 +25,6 @@
   /** @returns a Pointer to the only object of this Class */
   inline static ShellBuffer* getInstance() { if (!ShellBuffer::singletonRef) ShellBuffer::singletonRef = new ShellBuffer();  return ShellBuffer::singletonRef; };
+  /** @returns true if this class is instanciated, false otherwise */
+  inline static bool isInstanciated() { return (ShellBuffer::singletonRef == NULL)?true:false; };
 
   // BUFFER //
@@ -30,6 +35,7 @@
   void addBufferLine(const char* line, va_list arg);
   void moveBuffer(unsigned int lineCount);
-//    void moveBufferTo(unsigned int lineNumber);
+// void moveBufferTo(unsigned int lineNumber);
   const char* getBufferLine(unsigned int lineNumber);
+  inline tIterator<char>*  getBufferIterator() const { return bufferIterator; };
 
   private:
Index: /trunk/src/orxonox.cc
===================================================================
--- /trunk/src/orxonox.cc	(revision 5174)
+++ /trunk/src/orxonox.cc	(revision 5175)
@@ -51,4 +51,5 @@
 #include "shell.h"
 #include "shell_command.h"
+#include "shell_buffer.h"
 
 #include <string.h>
Index: /trunk/src/story_entities/world.cc
===================================================================
--- /trunk/src/story_entities/world.cc	(revision 5174)
+++ /trunk/src/story_entities/world.cc	(revision 5175)
@@ -116,5 +116,5 @@
 World::~World ()
 {
-  delete ShellBuffer::getInstance();
+  delete Shell::getInstance();
   PRINTF(3)("World::~World() - deleting current world\n");
 
@@ -196,5 +196,5 @@
 
   /* init the world interface */
-  ShellBuffer::getInstance();
+  Shell::getInstance();
 
   LightManager::getInstance();
