- Timestamp:
- May 22, 2006, 3:14:07 PM (19 years ago)
- Location:
- trunk/src/lib/shell
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/shell/shell_buffer.cc
r7744 r7761 35 35 36 36 this->lineCount = 0; 37 this->keepBufferArray[0] = '\0';38 37 this->bufferArray[0] = '\0'; 39 this->keepBuffer = false;40 38 41 39 this->setBufferSize(100); … … 123 121 void ShellBuffer::addBufferLine(const char* line, va_list arguments) 124 122 { 125 char* inputEnd;126 char* newLineBegin;127 char* newLineEnd;128 129 123 // copy the output to the bufferArray 130 124 vsprintf(this->bufferArray, line, arguments); 131 125 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()) 135 132 { 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++; 146 138 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. 154 145 { 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); 162 147 break; 163 148 } 164 149 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 169 151 170 152 if (this->buffer.size() > this->bufferSize) 171 153 this->buffer.pop_back(); 172 173 newLineBegin = newLineEnd+1;174 154 } 175 155 } -
trunk/src/lib/shell/shell_buffer.h
r7747 r7761 8 8 #define _SHELL_BUFFER_H 9 9 10 #include <string> 10 11 #include <list> 11 12 #include <stdarg.h> … … 61 62 Shell* shell; //!< the Registered Shell. 62 63 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. 65 65 66 66 unsigned long lineCount; //!< how many Lines have been written out so far.
Note: See TracChangeset
for help on using the changeset viewer.