Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5175 in orxonox.OLD for trunk/src/lib/shell/shell.cc


Ignore:
Timestamp:
Sep 11, 2005, 11:21:56 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: cleaner outtakes of the ShellBuffer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/shell/shell.cc

    r5174 r5175  
    1818#include "shell.h"
    1919#include "shell_command.h"
     20#include "shell_buffer.h"
     21
    2022
    2123#include "text_engine.h"
     
    4345  this->setName("Shell");
    4446
    45 
    46   this->bActive = false;
    47   this->bufferIterator = this->buffer->getIterator();
    48 
    49   this->inputHistory = new tList<char>;
    50   //this->commandList = new tList<ShellCommand>;
    51 
     47  this->setAbsCoor2D(3, -400);
    5248  this->textSize = 15;
    5349  this->lineSpacing = 5;
    54 
    55   //this->bufferSize = 0;
    56   this->setAbsCoor2D(3, -400);
     50  this->bActive = false;
     51
     52
     53  // BUFFER
     54  this->bufferText = NULL;
     55  this->setBufferDisplaySize(10);
     56
     57  // INPUT LINE
    5758  this->delayed = 0;
    5859  this->setRepeatDelay(.3, .05);
     
    6263  this->inputLine = new char[1];
    6364  this->inputLine[0] = '\0';
     65  this->inputHistory = new tList<char>;
     66  //this->commandList = new tList<ShellCommand>;
    6467
    6568  this->rebuildText();
     
    8992  delete this->inputLine;
    9093
    91   // delete all the Strings in the Buffers
    92   char* charElem = this->bufferIterator->firstElement();
    93   while (charElem != NULL)
    94   {
    95     delete charElem;
    96     charElem = this->bufferIterator->nextElement();
    97   }
    98   delete this->bufferIterator;
    99 
    100 //  if (this->completionList != NULL)
    101     //delete this->completionList;
    102 
    10394  Shell::singletonRef = NULL;
    10495}
     
    118109  this->setRelCoorSoft2D(0, 0, 1, 5);
    119110
    120   this->bufferIterator->lastElement();
     111  ShellBuffer::getInstance()->getBufferIterator()->lastElement();
    121112  for (int i = 0; i < this->bufferDisplaySize; i++)
    122     this->bufferText[i]->setText(this->bufferIterator->prevElement(), true);
     113    this->bufferText[i]->setText(ShellBuffer::getInstance()->getBufferIterator()->prevElement(), true);
    123114}
    124115
     
    135126  this->setRelCoorSoft2D(0, -400, 1, 5);
    136127
    137   this->bufferIterator->lastElement();
     128  ShellBuffer::getInstance()->getBufferIterator()->lastElement();
    138129  for (int i = 0; i < this->bufferDisplaySize; i++)
    139     this->bufferText[i]->setText(this->bufferIterator->prevElement(), false);
     130    this->bufferText[i]->setText(ShellBuffer::getInstance()->getBufferIterator()->prevElement(), false);
    140131}
    141132
     
    207198 * deletes all the Buffers
    208199 */
    209 void Shell::flushBuffers()
     200void Shell::flush()
    210201{
    211202  // remove all chars from the BufferTexts.
     
    216207    }
    217208
    218   // delete all the Chars in the Buffers
    219   tIterator<char>* charIterator = this->buffer->getIterator();
    220   char* charElem = charIterator->firstElement();
    221   while (charElem != NULL)
    222   {
    223     delete charElem;
    224 
    225     charElem = charIterator->nextElement();
    226   }
    227   delete charIterator;
    228   delete this->buffer;
    229   this->buffer = new tList<char>;
    230 }
    231 
    232 /**
    233  * adds a new Line to the List of Buffers
    234  * @param line the Line as in the first argument in printf
    235  */
    236 bool Shell::addBufferLineStatic(const char* line, ...)
    237 {
    238   va_list arguments;
    239   va_start(arguments, line);
    240 
    241 #if DEBUG < 3
    242   if (Shell::singletonRef == NULL)
    243 #endif
    244 
    245   vprintf(line, arguments);
    246 #if DEBUG < 3
    247   else
    248 #else
    249   if (Shell::singletonRef != NULL)
    250 #endif
    251     Shell::singletonRef->addBufferLine(line, arguments);
    252   return true;
    253 }
    254 
    255 /**
    256  * add a Line to the List of Buffers
    257  * @param line
    258  * @param arguments
    259  *
    260  * This function Adds one line to the buffer.
    261  * and displays the line as the First Line of the display-buffer
    262  */
    263 void Shell::addBufferLine(const char* line, va_list arguments)
    264 {
    265    vsprintf(this->bufferArray, line, arguments);
    266 
    267    char* inputEnd;
    268    char* newLineBegin;
    269    char* newLineEnd;
    270 
    271    // check if we have something left in the buffers
    272    if (unlikely(this->keepBuffer))
    273    {
    274      strcat(this->keepBufferArray, this->bufferArray);
    275      inputEnd = this->keepBufferArray + strlen(this->keepBufferArray);
    276      newLineBegin = this->keepBufferArray;
    277      this->keepBuffer = false;
    278    }
    279    else
    280    {
    281      inputEnd = this->bufferArray + strlen(this->bufferArray);
    282      newLineBegin = this->bufferArray;
    283    }
    284 
    285    // adding all the new Lines
    286    while (newLineBegin < inputEnd)
    287    {
    288      newLineEnd = strchr(newLineBegin, '\n');
    289      if (newLineEnd != NULL && *newLineEnd == '\n')
    290        *newLineEnd = '\0';
    291      else
    292      {
    293 //       newLineEnd = newLineBegin + strlen(newLineBegin);
    294        strcpy(this->keepBufferArray, newLineBegin);
    295        this->keepBuffer = true;
    296        break;
    297      }
    298 
    299      char* addLine = new char[strlen(newLineBegin)+1];
    300      strcpy(addLine, newLineBegin);
    301 
    302      this->buffer->add(addLine);
    303 
    304      if (this->buffer->getSize() > this->bufferSize)
    305      {
    306        delete this->buffer->firstElement();
    307        this->buffer->remove(this->buffer->firstElement());
    308      }
    309 
    310      if (this->bActive)
    311      {
    312        this->printToDisplayBuffer(addLine);
    313      }
    314      newLineBegin = newLineEnd+1;
    315    }
     209
     210    // BUFFER FLUSHING
    316211}
    317212
     
    345240
    346241/**
    347  * moves the buffer around lineCount lines upwards (negative values move down)
    348  * @param lineCount the Count of lines to move upwards
    349  *
    350  * @todo
    351  */
    352 void Shell::moveBuffer(unsigned int lineCount)
    353 {
    354 }
    355 
    356 /**
    357  * @param lineNumber the n-th line from the bottom
    358  * @returns the Buffer at Line lineNumber
    359  */
    360 const char* Shell::getBufferLine(unsigned int lineNumber)
    361 {
    362   tIterator<char>* charIterator = this->buffer->getIterator();
    363   char* charElem = charIterator->firstElement();
    364 
    365   int i = 1;
    366   while (charElem != NULL)
    367   {
    368     if (i++ < lineNumber)
    369     {
    370       delete charIterator;
    371       return charElem;
    372     }
    373 
    374     charElem = charIterator->nextElement();
    375   }
    376   delete charIterator;
    377 }
    378 
    379 /**
    380242 * deletes the InputLine
    381243 */
     
    446308bool Shell::executeCommand()
    447309{
    448   this->addBufferLineStatic("Execute Command: %s\n", this->inputLine);
     310  ShellBuffer::addBufferLineStatic("Execute Command: %s\n", this->inputLine);
    449311
    450312  char* newCommand = new char[strlen(this->inputLine)+1];
     
    464326void Shell::clear()
    465327{
    466   this->flushBuffers();
    467   this->addBufferLine("orxonox - shell\n ==================== \n", NULL);
     328  this->flush();
     329  ShellBuffer::addBufferLineStatic("orxonox - shell\n ==================== \n", NULL);
    468330}
    469331
     
    858720
    859721
    860   char* tmpChar = this->bufferIterator->firstElement();
     722  char* tmpChar = ShellBuffer::getInstance()->getBufferIterator()->firstElement();
    861723  while(tmpChar != NULL)
    862724  {
    863725    printf(tmpChar);
    864     tmpChar = this->bufferIterator->nextElement();
     726    tmpChar = ShellBuffer::getInstance()->getBufferIterator()->nextElement();
    865727  }
    866728}
Note: See TracChangeset for help on using the changeset viewer.