[4744] | 1 | /* |
---|
[1853] | 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 orx |
---|
| 5 | |
---|
| 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
[1855] | 10 | |
---|
| 11 | ### File Specific: |
---|
[5068] | 12 | main-programmer: Benjamin Grauer |
---|
[1855] | 13 | co-programmer: ... |
---|
[1853] | 14 | */ |
---|
| 15 | |
---|
[3955] | 16 | //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ |
---|
[1853] | 17 | |
---|
[5129] | 18 | #include "shell_command.h" |
---|
[1853] | 19 | |
---|
[5072] | 20 | #include "list.h" |
---|
[5129] | 21 | #include "debug.h" |
---|
[5113] | 22 | #include "class_list.h" |
---|
| 23 | |
---|
| 24 | #include "key_names.h" |
---|
[5075] | 25 | #include <stdarg.h> |
---|
| 26 | #include <stdio.h> |
---|
| 27 | |
---|
[1856] | 28 | using namespace std; |
---|
[1853] | 29 | |
---|
[5130] | 30 | ShellCommandBase::ShellCommandBase(const char* commandName, ClassID classID, void* functionPointer, unsigned int paramCount, va_list parameters) |
---|
[3365] | 31 | { |
---|
[5129] | 32 | this->classID = classID; |
---|
[5130] | 33 | this->functionPointer = functionPointer; |
---|
[5129] | 34 | this->commandName = new char[strlen(commandName)+1]; |
---|
| 35 | strcpy(this->commandName, commandName); |
---|
[5072] | 36 | |
---|
[5130] | 37 | // handling parameters, and storing them: |
---|
| 38 | this->paramCount = paramCount; |
---|
| 39 | this->parameters = new ShellParameterType[paramCount]; |
---|
| 40 | |
---|
| 41 | for (unsigned int i = 0; i < paramCount; i++) |
---|
| 42 | parameters[i] = va_arg(parameters, long); |
---|
| 43 | |
---|
| 44 | // adding this ShellCommand to the list of known Commands |
---|
[5129] | 45 | ShellCommandBase::commandList->add(this); |
---|
[5068] | 46 | } |
---|
[4320] | 47 | |
---|
[5130] | 48 | ShellCommandBase::~ShellCommandBase() |
---|
| 49 | { |
---|
| 50 | delete[] this->commandName; |
---|
| 51 | delete[] this->parameters; |
---|
| 52 | } |
---|
[1853] | 53 | |
---|
[5093] | 54 | |
---|
[5129] | 55 | tList<ShellCommandBase>* ShellCommandBase::commandList = NULL; |
---|
[5079] | 56 | |
---|
[5130] | 57 | bool ShellCommandBase::isRegistered(const char* commandName, ClassID classID, unsigned int paramCount, va_list parameters) |
---|
[5113] | 58 | { |
---|
[5129] | 59 | if (ShellCommandBase::commandList == NULL) |
---|
[5072] | 60 | { |
---|
[5129] | 61 | ShellCommandBase::commandList = new tList<ShellCommandBase>; |
---|
[5113] | 62 | return false; |
---|
| 63 | } |
---|
[5105] | 64 | |
---|
[5129] | 65 | tIterator<ShellCommandBase>* iterator = ShellCommandBase::commandList->getIterator(); |
---|
| 66 | ShellCommandBase* elem = iterator->firstElement(); |
---|
| 67 | while(elem != NULL) |
---|
[5113] | 68 | { |
---|
[5129] | 69 | if (classID == elem->classID && !strcmp(commandName, elem->commandName)) |
---|
[5113] | 70 | { |
---|
[5129] | 71 | // PRINTF(2)("Command already registered\n"); |
---|
| 72 | delete iterator; |
---|
| 73 | return true; |
---|
[5113] | 74 | } |
---|
[5129] | 75 | elem = iterator->nextElement(); |
---|
[5113] | 76 | } |
---|
[5129] | 77 | delete iterator; |
---|
[5113] | 78 | return true; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | |
---|