Changeset 5192 in orxonox.OLD for trunk/src/lib/shell
- Timestamp:
- Sep 18, 2005, 12:49:27 AM (19 years ago)
- Location:
- trunk/src/lib/shell
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/shell/shell_command.cc
r5190 r5192 63 63 bool ShellCommandClass::getCommandListOfClass(const char* className, tList<const char>* stringList) 64 64 { 65 if (stringList == NULL )65 if (stringList == NULL || className == NULL) 66 66 return false; 67 67 -
trunk/src/lib/shell/shell_completion.cc
r5191 r5192 69 69 tList<BaseObject>* objectList; //< the list of Objects stored in classID 70 70 bool emptyComplete = false; //< if the completion input is empty string. e.g "" 71 SHELLC_TYPE firstType = SHELLC_NONE; 72 SHELLC_TYPE secondType = SHELLC_NONE; 71 73 72 74 … … 101 103 PRINTF(5)("Listing all Classes\n"); 102 104 this->objectComplete("", CL_SHELL_COMMAND_CLASS); 103 return false;104 105 } 105 106 else if (inputSplits.getCount() == 1 && emptyComplete == false) … … 110 111 111 112 // OBJECT/FUNCTION COMPLETIONS 112 else if ( (inputSplits.getCount() == 1 && emptyComplete == true) ||113 113 else if ((inputSplits.getCount() == 1 && emptyComplete == true) || 114 (inputSplits.getCount() == 2 && emptyComplete == false)) 114 115 { 115 116 classID = ClassList::StringToID(inputSplits.getString(0)); 116 117 if (classID == CL_NULL) 118 { 117 119 return false; 118 if (inputSplits.getCount()==2)119 {120 if (completionLine[strlen(completionLine)-1] != ' ')121 this->objectComplete(inputSplits.getString(1), classID);122 120 } 123 121 else 124 this->objectComplete("", classID); 125 } 126 // else if (inputSplits.getCount() <= 3 ) 127 128 /* completionLine = new char[strlen(this->input->getText())+1]; 129 strcpy(completionLine, this->input->getText()); 130 131 char* commandBegin = strrchr(completionLine, ' '); 132 if (commandBegin == NULL) 133 commandBegin = completionLine; 122 { 123 firstType = SHELLC_CLASS; 124 if (inputSplits.getCount() == 2) 125 { 126 if (completionLine[strlen(completionLine)-1] != ' ') 127 this->objectComplete(inputSplits.getString(1), classID); 128 } 129 else 130 this->objectComplete("", classID); 131 } 132 } 133 134 if (emptyComplete == false) 135 this->generalComplete(inputSplits.getString(inputSplits.getCount()-1)); 134 136 else 135 { 136 if(commandBegin >= completionLine + strlen(completionLine)) 137 commandBegin = completionLine + strlen(completionLine); 138 else 139 commandBegin++; 140 } 141 142 char* objectStart; 143 if (objectStart = strstr(commandBegin, "::")) 144 { 145 char* classIdentity = new char[objectStart - commandBegin +1]; 146 strncpy(classIdentity, commandBegin, objectStart - commandBegin); 147 classIdentity[objectStart - commandBegin] = '\0'; 148 this->objectComplete(objectStart+2, ClassList::StringToID(classIdentity)); 149 delete[] classIdentity; 150 } 151 else 152 this->classComplete(commandBegin); 153 154 delete[] completionLine;*/ 137 this->generalComplete(""); 155 138 } 156 139 … … 167 150 if (clList != NULL) 168 151 { 169 const tList<ShellC_Element>* classList = this->addToCompleteList(clList, classBegin); 170 if (classList != NULL) 171 this->generalComplete(classList, classBegin, "CL: %s "); 172 else 152 if (!this->addToCompleteList(clList, classBegin)) 173 153 return false; 174 delete classList;175 154 } 176 155 else … … 193 172 { 194 173 //printf("%s\n", boList->firstElement()->getName()); 195 const tList<ShellC_Element>* objectList = this->addToCompleteList(boList, objectBegin); 196 if (objectList != NULL) 197 this->generalComplete(objectList, objectBegin, "%s "); 198 else 174 if (!this->addToCompleteList(boList, objectBegin)) 199 175 return false; 200 176 } … … 214 190 /** 215 191 * completes the inputline on grounds of an inputList 216 * @param stringList the List to parse through217 192 * @param begin the String to search in the inputList, and to extend with it. 218 193 * @param displayAs how to display the found value to the user, printf-style, !!with only one %s!! ex.: "::%s::" … … 221 196 * @return true if ok, false otherwise 222 197 */ 223 bool ShellCompletion::generalComplete(const tList<ShellC_Element>* stringList, constchar* begin, const char* displayAs, const char* addBack, const char* addFront)224 { 225 if ( stringList == NULL || this->input == NULL )226 return false; 227 if ( stringList->getSize() == 0)228 return false; 229 230 ShellC_Element* addElem = stringList->firstElement();198 bool ShellCompletion::generalComplete(const char* begin, const char* displayAs, const char* addBack, const char* addFront) 199 { 200 if (completionList == NULL || this->input == NULL ) 201 return false; 202 if (completionList->getSize() == 0) 203 return false; 204 205 ShellC_Element* addElem = completionList->firstElement(); 231 206 const char* addString = addElem->name; 232 207 unsigned int addLength = 0; … … 236 211 if (addString != NULL) 237 212 addLength = strlen(addString); 238 tIterator<ShellC_Element>* charIterator = stringList->getIterator();213 tIterator<ShellC_Element>* charIterator = completionList->getIterator(); 239 214 ShellC_Element* charElem = charIterator->firstElement(); 240 215 while (charElem != NULL) … … 262 237 this->input->addCharacters(adder); 263 238 264 if ( stringList->getSize() == 1)239 if (completionList->getSize() == 1) 265 240 { 266 241 if ( addBack != NULL ) … … 280 255 * !! The strings MUST NOT be deleted !! 281 256 */ 282 const tList<ShellC_Element>*ShellCompletion::addToCompleteList(const tList<const char>* inputList, const char* completionBegin)257 bool ShellCompletion::addToCompleteList(const tList<const char>* inputList, const char* completionBegin) 283 258 { 284 259 if (inputList == NULL || completionBegin == NULL) 285 return NULL;260 return false; 286 261 unsigned int searchLength = strlen(completionBegin); 287 262 … … 302 277 delete iterator; 303 278 304 return t his->completionList;279 return true; 305 280 } 306 281 … … 311 286 * !! The strings MUST NOT be deleted !! 312 287 */ 313 const tList<ShellC_Element>*ShellCompletion::addToCompleteList(const tList<BaseObject>* inputList, const char* completionBegin)288 bool ShellCompletion::addToCompleteList(const tList<BaseObject>* inputList, const char* completionBegin) 314 289 { 315 290 if (inputList == NULL || completionBegin == NULL) 316 return NULL;291 return false; 317 292 unsigned int searchLength = strlen(completionBegin); 318 293 … … 334 309 delete iterator; 335 310 336 return t his->completionList;311 return true; 337 312 } 338 313 -
trunk/src/lib/shell/shell_completion.h
r5187 r5192 16 16 17 17 typedef enum { 18 SHELLC_NONE, 18 19 SHELLC_CLASS, 19 20 SHELLC_OBJECT, 20 21 SHELLC_FUNCTION, 21 22 SHELLC_ALIAS, 22 } SHELL _CTYPE;23 } SHELLC_TYPE; 23 24 24 25 struct ShellC_Element{ 25 26 const char* name; //!< 26 SHELL _CTYPE type;27 SHELLC_TYPE type; 27 28 }; 28 29 … … 42 43 bool functionMatch(const char* functionBegin, long classID, unsigned int* length); 43 44 44 bool generalComplete(const tList<ShellC_Element>* stringList, constchar* begin, const char* displayAs = "%s", const char* addBack = NULL, const char* addFront = NULL);45 bool generalComplete(const char* begin, const char* displayAs = "%s", const char* addBack = NULL, const char* addFront = NULL); 45 46 46 const tList<ShellC_Element>*addToCompleteList(const tList<const char>* inputList, const char* completionBegin);47 const tList<ShellC_Element>*addToCompleteList(const tList<BaseObject>* inputList, const char* completionBegin);47 bool addToCompleteList(const tList<const char>* inputList, const char* completionBegin); 48 bool addToCompleteList(const tList<BaseObject>* inputList, const char* completionBegin); 48 49 void emptyCompletionList(); 49 50 // const tList<const char>* createCompleteList(const tList<ShellCommandBase>* inputList, const char* completionBegin);
Note: See TracChangeset
for help on using the changeset viewer.