[1390] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Fabian 'x3n' Landau |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
[1402] | 29 | #include <iostream> |
---|
[1434] | 30 | #include <map> |
---|
[1402] | 31 | |
---|
[1436] | 32 | #include <dirent.h> |
---|
| 33 | |
---|
[1390] | 34 | #include "ArgumentCompletionFunctions.h" |
---|
[1434] | 35 | #include "CoreIncludes.h" |
---|
| 36 | #include "Identifier.h" |
---|
| 37 | #include "ConfigValueContainer.h" |
---|
| 38 | #include "TclThreadManager.h" |
---|
[1441] | 39 | #include "util/Convert.h" |
---|
[1434] | 40 | #include "util/String.h" |
---|
[1436] | 41 | #include "util/SubString.h" |
---|
[1390] | 42 | |
---|
| 43 | namespace orxonox |
---|
| 44 | { |
---|
| 45 | namespace autocompletion |
---|
| 46 | { |
---|
[1430] | 47 | ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(fallback)() |
---|
[1390] | 48 | { |
---|
[1441] | 49 | return ArgumentCompletionList(); |
---|
[1390] | 50 | } |
---|
[1434] | 51 | |
---|
[1436] | 52 | ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(files)(const std::string& fragment) |
---|
| 53 | { |
---|
[1441] | 54 | ArgumentCompletionList dirlist; |
---|
| 55 | ArgumentCompletionList filelist; |
---|
[1436] | 56 | |
---|
| 57 | SubString tokens(fragment, "/", "", false, '\0', false, '\0', false, '\0', '\0', false, '\0'); |
---|
| 58 | |
---|
| 59 | std::string startdirectory = "."; |
---|
| 60 | if (fragment.size() > 0 && fragment[fragment.size() - 1] == '/' && tokens.size() > 0) |
---|
| 61 | startdirectory = tokens.subSet(0, tokens.size()).join("/"); |
---|
| 62 | else if (tokens.size() > 1) |
---|
| 63 | startdirectory = tokens.subSet(0, tokens.size() - 1).join("/"); |
---|
| 64 | |
---|
| 65 | struct stat fileInfo; |
---|
| 66 | struct dirent *currentFile; |
---|
| 67 | DIR *handler = 0; |
---|
| 68 | |
---|
| 69 | handler = opendir(startdirectory.c_str()); |
---|
| 70 | if (handler) |
---|
| 71 | { |
---|
| 72 | while ((currentFile = readdir(handler)) != 0) |
---|
| 73 | { |
---|
| 74 | if (strcmp(currentFile->d_name, ".") && strcmp(currentFile->d_name, "..")) |
---|
| 75 | { |
---|
| 76 | std::string path = startdirectory + "/" + currentFile->d_name; |
---|
| 77 | if (stat(path.c_str(), &fileInfo) == -1) |
---|
| 78 | { |
---|
| 79 | closedir(handler); |
---|
| 80 | break; |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | if (S_ISREG(fileInfo.st_mode)) // normal file |
---|
[1441] | 84 | filelist.push_back(ArgumentCompletionListElement(path, getLowercase(path), currentFile->d_name)); |
---|
[1436] | 85 | else if (S_ISDIR(fileInfo.st_mode)) // directory |
---|
[1441] | 86 | dirlist.push_back(ArgumentCompletionListElement(path + "/", getLowercase(path) + "/", std::string(currentFile->d_name) + "/")); |
---|
[1436] | 87 | else // special file |
---|
[1441] | 88 | filelist.push_back(ArgumentCompletionListElement(path, getLowercase(path), currentFile->d_name)); |
---|
[1436] | 89 | } |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | closedir(handler); |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | filelist.insert(filelist.begin(), dirlist.begin(), dirlist.end()); |
---|
| 96 | return filelist; |
---|
| 97 | } |
---|
| 98 | |
---|
[1434] | 99 | ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(configvalueclasses)() |
---|
| 100 | { |
---|
[1441] | 101 | ArgumentCompletionList classlist; |
---|
[1434] | 102 | |
---|
| 103 | for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getIdentifierMapBegin(); it != Identifier::getIdentifierMapEnd(); ++it) |
---|
| 104 | if ((*it).second->hasConfigValues()) |
---|
[1441] | 105 | classlist.push_back(ArgumentCompletionListElement((*it).second->getName(), getLowercase((*it).first))); |
---|
[1434] | 106 | |
---|
| 107 | return classlist; |
---|
| 108 | } |
---|
| 109 | |
---|
[1436] | 110 | ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(configvalues)(const std::string& fragment, const std::string& classname) |
---|
[1434] | 111 | { |
---|
[1441] | 112 | ArgumentCompletionList configvalues; |
---|
[1434] | 113 | std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getIdentifierMap().find(classname); |
---|
| 114 | |
---|
| 115 | if (identifier != Identifier::getIdentifierMapEnd() && (*identifier).second->hasConfigValues()) |
---|
| 116 | { |
---|
| 117 | for (std::map<std::string, ConfigValueContainer*>::const_iterator it = (*identifier).second->getConfigValueMapBegin(); it != (*identifier).second->getConfigValueMapEnd(); ++it) |
---|
[1441] | 118 | configvalues.push_back(ArgumentCompletionListElement((*it).second->getName(), getLowercase((*it).first))); |
---|
[1434] | 119 | } |
---|
| 120 | |
---|
| 121 | return configvalues; |
---|
| 122 | } |
---|
| 123 | |
---|
[1436] | 124 | ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(configvalue)(const std::string& fragment, const std::string& varname, const std::string& classname) |
---|
[1434] | 125 | { |
---|
[1441] | 126 | ArgumentCompletionList oldvalue; |
---|
[1434] | 127 | std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseIdentifierMap().find(getLowercase(classname)); |
---|
| 128 | if (identifier != Identifier::getLowercaseIdentifierMapEnd()) |
---|
| 129 | { |
---|
| 130 | std::map<std::string, ConfigValueContainer*>::const_iterator variable = (*identifier).second->getLowercaseConfigValueMap().find(getLowercase(varname)); |
---|
| 131 | if (variable != (*identifier).second->getLowercaseConfigValueMapEnd()) |
---|
| 132 | { |
---|
| 133 | std::string valuestring = (*variable).second->toString(); |
---|
[1441] | 134 | oldvalue.push_back(ArgumentCompletionListElement(valuestring, getLowercase(valuestring), "Old value: " + valuestring)); |
---|
[1434] | 135 | } |
---|
| 136 | } |
---|
| 137 | return oldvalue; |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(tclthreads)() |
---|
| 141 | { |
---|
[1441] | 142 | std::list<unsigned int> threadnumbers = TclThreadManager::getInstance().getThreadList(); |
---|
| 143 | ArgumentCompletionList threads; |
---|
| 144 | |
---|
| 145 | for (std::list<unsigned int>::const_iterator it = threadnumbers.begin(); it != threadnumbers.end(); ++it) |
---|
| 146 | threads.push_back(ArgumentCompletionListElement(getConvertedValue<unsigned int, std::string>(*it))); |
---|
| 147 | |
---|
| 148 | return threads; |
---|
[1434] | 149 | } |
---|
[1390] | 150 | } |
---|
| 151 | } |
---|