[4744] | 1 | /* |
---|
[1853] | 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 orx |
---|
| 5 | |
---|
| 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
[1855] | 10 | |
---|
| 11 | ### File Specific: |
---|
[5068] | 12 | main-programmer: Benjamin Grauer |
---|
[1855] | 13 | co-programmer: ... |
---|
[1853] | 14 | */ |
---|
| 15 | |
---|
[7374] | 16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_SHELL |
---|
[1853] | 17 | |
---|
[5129] | 18 | #include "shell_command.h" |
---|
[5639] | 19 | #include "shell_command_class.h" |
---|
[1853] | 20 | |
---|
[6222] | 21 | #include "compiler.h" |
---|
[5129] | 22 | #include "debug.h" |
---|
[5113] | 23 | #include "class_list.h" |
---|
| 24 | |
---|
| 25 | #include "key_names.h" |
---|
[5075] | 26 | |
---|
[7374] | 27 | namespace OrxShell |
---|
[3365] | 28 | { |
---|
[7394] | 29 | SHELL_COMMAND_STATIC(debug, ShellCommand, ShellCommand::debug); |
---|
[5141] | 30 | |
---|
[7394] | 31 | |
---|
[7374] | 32 | /** |
---|
[7394] | 33 | * @brief constructs and registers a new Command |
---|
[7374] | 34 | * @param commandName the name of the Command |
---|
| 35 | * @param className the name of the class to apply this command to |
---|
| 36 | * @param paramCount the count of parameters this command takes |
---|
| 37 | */ |
---|
| 38 | ShellCommand::ShellCommand(const std::string& commandName, const std::string& className, const Executor& executor) |
---|
| 39 | { |
---|
| 40 | this->setClassID(CL_SHELL_COMMAND, "ShellCommand"); |
---|
| 41 | PRINTF(5)("create shellcommand %s %s\n", commandName, className); |
---|
| 42 | this->setName(commandName); |
---|
[7398] | 43 | |
---|
| 44 | // copy the executor: |
---|
[7374] | 45 | this->executor = executor.clone(); |
---|
| 46 | this->executor->setName(commandName); |
---|
[7398] | 47 | |
---|
[7407] | 48 | for (unsigned int i = 0; i < this->executor->getParamCount(); i++) |
---|
| 49 | this->completors.push_back(new CompletorDefault(&this->executor->getDefaultValue(i))); |
---|
[7388] | 50 | this->alias = NULL; |
---|
[4320] | 51 | |
---|
[7374] | 52 | // this->classID = classID; |
---|
[7408] | 53 | this->shellClass = ShellCommandClass::acquireCommandClass(className); |
---|
[7398] | 54 | assert (this->shellClass != NULL); |
---|
[7399] | 55 | this->shellClass->registerCommand(this); |
---|
[7374] | 56 | } |
---|
| 57 | |
---|
| 58 | /** |
---|
[7394] | 59 | * @brief deconstructs a ShellCommand |
---|
[7374] | 60 | */ |
---|
| 61 | ShellCommand::~ShellCommand() |
---|
[5196] | 62 | { |
---|
[7399] | 63 | this->shellClass->unregisterCommand(this); |
---|
[7389] | 64 | if (this->alias != NULL) |
---|
[7374] | 65 | delete this->alias; |
---|
[7407] | 66 | while (!this->completors.empty()) |
---|
| 67 | { |
---|
| 68 | delete this->completors.back(); |
---|
| 69 | this->completors.pop_back(); |
---|
| 70 | } |
---|
[7374] | 71 | delete this->executor; |
---|
[5196] | 72 | } |
---|
[1853] | 73 | |
---|
[7374] | 74 | /** |
---|
[7398] | 75 | * @brief registers a new ShellCommand |
---|
[7374] | 76 | */ |
---|
| 77 | ShellCommand* ShellCommand::registerCommand(const std::string& commandName, const std::string& className, const Executor& executor) |
---|
| 78 | { |
---|
[7403] | 79 | if (ShellCommand::exists(commandName, className)) |
---|
[7374] | 80 | return NULL; |
---|
| 81 | else |
---|
| 82 | return new ShellCommand(commandName, className, executor); |
---|
[5636] | 83 | |
---|
[7374] | 84 | } |
---|
[5636] | 85 | |
---|
[7374] | 86 | /** |
---|
[7398] | 87 | * @brief unregister an existing commandName |
---|
[7374] | 88 | * @param className the name of the Class the command belongs to. |
---|
| 89 | * @param commandName the name of the command itself |
---|
| 90 | */ |
---|
| 91 | void ShellCommand::unregisterCommand(const std::string& commandName, const std::string& className) |
---|
| 92 | { |
---|
[5171] | 93 | |
---|
[7408] | 94 | ShellCommandClass* cmdClass = ShellCommandClass::acquireCommandClass(className); |
---|
[7399] | 95 | if (cmdClass != NULL) |
---|
| 96 | { |
---|
| 97 | std::vector<ShellCommand*>::iterator cmd; |
---|
| 98 | for (cmd = cmdClass->commandList.begin(); cmd < cmdClass->commandList.end(); cmd++) |
---|
| 99 | if (commandName == (*cmd)->getName()) |
---|
| 100 | delete (*cmd); |
---|
| 101 | } |
---|
[5113] | 102 | } |
---|
[5105] | 103 | |
---|
[7413] | 104 | /** |
---|
| 105 | * @brief gets a command if it has already been registered. |
---|
| 106 | * @param commandName the name of the Command |
---|
| 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); |
---|
[7408] | 113 | |
---|
[7413] | 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 | |
---|
[7374] | 122 | /** |
---|
[7408] | 123 | * @brief gets a command if it has already been registered. |
---|
[7374] | 124 | * @param commandName the name of the Command |
---|
[7413] | 125 | * @param className the name of the Class the command is in. |
---|
[7408] | 126 | * @returns The Registered Command, or NULL if it does not exist. |
---|
[7374] | 127 | */ |
---|
[7408] | 128 | const ShellCommand* const ShellCommand::getCommand(const std::string& commandName, const std::string& className) |
---|
[5113] | 129 | { |
---|
[7408] | 130 | const ShellCommandClass* checkClass = ShellCommandClass::getCommandClass(className); |
---|
[7403] | 131 | if (likely(checkClass != NULL)) |
---|
[7413] | 132 | return ShellCommand::getCommand(commandName, checkClass); |
---|
| 133 | return NULL; |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | /** |
---|
| 137 | * @brief takes out an InputLine, searching for a Command. |
---|
[7414] | 138 | * @see const ShellCommand* const ShellCommand::getCommandFromInput(const SubString& strings) |
---|
[7413] | 139 | * @param inputLine: the Input to analyse. |
---|
[7414] | 140 | * @param paramBegin: The begin of the Splitted SubStrings entry of the Parameters section. |
---|
[7413] | 141 | * @returns: The ShellCommand if found. |
---|
| 142 | */ |
---|
[7417] | 143 | const ShellCommand* const ShellCommand::getCommandFromInput(const std::string& inputLine, unsigned int& paramBegin, std::vector<BaseObject*>* boList) |
---|
[7413] | 144 | { |
---|
[7414] | 145 | ShellCommand::getCommandFromInput(SubString(inputLine, SubString::WhiteSpaces), paramBegin); |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | /** |
---|
| 149 | * @brief takes out an InputLine, searching for a Command. |
---|
| 150 | * @param strings: the Input to analyse. |
---|
| 151 | * @param paramBegin: The begin of the Splitted SubStrings entry of the Parameters section. |
---|
| 152 | * @returns: The ShellCommand if found. |
---|
| 153 | */ |
---|
[7417] | 154 | const ShellCommand* const ShellCommand::getCommandFromInput(const SubString& strings, unsigned int& paramBegin, std::vector<BaseObject*>* boList) |
---|
[7414] | 155 | { |
---|
[7413] | 156 | // no input, no Command. |
---|
| 157 | if (strings.size() == 0) |
---|
[7414] | 158 | { |
---|
| 159 | paramBegin = 0; |
---|
[7413] | 160 | return NULL; |
---|
[7414] | 161 | } |
---|
[7413] | 162 | |
---|
| 163 | // CHECK FOR ALIAS |
---|
| 164 | std::vector<ShellCommandAlias*>::const_iterator alias; |
---|
| 165 | for (alias = ShellCommandAlias::getAliases().begin(); alias != ShellCommandAlias::getAliases().end(); alias++ ) |
---|
[7374] | 166 | { |
---|
[7413] | 167 | if (strings[0] == (*alias)->getName()) |
---|
| 168 | { |
---|
| 169 | assert ((*alias)->getCommand() != NULL && (*alias)->getCommand()->shellClass != NULL); |
---|
| 170 | return (*alias)->getCommand(); |
---|
| 171 | } |
---|
[5779] | 172 | } |
---|
[7413] | 173 | |
---|
[7417] | 174 | // CHECK FOR COMMAND_CLASS |
---|
[7413] | 175 | const ShellCommandClass* cmdClass = ShellCommandClass::getCommandClass(strings[0]); |
---|
| 176 | if (cmdClass != NULL) |
---|
| 177 | { |
---|
| 178 | const ShellCommand* retCmd; |
---|
[7417] | 179 | // Function/Command right after Class |
---|
[7413] | 180 | if (strings.size() >= 1) |
---|
[7414] | 181 | { |
---|
[7413] | 182 | retCmd = ShellCommand::getCommand(strings[1], cmdClass); |
---|
[7417] | 183 | if (retCmd != NULL) |
---|
| 184 | { |
---|
| 185 | paramBegin = 2; |
---|
| 186 | return retCmd; |
---|
| 187 | } |
---|
[7414] | 188 | } |
---|
[7417] | 189 | // Function/Command after Class and 'Object' |
---|
[7413] | 190 | if (retCmd == NULL && strings.size() >= 2) |
---|
[7414] | 191 | { |
---|
[7413] | 192 | retCmd = ShellCommand::getCommand(strings[2], cmdClass); |
---|
[7417] | 193 | if (retCmd != NULL) |
---|
| 194 | { |
---|
[7415] | 195 | paramBegin = 3; |
---|
[7417] | 196 | return retCmd; |
---|
| 197 | } |
---|
[7414] | 198 | } |
---|
| 199 | if (retCmd != NULL) // check for the paramBegin. |
---|
| 200 | return retCmd; |
---|
[7413] | 201 | } |
---|
[7417] | 202 | // Nothing usefull found at all. |
---|
[7414] | 203 | paramBegin = 0; |
---|
| 204 | return NULL; |
---|
[5113] | 205 | } |
---|
| 206 | |
---|
[7417] | 207 | bool ShellCommand::fillObjectList(const std::string& objectDescriptor, ShellCommand* cmd, std::vector<BaseObject*>* boList) |
---|
| 208 | { |
---|
| 209 | assert (cmd != NULL && cmd->shellClass != NULL && boList != NULL); |
---|
[7413] | 210 | |
---|
[7417] | 211 | const std::list<BaseObject*>* objectList = ClassList::getList(cmd->shellClass->getName()); |
---|
| 212 | if (objectList != NULL) |
---|
| 213 | { |
---|
| 214 | std::list<BaseObject*>::const_iterator bo; |
---|
| 215 | |
---|
| 216 | // No Description given (only for speedup) |
---|
| 217 | if (objectDescriptor.empty()) |
---|
| 218 | { |
---|
| 219 | for (bo = objectList->begin(); bo != objectList->end(); bo++) |
---|
| 220 | boList->push_back(*bo); |
---|
| 221 | } |
---|
| 222 | // some description |
---|
| 223 | else |
---|
| 224 | { |
---|
| 225 | for (bo = objectList->begin(); bo != objectList->end(); bo++) |
---|
| 226 | if ((*bo)->getName() != NULL && nocaseCmp(objectDescriptor, (*bo)->getName(), objectDescriptor.size())) |
---|
| 227 | boList->push_back(*bo); |
---|
| 228 | } |
---|
| 229 | } |
---|
| 230 | } |
---|
| 231 | |
---|
[7408] | 232 | /** |
---|
| 233 | * @brief checks if a command has already been registered. |
---|
| 234 | * @param commandName the name of the Command |
---|
| 235 | * @param className the name of the Class the command should apply to. |
---|
| 236 | * @returns true, if the command is registered/false otherwise |
---|
| 237 | * |
---|
| 238 | * This is used internally, to see, if we have multiple command subscriptions. |
---|
| 239 | * This is checked in the registerCommand-function. |
---|
| 240 | */ |
---|
| 241 | bool ShellCommand::exists(const std::string& commandName, const std::string& className) |
---|
| 242 | { |
---|
| 243 | return (ShellCommand::getCommand(commandName, className) != NULL); |
---|
| 244 | } |
---|
[5140] | 245 | |
---|
[7408] | 246 | |
---|
[7374] | 247 | /** |
---|
[7394] | 248 | * @brief executes commands |
---|
[7374] | 249 | * @param executionString the string containing the following input |
---|
| 250 | * ClassName [ObjectName] functionName [parameter1[,parameter2[,...]]] |
---|
| 251 | * @return true on success, false otherwise. |
---|
| 252 | */ |
---|
| 253 | bool ShellCommand::execute(const std::string& executionString) |
---|
| 254 | { |
---|
| 255 | long classID = CL_NULL; //< the classID retrieved from the Class. |
---|
| 256 | ShellCommandClass* commandClass = NULL; //< the command class this command applies to. |
---|
| 257 | const std::list<BaseObject*>* objectList = NULL; //< the list of Objects stored in classID |
---|
| 258 | BaseObject* objectPointer = NULL; //< a pointer to th Object to Execute the command on |
---|
[7411] | 259 | // bool emptyComplete = false; //< if the completion input is empty string. e.g "" |
---|
[7374] | 260 | // long completeType = SHELLC_NONE; //< the Type we'd like to complete. |
---|
[7403] | 261 | |
---|
[7374] | 262 | SubString inputSplits(executionString, SubString::WhiteSpacesWithComma); |
---|
[5198] | 263 | |
---|
[7340] | 264 | |
---|
[7374] | 265 | // if we do not have any input return |
---|
| 266 | if (inputSplits.empty()) |
---|
| 267 | return false; |
---|
[7340] | 268 | |
---|
[7374] | 269 | // if we only have one input (!MUST BE AN ALIAS) |
---|
[7403] | 270 | // CHECK FOR ALIAS |
---|
| 271 | std::vector<ShellCommandAlias*>::const_iterator alias; |
---|
| 272 | for (alias = ShellCommandAlias::getAliases().begin(); alias != ShellCommandAlias::getAliases().end(); alias++ ) |
---|
[5198] | 273 | { |
---|
[7403] | 274 | if (inputSplits.getString(0) == (*alias)->getName() && (*alias)->getCommand() != NULL && |
---|
| 275 | (*alias)->getCommand()->shellClass != NULL ) |
---|
[5198] | 276 | { |
---|
[7403] | 277 | objectList = ClassList::getList((*alias)->getCommand()->shellClass->getName()); |
---|
| 278 | if (objectList != NULL) |
---|
[5198] | 279 | { |
---|
[7403] | 280 | (*(*alias)->getCommand()->executor)(objectList->front(), inputSplits.getSubSet(1).join()); |
---|
| 281 | return true; |
---|
[5198] | 282 | } |
---|
| 283 | } |
---|
[7403] | 284 | } |
---|
[7340] | 285 | |
---|
[7403] | 286 | // looking for a Matching Class (in the First Argument) |
---|
| 287 | std::vector<ShellCommandClass*>::iterator commandClassIT; |
---|
| 288 | for (commandClassIT = ShellCommandClass::commandClassList.begin(); commandClassIT != ShellCommandClass::commandClassList.end(); commandClassIT++) |
---|
| 289 | { |
---|
| 290 | if (inputSplits[0] == (*commandClassIT)->getName()) |
---|
[5203] | 291 | { |
---|
[7403] | 292 | //elemCL->getName(); |
---|
| 293 | classID = ClassList::StringToID((*commandClassIT)->getName()); |
---|
| 294 | commandClass = (*commandClassIT); |
---|
| 295 | objectList = ClassList::getList((ClassID)classID); |
---|
| 296 | break; |
---|
[5203] | 297 | } |
---|
[7403] | 298 | } |
---|
[5200] | 299 | |
---|
[7403] | 300 | // Second Agument. (either Object, or Function) |
---|
| 301 | if (commandClass != NULL && inputSplits.size() >= 2) |
---|
| 302 | { |
---|
| 303 | int fktPos = 1; // The position of the Function (either at pos 1(if object given), or 2) |
---|
| 304 | // If we have an ObjectList. |
---|
| 305 | if (objectList != NULL) |
---|
[5203] | 306 | { |
---|
[7403] | 307 | // Checking for a Match in the Objects of classID (else take the first) |
---|
| 308 | std::list<BaseObject*>::const_iterator object; |
---|
| 309 | for (object = objectList->begin(); object != objectList->end(); object++) |
---|
[5203] | 310 | { |
---|
[7403] | 311 | if ((*object)->getName() != NULL && inputSplits[1] == (*object)->getName()) |
---|
[5329] | 312 | { |
---|
[7403] | 313 | /// TODO make this work for multiple Objects at once. |
---|
| 314 | objectPointer = (*object); |
---|
| 315 | fktPos = 2; |
---|
| 316 | break; |
---|
[5329] | 317 | } |
---|
[7340] | 318 | } |
---|
[5203] | 319 | |
---|
[7403] | 320 | // if we did not find an Object with matching name, take the first. |
---|
| 321 | if (objectPointer == NULL) |
---|
| 322 | objectPointer = objectList->front(); |
---|
| 323 | } |
---|
| 324 | |
---|
| 325 | // match a function. |
---|
| 326 | if (commandClass != NULL && (fktPos == 1 || (fktPos == 2 && inputSplits.size() >= 3))) |
---|
| 327 | { |
---|
| 328 | std::vector<ShellCommand*>::iterator cmdIT; |
---|
| 329 | for (cmdIT = commandClass->commandList.begin(); cmdIT != commandClass->commandList.end(); cmdIT++) |
---|
[5203] | 330 | { |
---|
[7403] | 331 | if (inputSplits[fktPos] == (*cmdIT)->getName()) |
---|
[5203] | 332 | { |
---|
[7403] | 333 | if (objectPointer == NULL && (*cmdIT)->executor->getType() & Executor_Objective) |
---|
| 334 | return false; |
---|
| 335 | else |
---|
[7340] | 336 | { |
---|
[7403] | 337 | (*(*cmdIT)->executor)(objectPointer, inputSplits.getSubSet(fktPos+1).join()); /// TODO CHECK IF OK |
---|
| 338 | return true; |
---|
[7340] | 339 | } |
---|
[5203] | 340 | } |
---|
| 341 | } |
---|
| 342 | } |
---|
| 343 | } |
---|
[7374] | 344 | return false; |
---|
[5198] | 345 | } |
---|
[5148] | 346 | |
---|
[7411] | 347 | |
---|
[7374] | 348 | /** |
---|
[7401] | 349 | * @brief lets a command be described |
---|
[7374] | 350 | * @param description the description of the Given command |
---|
| 351 | */ |
---|
| 352 | ShellCommand* ShellCommand::describe(const std::string& description) |
---|
[7340] | 353 | { |
---|
[7374] | 354 | if (this == NULL) |
---|
| 355 | return NULL; |
---|
[7403] | 356 | this->description = description; |
---|
| 357 | return this; |
---|
[7340] | 358 | } |
---|
[5164] | 359 | |
---|
[7374] | 360 | /** |
---|
[7389] | 361 | * @brief adds an Alias to this Command |
---|
[7374] | 362 | * @param alias the name of the Alias to set |
---|
| 363 | * @returns itself |
---|
| 364 | */ |
---|
| 365 | ShellCommand* ShellCommand::setAlias(const std::string& alias) |
---|
[5196] | 366 | { |
---|
[7374] | 367 | if (this == NULL) |
---|
| 368 | return NULL; |
---|
[5196] | 369 | |
---|
[7374] | 370 | if (this->alias != NULL) |
---|
| 371 | { |
---|
| 372 | PRINTF(2)("not more than one Alias allowed for functions (%s::%s)\n", this->getName(), this->shellClass->getName()); |
---|
| 373 | } |
---|
| 374 | else |
---|
| 375 | { |
---|
| 376 | ShellCommandAlias* aliasCMD = new ShellCommandAlias(alias, this); |
---|
| 377 | this->alias = aliasCMD; |
---|
| 378 | } |
---|
| 379 | return this; |
---|
[5196] | 380 | } |
---|
[5195] | 381 | |
---|
[7374] | 382 | /** |
---|
| 383 | * @brief set the default values of the executor |
---|
| 384 | * @param value0 the first default value |
---|
| 385 | * @param value1 the second default value |
---|
| 386 | * @param value2 the third default value |
---|
| 387 | * @param value3 the fourth default value |
---|
| 388 | * @param value4 the fifth default value |
---|
| 389 | */ |
---|
| 390 | ShellCommand* ShellCommand::defaultValues(const MultiType& value0, const MultiType& value1, |
---|
| 391 | const MultiType& value2, const MultiType& value3, |
---|
| 392 | const MultiType& value4) |
---|
| 393 | { |
---|
| 394 | if (this == NULL || this->executor == NULL) |
---|
| 395 | return NULL; |
---|
[5207] | 396 | |
---|
[7374] | 397 | this->executor->defaultValues(value0, value1, value2, value3, value4); |
---|
[5207] | 398 | |
---|
[7374] | 399 | return this; |
---|
[5148] | 400 | } |
---|
| 401 | |
---|
[7412] | 402 | ShellCommand* ShellCommand::completionPlugin(unsigned int parameter, const CompletorPlugin& completorPlugin) |
---|
| 403 | { |
---|
| 404 | if (this == NULL || this->executor == NULL) |
---|
| 405 | return NULL; |
---|
| 406 | |
---|
| 407 | if (parameter >= this->executor->getParamCount()) |
---|
| 408 | { |
---|
| 409 | PRINTF(1)("Parameter %d not inside of valid ParameterCount %d of Command %s::%s\n", |
---|
[7413] | 410 | parameter, this->executor->getParamCount(), this->getName(), this->shellClass->getName()); |
---|
[7412] | 411 | } |
---|
| 412 | else |
---|
| 413 | { |
---|
| 414 | delete this->completors[parameter]; |
---|
| 415 | this->completors[parameter] = completorPlugin.clone(); |
---|
| 416 | } |
---|
| 417 | return this; |
---|
| 418 | } |
---|
| 419 | |
---|
| 420 | |
---|
[7374] | 421 | /** |
---|
[7401] | 422 | * @brief prints out nice information about the Shells Commands |
---|
[7374] | 423 | */ |
---|
| 424 | void ShellCommand::debug() |
---|
[5148] | 425 | { |
---|
[7394] | 426 | std::vector<ShellCommandClass*>::iterator classIT; |
---|
| 427 | for (classIT = ShellCommandClass::commandClassList.begin(); classIT != ShellCommandClass::commandClassList.end(); classIT++) |
---|
[7374] | 428 | { |
---|
| 429 | PRINT(0)("Class:'%s' registered %d commands: \n", (*classIT)->className.c_str(), (*classIT)->commandList.size()); |
---|
[5148] | 430 | |
---|
[7388] | 431 | std::vector<ShellCommand*>::iterator cmdIT; |
---|
[7374] | 432 | for (cmdIT = (*classIT)->commandList.begin(); cmdIT != (*classIT)->commandList.end(); cmdIT++) |
---|
| 433 | { |
---|
| 434 | PRINT(0)(" command:'%s' : params:%d: ", (*cmdIT)->getName(), (*cmdIT)->executor->getParamCount()); |
---|
| 435 | /// FIXME |
---|
| 436 | /* for (unsigned int i = 0; i< elem->paramCount; i++) |
---|
| 437 | printf("%s ", ShellCommand::paramToString(elem->parameters[i]));*/ |
---|
| 438 | if (!(*cmdIT)->description.empty()) |
---|
| 439 | printf("- %s", (*cmdIT)->description.c_str()); |
---|
| 440 | printf("\n"); |
---|
| 441 | |
---|
| 442 | } |
---|
[5170] | 443 | } |
---|
[5148] | 444 | } |
---|
| 445 | |
---|
[7374] | 446 | /** |
---|
[7401] | 447 | * @brief converts a Parameter to a String |
---|
[7374] | 448 | * @param parameter the Parameter we have. |
---|
| 449 | * @returns the Name of the Parameter at Hand |
---|
| 450 | */ |
---|
[7401] | 451 | const std::string& ShellCommand::paramToString(long parameter) |
---|
[7374] | 452 | { |
---|
| 453 | return MultiType::MultiTypeToString((MT_Type)parameter); |
---|
| 454 | } |
---|
| 455 | |
---|
[7389] | 456 | |
---|
[7412] | 457 | |
---|
| 458 | /////////// |
---|
| 459 | // ALIAS // |
---|
| 460 | /////////// |
---|
| 461 | |
---|
[7397] | 462 | /** |
---|
| 463 | * @param aliasName the name of the Alias |
---|
| 464 | * @param command the Command, to associate this alias with |
---|
| 465 | */ |
---|
[7389] | 466 | ShellCommandAlias::ShellCommandAlias(const std::string& aliasName, ShellCommand* command) |
---|
| 467 | { |
---|
| 468 | this->aliasName = aliasName; |
---|
| 469 | this->command = command; |
---|
| 470 | ShellCommandAlias::aliasList.push_back(this); |
---|
| 471 | }; |
---|
| 472 | |
---|
| 473 | ShellCommandAlias::~ShellCommandAlias() |
---|
| 474 | { |
---|
| 475 | std::vector<ShellCommandAlias*>::iterator delA = std::find(aliasList.begin(), aliasList.end(), this); |
---|
| 476 | if (delA != aliasList.end()) |
---|
| 477 | ShellCommandAlias::aliasList.push_back(this); |
---|
| 478 | |
---|
| 479 | } |
---|
| 480 | |
---|
| 481 | std::vector<ShellCommandAlias*> ShellCommandAlias::aliasList; |
---|
| 482 | /** |
---|
| 483 | * @brief collects the Aliases registered to the ShellCommands |
---|
| 484 | * @param stringList a List to paste the Aliases into. |
---|
| 485 | * @returns true on success, false otherwise |
---|
| 486 | */ |
---|
[7403] | 487 | |
---|
[7389] | 488 | bool ShellCommandAlias::getCommandListOfAlias(std::list<std::string>& stringList) |
---|
| 489 | { |
---|
| 490 | std::vector<ShellCommandAlias*>::iterator alias; |
---|
| 491 | for (alias = ShellCommandAlias::aliasList.begin(); alias != ShellCommandAlias::aliasList.end(); alias++) |
---|
| 492 | stringList.push_back((*alias)->getName()); |
---|
| 493 | return true; |
---|
| 494 | } |
---|
| 495 | |
---|
| 496 | |
---|
[5148] | 497 | } |
---|