| [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 <stdio.h> |
|---|
| 33 | //#include <stdlib.h> |
|---|
| 34 | //#include <errno.h> |
|---|
| 35 | //#include <sys/types.h> |
|---|
| 36 | //#include <sys/stat.h> |
|---|
| 37 | #include <dirent.h> |
|---|
| 38 | |
|---|
| [1390] | 39 | #include "ArgumentCompletionFunctions.h" |
|---|
| [1434] | 40 | #include "CoreIncludes.h" |
|---|
| 41 | #include "Identifier.h" |
|---|
| 42 | #include "ConfigValueContainer.h" |
|---|
| 43 | #include "TclThreadManager.h" |
|---|
| 44 | #include "util/String.h" |
|---|
| [1436] | 45 | #include "util/SubString.h" |
|---|
| [1390] | 46 | |
|---|
| 47 | namespace orxonox |
|---|
| 48 | { |
|---|
| 49 | namespace autocompletion |
|---|
| 50 | { |
|---|
| [1430] | 51 | ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(fallback)() |
|---|
| [1390] | 52 | { |
|---|
| [1430] | 53 | return std::list<std::pair<std::string, std::string> >(); |
|---|
| [1390] | 54 | } |
|---|
| [1434] | 55 | |
|---|
| [1436] | 56 | ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(files)(const std::string& fragment) |
|---|
| 57 | { |
|---|
| 58 | std::list<std::pair<std::string, std::string> > dirlist; |
|---|
| 59 | std::list<std::pair<std::string, std::string> > filelist; |
|---|
| 60 | |
|---|
| 61 | SubString tokens(fragment, "/", "", false, '\0', false, '\0', false, '\0', '\0', false, '\0'); |
|---|
| 62 | |
|---|
| 63 | std::string startdirectory = "."; |
|---|
| 64 | if (fragment.size() > 0 && fragment[fragment.size() - 1] == '/' && tokens.size() > 0) |
|---|
| 65 | startdirectory = tokens.subSet(0, tokens.size()).join("/"); |
|---|
| 66 | else if (tokens.size() > 1) |
|---|
| 67 | startdirectory = tokens.subSet(0, tokens.size() - 1).join("/"); |
|---|
| 68 | |
|---|
| 69 | std::cout << "startdir: " << startdirectory << std::endl; |
|---|
| 70 | |
|---|
| 71 | struct stat fileInfo; |
|---|
| 72 | struct dirent *currentFile; |
|---|
| 73 | DIR *handler = 0; |
|---|
| 74 | |
|---|
| 75 | handler = opendir(startdirectory.c_str()); |
|---|
| 76 | if (handler) |
|---|
| 77 | { |
|---|
| 78 | while ((currentFile = readdir(handler)) != 0) |
|---|
| 79 | { |
|---|
| 80 | if (strcmp(currentFile->d_name, ".") && strcmp(currentFile->d_name, "..")) |
|---|
| 81 | { |
|---|
| 82 | std::string path = startdirectory + "/" + currentFile->d_name; |
|---|
| 83 | if (stat(path.c_str(), &fileInfo) == -1) |
|---|
| 84 | { |
|---|
| 85 | closedir(handler); |
|---|
| 86 | break; |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | if (S_ISREG(fileInfo.st_mode)) // normal file |
|---|
| 90 | filelist.push_back(std::pair<std::string, std::string>(getLowercase(path), path)); |
|---|
| 91 | else if (S_ISDIR(fileInfo.st_mode)) // directory |
|---|
| 92 | dirlist.push_back(std::pair<std::string, std::string>(getLowercase(path) + "/", path + "/")); |
|---|
| 93 | else // special file |
|---|
| 94 | filelist.push_back(std::pair<std::string, std::string>(getLowercase(path), path)); |
|---|
| 95 | } |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | closedir(handler); |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | filelist.insert(filelist.begin(), dirlist.begin(), dirlist.end()); |
|---|
| 102 | return filelist; |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| [1434] | 105 | ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(configvalueclasses)() |
|---|
| 106 | { |
|---|
| 107 | std::list<std::pair<std::string, std::string> > classlist; |
|---|
| 108 | |
|---|
| 109 | for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getIdentifierMapBegin(); it != Identifier::getIdentifierMapEnd(); ++it) |
|---|
| 110 | if ((*it).second->hasConfigValues()) |
|---|
| 111 | classlist.push_back(std::pair<std::string, std::string>(getLowercase((*it).first), (*it).second->getName())); |
|---|
| 112 | |
|---|
| 113 | return classlist; |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| [1436] | 116 | ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(configvalues)(const std::string& fragment, const std::string& classname) |
|---|
| [1434] | 117 | { |
|---|
| 118 | std::list<std::pair<std::string, std::string> > configvalues; |
|---|
| 119 | std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getIdentifierMap().find(classname); |
|---|
| 120 | |
|---|
| 121 | if (identifier != Identifier::getIdentifierMapEnd() && (*identifier).second->hasConfigValues()) |
|---|
| 122 | { |
|---|
| 123 | for (std::map<std::string, ConfigValueContainer*>::const_iterator it = (*identifier).second->getConfigValueMapBegin(); it != (*identifier).second->getConfigValueMapEnd(); ++it) |
|---|
| 124 | configvalues.push_back(std::pair<std::string, std::string>(getLowercase((*it).first), (*it).second->getName())); |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | return configvalues; |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| [1436] | 130 | ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(configvalue)(const std::string& fragment, const std::string& varname, const std::string& classname) |
|---|
| [1434] | 131 | { |
|---|
| 132 | std::list<std::pair<std::string, std::string> > oldvalue; |
|---|
| 133 | std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseIdentifierMap().find(getLowercase(classname)); |
|---|
| 134 | if (identifier != Identifier::getLowercaseIdentifierMapEnd()) |
|---|
| 135 | { |
|---|
| 136 | std::map<std::string, ConfigValueContainer*>::const_iterator variable = (*identifier).second->getLowercaseConfigValueMap().find(getLowercase(varname)); |
|---|
| 137 | if (variable != (*identifier).second->getLowercaseConfigValueMapEnd()) |
|---|
| 138 | { |
|---|
| 139 | std::string valuestring = (*variable).second->toString(); |
|---|
| 140 | oldvalue.push_back(std::pair<std::string, std::string>(valuestring, valuestring)); |
|---|
| 141 | } |
|---|
| 142 | } |
|---|
| 143 | return oldvalue; |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(tclthreads)() |
|---|
| 147 | { |
|---|
| 148 | return TclThreadManager::getInstance().getThreadList(); |
|---|
| 149 | } |
|---|
| [1390] | 150 | } |
|---|
| 151 | } |
|---|