Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5195 in orxonox.OLD


Ignore:
Timestamp:
Sep 18, 2005, 2:13:28 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: alias-completion works too now :)

Location:
trunk/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/shell/shell_command.cc

    r5192 r5195  
    4141  this->classID = CL_NULL;
    4242  this->commandList = new tList<ShellCommandBase>;
     43  this->aliasList = new tList<ShellCommandAlias>;
    4344
    4445  ShellCommandClass::commandClassList->add(this);
     
    8889}
    8990
     91bool ShellCommandClass::getCommandListOfAlias(tList<const char>* stringList)
     92{
     93  if (stringList == NULL)
     94    return false;
     95
     96  tIterator<ShellCommandAlias>* iterator = ShellCommandClass::aliasList->getIterator();
     97  ShellCommandAlias* elem = iterator->firstElement();
     98  while(elem != NULL)
     99  {
     100    stringList->add(elem->getName());
     101    elem = iterator->nextElement();
     102  }
     103  delete iterator;
     104  return true;
     105}
     106
     107
    90108/**
    91109 * unregisters all Commands that exist
     
    93111void ShellCommandClass::unregisterAllCommands()
    94112{
     113  // unregister all commands
    95114  tIterator<ShellCommandClass>* iterator = ShellCommandClass::commandClassList->getIterator();
    96115  ShellCommandClass* elem = iterator->firstElement();
     
    105124  delete ShellCommandClass::commandClassList;
    106125  ShellCommandClass::commandClassList = NULL;
     126
     127  // unregister all aliases (there should be nothing to do here :))
     128  tIterator<ShellCommandAlias>* itAL = ShellCommandClass::aliasList->getIterator();
     129  ShellCommandAlias* elemAL = itAL->firstElement();
     130  while(elemAL != NULL)
     131  {
     132    delete elemAL;
     133    elemAL = itAL->nextElement();
     134  }
     135  delete itAL;
     136  delete ShellCommandClass::aliasList;
     137  ShellCommandClass::aliasList = NULL;
    107138}
    108139
     
    168199
    169200tList<ShellCommandClass>* ShellCommandClass::commandClassList = NULL;
     201tList<ShellCommandAlias>* ShellCommandClass::aliasList = NULL;
    170202
    171203/**
     
    428460}
    429461
     462ShellCommandBase* ShellCommandBase::setAlias(const char* alias)
     463{
     464  ShellCommandAlias* aliasCMD = new ShellCommandAlias(alias, this);
     465  ShellCommandClass::aliasList->add(aliasCMD);
     466}
     467
    430468/**
    431469 * see ShellCommandBase::debug()
  • trunk/src/lib/shell/shell_command.h

    r5190 r5195  
    5252  public:
    5353    static const tList<ShellCommandClass>* getCommandClassList() { return ShellCommandClass::commandClassList; };
    54     static bool ShellCommandClass::getCommandListOfClass(const char* className, tList<const char>* stringList);
     54    static bool getCommandListOfClass(const char* className, tList<const char>* stringList);
     55    static bool getCommandListOfAlias(tList<const char>* aliasList);
    5556
    5657    static ShellCommandClass* getCommandClass(const char* className);
     
    6970    tList<ShellCommandBase>*         commandList;               //!< A list of Commands from this Class
    7071    static tList<ShellCommandClass>* commandClassList;          //!< A list of Classes
    71     static tList<ShellCommandAlias>* aliasesList;               //!< An Alias to A Command. (only for classes with one Instance)
     72    static tList<ShellCommandAlias>* aliasList;                 //!< An Alias to A Command. (only for classes with one Instance)
    7273};
    7374
     
    320321  public:
    321322    ShellCommandAlias(const char* aliasName, ShellCommandBase* command) { this->aliasName = aliasName; this->command = command; };
     323
     324    const char* getName() const { return this->aliasName; };
     325    ShellCommandBase* getCommand() const { return this->command; };
    322326  private:
    323327    const char*         aliasName;
  • trunk/src/lib/shell/shell_completion.cc

    r5194 r5195  
    108108  if (inputSplits.getCount() == 0)
    109109  {
    110     PRINTF(5)("Listing all Classes\n");
    111110    completeType |= SHELLC_CLASS;
     111    completeType |= SHELLC_ALIAS;
     112
    112113  }
    113114  else if (inputSplits.getCount() == 1 && emptyComplete == false)
    114115  {
    115     printf("trying to complete a Class with '%s'\n", inputSplits.getString(0));
    116116    completeType |= SHELLC_CLASS;
     117    completeType |= SHELLC_ALIAS;
    117118  }
    118119
     
    148149  if (completeType & SHELLC_FUNCTION)
    149150    this->functionComplete(completeString, classID);
     151  if (completeType & SHELLC_ALIAS)
     152    this->aliasComplete(completeString);
    150153
    151154
     
    211214  return true;
    212215}
     216
     217bool ShellCompletion::aliasComplete(const char* aliasBegin)
     218{
     219  if (unlikely(aliasBegin == NULL))
     220    return false;
     221  tList<const char> aliasList;
     222  ShellCommandClass::getCommandListOfAlias(&aliasList);
     223  //printf("%s\n", boList->firstElement()->getName());
     224  if (!this->addToCompleteList(&aliasList, aliasBegin))
     225    return false;
     226  return true;
     227}
     228
    213229
    214230/**
  • trunk/src/lib/shell/shell_completion.h

    r5194 r5195  
    4242  bool functionComplete(const char* functionBegin, long classID);
    4343  bool functionMatch(const char* functionBegin, long classID, unsigned int* length);
     44  bool aliasComplete(const char* aliasBegin);
    4445
    4546  bool generalComplete(const char* begin, const char* displayAs = "%s", const char* addBack = NULL, const char* addFront = NULL);
     
    4849  bool addToCompleteList(const tList<BaseObject>* inputList, const char* completionBegin);
    4950  void emptyCompletionList();
    50 //    const tList<const char>* createCompleteList(const tList<ShellCommandBase>* inputList, const char* completionBegin);
    51 
    5251
    5352 private:
  • trunk/src/util/loading/game_loader.cc

    r5162 r5195  
    3434
    3535
    36 SHELL_COMMAND(quit, GameLoader, stop);
     36SHELL_COMMAND(quit, GameLoader, stop)
     37    ->describe("quits the game")
     38    ->setAlias("orxoquit");
    3739
    3840
Note: See TracChangeset for help on using the changeset viewer.