Changeset 5175 in orxonox.OLD for trunk/src/lib/shell/shell.cc
- Timestamp:
- Sep 11, 2005, 11:21:56 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/shell/shell.cc
r5174 r5175 18 18 #include "shell.h" 19 19 #include "shell_command.h" 20 #include "shell_buffer.h" 21 20 22 21 23 #include "text_engine.h" … … 43 45 this->setName("Shell"); 44 46 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); 52 48 this->textSize = 15; 53 49 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 57 58 this->delayed = 0; 58 59 this->setRepeatDelay(.3, .05); … … 62 63 this->inputLine = new char[1]; 63 64 this->inputLine[0] = '\0'; 65 this->inputHistory = new tList<char>; 66 //this->commandList = new tList<ShellCommand>; 64 67 65 68 this->rebuildText(); … … 89 92 delete this->inputLine; 90 93 91 // delete all the Strings in the Buffers92 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 103 94 Shell::singletonRef = NULL; 104 95 } … … 118 109 this->setRelCoorSoft2D(0, 0, 1, 5); 119 110 120 this->bufferIterator->lastElement();111 ShellBuffer::getInstance()->getBufferIterator()->lastElement(); 121 112 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); 123 114 } 124 115 … … 135 126 this->setRelCoorSoft2D(0, -400, 1, 5); 136 127 137 this->bufferIterator->lastElement();128 ShellBuffer::getInstance()->getBufferIterator()->lastElement(); 138 129 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); 140 131 } 141 132 … … 207 198 * deletes all the Buffers 208 199 */ 209 void Shell::flush Buffers()200 void Shell::flush() 210 201 { 211 202 // remove all chars from the BufferTexts. … … 216 207 } 217 208 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 316 211 } 317 212 … … 345 240 346 241 /** 347 * moves the buffer around lineCount lines upwards (negative values move down)348 * @param lineCount the Count of lines to move upwards349 *350 * @todo351 */352 void Shell::moveBuffer(unsigned int lineCount)353 {354 }355 356 /**357 * @param lineNumber the n-th line from the bottom358 * @returns the Buffer at Line lineNumber359 */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 /**380 242 * deletes the InputLine 381 243 */ … … 446 308 bool Shell::executeCommand() 447 309 { 448 this->addBufferLineStatic("Execute Command: %s\n", this->inputLine);310 ShellBuffer::addBufferLineStatic("Execute Command: %s\n", this->inputLine); 449 311 450 312 char* newCommand = new char[strlen(this->inputLine)+1]; … … 464 326 void Shell::clear() 465 327 { 466 this->flush Buffers();467 this->addBufferLine("orxonox - shell\n ==================== \n", NULL);328 this->flush(); 329 ShellBuffer::addBufferLineStatic("orxonox - shell\n ==================== \n", NULL); 468 330 } 469 331 … … 858 720 859 721 860 char* tmpChar = this->bufferIterator->firstElement();722 char* tmpChar = ShellBuffer::getInstance()->getBufferIterator()->firstElement(); 861 723 while(tmpChar != NULL) 862 724 { 863 725 printf(tmpChar); 864 tmpChar = this->bufferIterator->nextElement();726 tmpChar = ShellBuffer::getInstance()->getBufferIterator()->nextElement(); 865 727 } 866 728 }
Note: See TracChangeset
for help on using the changeset viewer.