Changeset 7221 in orxonox.OLD for trunk/src/lib/shell/shell_input.cc
- Timestamp:
- Mar 15, 2006, 3:10:45 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/shell/shell_input.cc
r6222 r7221 41 41 * this also generates a ShellCompletion automatically. 42 42 */ 43 ShellInput::ShellInput () : Text ( (const char*)NULL)43 ShellInput::ShellInput () : Text ("") 44 44 { 45 45 this->pressedKey = SDLK_FIRST; 46 46 this->setClassID(CL_SHELL_INPUT, "ShellInput"); 47 47 48 this->inputLine = new char[1]; 49 this->inputLine[0] = '\0'; 48 this->inputLine = ""; 50 49 this->historyIT = this->history.begin(); 51 50 this->setHistoryLength(50); … … 70 69 { 71 70 // delete what has to be deleted here 72 delete[] this->inputLine;73 71 delete this->completion; 74 72 75 73 while (!this->history.empty()) 76 74 { 77 delete[] this->history.front();78 75 this->history.pop_front(); 79 76 } … … 96 93 void ShellInput::flush() 97 94 { 98 if (likely(this->inputLine != NULL)) 99 { 100 delete[] this->inputLine; 101 } 102 this->inputLine = new char[1]; 103 *this->inputLine = '\0'; 104 this->setText(this->inputLine, true); 95 this->inputLine.clear(); 96 this->setText(this->inputLine); 105 97 } 106 98 … … 109 101 * @param text the new Text to set as InputLine 110 102 */ 111 void ShellInput::setInputText(const char* text) 112 { 113 delete[] this->inputLine; 114 if (text == NULL) 115 { 116 this->inputLine = new char[1]; 117 this->inputLine[0] = '\0'; 118 } 119 else 120 { 121 this->inputLine = new char[strlen(text)+1]; 122 strcpy(this->inputLine, text); 123 } 124 this->setText(this->inputLine, true); 103 void ShellInput::setInputText(const std::string& text) 104 { 105 this->inputLine = text; 106 this->setText(this->inputLine); 125 107 } 126 108 … … 134 116 if (this->historyScrolling) 135 117 { 136 delete[] this->history.back();137 118 this->history.pop_back(); 138 119 this->historyScrolling = false; 139 120 } 140 121 141 char* addCharLine = new char[strlen(this->inputLine)+2]; 142 143 sprintf(addCharLine, "%s%c", this->inputLine, character); 144 delete[] this->inputLine; 145 this->inputLine = addCharLine; 146 this->setText(this->inputLine, true); 122 this->inputLine += character; 123 this->setText(this->inputLine); 147 124 } 148 125 … … 151 128 * @param characters a \\0 terminated char-array to add to the InputLine 152 129 */ 153 void ShellInput::addCharacters(const char*characters)130 void ShellInput::addCharacters(const std::string& characters) 154 131 { 155 132 if (this->historyScrolling) 156 133 { 157 delete[] this->history.back();158 134 this->history.pop_back(); 159 135 this->historyScrolling = false; 160 136 } 161 137 162 char* addCharLine = new char[strlen(this->inputLine)+strlen(characters)+1]; 163 164 sprintf(addCharLine, "%s%s", this->inputLine, characters); 165 delete[] this->inputLine; 166 this->inputLine = addCharLine; 167 this->setText(this->inputLine, true); 138 this->inputLine += characters; 139 this->setText(this->inputLine); 168 140 } 169 141 … … 176 148 if (this->historyScrolling) 177 149 { 178 delete[] this->history.back();179 150 this->history.pop_back(); 180 151 this->historyScrolling = false; 181 152 } 182 183 if (strlen(this->inputLine) == 0) 184 return; 185 186 if (characterCount > strlen(this->inputLine)) 187 characterCount = strlen(this->inputLine); 188 189 char* removeCharLine = new char[strlen(this->inputLine)-characterCount+1]; 190 191 strncpy(removeCharLine, this->inputLine, strlen(this->inputLine)-characterCount); 192 removeCharLine[strlen(this->inputLine)-characterCount] = '\0'; 193 delete[] this->inputLine; 194 this->inputLine = removeCharLine; 195 this->setText(this->inputLine, true); 153 if (this->inputLine.size() < characterCount) 154 characterCount = this->inputLine.size(); 155 156 this->inputLine.erase(this->inputLine.size() - characterCount, this->inputLine.size()); 157 this->setText(this->inputLine); 196 158 } 197 159 … … 202 164 bool ShellInput::executeCommand() 203 165 { 204 ShellBuffer::addBufferLineStatic("Execute Command: %s\n", this->inputLine );205 206 if ( strlen(this->inputLine) == 0)166 ShellBuffer::addBufferLineStatic("Execute Command: %s\n", this->inputLine.c_str()); 167 168 if (this->inputLine.empty()) 207 169 return false; 208 170 209 char* newCommand = new char[strlen(this->inputLine)+1]; 210 strcpy(newCommand, this->inputLine); 211 212 ShellCommand::execute(newCommand); 171 ShellCommand::execute(this->inputLine); 213 172 214 173 // removing the eventually added Entry (from scrolling) to the List 215 174 if (this->historyScrolling) 216 175 { 217 delete[] this->history.back();218 176 this->history.pop_back(); 219 177 this->historyScrolling = false; … … 221 179 222 180 // adding the new Command to the History 223 this->history.push_back( newCommand);181 this->history.push_back(this->inputLine); 224 182 if (this->history.size() > this->historyLength) 225 183 { 226 delete[] this->history.front();227 184 this->history.pop_front(); 228 185 } … … 241 198 if (!this->historyScrolling) 242 199 { 243 char* currentText = new char[strlen(this->inputLine)+1]; 244 strcpy(currentText, this->inputLine); 245 this->history.push_back(currentText); 200 this->history.push_back(this->inputLine); 246 201 this->historyScrolling = true; 247 202 this->historyIT = --this->history.end(); … … 250 205 if(this->historyIT != this->history.begin()) 251 206 { 252 char*prevElem = *(--this->historyIT);253 if (prevElem == NULL)207 std::string prevElem = *(--this->historyIT); 208 /*if (prevElem == NULL) /// TODO STD 254 209 return; 255 else 210 else */ 256 211 { 257 212 this->flush(); … … 270 225 if (this->historyIT != this->history.end()) 271 226 { 272 char*nextElem = *(++this->historyIT);273 if (nextElem == NULL)227 std::string nextElem = *(++this->historyIT); 228 /* if (nextElem == NULL) /// TODO FIX STD 274 229 return; 275 else 230 else */ 276 231 { 277 232 this->flush(); … … 285 240 * prints out some nice help about the Shell 286 241 */ 287 void ShellInput::help(const char* className, const char*functionName)288 { 289 printf("%s::%s\n", className , functionName);290 291 if ( strlen(className) == 0)242 void ShellInput::help(const std::string& className, const std::string& functionName) 243 { 244 printf("%s::%s\n", className.c_str(), functionName.c_str()); 245 246 if (className.empty()) 292 247 { 293 248 PRINT(0)("Help for the most important Shell-commands\n"); … … 298 253 PRINT(0)("- Also try 'help className'"); 299 254 } 300 else if ( strlen (className) > 0 && strlen (functionName) == 0)255 else if (!className.empty() && functionName.empty()) 301 256 { 302 257 ShellCommandClass::help(className);
Note: See TracChangeset
for help on using the changeset viewer.