Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5178 in orxonox.OLD for trunk/src


Ignore:
Timestamp:
Sep 13, 2005, 12:12:11 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: added class ShellInput for the InputLine, also worked a bit on ShellCompletion

Location:
trunk/src/lib/shell
Files:
5 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/shell/Makefile.am

    r5173 r5178  
    66libORXshell_a_SOURCES = shell.cc \
    77                        shell_buffer.cc \
     8                        shell_input.cc \
    89                        shell_command.cc \
    910                        shell_completion.cc
     
    1213noinst_HEADERS= shell.h \
    1314                shell_buffer.h \
     15                shell_input.h \
    1416                shell_command.h \
    1517                shell_completion.h
  • trunk/src/lib/shell/Makefile.in

    r5173 r5178  
    5555libORXshell_a_LIBADD =
    5656am_libORXshell_a_OBJECTS = shell.$(OBJEXT) shell_buffer.$(OBJEXT) \
    57         shell_command.$(OBJEXT) shell_completion.$(OBJEXT)
     57        shell_input.$(OBJEXT) shell_command.$(OBJEXT) \
     58        shell_completion.$(OBJEXT)
    5859libORXshell_a_OBJECTS = $(am_libORXshell_a_OBJECTS)
    5960DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)
     
    6364@AMDEP_TRUE@    ./$(DEPDIR)/shell_buffer.Po \
    6465@AMDEP_TRUE@    ./$(DEPDIR)/shell_command.Po \
    65 @AMDEP_TRUE@    ./$(DEPDIR)/shell_completion.Po
     66@AMDEP_TRUE@    ./$(DEPDIR)/shell_completion.Po \
     67@AMDEP_TRUE@    ./$(DEPDIR)/shell_input.Po
    6668CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
    6769        $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
     
    187189libORXshell_a_SOURCES = shell.cc \
    188190                        shell_buffer.cc \
     191                        shell_input.cc \
    189192                        shell_command.cc \
    190193                        shell_completion.cc
     
    192195noinst_HEADERS = shell.h \
    193196                shell_buffer.h \
     197                shell_input.h \
    194198                shell_command.h \
    195199                shell_completion.h
     
    246250@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/shell_command.Po@am__quote@
    247251@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/shell_completion.Po@am__quote@
     252@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/shell_input.Po@am__quote@
    248253
    249254.cc.o:
  • trunk/src/lib/shell/shell.h

    r5176 r5178  
    99#include "element_2d.h"
    1010#include "event_listener.h"
    11 //#include "shell_buffer.h"
    1211
    1312#include <stdarg.h>
    14 
    15 #define      SHELL_BUFFER_SIZE       16384
    1613
    1714// FORWARD DECLARATION
     
    5956    void addCharacters(const char* characters);
    6057    void removeCharacters(unsigned int characterCount = 1);
     58    void setRepeatDelay(float repeatDelay, float repeatRate);
    6159    bool executeCommand();
    6260
    6361    void clear();
    6462
    65     void setRepeatDelay(float repeatDelay, float repeatRate);
    6663
    6764    // EventListener
  • trunk/src/lib/shell/shell_completion.cc

    r5170 r5178  
    1818#include "shell_completion.h"
    1919
     20#include "base_object.h"
     21#include "class_list.h"
     22#include "list.h"
     23#include "debug.h"
     24
     25#include "stdlibincl.h"
     26
    2027using namespace std;
    21 
    2228
    2329/**
     
    4955  // delete what has to be deleted here
    5056}
     57
     58
     59
     60/**
     61 * autocompletes the Shell's inputLine
     62 * @returns true, if a result was found, false otherwise
     63 *
     64 * @todo implement it!!
     65 */
     66bool ShellCompletion::autoComplete(const char* inputLine)
     67{
     68  //PRINTF(3)("AutoCompletion not implemented yet\n");
     69
     70  char* completionLine = new char[strlen(inputLine)+1];
     71  strcpy(completionLine, inputLine);
     72
     73  char* commandBegin = strrchr(completionLine, ' ');
     74  if (commandBegin == NULL)
     75    commandBegin = completionLine;
     76  else
     77  {
     78    if(commandBegin >= completionLine + strlen(completionLine))
     79      commandBegin = completionLine + strlen(completionLine);
     80    else
     81      commandBegin++;
     82  }
     83
     84  char* objectStart;
     85  if (objectStart = strstr(commandBegin, "::"))
     86  {
     87    char* classIdentity = new char[objectStart - commandBegin +1];
     88    strncpy(classIdentity, commandBegin, objectStart - commandBegin);
     89    classIdentity[objectStart - commandBegin] = '\0';
     90    this->objectComplete(objectStart+2, ClassList::StringToID(classIdentity));
     91    delete[] classIdentity;
     92  }
     93  else
     94    this->classComplete(commandBegin);
     95
     96  delete[] completionLine;
     97}
     98
     99/**
     100 * autocompletes a className
     101 * @param classBegin the Beginning of a String to autoComplete
     102 * @return true on success, false otherwise
     103 */
     104bool ShellCompletion::classComplete(const char* classBegin)
     105{
     106  if (unlikely(classBegin == NULL))
     107    return false;
     108  const tList<const char>* clList = ClassList::getClassList();
     109  if (clList != NULL)
     110  {
     111    const tList<const char>* classList = this->createCompleteList(clList, classBegin);
     112    if (classList != NULL)
     113      this->generalComplete(classList, classBegin, "%s::", "::");
     114    else
     115      return false;
     116  }
     117  else
     118    return false;
     119  return true;
     120}
     121
     122/**
     123 * autocompletes an ObjectName
     124 * @param objectBegin the beginning string of a Object
     125 * @param classID the ID of the Class to search for.
     126 * @return true on success, false otherwise
     127 */
     128bool ShellCompletion::objectComplete(const char* objectBegin, long classID)
     129{
     130  printf("%s\n", objectBegin);
     131
     132  if (unlikely(objectBegin == NULL))
     133    return false;
     134  tList<BaseObject>* boList = ClassList::getList(classID);
     135  if (boList != NULL)
     136  {
     137    printf("\n", boList->firstElement()->getName());
     138    const tList<const char>* objectList = this->createCompleteList(boList, objectBegin);
     139    if (objectList != NULL)
     140      this->generalComplete(objectList, objectBegin, "%s");
     141    else
     142      return false;
     143  }
     144  else
     145    return false;
     146  return true;
     147}
     148
     149/**
     150 * completes a Function
     151 * @param functionBegin the beginning of the function String
     152 */
     153bool ShellCompletion::functionComplete(const char* functionBegin)
     154{
     155}
     156
     157/**
     158 * completes the inputline on grounds of an inputList
     159 * @param stringList the List to parse through
     160 * @param begin the String to search in the inputList, and to extend with it.
     161 * @param displayAs how to display the found value to the user, printf-style, !!with only one %s!! ex.: "::%s::"
     162 * @param addBack what should be added at the end of the completion
     163 * @param addFront what should be added to the front of one finished completion
     164 * @return true if ok, false otherwise
     165 */
     166bool ShellCompletion::generalComplete(const tList<const char>* stringList, const char* begin, const char* displayAs, const char* addBack, const char* addFront)
     167{
     168  if (stringList->getSize() == 0)
     169    return false;
     170
     171  const char* addString = stringList->firstElement();
     172  unsigned int addLength = 0;
     173  unsigned int inputLenght = strlen(begin);
     174
     175  if (addString != NULL)
     176    addLength = strlen(addString);
     177  tIterator<const char>* charIterator = stringList->getIterator();
     178  const char* charElem = charIterator->firstElement();
     179  while (charElem != NULL)
     180  {
     181    PRINTF(0)(displayAs, charElem);
     182    for (unsigned int i = inputLenght; i < addLength; i++)
     183      if (addString[i] != charElem[i])
     184    {
     185      addLength = i;
     186      break;
     187    }
     188    charElem = charIterator->nextElement();
     189  }
     190  delete charIterator;
     191
     192  if (addLength >= inputLenght)
     193  {
     194    char* adder = new char[addLength+1];
     195    strncpy(adder, addString, addLength);
     196    adder[addLength] = '\0';
     197
     198
     199/*    this->removeCharacters(inputLenght);
     200    this->addCharacters(adder);
     201    if (addBack != NULL && stringList->getSize() == 1)
     202      this->addCharacters("::");
     203    delete[] adder;*/
     204  }
     205  return true;
     206}
     207
     208/**
     209 * searches for classes, which beginn with classNameBegin
     210 * @param inputList the List to parse through
     211 * @param classNameBegin the beginning string
     212 * @return a NEW char-array with ClassNames. The LIST should be deleted afterwards,
     213 * !! The strings MUST NOT be deleted !!
     214 */
     215const tList<const char>* ShellCompletion::createCompleteList(const tList<const char>* inputList, const char* classNameBegin)
     216{
     217  if (inputList == NULL || classNameBegin == NULL)
     218    return NULL;
     219  unsigned int searchLength = strlen(classNameBegin);
     220  if (this->completionList != NULL)
     221    delete this->completionList;
     222  this->completionList = new tList<const char>;
     223
     224//  tList<const char>* classList = ClassList::getClassList();
     225
     226  tIterator<const char>* iterator = inputList->getIterator();
     227  const char* enumString = iterator->firstElement();
     228  while (enumString != NULL)
     229  {
     230    if (strlen(enumString)>searchLength+1 &&
     231        !strncasecmp(enumString, classNameBegin, searchLength))
     232    {
     233      this->completionList->add(enumString);
     234    }
     235    enumString = iterator->nextElement();
     236  }
     237  delete iterator;
     238
     239  return this->completionList;
     240}
     241
     242/**
     243 * searches for classes, which beginn with classNameBegin
     244 * @param inputList the List to parse through
     245 * @param classNameBegin the beginning string
     246 * @return a NEW char-array with ClassNames. The LIST should be deleted afterwards,
     247 * !! The strings MUST NOT be deleted !!
     248 */
     249const tList<const char>* ShellCompletion::createCompleteList(const tList<BaseObject>* inputList, const char* classNameBegin)
     250{
     251  if (inputList == NULL || classNameBegin == NULL)
     252    return NULL;
     253  unsigned int searchLength = strlen(classNameBegin);
     254  if (this->completionList != NULL)
     255    delete this->completionList;
     256  this->completionList = new tList<const char>;
     257
     258  tIterator<BaseObject>* iterator = inputList->getIterator();
     259  BaseObject* enumBO = iterator->firstElement();
     260  while (enumBO != NULL)
     261  {
     262    if (enumBO->getName() != NULL &&
     263        strlen(enumBO->getName())>searchLength+1 &&
     264        !strncasecmp(enumBO->getName(), classNameBegin, searchLength))
     265    {
     266      this->completionList->add(enumBO->getName());
     267    }
     268    enumBO = iterator->nextElement();
     269  }
     270  delete iterator;
     271
     272  return this->completionList;
     273}
  • trunk/src/lib/shell/shell_completion.h

    r5170 r5178  
    88
    99// FORWARD DECLARATION
    10 
     10class BaseObject;
     11template<class T> class tList;
     12#ifndef NULL
     13#define NULL 0            //!< a pointer to NULL
     14#endif
    1115
    1216//! A class for ...
     
    1721  virtual ~ShellCompletion();
    1822
     23  bool autoComplete(const char* inputLine);
     24  bool classComplete(const char* classBegin);
     25  bool objectComplete(const char* objectBegin, long classID);
     26  bool functionComplete(const char* functionBegin);
     27
     28  bool generalComplete(const tList<const char>* stringList, const char* begin, const char* displayAs = "%s", const char* addBack = NULL, const char* addFront = NULL);
     29
     30  const tList<const char>* createCompleteList(const tList<const char>* inputList, const char* classNameBegin);
     31  const tList<const char>* createCompleteList(const tList<BaseObject>* inputList, const char* classNameBegin);
     32//    const tList<const char>* createCompleteList(const tList<ShellCommandBase>* inputList, const char* classNameBegin);
     33
    1934
    2035 private:
    21 
     36   tList<const char>*       completionList;          //!< A list of completions, that are io.
    2237};
    2338
  • trunk/src/lib/shell/shell_input.cc

    r5177 r5178  
    1616//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
    1717
    18 #include "proto_class.h"
     18#include "shell_input.h"
    1919
    2020using namespace std;
     
    2525 * @todo this constructor is not jet implemented - do it
    2626*/
    27 ProtoClass::ProtoClass ()
     27ShellInput::ShellInput ()
    2828{
    29    this->setClassID(CL_PROTO_ID, "ProtoClass");
    3029
    31    /* If you make a new class, what is most probably the case when you write this file
    32       don't forget to:
    33        1. Add the new file new_class.cc to the ./src/Makefile.am
    34        2. Add the class identifier to ./src/class_id.h eg. CL_NEW_CLASS
    35 
    36       Advanced Topics:
    37       - if you want to let your object be managed via the ObjectManager make sure to read
    38         the object_manager.h header comments. You will use this most certanly only if you
    39         make many objects of your class, like a weapon bullet.
    40    */
    4130}
    42 
    4331
    4432/**
    4533 * standard deconstructor
    4634*/
    47 ProtoClass::~ProtoClass ()
     35ShellInput::~ShellInput ()
    4836{
    4937  // delete what has to be deleted here
  • trunk/src/lib/shell/shell_input.h

    r5177 r5178  
    11/*!
    2  * @file proto_class.h
     2 * @file shell_input.h
    33 * @brief Definition of ...
    44*/
    55
    6 #ifndef _PROTO_CLASS_H
    7 #define _PROTO_CLASS_H
    8 
    9 #include "base_object.h"
     6#ifndef _SHELL_INPUT_H
     7#define _SHELL_INPUT_H
    108
    119// FORWARD DECLARATION
    12 
     10class Text;
     11template<class T> class tList;
    1312
    1413
    1514//! A class for ...
    16 class ProtoClass : public BaseObject {
     15class ShellInput {
    1716
    1817 public:
    19   ProtoClass();
    20   virtual ~ProtoClass();
     18  ShellInput();
     19  virtual ~ShellInput();
     20
     21
     22  // InputLine
     23  void flush();
     24  void addCharacter(char character);
     25  void addCharacters(const char* characters);
     26  void removeCharacters(unsigned int characterCount = 1);
     27  void setRepeatDelay(float repeatDelay, float repeatRate);
    2128
    2229
    2330 private:
     31    // HANDLING TEXT INPUT
     32   Text*                    inputLineText;          //!< The inputLine of the Shell
     33   char*                    inputLine;              //!< the Char-Array of the Buffer
     34   float                    repeatRate;             //!< The Repeat-Delay.
     35   float                    repeatDelay;            //!< The delay of the first Character of a given Character.
     36   float                    delayed;                //!< how much of the delay is remaining.
     37   int                      pressedKey;             //!< the pressed key that will be repeated.
     38
     39   tList<char>*             inputHistory;           //!< The history of given commands.
    2440
    2541};
    2642
    27 #endif /* _PROTO_CLASS_H */
     43#endif /* _SHELL_INPUT_H */
Note: See TracChangeset for help on using the changeset viewer.