- Timestamp:
- Apr 28, 2006, 12:54:04 AM (19 years ago)
- Location:
- trunk/src/lib/shell
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/shell/shell_command.cc
r7412 r7413 102 102 } 103 103 104 105 104 /** 106 105 * @brief gets a command if it has already been registered. 107 106 * @param commandName the name of the Command 108 * @param className the name of the Class the command should apply to. 107 * @param cmdClass the CommandClass of the Class the command is in. 108 * @returns The Registered Command, or NULL if it does not exist. 109 */ 110 const ShellCommand* const ShellCommand::getCommand(const std::string& commandName, const ShellCommandClass* cmdClass) 111 { 112 assert(cmdClass != NULL); 113 114 std::vector<ShellCommand*>::const_iterator elem; 115 for (elem = cmdClass->commandList.begin(); elem != cmdClass->commandList.end(); elem++) 116 if (commandName == (*elem)->getName()) 117 return (*elem); 118 return NULL; 119 } 120 121 122 /** 123 * @brief gets a command if it has already been registered. 124 * @param commandName the name of the Command 125 * @param className the name of the Class the command is in. 109 126 * @returns The Registered Command, or NULL if it does not exist. 110 127 */ … … 113 130 const ShellCommandClass* checkClass = ShellCommandClass::getCommandClass(className); 114 131 if (likely(checkClass != NULL)) 115 { 116 std::vector<ShellCommand*>::const_iterator elem; 117 for (elem = checkClass->commandList.begin(); elem != checkClass->commandList.end(); elem++) 118 if (commandName == (*elem)->getName()) 119 { 120 PRINTF(2)("Command '%s::%s' already registered\n", className.c_str(), commandName.c_str()); 121 return (*elem); 122 } 123 } 132 return ShellCommand::getCommand(commandName, checkClass); 124 133 return NULL; 125 134 } 135 136 /** 137 * @brief takes out an InputLine, searching for a Command. 138 * @param inputLine: the Input to analyse. 139 * @returns: The ShellCommand if found. 140 */ 141 const ShellCommand* const ShellCommand::getCommandFromInput(const std::string& inputLine) 142 { 143 SubString strings(inputLine, SubString::WhiteSpaces); 144 // no input, no Command. 145 if (strings.size() == 0) 146 return NULL; 147 148 // CHECK FOR ALIAS 149 std::vector<ShellCommandAlias*>::const_iterator alias; 150 for (alias = ShellCommandAlias::getAliases().begin(); alias != ShellCommandAlias::getAliases().end(); alias++ ) 151 { 152 if (strings[0] == (*alias)->getName()) 153 { 154 assert ((*alias)->getCommand() != NULL && (*alias)->getCommand()->shellClass != NULL); 155 return (*alias)->getCommand(); 156 } 157 } 158 159 const ShellCommandClass* cmdClass = ShellCommandClass::getCommandClass(strings[0]); 160 if (cmdClass != NULL) 161 { 162 const ShellCommand* retCmd; 163 if (strings.size() >= 1) 164 retCmd = ShellCommand::getCommand(strings[1], cmdClass); 165 if (retCmd == NULL && strings.size() >= 2) 166 retCmd = ShellCommand::getCommand(strings[2], cmdClass); 167 return retCmd; 168 169 } 170 } 171 126 172 127 173 /** … … 303 349 { 304 350 PRINTF(1)("Parameter %d not inside of valid ParameterCount %d of Command %s::%s\n", 305 parameter, this->executor->getParamCount(), this->getName(), this->shellClass->getName());351 parameter, this->executor->getParamCount(), this->getName(), this->shellClass->getName()); 306 352 } 307 353 else -
trunk/src/lib/shell/shell_command.h
r7412 r7413 74 74 static void unregisterCommand(const std::string& commandName, const std::string& className); 75 75 static const ShellCommand* const getCommand(const std::string& commandName, const std::string& className); 76 static const ShellCommand* const getCommand(const std::string& commandName, const ShellCommandClass* cmdClass); 76 77 static bool exists(const std::string& commandName, const std::string& className); 78 static const ShellCommand* const getCommandFromInput(const std::string& inputLine); 77 79 78 80 const ShellCommandClass* const getCommandClass() const { return this->shellClass; }; -
trunk/src/lib/shell/shell_completion.cc
r7412 r7413 57 57 std::string completeString = ""; //< the string to complete. 58 58 unsigned int parameterBegin = 0; //< The SubString-entry, the Parameters begin. 59 const ShellCommand* command = NULL; //< The Command. 59 60 60 61 … … 82 83 // OBJECT/FUNCTION COMPLETIONS 83 84 else if ((emptyComplete && inputSplits.size() == 1) || 84 85 (!emptyComplete && inputSplits.size() == 2)) 85 86 { 86 87 classID = ClassList::StringToID(inputSplits.getString(0)); … … 99 100 100 101 // Looking for ParameterCompletions. 102 if (completeType == NullCompletion) 103 { 104 if ((command = ShellCommand::getCommandFromInput(input)) != NULL) 105 completeType |= ParamCompletion; 106 } 101 107 102 108 if (completeType & ClassCompletion) … … 108 114 if (completeType & AliasCompletion) 109 115 this->aliasComplete(completeString); 110 111 if (completeType == NullCompletion) 112 { 113 const ShellCommand* sc = ShellCommand::getCommand(inputSplits[2], inputSplits[0]); 114 if (sc != NULL) 115 { 116 std::vector<std::string> completed; 117 sc->getCompletorPlugin(0)->addToCompleteList(completed, inputSplits[inputSplits.size()-1]); 118 for (unsigned int i = 0; i < completed.size(); i++) 119 this->completionList.push_back(CompletionElement(completed[i], ParamCompletion)); 120 } 121 } 116 if (completeType & ParamCompletion) 117 this->paramComplete(completeString, command); 118 122 119 123 120 … … 157 154 std::list<std::string> fktList; 158 155 ShellCommandClass::getCommandListOfClass(className, fktList); 159 //printf("%s\n", boList->firstElement()->getName());160 156 if (!this->addToCompleteList(fktList, commandBegin, FunctionCompletion)) 161 157 return false; … … 172 168 std::list<std::string> aliasList; 173 169 ShellCommandAlias::getCommandListOfAlias(aliasList); 174 //printf("%s\n", boList->firstElement()->getName());175 170 if (!this->addToCompleteList(aliasList, aliasBegin, AliasCompletion)) 176 171 return false; 177 172 return true; 173 } 174 175 /** 176 * @brief completes Parameters. 177 * @param paramBegin: Begin of the Parameters. 178 * @returns true on succes, false if something went wrong 179 */ 180 bool ShellCompletion::paramComplete(const std::string& paramBegin, const ShellCommand* command) 181 { 182 std::vector<std::string> completed; 183 command->getCompletorPlugin(0)->addToCompleteList(completed, paramBegin); 184 for (unsigned int i = 0; i < completed.size(); i++) 185 this->completionList.push_back(CompletionElement(completed[i], ParamCompletion)); 178 186 } 179 187 … … 197 205 CompletionElement addElem = completionList.front(); 198 206 const std::string& addString = addElem.name; 199 unsigned int addLength = 0;207 unsigned int addLength = addString.size(); 200 208 unsigned int inputLenght = begin.size(); 201 209 202 // Determin the longest Match 203 addLength = addString.size(); 204 210 // Determin the longest Match (starting with the first candidate in full length). 205 211 CompletionType changeType = NullCompletion; 206 212 std::vector<CompletionElement>::iterator charIT; 207 213 for (charIT = completionList.begin(); charIT != completionList.end(); charIT++) 208 214 { 215 printf("== %s\n", (*charIT).name.c_str()); 209 216 if ((*charIT).type != changeType) 210 217 { … … 217 224 for (unsigned int i = inputLenght; i < addLength; i++) 218 225 if (addString[i] != (*charIT).name[i]) 219 {220 226 addLength = i; 221 // break;222 }223 227 } 224 228 PRINT(0)("\n"); -
trunk/src/lib/shell/shell_completion.h
r7412 r7413 19 19 namespace OrxShell 20 20 { 21 class ShellCommand; 22 21 23 //! A class for Completing the an InputString. 22 24 class ShellCompletion … … 54 56 bool commandComplete(const std::string& commandBegin, const std::string& className); 55 57 bool aliasComplete(const std::string& aliasBegin); 58 bool paramComplete(const std::string& paramBegin, const ShellCommand* command); 56 59 57 60 // Generally Completes.
Note: See TracChangeset
for help on using the changeset viewer.