Changeset 5148 in orxonox.OLD for trunk/src/util
- Timestamp:
- Aug 27, 2005, 12:17:50 PM (19 years ago)
- Location:
- trunk/src/util
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/util/shell.cc
r5145 r5148 79 79 80 80 ShellCommand<Shell>::registerCommand("clear", CL_SHELL, &Shell::clear); 81 ShellCommand<Shell>::registerCommand("testS", CL_SHELL, &Shell::testS); 81 82 ShellCommand<Shell>::registerCommand("testI", CL_SHELL, &Shell::testI); 82 ShellCommand<Shell>::registerCommand("testS", CL_SHELL, &Shell::testS);83 83 } 84 84 … … 92 92 { 93 93 printf("This is the Test for one String '%s'\n", s); 94 95 94 } 96 95 -
trunk/src/util/shell_command.cc
r5147 r5148 33 33 this->setName(commandName); 34 34 35 va_list parameters;36 va_start(parameters, paramCount);37 38 35 this->classID = classID; 39 36 this->className = ClassList::IDToString(classID); … … 48 45 paramCount = FUNCTOR_MAX_ARGUMENTS; 49 46 this->paramCount = paramCount; 50 this->parameters = new long[paramCount]; 47 this->parameters = new unsigned int[paramCount]; 48 49 va_list parameterList; 50 va_start(parameterList, paramCount); 51 51 52 52 for (unsigned int i = 0; i < paramCount; i++) 53 53 { 54 this->parameters[i] = va_arg(parameter s, long);54 this->parameters[i] = va_arg(parameterList, int); 55 55 56 56 switch (this->parameters[i]) 57 57 { 58 58 case ParameterBool: 59 this->defaultBools[i] = va_arg(parameter s, int);59 this->defaultBools[i] = va_arg(parameterList, int); 60 60 break; 61 61 case ParameterChar: 62 62 this->defaultStrings[i] = new char[2]; 63 sprintf(this->defaultStrings[0], "%c", va_arg(parameter s, int));63 sprintf(this->defaultStrings[0], "%c", va_arg(parameterList, int)); 64 64 break; 65 65 case ParameterString: 66 this->defaultStrings[i] = va_arg(parameter s, char*);66 this->defaultStrings[i] = va_arg(parameterList, char*); 67 67 break; 68 68 case ParameterInt: 69 this->defaultInts[i] = va_arg(parameter s, int);69 this->defaultInts[i] = va_arg(parameterList, int); 70 70 break; 71 71 case ParameterUInt: 72 this->defaultInts[i] = va_arg(parameter s, unsigned int);72 this->defaultInts[i] = va_arg(parameterList, unsigned int); 73 73 break; 74 74 case ParameterFloat: 75 this->defaultFloats[i] = va_arg(parameter s, double);75 this->defaultFloats[i] = va_arg(parameterList, double); 76 76 break; 77 77 case ParameterLong: 78 this->defaultInts[i] = va_arg(parameter s, long);78 this->defaultInts[i] = va_arg(parameterList, long); 79 79 break; 80 80 default: … … 97 97 bool ShellCommandBase::isRegistered(const char* commandName, ClassID classID, unsigned int paramCount, ...) 98 98 { 99 va_list parameter s;100 va_start(parameter s, paramCount);99 va_list parameterList; 100 va_start(parameterList, paramCount); 101 101 102 102 if (ShellCommandBase::commandList == NULL) 103 103 { 104 104 ShellCommandBase::commandList = new tList<ShellCommandBase>; 105 ShellCommand<ShellCommandBase>::registerCommand("debug", CL_SHELL_COMMAND, &ShellCommandBase::debug); 105 106 return false; 106 107 } … … 126 127 * executes commands 127 128 * @param executionString the string containing the following input 128 * <ClassName> [<ObjectName>] <functionName>[parameter1[,parameter2[,...]]]129 * ClassName [ObjectName] functionName [parameter1[,parameter2[,...]]] 129 130 * @return true on success, false otherwise. 130 131 */ … … 156 157 continue; 157 158 } 159 PRINTF(4)("Command %s matches\n", elem->getName()); 158 160 // getting singleton-reference 159 161 tList<BaseObject>* list = ClassList::getList(elem->classID); 160 if (list )162 if (list != NULL) 161 163 objectPointer = list->firstElement(); 162 164 } … … 195 197 continue; 196 198 } 197 PRINTF( 5)("Function '%s' found\n", commandBegin);199 PRINTF(4)("Function '%s' found\n", commandBegin); 198 200 } 199 201 const char* paramBegin = strchr(commandBegin, ' '); … … 203 205 paramBegin++; 204 206 207 PRINTF(3)("Parameters to Pass: %s\n", paramBegin); 205 208 if (objectPointer != NULL && paramBegin != NULL) 206 209 { … … 215 218 return true; 216 219 } 220 221 222 void ShellCommandBase::debug() 223 { 224 if (ShellCommandBase::commandList == NULL) 225 { 226 PRINT(0)("No Command registered so far\n"); 227 return; 228 } 229 230 tIterator<ShellCommandBase>* iterator = ShellCommandBase::commandList->getIterator(); 231 ShellCommandBase* elem = iterator->firstElement(); 232 while(elem != NULL) 233 { 234 PRINT(0)("Class %s registered command %s with %d parameters: ", elem->className, elem->getName(), elem->paramCount); 235 for (unsigned int i = 0; i< elem->paramCount; i++) 236 printf(ShellCommandBase::paramToString(elem->parameters[i])); 237 printf("\n"); 238 239 elem = iterator->nextElement(); 240 } 241 delete iterator; 242 } 243 244 245 246 const char* ShellCommandBase::paramToString(long parameter) 247 { 248 switch (parameter) 249 { 250 case ParameterBool: 251 return "BOOL"; 252 break; 253 case ParameterChar: 254 return "CHAR"; 255 break; 256 case ParameterString: 257 return "STRING"; 258 break; 259 case ParameterInt: 260 return "INT"; 261 break; 262 case ParameterUInt: 263 return "UINT"; 264 break; 265 case ParameterFloat: 266 return "FLOAT"; 267 break; 268 case ParameterLong: 269 return "LONG"; 270 break; 271 default: 272 return "NULL"; 273 break; 274 } 275 } -
trunk/src/util/shell_command.h
r5147 r5148 45 45 } 46 46 47 47 // CONSTRUCTORS 48 48 #define ShellCommandConstructor0 \ 49 49 void (T::*functionPointer_0)(); \ … … 70 70 #define ShellCommandExecute1(t1) \ 71 71 else if (this->paramCount == 1 && this->parameters[0] == t1##_PARAM) \ 72 72 (dynamic_cast<T*>(object)->*functionPointer_1_##t1)(t1##_FUNC(parameters, 0)) 73 73 74 74 … … 90 90 91 91 static bool isRegistered(const char* commandName, ClassID classID, unsigned int paramCount, ...); 92 static const char* paramToString(long parameter); 92 93 94 void debug(); 93 95 private: 94 96 virtual void executeCommand (BaseObject* object, const char* parameters) = NULL; … … 97 99 void* functionPointer; //!< The pointeer to the function of the Class (or static pointer if ClassID == CL_NULL ) 98 100 unsigned int paramCount; //!< the count of parameters 99 long*parameters; //!< Parameters101 unsigned int* parameters; //!< Parameters 100 102 bool isSingleton; //!< if the Class is Singleton @todo autocheck 101 103 … … 143 145 #define FUNCTOR_LIST(x) ShellCommandRegister ## x 144 146 //#include "functor_list.h" 145 FUNCTOR_LIST(0);146 FUNCTOR_LIST(1)(l_INT);147 FUNCTOR_LIST(1)(l_STRING);147 FUNCTOR_LIST(0); 148 FUNCTOR_LIST(1)(l_INT); 149 FUNCTOR_LIST(1)(l_STRING); 148 150 #undef FUNCTOR_LIST 149 151 … … 160 162 { 161 163 if (parameters != NULL) 162 SubString params(parameters, ',');164 //SubString params(parameters, ','); 163 165 #define FUNCTOR_LIST(x) ShellCommandExecute ## x 164 166 //#include "functor_list.h" 165 167 FUNCTOR_LIST(0); 166 168 FUNCTOR_LIST(1)(l_INT); 167 FUNCTOR_LIST(1)(l_STRING);169 //FUNCTOR_LIST(1)(l_STRING); 168 170 #undef FUNCTOR_LIST 169 171 }
Note: See TracChangeset
for help on using the changeset viewer.