Changeset 7225 in orxonox.OLD for trunk/src/lib/shell
- Timestamp:
- Mar 18, 2006, 12:04:39 PM (19 years ago)
- Location:
- trunk/src/lib/shell
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/shell/shell_command.cc
r7221 r7225 36 36 * @param paramCount the count of parameters this command takes 37 37 */ 38 ShellCommand::ShellCommand(const char* commandName, const char*className, const Executor& executor)38 ShellCommand::ShellCommand(const std::string& commandName, const std::string& className, const Executor& executor) 39 39 { 40 40 this->setClassID(CL_SHELL_COMMAND, "ShellCommand"); … … 66 66 * registers a new ShellCommand 67 67 */ 68 ShellCommand* ShellCommand::registerCommand(const char* commandName, const char*className, const Executor& executor)68 ShellCommand* ShellCommand::registerCommand(const std::string& commandName, const std::string& className, const Executor& executor) 69 69 { 70 70 if (ShellCommand::isRegistered(commandName, className)) … … 80 80 * @param commandName the name of the command itself 81 81 */ 82 void ShellCommand::unregisterCommand(const char* commandName, const char*className)82 void ShellCommand::unregisterCommand(const std::string& commandName, const std::string& className) 83 83 { 84 84 /// FIXME … … 118 118 * This is checked in the registerCommand-function. 119 119 */ 120 bool ShellCommand::isRegistered(const char* commandName, const char*className)120 bool ShellCommand::isRegistered(const std::string& commandName, const std::string& className) 121 121 { 122 122 if (ShellCommandClass::commandClassList == NULL) … … 132 132 for (elem = checkClass->commandList.begin(); elem != checkClass->commandList.end(); elem++) 133 133 { 134 if ( !strcmp(commandName, (*elem)->getName()))135 { 136 PRINTF(2)("Command '%s::%s' already registered\n", className , commandName);134 if (commandName == (*elem)->getName()) 135 { 136 PRINTF(2)("Command '%s::%s' already registered\n", className.c_str(), commandName.c_str()); 137 137 return true; 138 138 } … … 272 272 * @returns itself 273 273 */ 274 ShellCommand* ShellCommand::setAlias(const char*alias)274 ShellCommand* ShellCommand::setAlias(const std::string& alias) 275 275 { 276 276 if (this == NULL) … … 352 352 { 353 353 return MultiType::MultiTypeToString((MT_Type)parameter); 354 // FIXME 355 /* switch (parameter) 356 { 357 case ParameterBool: 358 return "BOOL"; 359 break; 360 case ParameterChar: 361 return "CHAR"; 362 break; 363 case ParameterString: 364 return "STRING"; 365 break; 366 case ParameterInt: 367 return "INT"; 368 break; 369 case ParameterUInt: 370 return "UINT"; 371 break; 372 case ParameterFloat: 373 return "FLOAT"; 374 break; 375 case ParameterLong: 376 return "LONG"; 377 break; 378 default: 379 return "NULL"; 380 break; 381 }*/ 382 } 354 } -
trunk/src/lib/shell/shell_command.h
r7221 r7225 64 64 65 65 ShellCommand* describe(const std::string& description); 66 ShellCommand* setAlias(const char*alias);66 ShellCommand* setAlias(const std::string& alias); 67 67 ShellCommand* defaultValues(const MultiType& value0 = MT_NULL, const MultiType& value1 = MT_NULL, 68 68 const MultiType& value2 = MT_NULL, const MultiType& value3 = MT_NULL, 69 69 const MultiType& value4 = MT_NULL); 70 70 71 static ShellCommand* registerCommand(const char* commandName, const char*className, const Executor& executor);71 static ShellCommand* registerCommand(const std::string& commandName, const std::string& className, const Executor& executor); 72 72 73 static void unregisterCommand(const char* commandName, const char*className);73 static void unregisterCommand(const std::string& commandName, const std::string& className); 74 74 75 75 static void debug(); 76 76 77 77 protected: 78 ShellCommand(const char* commandName, const char*className, const Executor& executor);78 ShellCommand(const std::string& commandName, const std::string& className, const Executor& executor); 79 79 ~ShellCommand(); 80 80 81 static bool isRegistered(const char* commandName, const char*className);81 static bool isRegistered(const std::string& commandName, const std::string& className); 82 82 static const char* paramToString(long parameter); 83 83 -
trunk/src/lib/shell/shell_completion.cc
r7221 r7225 142 142 * @return true on success, false otherwise 143 143 */ 144 bool ShellCompletion::classComplete(const char* classBegin) 145 { 146 if (unlikely(classBegin == NULL)) 147 return false; 144 bool ShellCompletion::classComplete(const std::string& classBegin) 145 { 148 146 const std::list<std::string>* clList = ClassList::getClassNames(); 149 147 if (clList != NULL) … … 163 161 * @return true on success, false otherwise 164 162 */ 165 bool ShellCompletion::objectComplete(const char* objectBegin, long classID) 166 { 167 if (unlikely(objectBegin == NULL)) 168 return false; 163 bool ShellCompletion::objectComplete(const std::string& objectBegin, long classID) 164 { 169 165 const std::list<BaseObject*>* boList = ClassList::getList((ClassID)classID); 170 166 if (boList != NULL) … … 186 182 * @param classID the class' ID to complete the function of 187 183 */ 188 bool ShellCompletion::functionComplete(const char* functionBegin, const char* className) 189 { 190 if (unlikely(functionBegin == NULL)) 191 return false; 184 bool ShellCompletion::functionComplete(const std::string& functionBegin, const std::string& className) 185 { 192 186 std::list<std::string> fktList; 193 187 ShellCommandClass::getCommandListOfClass(className, &fktList); … … 203 197 * @returns true on succes, false if something went wrong 204 198 */ 205 bool ShellCompletion::aliasComplete(const char* aliasBegin) 206 { 207 if (unlikely(aliasBegin == NULL)) 208 return false; 199 bool ShellCompletion::aliasComplete(const std::string& aliasBegin) 200 { 209 201 std::list<std::string> aliasList; 210 202 ShellCommandClass::getCommandListOfAlias(&aliasList); … … 224 216 * @return true if ok, false otherwise 225 217 */ 226 bool ShellCompletion::generalComplete(const char* begin, const char* displayAs, const char* addBack, const char*addFront)218 bool ShellCompletion::generalComplete(const std::string& begin, const std::string& displayAs, const std::string& addBack, const std::string& addFront) 227 219 { 228 220 if (this->input == NULL ) … … 232 224 233 225 ShellC_Element addElem = completionList.front(); 234 const char*addString = addElem.name;226 const std::string& addString = addElem.name; 235 227 unsigned int addLength = 0; 236 unsigned int inputLenght = strlen(begin);228 unsigned int inputLenght = begin.size(); 237 229 238 230 // Determin the longest Match 239 if (addString != NULL) 240 addLength = strlen(addString); 231 addLength = addString.size(); 241 232 242 233 SHELLC_TYPE changeType = SHELLC_NONE; … … 251 242 changeType = (*charIT).type; 252 243 } 253 PRINTF(0)("%s ", (*charIT).name );244 PRINTF(0)("%s ", (*charIT).name.c_str()); 254 245 for (unsigned int i = inputLenght; i < addLength; i++) 255 246 if (addString[i] != (*charIT).name[i]) … … 263 254 if (addLength >= inputLenght) 264 255 { 265 char* adder = new char[addLength+1]; 266 strncpy(adder, addString, addLength); 267 adder[addLength] = '\0'; 256 std::string adder = addString; 257 adder.resize(addLength); 268 258 269 259 if (this->input) … … 274 264 if (completionList.size() == 1) 275 265 { 276 if ( addBack != NULL)266 if ( addBack != "") 277 267 this->input->addCharacters(addBack); 278 268 this->input->addCharacter(' '); 279 269 } 280 delete[] adder;281 270 } 282 271 } … … 290 279 * !! The strings MUST NOT be deleted !! 291 280 */ 292 bool ShellCompletion::addToCompleteList(const std::list<std::string>* inputList, const char*completionBegin, SHELLC_TYPE type)293 { 294 if (inputList == NULL || completionBegin == NULL)295 return false; 296 unsigned int searchLength = strlen(completionBegin);281 bool ShellCompletion::addToCompleteList(const std::list<std::string>* inputList, const std::string& completionBegin, SHELLC_TYPE type) 282 { 283 if (inputList == NULL) 284 return false; 285 unsigned int searchLength = completionBegin.size(); 297 286 298 287 list<std::string>::const_iterator string; … … 300 289 { 301 290 if ((*string).size() >= searchLength && 302 !strncasecmp((*string).c_str(), completionBegin , searchLength))291 !strncasecmp((*string).c_str(), completionBegin.c_str(), searchLength)) 303 292 { 304 293 ShellC_Element newElem; … … 317 306 * !! The strings MUST NOT be deleted !! 318 307 */ 319 bool ShellCompletion::addToCompleteList(const std::list<BaseObject*>* inputList, const char*completionBegin, SHELLC_TYPE type)320 { 321 if (inputList == NULL || completionBegin == NULL)322 return false; 323 unsigned int searchLength = strlen(completionBegin);308 bool ShellCompletion::addToCompleteList(const std::list<BaseObject*>* inputList, const std::string& completionBegin, SHELLC_TYPE type) 309 { 310 if (inputList == NULL) 311 return false; 312 unsigned int searchLength = completionBegin.size(); 324 313 325 314 list<BaseObject*>::const_iterator bo; … … 328 317 if ((*bo)->getName() != NULL && 329 318 strlen((*bo)->getName()) >= searchLength && 330 !strncasecmp((*bo)->getName(), completionBegin, searchLength))319 !strncasecmp((*bo)->getName(), completionBegin.c_str(), searchLength)) 331 320 { 332 321 ShellC_Element newElem; -
trunk/src/lib/shell/shell_completion.h
r7221 r7225 11 11 12 12 #include <list> 13 #include <string> 13 14 14 15 // FORWARD DECLARATION … … 30 31 //! A struct for ShellElements (these are used as containers to identify an Input for what it is) 31 32 struct ShellC_Element{ 32 const char*name; //!< the Name of the Element to be completed.33 std::string name; //!< the Name of the Element to be completed. 33 34 SHELLC_TYPE type; //!< the type of the Element 34 35 }; … … 42 43 43 44 bool autoComplete(ShellInput* input = NULL); 44 bool classComplete(const char*classBegin);45 bool classComplete(const std::string& classBegin); 45 46 // long classMatch(const char* input, unsigned int* length); 46 bool objectComplete(const char*objectBegin, long classID);47 bool objectComplete(const std::string& objectBegin, long classID); 47 48 // bool objectMatch(const char* objectBegin, long classID, unsigned int* length); 48 bool functionComplete(const char* functionBegin, const char*className);49 bool functionComplete(const std::string& functionBegin, const std::string& className); 49 50 // bool functionMatch(const char* functionBegin, long classID, unsigned int* length); 50 bool aliasComplete(const char*aliasBegin);51 bool aliasComplete(const std::string& aliasBegin); 51 52 52 bool generalComplete(const char* begin, const char* displayAs = "%s", const char* addBack = NULL, const char* addFront = NULL); 53 bool generalComplete(const std::string& begin, const std::string& displayAs = "%s", 54 const std::string& addBack = "", const std::string& addFront = ""); 53 55 54 bool addToCompleteList(const std::list<std::string>* inputList, const char*completionBegin, SHELLC_TYPE type);55 bool addToCompleteList(const std::list<BaseObject*>* inputList, const char*completionBegin, SHELLC_TYPE type);56 bool addToCompleteList(const std::list<std::string>* inputList, const std::string& completionBegin, SHELLC_TYPE type); 57 bool addToCompleteList(const std::list<BaseObject*>* inputList, const std::string& completionBegin, SHELLC_TYPE type); 56 58 void emptyCompletionList(); 57 59
Note: See TracChangeset
for help on using the changeset viewer.