Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5100 in orxonox.OLD for trunk/src/util


Ignore:
Timestamp:
Aug 22, 2005, 12:42:28 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: testing some AutoCompletion in the Shell.

Location:
trunk/src/util
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/util/loading/load_param.cc

    r5099 r5100  
    1717
    1818#include "list.h"
     19#include "array.h"
    1920#include "base_object.h"
    2021
     
    354355/**
    355356 *  prints out all loadable Classes, and their parameters
     357 * @param fileName prints the output to a File
     358 * @todo implement it
    356359*/
    357360void LoadClassDescription::printAll(const char* fileName)
     
    380383}
    381384
    382 
     385/**
     386 * searches for classes, which beginn with classNameBegin
     387 * @param classNameBegin the beginning string of a Class
     388 * @return a NEW char-array with ClassNames. The ARRAY should be deleted afterwards,
     389 * !! The strings MUST NOT be deleted !!
     390 */
     391Array<char*>* LoadClassDescription::searchClassWithShort(const char* classNameBegin)
     392{
     393  unsigned int searchLength = strlen(classNameBegin);
     394  Array<char*>* retVal = new Array<char*>;
     395
     396  tIterator<LoadClassDescription>* iterator = LoadClassDescription::classList->getIterator();
     397  LoadClassDescription* enumClassDesc = iterator->nextElement();
     398  while (enumClassDesc)
     399  {
     400    if (strlen(enumClassDesc->className)>searchLength+1 &&
     401        !strncasecmp(enumClassDesc->className, classNameBegin, searchLength))
     402    {
     403      retVal->addEntry(enumClassDesc->className);
     404    }
     405    enumClassDesc = iterator->nextElement();
     406  }
     407  delete iterator;
     408
     409  retVal->finalizeArray();
     410  return retVal;
     411}
     412
     413// const LoadParamDescription* LoadParamDescription::getClass(const char* className)
     414// {
     415//   tIterator<LoadClassDescription>* iterator = LoadClassDescription::classList->getIterator();
     416//   LoadClassDescription* enumClassDesc = iterator->nextElement();
     417//   while (enumClassDesc)
     418//   {
     419//     if (!strcmp(enumClassDesc->className, classNameBegin, className))
     420//     {
     421//       delete iterator;
     422//       return enumClassDesc;
     423//     }
     424//     enumClassDesc = iterator->nextElement();
     425//   }
     426//   delete iterator;
     427//
     428//   return NULL;
     429// }
    383430
    384431/**
  • trunk/src/util/loading/load_param.h

    r5099 r5100  
    3131// Forward Declaration //
    3232template<class T> class tList;
     33template<class T> class Array;
    3334
    3435//! macro that makes it even more easy to load a Parameter
     
    310311  LoadParamDescription* addParam(const char* paramName);
    311312
    312 
    313313  static void printAll(const char* fileName = NULL);
     314  static Array<char*>* searchClassWithShort(const char* classNameBegin);
     315//  static const LoadParamDescription* getClass(const char* className);
    314316
    315317 private:
  • trunk/src/util/shell.cc

    r5099 r5100  
    2020#include "text_engine.h"
    2121#include "list.h"
     22#include "array.h"
    2223#include "graphics_engine.h"
    2324#include "event_handler.h"
    2425
     26#include "load_param.h"
    2527#include "debug.h"
    2628#include <stdarg.h>
     
    439441 * autocompletes the Shell's inputLine
    440442 * @returns true, if a result was found, false otherwise
     443 *
     444 * @todo implement it!!
    441445 */
    442446bool Shell::autoComplete()
    443447{
    444   PRINTF(3)("AutoCompletion not implemented yet\n");
     448  //PRINTF(3)("AutoCompletion not implemented yet\n");
     449
     450  char* completionLine = new char[strlen(inputLine)+1];
     451  strcpy(completionLine, this->inputLine);
     452
     453   char* commandBegin = strrchr(completionLine, ' ');
     454  if (commandBegin == NULL)
     455    commandBegin = completionLine;
     456  else
     457  {
     458    if(commandBegin >= completionLine + strlen(completionLine))
     459      commandBegin = completionLine + strlen(completionLine);
     460    else
     461      commandBegin++;
     462  }
     463
     464  printf("%s\n",commandBegin);
     465   Array<char*>* classArray = LoadClassDescription::searchClassWithShort(commandBegin);
     466   if (classArray->getCount() == 0)
     467   {
     468     delete[] completionLine;
     469     delete classArray;
     470     //PRINTF(0)("no completion found for %s\n", commandBegin);
     471     return false;
     472   }
     473
     474   for (unsigned int i = 0; i < classArray->getCount(); i++)
     475   {
     476     PRINTF(0)("%s\n", classArray->getEntry(i));
     477   }
     478   if (classArray->getCount() == 1)
     479   {
     480     this->removeCharacters(strlen(commandBegin));
     481     this->addCharacters(classArray->getEntry(0));
     482     this->addCharacter(' ');
     483   }
     484
     485   delete[] completionLine;
     486   delete classArray;
    445487}
    446488
Note: See TracChangeset for help on using the changeset viewer.