- Timestamp:
- Sep 11, 2005, 11:21:56 PM (19 years ago)
- Location:
- trunk/src
- Files:
-
- 6 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 } -
trunk/src/lib/shell/shell.h
r5174 r5175 39 39 /** @returns a Pointer to the only object of this Class */ 40 40 inline static Shell* getInstance() { if (!Shell::singletonRef) Shell::singletonRef = new Shell(); return Shell::singletonRef; }; 41 /** @returns true if this class is instanciated, false otherwise */ 42 inline static bool isInstanciated() { return (Shell::singletonRef == NULL)?true:false; }; 41 43 42 44 void activate(); … … 46 48 void rebuildText(); 47 49 48 // BUFFER // 49 /** @param bufferSize the new Buffer-Size */ 50 void setBufferSize(unsigned int bufferSize) { this->bufferSize = bufferSize; }; 50 // BUFFERS 51 51 void setBufferDisplaySize(unsigned int bufferDisplaySize); 52 void flushBuffers(); 53 static bool addBufferLineStatic(const char* line, ...); 54 void addBufferLine(const char* line, va_list arg); 52 void flush(); 55 53 void printToDisplayBuffer(const char* text); 56 void moveBuffer(unsigned int lineCount);57 // void moveBufferTo(unsigned int lineNumber);58 const char* getBufferLine(unsigned int lineNumber);59 54 60 55 // InputLine … … 103 98 static Shell* singletonRef; //!< The singleton-reference to the only memeber of this class. 104 99 105 unsigned int bufferSize; //!< The Size of the buffer106 100 unsigned int bufferDisplaySize; //!< The Size of the Display-buffer, in lines (not in characters) 107 101 102 // HANDLING TEXT INPUT 108 103 Text* inputLineText; //!< The inputLine of the Shell 109 104 char* inputLine; //!< the Char-Array of the Buffer … … 112 107 float delayed; //!< how much of the delay is remaining. 113 108 int pressedKey; //!< the pressed key that will be repeated. 114 115 tList<char>* buffer; //!< A list of stored char-arrays(strings) to store the history116 tIterator<char>* bufferIterator; //!< An iterator for the Shells main buffer.117 109 118 110 tList<char>* inputHistory; //!< The history of given commands. … … 124 116 bool bActive; //!< if the shell is active; 125 117 126 char bufferArray[SHELL_BUFFER_SIZE]; //!< a BUFFER for fast writing127 char keepBufferArray[SHELL_BUFFER_SIZE]; //!< a BUFFER to have multi-non-newLine commands be copied into the shell.128 bool keepBuffer; //!< if the keepbuffer contains unfinished lines.129 130 118 // completion 131 119 tList<const char>* completionList; //!< A list of completions, that are io. -
trunk/src/lib/shell/shell_buffer.cc
r5174 r5175 19 19 #include "debug.h" 20 20 #include "list.h" 21 #include "shell.h" 21 22 22 23 #include "stdlibincl.h" … … 31 32 ShellBuffer::ShellBuffer () 32 33 { 34 ShellBuffer::singletonRef = this; 35 36 this->lineCount = 0; 33 37 this->keepBufferArray[0] = '\0'; 34 38 this->keepBuffer = false; 35 39 this->buffer = new tList<char>; 40 this->bufferIterator = this->buffer->getIterator(); 36 41 37 42 this->setBufferSize(10); … … 45 50 ShellBuffer::~ShellBuffer () 46 51 { 52 if (Shell::isInstanciated()) 53 delete Shell::getInstance(); 47 54 55 this->flushBuffers(); 56 delete bufferIterator; 48 57 delete buffer; 49 58 … … 57 66 { 58 67 // delete all the Chars in the Buffers 59 tIterator<char>* charIterator = this->buffer->getIterator(); 60 char* charElem = charIterator->firstElement(); 68 char* charElem = bufferIterator->firstElement(); 61 69 while (charElem != NULL) 62 70 { 63 71 delete charElem; 64 72 65 charElem = charIterator->nextElement();73 charElem = bufferIterator->nextElement(); 66 74 } 67 delete charIterator;75 delete this->bufferIterator; 68 76 delete this->buffer; 69 77 this->buffer = new tList<char>; 78 this->bufferIterator = this->buffer->getIterator(); 70 79 } 71 80 … … 141 150 142 151 this->buffer->add(addLine); 152 this->lineCount++; 143 153 144 154 if (this->buffer->getSize() > this->bufferSize) -
trunk/src/lib/shell/shell_buffer.h
r5174 r5175 14 14 template<class T> class tList; 15 15 template<class T> class tIterator; 16 #ifndef NULL 17 #define NULL 0 //!< a pointer to NULL 18 #endif 16 19 17 20 //! A class for ... … … 22 25 /** @returns a Pointer to the only object of this Class */ 23 26 inline static ShellBuffer* getInstance() { if (!ShellBuffer::singletonRef) ShellBuffer::singletonRef = new ShellBuffer(); return ShellBuffer::singletonRef; }; 27 /** @returns true if this class is instanciated, false otherwise */ 28 inline static bool isInstanciated() { return (ShellBuffer::singletonRef == NULL)?true:false; }; 24 29 25 30 // BUFFER // … … 30 35 void addBufferLine(const char* line, va_list arg); 31 36 void moveBuffer(unsigned int lineCount); 32 // 37 // void moveBufferTo(unsigned int lineNumber); 33 38 const char* getBufferLine(unsigned int lineNumber); 39 inline tIterator<char>* getBufferIterator() const { return bufferIterator; }; 34 40 35 41 private: -
trunk/src/orxonox.cc
r5171 r5175 51 51 #include "shell.h" 52 52 #include "shell_command.h" 53 #include "shell_buffer.h" 53 54 54 55 #include <string.h> -
trunk/src/story_entities/world.cc
r5174 r5175 116 116 World::~World () 117 117 { 118 delete Shell Buffer::getInstance();118 delete Shell::getInstance(); 119 119 PRINTF(3)("World::~World() - deleting current world\n"); 120 120 … … 196 196 197 197 /* init the world interface */ 198 Shell Buffer::getInstance();198 Shell::getInstance(); 199 199 200 200 LightManager::getInstance();
Note: See TracChangeset
for help on using the changeset viewer.