Changeset 5779 in orxonox.OLD for trunk/src/lib/shell
- Timestamp:
- Nov 26, 2005, 2:20:58 PM (19 years ago)
- Location:
- trunk/src/lib/shell
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/shell/shell_command.cc
r5656 r5779 47 47 this->shellClass = ShellCommandClass::getCommandClass(className); //ClassList::IDToString(classID); 48 48 if (this->shellClass != NULL) 49 this->shellClass->commandList ->add(this);49 this->shellClass->commandList.push_back(this); 50 50 } 51 51 … … 82 82 void ShellCommand::unregisterCommand(const char* commandName, const char* className) 83 83 { 84 if (ShellCommandClass::commandClassList == NULL) 84 /// FIXME 85 /* if (ShellCommandClass::commandClassList == NULL) 85 86 ShellCommandClass::initCommandClassList(); 86 87 … … 89 90 if (checkClass != NULL) 90 91 { 91 tIterator<ShellCommand>* iterator = checkClass->commandList->getIterator(); 92 ShellCommand* elem = iterator->firstElement(); 93 while(elem != NULL) 94 { 95 if (!strcmp(commandName, elem->getName())) 96 { 97 checkClass->commandList->remove(elem); 98 delete elem; 92 std::list<ShellCommand*>::iterator elem; 93 for (elem = checkClass->commandList.begin(); elem != checkClass->commandList.end(); elem++) 94 { 95 if (!strcmp(commandName, (*elem)->getName())) 96 { 97 delete (*elem); 98 checkClass->commandList.remove(*elem); 99 99 break; 100 100 } 101 elem = iterator->nextElement(); 102 } 103 delete iterator; 104 105 if (checkClass->commandList->getSize() == 0) 101 } 102 103 if (checkClass->commandList->size() == 0) 106 104 { 107 105 ShellCommandClass::commandClassList->remove(checkClass); 108 106 delete checkClass; 109 107 } 110 } 108 }*/ 111 109 } 112 110 … … 132 130 if (checkClass != NULL) 133 131 { 134 tIterator<ShellCommand>* iterator = checkClass->commandList->getIterator(); 135 ShellCommand* elem = iterator->firstElement(); 136 while(elem != NULL) 137 { 138 if (!strcmp(commandName, elem->getName())) 139 { 140 PRINTF(2)("Command already registered\n"); 141 delete iterator; 142 return true; 143 } 144 elem = iterator->nextElement(); 145 } 146 delete iterator; 132 std::list<ShellCommand*>::const_iterator elem; 133 for (elem = checkClass->commandList.begin(); elem != checkClass->commandList.end(); elem++) 134 { 135 if (!strcmp(commandName, (*elem)->getName())) 136 { 137 PRINTF(2)("Command '%s::%s' already registered\n", className, commandName); 138 return true; 139 } 140 } 147 141 return false; 148 142 } … … 163 157 return false; 164 158 165 long classID = CL_NULL; //< the classID retrieved from the Class.166 ShellCommandClass* commandClass = NULL; //< the command class this command applies to.167 tList<BaseObject>* objectList = NULL; //< the list of Objects stored in classID168 BaseObject* objectPointer = NULL; //< a pointer to th Object to Execute the command on169 bool emptyComplete = false; //< if the completion input is empty string. e.g ""170 unsigned int fktPos = 1; //< the position of the function (needed for finding it)171 // long completeType = SHELLC_NONE; //< the Type we'd like to complete.159 long classID = CL_NULL; //< the classID retrieved from the Class. 160 ShellCommandClass* commandClass = NULL; //< the command class this command applies to. 161 std::list<BaseObject*>* objectList = NULL; //< the list of Objects stored in classID 162 BaseObject* objectPointer = NULL; //< a pointer to th Object to Execute the command on 163 bool emptyComplete = false; //< if the completion input is empty string. e.g "" 164 unsigned int fktPos = 1; //< the position of the function (needed for finding it) 165 // long completeType = SHELLC_NONE; //< the Type we'd like to complete. 172 166 SubString inputSplits(executionString, " \t\n,"); 173 167 … … 179 173 if (ShellCommandClass::aliasList != NULL) 180 174 { 181 tIterator<ShellCommandAlias>* itAL = ShellCommandClass::aliasList->getIterator(); 182 ShellCommandAlias* elemAL = itAL->firstElement(); 183 while(elemAL != NULL) 184 { 185 if (elemAL->getName() != NULL && !strcmp(elemAL->getName(), inputSplits.getString(0)) && elemAL->getCommand() != NULL && 186 elemAL->getCommand()->shellClass != NULL ) 175 list<ShellCommandAlias*>::iterator alias; 176 for (alias = ShellCommandClass::aliasList->begin(); alias != ShellCommandClass::aliasList->end(); alias++ ) 177 { 178 if ((*alias)->getName() != NULL && !strcmp((*alias)->getName(), inputSplits.getString(0)) && (*alias)->getCommand() != NULL && 179 (*alias)->getCommand()->shellClass != NULL ) 187 180 { 188 objectList = ClassList::getList( elemAL->getCommand()->shellClass->getName());181 objectList = ClassList::getList((*alias)->getCommand()->shellClass->getName()); 189 182 if (objectList != NULL) 190 183 { 191 184 if (inputSplits.getCount() > 1) 192 elemAL->getCommand()->executor->execute(objectList->firstElement(), executionString+inputSplits.getOffset(1));185 (*alias)->getCommand()->executor->execute(objectList->front(), executionString+inputSplits.getOffset(1)); 193 186 else 194 elemAL->getCommand()->executor->execute(objectList->firstElement(), ""); 195 delete itAL; 187 (*alias)->getCommand()->executor->execute(objectList->front(), ""); 188 return true; 189 } 190 } 191 } 192 } 193 // looking for a Matching Class 194 if (likely(ShellCommandClass::commandClassList != NULL)) 195 { 196 list<ShellCommandClass*>::iterator commandClassIT; 197 for (commandClassIT = ShellCommandClass::commandClassList->begin(); commandClassIT != ShellCommandClass::commandClassList->end(); commandClassIT++) 198 { 199 if ((*commandClassIT)->getName() && !strcasecmp(inputSplits.getString(0), (*commandClassIT)->getName())) 200 { 201 //elemCL->getName(); 202 classID = ClassList::StringToID((*commandClassIT)->getName()); 203 commandClass = (*commandClassIT); 204 objectList = ClassList::getList(classID); 205 break; 206 } 207 } 208 } 209 210 if (commandClass != NULL && inputSplits.getCount() >= 2) 211 { 212 if (objectList != NULL) 213 { 214 // Checking for a Match in the Objects of classID (else take the first) 215 list<BaseObject*>::const_iterator object; 216 for (object = objectList->begin(); object != objectList->end(); object++) 217 { 218 if ((*object)->getName() != NULL && !strcasecmp((*object)->getName(), inputSplits.getString(1))) 219 { 220 objectPointer = (*object); 221 fktPos = 2; 222 break; 223 } 224 } 225 226 // 227 if (objectPointer == NULL) 228 objectPointer = objectList->front(); 229 } 230 // match a function. 231 if (commandClass != NULL && (fktPos == 1 || (fktPos == 2 && inputSplits.getCount() >= 3))) 232 { 233 list<ShellCommand*>::iterator cmdIT; 234 for (cmdIT = commandClass->commandList.begin(); cmdIT != commandClass->commandList.end(); cmdIT++) 235 { 236 if (!strcmp((*cmdIT)->getName(), inputSplits.getString(fktPos))) 237 { 238 if (objectPointer == NULL && (*cmdIT)->executor->getType() & Executor_Objective) 239 return false; 240 if (inputSplits.getCount() > fktPos+1) 241 (*cmdIT)->executor->execute(objectPointer, executionString+inputSplits.getOffset(fktPos +1)); 242 else 243 (*cmdIT)->executor->execute(objectPointer, ""); 196 244 return true; 197 245 } 198 246 } 199 elemAL = itAL->nextElement();200 }201 delete itAL;202 }203 // looking for a Matching Class204 if (likely(ShellCommandClass::commandClassList != NULL))205 {206 tIterator<ShellCommandClass>* itCL = ShellCommandClass::commandClassList->getIterator();207 ShellCommandClass* elemCL = itCL->firstElement();208 while(elemCL != NULL)209 {210 if (elemCL->getName() && !strcasecmp(inputSplits.getString(0), elemCL->getName()))211 {212 //elemCL->getName();213 classID = ClassList::StringToID(elemCL->getName());214 commandClass = elemCL;215 objectList = ClassList::getList(classID);216 break;217 }218 elemCL = itCL->nextElement();219 }220 delete itCL;221 }222 223 if (commandClass != NULL && inputSplits.getCount() >= 2)224 {225 if (objectList != NULL)226 {227 // Checking for a Match in the Objects of classID (else take the first)228 tIterator<BaseObject>* itBO = objectList->getIterator();229 BaseObject* enumBO = itBO->firstElement();230 while(enumBO)231 {232 if (enumBO->getName() != NULL && !strcasecmp(enumBO->getName(), inputSplits.getString(1)))233 {234 objectPointer = enumBO;235 fktPos = 2;236 break;237 }238 enumBO = itBO->nextElement();239 }240 delete itBO;241 242 //243 if (objectPointer == NULL)244 objectPointer = objectList->firstElement();245 }246 // match a function.247 if (commandClass != NULL && (fktPos == 1 || (fktPos == 2 && inputSplits.getCount() >= 3)))248 {249 tIterator<ShellCommand>* itCMD = commandClass->commandList->getIterator();250 ShellCommand* enumCMD = itCMD->firstElement();251 while (enumCMD != NULL)252 {253 if (!strcmp(enumCMD->getName(), inputSplits.getString(fktPos)))254 {255 if (objectPointer == NULL && enumCMD->executor->getType() & Executor_Objective)256 {257 delete itCMD;258 return false;259 }260 if (inputSplits.getCount() > fktPos+1)261 enumCMD->executor->execute(objectPointer, executionString+inputSplits.getOffset(fktPos +1));262 else263 enumCMD->executor->execute(objectPointer, "");264 delete itCMD;265 return true;266 }267 268 enumCMD = itCMD->nextElement();269 }270 delete itCMD;271 247 } 272 248 } … … 306 282 { 307 283 if (ShellCommandClass::aliasList == NULL) 308 ShellCommandClass::aliasList = new tList<ShellCommandAlias>;284 ShellCommandClass::aliasList = new std::list<ShellCommandAlias*>; 309 285 310 286 ShellCommandAlias* aliasCMD = new ShellCommandAlias(alias, this); 311 ShellCommandClass::aliasList-> add(aliasCMD);287 ShellCommandClass::aliasList->push_back(aliasCMD); 312 288 this->alias = aliasCMD; 313 289 } … … 348 324 } 349 325 350 tIterator<ShellCommandClass>* iteratorCL = ShellCommandClass::commandClassList->getIterator(); 351 ShellCommandClass* elemCL = iteratorCL->firstElement(); 352 while(elemCL != NULL) 353 { 354 PRINT(0)("Class:'%s' registered %d commands: \n", elemCL->className, elemCL->commandList->getSize()); 355 tIterator<ShellCommand>* iterator = elemCL->commandList->getIterator(); 356 const ShellCommand* elem = iterator->firstElement(); 357 while(elem != NULL) 358 { 359 PRINT(0)(" command:'%s' : params:%d: ", elem->getName(), elem->executor->getParamCount()); 326 list<ShellCommandClass*>::iterator classIT; 327 for (classIT = ShellCommandClass::commandClassList->begin(); classIT != ShellCommandClass::commandClassList->end(); classIT++) 328 { 329 PRINT(0)("Class:'%s' registered %d commands: \n", (*classIT)->className, (*classIT)->commandList.size()); 330 331 list<ShellCommand*>::iterator cmdIT; 332 for (cmdIT = (*classIT)->commandList.begin(); cmdIT != (*classIT)->commandList.end(); cmdIT++) 333 { 334 PRINT(0)(" command:'%s' : params:%d: ", (*cmdIT)->getName(), (*cmdIT)->executor->getParamCount()); 360 335 /// FIXME 361 336 /* for (unsigned int i = 0; i< elem->paramCount; i++) 362 337 printf("%s ", ShellCommand::paramToString(elem->parameters[i]));*/ 363 if ( elem->description != NULL)364 printf("- %s", elem->description);338 if ((*cmdIT)->description != NULL) 339 printf("- %s", (*cmdIT)->description); 365 340 printf("\n"); 366 341 367 elem = iterator->nextElement(); 368 } 369 delete iterator; 370 elemCL = iteratorCL->nextElement(); 371 } 372 delete iteratorCL; 342 } 343 } 373 344 } 374 345 -
trunk/src/lib/shell/shell_command.h
r5690 r5779 108 108 109 109 private: 110 const char* 110 const char* aliasName; //!< the name of the Alias 111 111 ShellCommand* command; //!< a pointer to the command, this alias executes. 112 112 }; -
trunk/src/lib/shell/shell_command_class.cc
r5644 r5779 29 29 using namespace std; 30 30 31 tList<ShellCommandClass>* ShellCommandClass::commandClassList = NULL;32 tList<ShellCommandAlias>* ShellCommandClass::aliasList = NULL;31 std::list<ShellCommandClass*>* ShellCommandClass::commandClassList = NULL; 32 std::list<ShellCommandAlias*>* ShellCommandClass::aliasList = NULL; 33 33 34 34 /** … … 43 43 this->className = className; 44 44 this->classID = CL_NULL; 45 this->commandList = new tList<ShellCommand>; 46 47 ShellCommandClass::commandClassList->add(this); 45 46 ShellCommandClass::commandClassList->push_back(this); 48 47 } 49 48 … … 53 52 ShellCommandClass::~ShellCommandClass() 54 53 { 55 tIterator<ShellCommand>* iterator = this->commandList->getIterator(); 56 ShellCommand* elem = iterator->firstElement(); 57 while(elem != NULL) 58 { 59 delete elem; 60 elem = iterator->nextElement(); 61 } 62 delete iterator; 63 delete this->commandList; 54 while(this->commandList.size() > 0) 55 { 56 delete this->commandList.front(); 57 this->commandList.pop_front(); 58 } 64 59 } 65 60 … … 70 65 * @returns true on success, false otherwise 71 66 */ 72 bool ShellCommandClass::getCommandListOfClass(const char* className, tList<const char>* stringList)67 bool ShellCommandClass::getCommandListOfClass(const char* className, std::list<const char*>* stringList) 73 68 { 74 69 if (stringList == NULL || className == NULL) 75 70 return false; 76 71 77 tIterator<ShellCommandClass>* iterator = ShellCommandClass::commandClassList->getIterator(); 78 ShellCommandClass* elem = iterator->firstElement(); 79 while(elem != NULL) 80 { 81 if (!strcmp (elem->getName(), className)) 82 { 83 tIterator<ShellCommand>* itFkt = elem->commandList->getIterator(); 84 ShellCommand* command = itFkt->firstElement(); 85 while (command != NULL) 86 { 87 stringList->add(command->getName()); 88 command = itFkt->nextElement(); 89 } 90 delete itFkt; 91 } 92 93 elem = iterator->nextElement(); 94 } 95 delete iterator; 72 list<ShellCommandClass*>::iterator elem; 73 for(elem = ShellCommandClass::commandClassList->begin(); elem != ShellCommandClass::commandClassList->end(); elem++) 74 { 75 if (!strcmp ((*elem)->getName(), className)) 76 { 77 list<ShellCommand*>::iterator command; 78 for(command = (*elem)->commandList.begin(); command != (*elem)->commandList.end(); command++) 79 stringList->push_back((*command)->getName()); 80 } 81 } 96 82 return true; 97 83 } … … 102 88 * @returns true on success, false otherwise 103 89 */ 104 bool ShellCommandClass::getCommandListOfAlias( tList<const char>* stringList)90 bool ShellCommandClass::getCommandListOfAlias(std::list<const char*>* stringList) 105 91 { 106 92 if (stringList == NULL || ShellCommandClass::aliasList == NULL) 107 93 return false; 108 94 109 tIterator<ShellCommandAlias>* iterator = ShellCommandClass::aliasList->getIterator(); 110 ShellCommandAlias* elem = iterator->firstElement(); 111 while(elem != NULL) 112 { 113 stringList->add(elem->getName()); 114 elem = iterator->nextElement(); 115 } 116 delete iterator; 117 return true; 95 list<ShellCommandAlias*>::iterator alias; 96 for (alias = ShellCommandClass::aliasList->begin(); alias != ShellCommandClass::aliasList->end(); alias++) 97 stringList->push_back((*alias)->getName()); 98 return true; 118 99 } 119 100 … … 123 104 void ShellCommandClass::unregisterAllCommands() 124 105 { 125 if (ShellCommandClass::commandClassList != NULL) 106 /// FIXME 107 108 /* if (ShellCommandClass::commandClassList != NULL) 126 109 { 127 110 // unregister all commands … … 153 136 delete ShellCommandClass::aliasList; 154 137 ShellCommandClass::aliasList = NULL; 155 } 138 }*/ 156 139 } 157 140 … … 166 149 initCommandClassList(); 167 150 168 tIterator<ShellCommandClass>* iterator = ShellCommandClass::commandClassList->getIterator(); 169 ShellCommandClass* elem = iterator->firstElement(); 170 while(elem != NULL) 171 { 172 if (!strcmp(className, elem->className)) 173 { 174 if (elem->classID == CL_NULL) 175 elem->classID = ClassList::StringToID(className); 176 177 delete iterator; 178 return elem; 179 } 180 elem = iterator->nextElement(); 181 } 182 delete iterator; 151 list<ShellCommandClass*>::const_iterator classIT; 152 for (classIT = ShellCommandClass::commandClassList->begin(); classIT != ShellCommandClass::commandClassList->end(); classIT++) 153 { 154 if (!strcmp(className, (*classIT)->className)) 155 { 156 if ((*classIT)->classID == CL_NULL) 157 (*classIT)->classID = ClassList::StringToID(className); 158 159 return (*classIT); 160 } 161 } 183 162 return NULL; 184 163 } … … 194 173 initCommandClassList(); 195 174 196 tIterator<ShellCommandClass>* iterator = ShellCommandClass::commandClassList->getIterator(); 197 ShellCommandClass* elem = iterator->firstElement(); 198 while(elem != NULL) 199 { 200 if (!strcmp(className, elem->className)) 201 { 202 delete iterator; 203 return elem; 204 } 205 elem = iterator->nextElement(); 206 } 207 delete iterator; 175 list<ShellCommandClass*>::iterator classIT; 176 for (classIT = ShellCommandClass::commandClassList->begin(); classIT != ShellCommandClass::commandClassList->end(); classIT++) 177 { 178 if (!strcmp(className, (*classIT)->className)) 179 { 180 return (*classIT); 181 } 182 } 208 183 return new ShellCommandClass(className); 209 184 } … … 216 191 if (ShellCommandClass::commandClassList == NULL) 217 192 { 218 ShellCommandClass::commandClassList = new tList<ShellCommandClass>;193 ShellCommandClass::commandClassList = new std::list<ShellCommandClass*>; 219 194 ShellCommand::registerCommand("debug", "ShellCommand", ExecutorStatic<ShellCommand>(ShellCommand::debug)); 220 195 } … … 231 206 if (likely(ShellCommandClass::commandClassList != NULL)) 232 207 { 233 tIterator<ShellCommandClass>* itCL = ShellCommandClass::commandClassList->getIterator(); 234 ShellCommandClass* elemCL = itCL->firstElement(); 235 while(elemCL != NULL) 236 { 237 if (elemCL->className && !strcasecmp(className, elemCL->className)) 208 list<ShellCommandClass*>::iterator classIT; 209 for (classIT = ShellCommandClass::commandClassList->begin(); classIT != ShellCommandClass::commandClassList->end(); classIT++) 210 { 211 if ((*classIT)->className && !strcasecmp(className, (*classIT)->className)) 238 212 { 239 PRINT(0)("Class:'%s' registered %d commands: \n", elemCL->className, elemCL->commandList->getSize()); 240 tIterator<ShellCommand>* iterator = elemCL->commandList->getIterator(); 241 const ShellCommand* elem = iterator->firstElement(); 242 while(elem != NULL) 213 PRINT(0)("Class:'%s' registered %d commands: \n", (*classIT)->className, (*classIT)->commandList.size()); 214 list<ShellCommand*>::const_iterator cmdIT; 215 for (cmdIT = (*classIT)->commandList.begin(); cmdIT != (*classIT)->commandList.end(); cmdIT++) 243 216 { 244 PRINT(0)(" command:'%s' : params:%d: ", elem->getName(), elem->executor->getParamCount());217 PRINT(0)(" command:'%s' : params:%d: ", (*cmdIT)->getName(), (*cmdIT)->executor->getParamCount()); 245 218 /// FIXME 246 219 /* for (unsigned int i = 0; i< elem->paramCount; i++) 247 220 PRINT(0)("%s ", ShellCommand::paramToString(elem->parameters[i]));*/ 248 if ( elem->description != NULL)249 PRINT(0)("- %s", elem->description);221 if ((*cmdIT)->description != NULL) 222 PRINT(0)("- %s", (*cmdIT)->description); 250 223 PRINT(0)("\n"); 251 elem = iterator->nextElement();252 224 } 253 delete iterator;254 255 delete itCL;256 225 return; 257 226 } 258 elemCL = itCL->nextElement(); 259 } 260 delete itCL; 227 } 261 228 PRINTF(3)("Class %s not found in Command's classes\n", className); 262 229 } -
trunk/src/lib/shell/shell_command_class.h
r5639 r5779 8 8 9 9 #include "base_object.h" 10 #include <list> 10 11 11 12 … … 26 27 public: 27 28 /** @returns the CommandClassList */ 28 static const tList<ShellCommandClass>* getCommandClassList() { return ShellCommandClass::commandClassList; };29 static bool getCommandListOfClass(const char* className, tList<const char>* stringList);30 static bool getCommandListOfAlias( tList<const char>* aliasList);29 static const std::list<ShellCommandClass*>* getCommandClassList() { return ShellCommandClass::commandClassList; }; 30 static bool getCommandListOfClass(const char* className, std::list<const char*>* stringList); 31 static bool getCommandListOfAlias(std::list<const char*>* aliasList); 31 32 32 33 static ShellCommandClass* getCommandClass(const char* className); … … 43 44 44 45 private: 45 const char* className; //!< The Name of the Class. This should match the ClassName of the Commands Class.46 long classID; //!< The classID of this Class47 tList<ShellCommand>*commandList; //!< A list of Commands from this Class48 static tList<ShellCommandClass>*commandClassList; //!< A list of Classes49 static tList<ShellCommandAlias>*aliasList; //!< An Alias to A Command. (only for classes with one Instance)46 const char* className; //!< The Name of the Class. This should match the ClassName of the Commands Class. 47 long classID; //!< The classID of this Class 48 std::list<ShellCommand*> commandList; //!< A list of Commands from this Class 49 static std::list<ShellCommandClass*>* commandClassList; //!< A list of Classes 50 static std::list<ShellCommandAlias*>* aliasList; //!< An Alias to A Command. (only for classes with one Instance) 50 51 }; 51 52 -
trunk/src/lib/shell/shell_completion.cc
r5656 r5779 63 63 bool ShellCompletion::autoComplete(ShellInput* input) 64 64 { 65 const char* completionLine; //< the inputLine we complete.66 67 long classID; //< the classID retrieved from the Class.68 tList<BaseObject>* objectList; //< the list of Objects stored in classID69 bool emptyComplete = false; //< if the completion input is empty string. e.g ""70 long completeType = SHELLC_NONE; //< the Type we'd like to complete.71 const char* completeString; //< the string to complete.65 const char* completionLine; //< the inputLine we complete. 66 67 long classID; //< the classID retrieved from the Class. 68 std::list<BaseObject*>* objectList; //< the list of Objects stored in classID 69 bool emptyComplete = false; //< if the completion input is empty string. e.g "" 70 long completeType = SHELLC_NONE; //< the Type we'd like to complete. 71 const char* completeString; //< the string to complete. 72 72 73 73 … … 159 159 if (unlikely(classBegin == NULL)) 160 160 return false; 161 const tList<const char>* clList = ClassList::getClassList();161 const std::list<const char*>* clList = ClassList::getClassList(); 162 162 if (clList != NULL) 163 163 { … … 180 180 if (unlikely(objectBegin == NULL)) 181 181 return false; 182 const tList<BaseObject>* boList = ClassList::getList(classID);182 const std::list<BaseObject*>* boList = ClassList::getList(classID); 183 183 if (boList != NULL) 184 184 { … … 203 203 if (unlikely(functionBegin == NULL)) 204 204 return false; 205 tList<const char> fktList;205 std::list<const char*> fktList; 206 206 ShellCommandClass::getCommandListOfClass(className, &fktList); 207 207 //printf("%s\n", boList->firstElement()->getName()); … … 220 220 if (unlikely(aliasBegin == NULL)) 221 221 return false; 222 tList<const char> aliasList;222 std::list<const char*> aliasList; 223 223 ShellCommandClass::getCommandListOfAlias(&aliasList); 224 224 //printf("%s\n", boList->firstElement()->getName()); … … 241 241 if (completionList == NULL || this->input == NULL ) 242 242 return false; 243 if (completionList-> getSize() == 0)244 return false; 245 246 ShellC_Element* addElem = completionList->f irstElement();243 if (completionList->size() == 0) 244 return false; 245 246 ShellC_Element* addElem = completionList->front(); 247 247 const char* addString = addElem->name; 248 248 unsigned int addLength = 0; … … 252 252 if (addString != NULL) 253 253 addLength = strlen(addString); 254 tIterator<ShellC_Element>* charIterator = completionList->getIterator(); 255 ShellC_Element* charElem = charIterator->firstElement(); 254 256 255 SHELLC_TYPE changeType = SHELLC_NONE; 257 while (charElem != NULL) 258 { 259 if (charElem->type != changeType) 256 list<ShellC_Element*>::iterator charIT; 257 for (charIT = completionList->begin(); charIT != completionList->end(); charIT++) 258 { 259 if ((*charIT)->type != changeType) 260 260 { 261 261 if (changeType != SHELLC_NONE) 262 262 PRINT(0)("\n"); 263 PRINT(0)("%s: ", ShellCompletion::typeToString( charElem->type));264 changeType = charElem->type;265 } 266 PRINTF(0)("%s ", charElem->name);263 PRINT(0)("%s: ", ShellCompletion::typeToString((*charIT)->type)); 264 changeType = (*charIT)->type; 265 } 266 PRINTF(0)("%s ", (*charIT)->name); 267 267 for (unsigned int i = inputLenght; i < addLength; i++) 268 if (addString[i] != charElem->name[i])268 if (addString[i] != (*charIT)->name[i]) 269 269 { 270 270 addLength = i; 271 271 // break; 272 272 } 273 charElem = charIterator->nextElement(); 274 } 275 delete charIterator; 273 } 276 274 PRINT(0)("\n"); 277 275 … … 287 285 this->input->addCharacters(adder); 288 286 289 if (completionList-> getSize() == 1)287 if (completionList->size() == 1) 290 288 { 291 289 if ( addBack != NULL ) … … 305 303 * !! The strings MUST NOT be deleted !! 306 304 */ 307 bool ShellCompletion::addToCompleteList(const tList<const char>* inputList, const char* completionBegin, SHELLC_TYPE type)305 bool ShellCompletion::addToCompleteList(const std::list<const char*>* inputList, const char* completionBegin, SHELLC_TYPE type) 308 306 { 309 307 if (inputList == NULL || completionBegin == NULL) … … 311 309 unsigned int searchLength = strlen(completionBegin); 312 310 313 tIterator<const char>* iterator = inputList->getIterator(); 314 const char* enumString = iterator->firstElement(); 315 while (enumString != NULL) 316 { 317 if (strlen(enumString) >= searchLength && 318 !strncasecmp(enumString, completionBegin, searchLength)) 319 { 320 printf("%s\n", enumString); 311 list<const char*>::const_iterator string; 312 for (string = inputList->begin(); string != inputList->end(); string++) 313 { 314 if (strlen(*string) >= searchLength && 315 !strncasecmp(*string, completionBegin, searchLength)) 316 { 317 printf("%s\n", *string); 321 318 ShellC_Element* newElem = new ShellC_Element; 322 newElem->name = enumString;319 newElem->name = *string; 323 320 newElem->type = type; 324 this->completionList->add(newElem); 325 } 326 enumString = iterator->nextElement(); 327 } 328 delete iterator; 329 321 this->completionList->push_back(newElem); 322 } 323 } 330 324 return true; 331 325 } … … 337 331 * !! The strings MUST NOT be deleted !! 338 332 */ 339 bool ShellCompletion::addToCompleteList(const tList<BaseObject>* inputList, const char* completionBegin, SHELLC_TYPE type)333 bool ShellCompletion::addToCompleteList(const std::list<BaseObject*>* inputList, const char* completionBegin, SHELLC_TYPE type) 340 334 { 341 335 if (inputList == NULL || completionBegin == NULL) … … 343 337 unsigned int searchLength = strlen(completionBegin); 344 338 345 tIterator<BaseObject>* iterator = inputList->getIterator(); 346 BaseObject* enumBO = iterator->firstElement(); 347 while (enumBO != NULL) 348 { 349 if (enumBO->getName() != NULL && 350 strlen(enumBO->getName()) >= searchLength && 351 !strncasecmp(enumBO->getName(), completionBegin, searchLength)) 339 list<BaseObject*>::const_iterator bo; 340 for(bo = inputList->begin(); bo != inputList->end(); bo++) 341 { 342 if ((*bo)->getName() != NULL && 343 strlen((*bo)->getName()) >= searchLength && 344 !strncasecmp((*bo)->getName(), completionBegin, searchLength)) 352 345 { 353 346 ShellC_Element* newElem = new ShellC_Element; 354 newElem->name = enumBO->getName();347 newElem->name = (*bo)->getName(); 355 348 newElem->type = type; 356 this->completionList->add(newElem); 357 } 358 enumBO = iterator->nextElement(); 359 } 360 delete iterator; 349 this->completionList->push_back(newElem); 350 } 351 } 361 352 362 353 return true; … … 372 363 if (this->completionList != NULL) 373 364 { 374 tIterator<ShellC_Element>* elemIT = this->completionList->getIterator(); 375 ShellC_Element* elem = elemIT->firstElement(); 376 while (elem != NULL) 377 { 378 delete elem; 379 elem = elemIT->nextElement(); 380 } 381 delete this->completionList; 382 } 383 this->completionList = new tList<ShellC_Element>; 365 while (this->completionList->size() > 0) 366 { 367 delete this->completionList->front(); 368 this->completionList->pop_front(); 369 } 370 } 384 371 } 385 372 -
trunk/src/lib/shell/shell_completion.h
r5371 r5779 9 9 #ifndef _SHELL_COMPLETION_H 10 10 #define _SHELL_COMPLETION_H 11 12 #include <list> 11 13 12 14 // FORWARD DECLARATION … … 51 53 bool generalComplete(const char* begin, const char* displayAs = "%s", const char* addBack = NULL, const char* addFront = NULL); 52 54 53 bool addToCompleteList(const tList<const char>* inputList, const char* completionBegin, SHELLC_TYPE type);54 bool addToCompleteList(const tList<BaseObject>* inputList, const char* completionBegin, SHELLC_TYPE type);55 bool addToCompleteList(const std::list<const char*>* inputList, const char* completionBegin, SHELLC_TYPE type); 56 bool addToCompleteList(const std::list<BaseObject*>* inputList, const char* completionBegin, SHELLC_TYPE type); 55 57 void emptyCompletionList(); 56 58 … … 58 60 59 61 private: 60 tList<ShellC_Element>*completionList; //!< A list of completions, that are io.61 ShellInput* input; //!< the input this completion works on.62 std::list<ShellC_Element*>* completionList; //!< A list of completions, that are io. 63 ShellInput* input; //!< the input this completion works on. 62 64 }; 63 65
Note: See TracChangeset
for help on using the changeset viewer.