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