Changeset 5779 in orxonox.OLD for trunk/src/lib/shell/shell_command.cc
- Timestamp:
- Nov 26, 2005, 2:20:58 PM (19 years ago)
- File:
-
- 1 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
Note: See TracChangeset
for help on using the changeset viewer.