Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7221 in orxonox.OLD for trunk/src/lib/shell


Ignore:
Timestamp:
Mar 15, 2006, 3:10:45 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the std-branche back, it runs on windows and Linux

svn merge https://svn.orxonox.net/orxonox/branches/std . -r7202:HEAD

Location:
trunk/src/lib/shell
Files:
10 edited

Legend:

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

    r7198 r7221  
    8585  this->lineSpacing = 0;
    8686  this->bActive = true;
    87   this->fontFile = new char[strlen(SHELL_DEFAULT_FONT)+1];
    88   strcpy(this->fontFile, SHELL_DEFAULT_FONT);
     87  this->fontFile = SHELL_DEFAULT_FONT;
    8988
    9089
     
    110109    delete this->bufferText[i];
    111110  delete[] this->bufferText;
    112   delete[] this->fontFile;
    113111  // delete the inputLine
    114112  delete this->shellInput;
     
    139137    if (!top)
    140138    {
    141       this->bufferText[i]->setText((*textLine), true);
     139      this->bufferText[i]->setText((*textLine));
    142140    if (textLine != ShellBuffer::getInstance()->getBuffer()->begin())
    143141      top = true;
     
    167165    if (textLine != ShellBuffer::getInstance()->getBuffer()->begin())
    168166    {
    169       this->bufferText[i]->setText((*textLine), false);
     167      this->bufferText[i]->setText((*textLine));
    170168      textLine--;
    171169    }
     
    181179 * (be aware that within orxonox fontFile is relative to the Data-Dir)
    182180 */
    183 void Shell::setFont(const char* fontFile)
     181void Shell::setFont(const std::string& fontFile)
    184182{
    185183//   if (!ResourceManager::isInDataDir(fontFile))
    186184//     return false;
    187185
    188   if (this->fontFile != NULL)
    189     delete[] this->fontFile;
    190 
    191   this->fontFile = new char[strlen(fontFile)+1];
    192   strcpy(this->fontFile, fontFile);
     186  this->fontFile = fontFile;
    193187
    194188  this->rebuildText();
     
    245239 * @param fileName the filename of the Image to load
    246240 */
    247 void Shell::setBackgroundImage(const char* fileName)
     241void Shell::setBackgroundImage(const std::string& fileName)
    248242{
    249243  this->backgroundMaterial->setDiffuseMap(fileName);
     
    340334    for (int i = 0; i < this->bufferDisplaySize; i++)
    341335    {
    342       this->bufferText[i]->setText(NULL, true);
     336      this->bufferText[i]->setText("");
    343337    }
    344338
     
    351345 * @param text the text to output.
    352346 */
    353 void Shell::printToDisplayBuffer(const char* text)
     347void Shell::printToDisplayBuffer(const std::string& text)
    354348{
    355349  if(likely(bufferText != NULL))
     
    382376    this->bufferText[0] = lastText;
    383377
    384     this->bufferText[0]->setText(text, true);
     378    this->bufferText[0]->setText(text);
    385379  }
    386380}
     
    427421  for (unsigned int i = 0; i < this->bufferDisplaySize; i++)
    428422  {
    429     this->bufferText[i]->setText((*it), false);
     423    this->bufferText[i]->setText((*it));
    430424    it--;
    431425  }
  • trunk/src/lib/shell/shell.h

    r5784 r7221  
    5353    inline bool isActive() const { return this->bActive; };
    5454
    55     void setFont(const char* fontFile);
     55    void setFont(const std::string& fontFile);
    5656    void setTextSize(unsigned int textSize, unsigned int lineSpacing = 1);
    5757    void setTextColor(float r, float g, float b, float a);
    5858    void setBackgroundColor(float r, float g, float b, float a);
    59     void setBackgroundImage(const char* fileName);
     59    void setBackgroundImage(const std::string& fileName);
    6060
    6161    void resetValues();
     
    6464    // BUFFERS
    6565    void setBufferDisplaySize(unsigned int bufferDisplaySize);
    66     void printToDisplayBuffer(const char* text);
     66    void printToDisplayBuffer(const std::string& text);
    6767    void moveDisplayBuffer(int lineCount);
    6868
     
    8383
    8484    //     void testI (int i);
    85     //     void testS (const char* s);
     85    //     void testS (const std::string& s);
    8686    //     void testB (bool b);
    8787    //     void testF (float f);
    88     //     void testSF (const char* s, float f);
     88    //     void testSF (const std::string& s, float f);
    8989
    9090  private:
     
    9595    unsigned int                textSize;               //!< The size of the text.
    9696    float                       textColor[4];           //!< The text's color [r,g,b,a].
    97     char*                       fontFile;               //!< The file containing the font.
     97    std::string                 fontFile;               //!< The file containing the font.
    9898    Material*                   backgroundMaterial;     //!< A material for the background.
    9999
  • trunk/src/lib/shell/shell_command.cc

    r7201 r7221  
    4141  PRINTF(5)("create shellcommand %s %s\n", commandName, className);
    4242  this->setName(commandName);
    43   this->description = NULL;
    44   this->alias = NULL;
    4543  this->executor = executor.clone();
    4644  this->executor->setName(commandName);
     
    153151 * @return true on success, false otherwise.
    154152 */
    155 bool ShellCommand::execute(const char* executionString)
     153bool ShellCommand::execute(const std::string& executionString)
    156154{
    157155  if (ShellCommandClass::commandClassList == NULL)
     
    177175      for (alias = ShellCommandClass::aliasList->begin(); alias != ShellCommandClass::aliasList->end(); alias++ )
    178176      {
    179         if ((*alias)->getName() != NULL && !strcmp((*alias)->getName(), inputSplits.getString(0)) && (*alias)->getCommand() != NULL &&
     177        if (inputSplits.getString(0) == (*alias)->getName() && (*alias)->getCommand() != NULL &&
    180178            (*alias)->getCommand()->shellClass != NULL )
    181179        {
     
    184182          {
    185183            if (inputSplits.getCount() > 1)
    186               (*alias)->getCommand()->executor->execute(objectList->front(), executionString+inputSplits.getOffset(1));
     184            {
     185
     186              (*alias)->getCommand()->executor->execute(objectList->front(), executionString.substr(inputSplits.getOffset(1))); /// TODO CHECK IF OK
     187            }
    187188            else
    188189              (*alias)->getCommand()->executor->execute(objectList->front(), "");
     
    198199      for (commandClassIT = ShellCommandClass::commandClassList->begin(); commandClassIT != ShellCommandClass::commandClassList->end(); commandClassIT++)
    199200      {
    200         if ((*commandClassIT)->getName() && !strcasecmp(inputSplits.getString(0), (*commandClassIT)->getName()))
     201        if ((*commandClassIT)->getName() && inputSplits.getString(0) == (*commandClassIT)->getName())
    201202        {
    202203          //elemCL->getName();
     
    217218        for (object = objectList->begin(); object != objectList->end(); object++)
    218219        {
    219           if ((*object)->getName() != NULL && !strcasecmp((*object)->getName(), inputSplits.getString(1)))
     220          if ((*object)->getName() != NULL && inputSplits.getString(1) == (*object)->getName() )
    220221          {
    221222            objectPointer = (*object);
     
    235236        for (cmdIT = commandClass->commandList.begin(); cmdIT != commandClass->commandList.end(); cmdIT++)
    236237        {
    237           if (!strcmp((*cmdIT)->getName(), inputSplits.getString(fktPos)))
     238          if (inputSplits.getString(fktPos) == (*cmdIT)->getName())
    238239          {
    239240            if (objectPointer == NULL && (*cmdIT)->executor->getType() & Executor_Objective)
    240241              return false;
    241242            if (inputSplits.getCount() > fktPos+1)
    242               (*cmdIT)->executor->execute(objectPointer, executionString+inputSplits.getOffset(fktPos +1));
     243              (*cmdIT)->executor->execute(objectPointer, executionString.substr(inputSplits.getOffset(fktPos +1))); /// TODO CHECK IF OK
    243244            else
    244245              (*cmdIT)->executor->execute(objectPointer, "");
     
    255256 * @param description the description of the Given command
    256257 */
    257 ShellCommand* ShellCommand::describe(const char* description)
     258ShellCommand* ShellCommand::describe(const std::string& description)
    258259{
    259260  if (this == NULL)
     
    326327  for (classIT = ShellCommandClass::commandClassList->begin(); classIT != ShellCommandClass::commandClassList->end(); classIT++)
    327328  {
    328     PRINT(0)("Class:'%s' registered %d commands: \n", (*classIT)->className, (*classIT)->commandList.size());
     329    PRINT(0)("Class:'%s' registered %d commands: \n", (*classIT)->className.c_str(), (*classIT)->commandList.size());
    329330
    330331    list<ShellCommand*>::iterator cmdIT;
     
    335336      /*      for (unsigned int i = 0; i< elem->paramCount; i++)
    336337       printf("%s ", ShellCommand::paramToString(elem->parameters[i]));*/
    337       if ((*cmdIT)->description != NULL)
    338        printf("- %s", (*cmdIT)->description);
     338      if (!(*cmdIT)->description.empty())
     339        printf("- %s", (*cmdIT)->description.c_str());
    339340      printf("\n");
    340341
  • trunk/src/lib/shell/shell_command.h

    r7201 r7221  
    6161  friend class ShellCommandClass;
    6262  public:
    63     static bool execute (const char* executionString);
     63    static bool execute (const std::string& executionString);
    6464
    65     ShellCommand* describe(const char* description);
     65    ShellCommand* describe(const std::string& description);
    6666    ShellCommand* setAlias(const char* alias);
    6767    ShellCommand* defaultValues(const MultiType& value0 = MT_NULL, const MultiType& value1 = MT_NULL,
     
    8989    ShellCommandAlias*               alias;                                //!< An Alias for the Class.
    9090
    91     const char*                      description;                          //!< A description for this commnand. (initially NULL). Assigned with (create)->describe("blablabla");
     91    std::string                      description;                          //!< A description for this commnand. (initially NULL). Assigned with (create)->describe("blablabla");
    9292    Executor*                        executor;                             //!< The Executor, that really executes the Function.
    9393
     
    100100  public:
    101101    /** @returns the Name of the Alias. */
    102     const char* getName() const { return this->aliasName; };
     102    const std::string& getName() const { return this->aliasName; };
    103103    /** @returns the Command, this Alias is asociated with */
    104104    ShellCommand* getCommand() const { return this->command; };
     
    106106  private:
    107107    /** @param aliasName the name of the Alias @param command the Command, to associate this alias with */
    108     ShellCommandAlias(const char* aliasName, ShellCommand* command) { this->aliasName = aliasName; this->command = command; };
     108    ShellCommandAlias(const std::string& aliasName, ShellCommand* command) { this->aliasName = aliasName; this->command = command; };
    109109
    110110  private:
    111     const char*     aliasName;       //!< the name of the Alias
     111    std::string     aliasName;       //!< the name of the Alias
    112112    ShellCommand*   command;         //!< a pointer to the command, this alias executes.
    113113};
  • trunk/src/lib/shell/shell_command_class.cc

    r5780 r7221  
    3636 * @param className the Name of the command-class to create
    3737 */
    38 ShellCommandClass::ShellCommandClass(const char* className)
     38ShellCommandClass::ShellCommandClass(const std::string& className)
     39  : className(className)
    3940{
    4041  this->setClassID(CL_SHELL_COMMAND_CLASS, "ShellCommandClass");
    4142  this->setName(className);
    4243
    43   this->className = className;
    4444  this->classID = CL_NULL;
    4545
     
    6565 * @returns true on success, false otherwise
    6666 */
    67 bool ShellCommandClass::getCommandListOfClass(const char* className, std::list<const char*>* stringList)
    68 {
    69   if (stringList == NULL || className == NULL)
     67bool ShellCommandClass::getCommandListOfClass(const std::string& className, std::list<std::string>* stringList)
     68{
     69  if (stringList == NULL)
    7070    return false;
    7171
     
    7373  for(elem = ShellCommandClass::commandClassList->begin(); elem != ShellCommandClass::commandClassList->end(); elem++)
    7474  {
    75     if (!strcmp ((*elem)->getName(), className))
     75    if (className == (*elem)->getName())
    7676    {
    7777      list<ShellCommand*>::iterator command;
     
    8888 * @returns true on success, false otherwise
    8989 */
    90 bool ShellCommandClass::getCommandListOfAlias(std::list<const char*>* stringList)
     90bool ShellCommandClass::getCommandListOfAlias(std::list<std::string>* stringList)
    9191{
    9292  if (stringList == NULL || ShellCommandClass::aliasList == NULL)
     
    130130 * @returns the CommandClass if found, NULL otherwise
    131131 */
    132 const ShellCommandClass* ShellCommandClass::isRegistered(const char* className)
     132const ShellCommandClass* ShellCommandClass::isRegistered(const std::string& className)
    133133{
    134134  if (ShellCommandClass::commandClassList == NULL)
     
    138138  for (classIT = ShellCommandClass::commandClassList->begin(); classIT != ShellCommandClass::commandClassList->end(); classIT++)
    139139  {
    140     if (!strcmp(className, (*classIT)->className))
     140    if (className == (*classIT)->className)
    141141    {
    142142      if ((*classIT)->classID == CL_NULL)
     
    154154 * @returns the CommandClass if found, or a new CommandClass if not
    155155 */
    156 ShellCommandClass* ShellCommandClass::getCommandClass(const char* className)
     156ShellCommandClass* ShellCommandClass::getCommandClass(const std::string& className)
    157157{
    158158  if (ShellCommandClass::commandClassList == NULL)
     
    162162  for (classIT = ShellCommandClass::commandClassList->begin(); classIT != ShellCommandClass::commandClassList->end(); classIT++)
    163163  {
    164     if (!strcmp(className, (*classIT)->className))
     164    if (className == (*classIT)->className)
    165165    {
    166166      return (*classIT);
     
    186186 * @param className: the Class of Commands to show help about
    187187 */
    188 void ShellCommandClass::help(const char* className)
    189 {
    190   if (className == NULL)
    191     return;
     188void ShellCommandClass::help(const std::string& className)
     189{
    192190  if (likely(ShellCommandClass::commandClassList != NULL))
    193191  {
     
    195193    for (classIT = ShellCommandClass::commandClassList->begin(); classIT != ShellCommandClass::commandClassList->end(); classIT++)
    196194    {
    197       if ((*classIT)->className && !strcasecmp(className, (*classIT)->className))
     195      if (className == (*classIT)->className)
    198196      {
    199         PRINT(0)("Class:'%s' registered %d commands: \n", (*classIT)->className, (*classIT)->commandList.size());
     197        PRINT(0)("Class:'%s' registered %d commands: \n", (*classIT)->className.c_str(), (*classIT)->commandList.size());
    200198        list<ShellCommand*>::const_iterator cmdIT;
    201199        for (cmdIT = (*classIT)->commandList.begin(); cmdIT != (*classIT)->commandList.end(); cmdIT++)
     
    205203          /*          for (unsigned int i = 0; i< elem->paramCount; i++)
    206204            PRINT(0)("%s ", ShellCommand::paramToString(elem->parameters[i]));*/
    207           if ((*cmdIT)->description != NULL)
    208             PRINT(0)("- %s", (*cmdIT)->description);
     205          if (!(*cmdIT)->description.empty())
     206            PRINT(0)("- %s", (*cmdIT)->description.c_str());
    209207          PRINT(0)("\n");
    210208        }
     
    212210      }
    213211    }
    214     PRINTF(3)("Class %s not found in Command's classes\n", className);
     212    PRINTF(3)("Class %s not found in Command's classes\n", className.c_str());
    215213  }
    216214  else
  • trunk/src/lib/shell/shell_command_class.h

    r6981 r7221  
    2727    /** @returns the CommandClassList */
    2828    static const std::list<ShellCommandClass*>* getCommandClassList() { return ShellCommandClass::commandClassList; };
    29     static bool getCommandListOfClass(const char* className, std::list<const char*>* stringList);
    30     static bool getCommandListOfAlias(std::list<const char*>* aliasList);
     29    static bool getCommandListOfClass(const std::string& className, std::list<std::string>* stringList);
     30    static bool getCommandListOfAlias(std::list<std::string>* aliasList);
    3131
    32     static ShellCommandClass* getCommandClass(const char* className);
     32    static ShellCommandClass* getCommandClass(const std::string& className);
    3333    static void unregisterAllCommands();
    3434
    35     static void help (const char* className);
     35    static void help (const std::string& className);
    3636
    3737  private:
    38     ShellCommandClass(const char* className);
     38    ShellCommandClass(const std::string& className);
    3939    virtual ~ShellCommandClass();
    4040
    41     static const ShellCommandClass* isRegistered(const char* className);
     41    static const ShellCommandClass* isRegistered(const std::string& className);
    4242    static void initCommandClassList();
    4343
    4444  private:
    45     const char*                            className;                 //!< The Name of the Class. This should match the ClassName of the Commands Class.
     45    const std::string                      className;                 //!< The Name of the Class. This should match the ClassName of the Commands Class.
    4646    long                                   classID;                   //!< The classID of this Class
    4747    std::list<ShellCommand*>               commandList;               //!< A list of Commands from this Class
  • trunk/src/lib/shell/shell_completion.cc

    r5885 r7221  
    7676
    7777  // Check if we are in a input. eg. the supplied string "class " and now we complete either function or object
    78   if (this->input->getInput() != NULL &&
    79       strrchr(this->input->getInput(), ' ') >= this->input->getInput() + strlen(this->input->getInput())-1)
     78  if (this->input->getInput()[this->input->getInput().size()-1] == ' ')
    8079  {
    8180    emptyComplete = true;
     
    8382
    8483  // CREATE INPUTS
    85   if (this->input->getInput() == NULL)
    86     completionLine = "";
    87   else
    88     completionLine = this->input->getInput() + strspn(this->input->getInput(), " \t\n");
    89   SubString inputSplits(completionLine, " \t\n,");
     84  SubString inputSplits(this->input->getInput(), " \t\n,");
    9085
    9186  // What String will be completed
     
    9388    completeString = "";
    9489  else
    95     completeString = inputSplits.getString(inputSplits.getCount()-1);
     90    completeString = inputSplits.getString(inputSplits.getCount()-1).c_str();
    9691
    9792  // CLASS COMPLETION
     
    111106            (inputSplits.getCount() == 2 && emptyComplete == false))
    112107  {
    113     classID = ClassList::StringToID(inputSplits.getString(0));
     108    classID = ClassList::StringToID(inputSplits.getString(0).c_str()); //FIXME
    114109    objectList = ClassList::getList((ClassID)classID);
    115110    if (classID != CL_NULL)
     
    121116            (inputSplits.getCount() == 3 && emptyComplete == false))
    122117  {
    123     classID = ClassList::StringToID(inputSplits.getString(0));
     118    classID = ClassList::StringToID(inputSplits.getString(0) .c_str()); // FIXME
    124119    if (classID == CL_NULL)
    125120      return false;
     
    133128    this->objectComplete(completeString, classID);
    134129  if (completeType & SHELLC_FUNCTION)
    135     this->functionComplete(completeString, inputSplits.getString(0));
     130    this->functionComplete(completeString, inputSplits.getString(0).c_str()); // FIXME
    136131  if (completeType & SHELLC_ALIAS)
    137132    this->aliasComplete(completeString);
     
    151146  if (unlikely(classBegin == NULL))
    152147    return false;
    153   const std::list<const char*>* clList = ClassList::getClassNames();
     148  const std::list<std::string>* clList = ClassList::getClassNames();
    154149  if (clList != NULL)
    155150  {
     
    195190  if (unlikely(functionBegin == NULL))
    196191    return false;
    197   std::list<const char*> fktList;
     192  std::list<std::string> fktList;
    198193  ShellCommandClass::getCommandListOfClass(className, &fktList);
    199194  //printf("%s\n", boList->firstElement()->getName());
     
    212207  if (unlikely(aliasBegin == NULL))
    213208    return false;
    214   std::list<const char*> aliasList;
     209  std::list<std::string> aliasList;
    215210  ShellCommandClass::getCommandListOfAlias(&aliasList);
    216211  //printf("%s\n", boList->firstElement()->getName());
     
    295290 * !! The strings MUST NOT be deleted !!
    296291 */
    297 bool ShellCompletion::addToCompleteList(const std::list<const char*>* inputList, const char* completionBegin, SHELLC_TYPE type)
     292bool ShellCompletion::addToCompleteList(const std::list<std::string>* inputList, const char* completionBegin, SHELLC_TYPE type)
    298293{
    299294  if (inputList == NULL || completionBegin == NULL)
     
    301296  unsigned int searchLength = strlen(completionBegin);
    302297
    303   list<const char*>::const_iterator string;
     298  list<std::string>::const_iterator string;
    304299  for (string = inputList->begin(); string != inputList->end(); string++)
    305300  {
    306     if (strlen(*string) >= searchLength &&
    307         !strncasecmp(*string, completionBegin, searchLength))
     301    if ((*string).size() >= searchLength &&
     302          !strncasecmp((*string).c_str(), completionBegin, searchLength))
    308303    {
    309304      ShellC_Element newElem;
    310       newElem.name = *string;
     305      newElem.name = (*string).c_str();
    311306      newElem.type = type;
    312307      this->completionList.push_back(newElem);
  • trunk/src/lib/shell/shell_completion.h

    r5784 r7221  
    5252  bool generalComplete(const char* begin, const char* displayAs = "%s", const char* addBack = NULL, const char* addFront = NULL);
    5353
    54   bool addToCompleteList(const std::list<const char*>* inputList, const char* completionBegin, SHELLC_TYPE type);
     54  bool addToCompleteList(const std::list<std::string>* inputList, const char* completionBegin, SHELLC_TYPE type);
    5555  bool addToCompleteList(const std::list<BaseObject*>* inputList, const char* completionBegin, SHELLC_TYPE type);
    5656  void emptyCompletionList();
  • trunk/src/lib/shell/shell_input.cc

    r6222 r7221  
    4141 * this also generates a ShellCompletion automatically.
    4242*/
    43 ShellInput::ShellInput () : Text ((const char*)NULL)
     43ShellInput::ShellInput () : Text ("")
    4444{
    4545  this->pressedKey = SDLK_FIRST;
    4646  this->setClassID(CL_SHELL_INPUT, "ShellInput");
    4747
    48   this->inputLine = new char[1];
    49   this->inputLine[0] = '\0';
     48  this->inputLine = "";
    5049  this->historyIT = this->history.begin();
    5150  this->setHistoryLength(50);
     
    7069{
    7170  // delete what has to be deleted here
    72   delete[] this->inputLine;
    7371  delete this->completion;
    7472
    7573  while (!this->history.empty())
    7674  {
    77     delete[] this->history.front();
    7875    this->history.pop_front();
    7976  }
     
    9693void ShellInput::flush()
    9794{
    98   if (likely(this->inputLine != NULL))
    99   {
    100     delete[] this->inputLine;
    101   }
    102   this->inputLine = new char[1];
    103   *this->inputLine = '\0';
    104   this->setText(this->inputLine, true);
     95  this->inputLine.clear();
     96  this->setText(this->inputLine);
    10597}
    10698
     
    109101 * @param text the new Text to set as InputLine
    110102 */
    111 void ShellInput::setInputText(const char* text)
    112 {
    113   delete[] this->inputLine;
    114   if (text == NULL)
    115   {
    116     this->inputLine = new char[1];
    117     this->inputLine[0] = '\0';
    118   }
    119   else
    120   {
    121     this->inputLine = new char[strlen(text)+1];
    122     strcpy(this->inputLine, text);
    123   }
    124   this->setText(this->inputLine, true);
     103void ShellInput::setInputText(const std::string& text)
     104{
     105  this->inputLine = text;
     106  this->setText(this->inputLine);
    125107}
    126108
     
    134116  if (this->historyScrolling)
    135117  {
    136     delete[] this->history.back();
    137118    this->history.pop_back();
    138119    this->historyScrolling = false;
    139120  }
    140121
    141   char* addCharLine = new char[strlen(this->inputLine)+2];
    142 
    143   sprintf(addCharLine, "%s%c", this->inputLine, character);
    144   delete[] this->inputLine;
    145   this->inputLine = addCharLine;
    146   this->setText(this->inputLine, true);
     122  this->inputLine += character;
     123  this->setText(this->inputLine);
    147124}
    148125
     
    151128 * @param characters a \\0 terminated char-array to add to the InputLine
    152129 */
    153 void ShellInput::addCharacters(const char* characters)
     130void ShellInput::addCharacters(const std::string& characters)
    154131{
    155132  if (this->historyScrolling)
    156133  {
    157     delete[] this->history.back();
    158134    this->history.pop_back();
    159135    this->historyScrolling = false;
    160136  }
    161137
    162   char* addCharLine = new char[strlen(this->inputLine)+strlen(characters)+1];
    163 
    164   sprintf(addCharLine, "%s%s", this->inputLine, characters);
    165   delete[] this->inputLine;
    166   this->inputLine = addCharLine;
    167   this->setText(this->inputLine, true);
     138  this->inputLine += characters;
     139  this->setText(this->inputLine);
    168140}
    169141
     
    176148  if (this->historyScrolling)
    177149  {
    178     delete[] this->history.back();
    179150    this->history.pop_back();
    180151    this->historyScrolling = false;
    181152  }
    182 
    183   if (strlen(this->inputLine) == 0)
    184     return;
    185 
    186   if (characterCount > strlen(this->inputLine))
    187     characterCount = strlen(this->inputLine);
    188 
    189   char* removeCharLine = new char[strlen(this->inputLine)-characterCount+1];
    190 
    191   strncpy(removeCharLine, this->inputLine, strlen(this->inputLine)-characterCount);
    192   removeCharLine[strlen(this->inputLine)-characterCount] = '\0';
    193   delete[] this->inputLine;
    194   this->inputLine = removeCharLine;
    195   this->setText(this->inputLine, true);
     153  if (this->inputLine.size() < characterCount)
     154    characterCount = this->inputLine.size();
     155
     156  this->inputLine.erase(this->inputLine.size() - characterCount, this->inputLine.size());
     157  this->setText(this->inputLine);
    196158}
    197159
     
    202164bool ShellInput::executeCommand()
    203165{
    204   ShellBuffer::addBufferLineStatic("Execute Command: %s\n", this->inputLine);
    205 
    206   if (strlen(this->inputLine) == 0)
     166  ShellBuffer::addBufferLineStatic("Execute Command: %s\n", this->inputLine.c_str());
     167
     168  if (this->inputLine.empty())
    207169    return false;
    208170
    209   char* newCommand = new char[strlen(this->inputLine)+1];
    210   strcpy(newCommand, this->inputLine);
    211 
    212   ShellCommand::execute(newCommand);
     171  ShellCommand::execute(this->inputLine);
    213172
    214173  // removing the eventually added Entry (from scrolling) to the List
    215174  if (this->historyScrolling)
    216175  {
    217     delete[] this->history.back();
    218176    this->history.pop_back();
    219177    this->historyScrolling = false;
     
    221179
    222180  // adding the new Command to the History
    223   this->history.push_back(newCommand);
     181  this->history.push_back(this->inputLine);
    224182  if (this->history.size() > this->historyLength)
    225183  {
    226     delete[] this->history.front();
    227184    this->history.pop_front();
    228185  }
     
    241198  if (!this->historyScrolling)
    242199  {
    243     char* currentText = new char[strlen(this->inputLine)+1];
    244     strcpy(currentText, this->inputLine);
    245     this->history.push_back(currentText);
     200    this->history.push_back(this->inputLine);
    246201    this->historyScrolling = true;
    247202    this->historyIT = --this->history.end();
     
    250205  if(this->historyIT != this->history.begin())
    251206  {
    252     char* prevElem = *(--this->historyIT);
    253     if (prevElem == NULL)
     207    std::string prevElem = *(--this->historyIT);
     208    /*if (prevElem == NULL) /// TODO STD
    254209      return;
    255     else
     210    else */
    256211    {
    257212      this->flush();
     
    270225  if (this->historyIT != this->history.end())
    271226  {
    272     char* nextElem = *(++this->historyIT);
    273     if (nextElem == NULL)
     227    std::string nextElem = *(++this->historyIT);
     228    /*    if (nextElem == NULL) /// TODO FIX STD
    274229      return;
    275     else
     230    else */
    276231    {
    277232      this->flush();
     
    285240 * prints out some nice help about the Shell
    286241 */
    287 void ShellInput::help(const char* className, const char* functionName)
    288 {
    289   printf("%s::%s\n", className, functionName);
    290 
    291   if (strlen(className) == 0)
     242void ShellInput::help(const std::string& className, const std::string& functionName)
     243{
     244  printf("%s::%s\n", className.c_str(), functionName.c_str());
     245
     246  if (className.empty())
    292247  {
    293248    PRINT(0)("Help for the most important Shell-commands\n");
     
    298253    PRINT(0)("- Also try 'help className'");
    299254  }
    300   else if (strlen (className) > 0 && strlen (functionName) == 0)
     255  else if (!className.empty() && functionName.empty())
    301256  {
    302257    ShellCommandClass::help(className);
  • trunk/src/lib/shell/shell_input.h

    r5786 r7221  
    3131
    3232  /** @returns the inputLine */
    33   const char* getInput() const { return this->inputLine; };
     33  const std::string& getInput() const { return this->inputLine; };
    3434
    3535  // InputLine
    3636  void flush();
    37   void setInputText(const char* text);
     37  void setInputText(const std::string& text);
    3838  void addCharacter(char character);
    39   void addCharacters(const char* characters);
     39  void addCharacters(const std::string& characters);
    4040  void removeCharacters(unsigned int characterCount = 1);
    4141  void setRepeatDelay(float repeatDelay, float repeatRate);
     
    4747  void historyMoveDown();
    4848
    49   void help(const char* className = "", const char* function = "");
     49  void help(const std::string& className = "", const std::string& function = "");
    5050
    5151  virtual void tick(float dt);
     
    5454 private:
    5555    // HANDLING TEXT INPUT
    56    ShellCompletion*            completion;             //!< The Completion Interface.
     56   ShellCompletion*                  completion;       //!< The Completion Interface.
    5757
    58    char*                       inputLine;              //!< the Char-Array of the Buffer
    59    float                       repeatRate;             //!< The Repeat-Delay.
    60    float                       repeatDelay;            //!< The delay of the first Character of a given Character.
    61    float                       delayed;                //!< how much of the delay is remaining.
    62    Uint16                      pressedKey;             //!< the pressed key that will be repeated.
     58   std::string                       inputLine;        //!< the Char-Array of the Buffer
     59   float                             repeatRate;       //!< The Repeat-Delay.
     60   float                             repeatDelay;      //!< The delay of the first Character of a given Character.
     61   float                             delayed;          //!< how much of the delay is remaining.
     62   Uint16                            pressedKey;       //!< the pressed key that will be repeated.
    6363
    64    std::list<char*>            history;                //!< The history of given commands.
    65    std::list<char*>::iterator  historyIT;
    66    unsigned int                historyLength;          //!< The maximum length of the InputHistory.
    67    bool                        historyScrolling;      //!< true if we are scrolling through the history.
     64   std::list<std::string>            history;          //!< The history of given commands.
     65   std::list<std::string>::iterator  historyIT;        //!< The locator that tells us, where we are in the history.
     66   unsigned int                      historyLength;    //!< The maximum length of the InputHistory.
     67   bool                              historyScrolling; //!< true if we are scrolling through the history.
    6868};
    6969
Note: See TracChangeset for help on using the changeset viewer.