Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7761 in orxonox.OLD for trunk/src/lib


Ignore:
Timestamp:
May 22, 2006, 3:14:07 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: ShellBuffer with STD::STRING… hope it works

Location:
trunk/src/lib/shell
Files:
2 edited

Legend:

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

    r7744 r7761  
    3535
    3636    this->lineCount = 0;
    37     this->keepBufferArray[0] = '\0';
    3837    this->bufferArray[0] = '\0';
    39     this->keepBuffer = false;
    4038
    4139    this->setBufferSize(100);
     
    123121  void ShellBuffer::addBufferLine(const char* line, va_list arguments)
    124122  {
    125     char* inputEnd;
    126     char* newLineBegin;
    127     char* newLineEnd;
    128 
    129123    // copy the output to the bufferArray
    130124    vsprintf(this->bufferArray, line, arguments);
    131125
    132     // check if we have something left in the buffers
    133     // if so, append the new String to this one.
    134     if (unlikely(this->keepBuffer))
     126    std::string inputBuffer = this->keepBuffer + this->bufferArray;
     127
     128    int lineBegin = 0;
     129    int lineEnd = 0;
     130    // adding all the new Lines
     131    while (lineEnd < inputBuffer.size())
    135132    {
    136       strcat(this->keepBufferArray, this->bufferArray);
    137       inputEnd = this->keepBufferArray + strlen(this->bufferArray);
    138       newLineBegin = this->keepBufferArray;
    139       this->keepBuffer = false;
    140     }
    141     else
    142     {
    143       inputEnd = this->bufferArray + strlen(this->bufferArray);
    144       newLineBegin = this->bufferArray;
    145     }
     133      lineBegin = lineEnd;
     134      lineEnd = inputBuffer.find('\n', (lineBegin == 0) ? 0: ++lineBegin);
     135      if (likely(lineEnd != std::string::npos ))
     136      {
     137        this->lineCount++;
    146138
    147     // adding all the new Lines
    148     while (newLineBegin < inputEnd)
    149     {
    150       newLineEnd = strchr(newLineBegin, '\n');
    151       if (likely(newLineEnd != NULL && *newLineEnd == '\n'))
    152         *newLineEnd = '\0';
    153       else
     139        printf("Test:: %s \n", inputBuffer.substr(lineBegin, lineEnd - lineBegin).c_str());
     140        this->buffer.push_front(inputBuffer.substr(lineBegin, lineEnd - lineBegin));
     141        if (likely (this->shell != NULL) && unlikely (this->shell->isActive()))
     142          this->shell->printToDisplayBuffer(this->buffer.front());
     143      }
     144      else      // No end of Line reached.
    154145      {
    155         unsigned int len = strlen(newLineBegin);
    156         char* copyBuffer = new char[len+1];
    157         strcpy(copyBuffer, newLineBegin);
    158         strncpy(this->keepBufferArray, copyBuffer, len);
    159         delete[] copyBuffer;
    160         this->keepBufferArray[len] = '\0';
    161         this->keepBuffer = true;
     146        this->keepBuffer = inputBuffer.substr(lineBegin, inputBuffer.size() - lineBegin);
    162147        break;
    163148      }
    164149
    165       this->lineCount++;
    166       this->buffer.push_front(newLineBegin);
    167       if (likely (this->shell != NULL) && unlikely (this->shell->isActive()))
    168         this->shell->printToDisplayBuffer(newLineBegin);
     150
    169151
    170152      if (this->buffer.size() > this->bufferSize)
    171153        this->buffer.pop_back();
    172 
    173       newLineBegin = newLineEnd+1;
    174154    }
    175155  }
  • trunk/src/lib/shell/shell_buffer.h

    r7747 r7761  
    88#define _SHELL_BUFFER_H
    99
     10#include <string>
    1011#include <list>
    1112#include <stdarg.h>
     
    6162    Shell*                        shell;                              //!< the Registered Shell.
    6263    char                          bufferArray[SHELL_BUFFER_SIZE];     //!< a BUFFER for fast writing
    63     char                          keepBufferArray[SHELL_BUFFER_SIZE]; //!< a BUFFER to have multi-non-newLine commands be copied into the shell.
    64     bool                          keepBuffer;                         //!< if the keepbuffer contains unfinished lines.
     64    std::string                   keepBuffer;                         //!< a BUFFER to have multi-non-newLine commands be copied into the shell.
    6565
    6666    unsigned long                 lineCount;                          //!< how many Lines have been written out so far.
Note: See TracChangeset for help on using the changeset viewer.