- Timestamp:
- Sep 13, 2005, 12:12:11 AM (19 years ago)
- Location:
- trunk/src/lib/shell
- Files:
-
- 5 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/shell/Makefile.am
r5173 r5178 6 6 libORXshell_a_SOURCES = shell.cc \ 7 7 shell_buffer.cc \ 8 shell_input.cc \ 8 9 shell_command.cc \ 9 10 shell_completion.cc … … 12 13 noinst_HEADERS= shell.h \ 13 14 shell_buffer.h \ 15 shell_input.h \ 14 16 shell_command.h \ 15 17 shell_completion.h -
trunk/src/lib/shell/Makefile.in
r5173 r5178 55 55 libORXshell_a_LIBADD = 56 56 am_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) 58 59 libORXshell_a_OBJECTS = $(am_libORXshell_a_OBJECTS) 59 60 DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) … … 63 64 @AMDEP_TRUE@ ./$(DEPDIR)/shell_buffer.Po \ 64 65 @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 66 68 CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ 67 69 $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) … … 187 189 libORXshell_a_SOURCES = shell.cc \ 188 190 shell_buffer.cc \ 191 shell_input.cc \ 189 192 shell_command.cc \ 190 193 shell_completion.cc … … 192 195 noinst_HEADERS = shell.h \ 193 196 shell_buffer.h \ 197 shell_input.h \ 194 198 shell_command.h \ 195 199 shell_completion.h … … 246 250 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/shell_command.Po@am__quote@ 247 251 @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@ 248 253 249 254 .cc.o: -
trunk/src/lib/shell/shell.h
r5176 r5178 9 9 #include "element_2d.h" 10 10 #include "event_listener.h" 11 //#include "shell_buffer.h"12 11 13 12 #include <stdarg.h> 14 15 #define SHELL_BUFFER_SIZE 1638416 13 17 14 // FORWARD DECLARATION … … 59 56 void addCharacters(const char* characters); 60 57 void removeCharacters(unsigned int characterCount = 1); 58 void setRepeatDelay(float repeatDelay, float repeatRate); 61 59 bool executeCommand(); 62 60 63 61 void clear(); 64 62 65 void setRepeatDelay(float repeatDelay, float repeatRate);66 63 67 64 // EventListener -
trunk/src/lib/shell/shell_completion.cc
r5170 r5178 18 18 #include "shell_completion.h" 19 19 20 #include "base_object.h" 21 #include "class_list.h" 22 #include "list.h" 23 #include "debug.h" 24 25 #include "stdlibincl.h" 26 20 27 using namespace std; 21 22 28 23 29 /** … … 49 55 // delete what has to be deleted here 50 56 } 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 */ 66 bool 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 */ 104 bool 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 */ 128 bool 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 */ 153 bool 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 */ 166 bool 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 */ 215 const 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 */ 249 const 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 8 8 9 9 // FORWARD DECLARATION 10 10 class BaseObject; 11 template<class T> class tList; 12 #ifndef NULL 13 #define NULL 0 //!< a pointer to NULL 14 #endif 11 15 12 16 //! A class for ... … … 17 21 virtual ~ShellCompletion(); 18 22 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 19 34 20 35 private: 21 36 tList<const char>* completionList; //!< A list of completions, that are io. 22 37 }; 23 38 -
trunk/src/lib/shell/shell_input.cc
r5177 r5178 16 16 //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ 17 17 18 #include " proto_class.h"18 #include "shell_input.h" 19 19 20 20 using namespace std; … … 25 25 * @todo this constructor is not jet implemented - do it 26 26 */ 27 ProtoClass::ProtoClass()27 ShellInput::ShellInput () 28 28 { 29 this->setClassID(CL_PROTO_ID, "ProtoClass");30 29 31 /* If you make a new class, what is most probably the case when you write this file32 don't forget to:33 1. Add the new file new_class.cc to the ./src/Makefile.am34 2. Add the class identifier to ./src/class_id.h eg. CL_NEW_CLASS35 36 Advanced Topics:37 - if you want to let your object be managed via the ObjectManager make sure to read38 the object_manager.h header comments. You will use this most certanly only if you39 make many objects of your class, like a weapon bullet.40 */41 30 } 42 43 31 44 32 /** 45 33 * standard deconstructor 46 34 */ 47 ProtoClass::~ProtoClass()35 ShellInput::~ShellInput () 48 36 { 49 37 // delete what has to be deleted here -
trunk/src/lib/shell/shell_input.h
r5177 r5178 1 1 /*! 2 * @file proto_class.h2 * @file shell_input.h 3 3 * @brief Definition of ... 4 4 */ 5 5 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 10 8 11 9 // FORWARD DECLARATION 12 10 class Text; 11 template<class T> class tList; 13 12 14 13 15 14 //! A class for ... 16 class ProtoClass : public BaseObject {15 class ShellInput { 17 16 18 17 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); 21 28 22 29 23 30 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. 24 40 25 41 }; 26 42 27 #endif /* _ PROTO_CLASS_H */43 #endif /* _SHELL_INPUT_H */
Note: See TracChangeset
for help on using the changeset viewer.