- Timestamp:
- May 27, 2008, 3:01:49 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/console/src/core/ArgumentCompletionFunctions.cc
r1434 r1436 30 30 #include <map> 31 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 32 39 #include "ArgumentCompletionFunctions.h" 33 40 #include "CoreIncludes.h" … … 36 43 #include "TclThreadManager.h" 37 44 #include "util/String.h" 45 #include "util/SubString.h" 38 46 39 47 namespace orxonox … … 44 52 { 45 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 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; 46 103 } 47 104 … … 57 114 } 58 115 59 ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(configvalues)(const std::string& classname)116 ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(configvalues)(const std::string& fragment, const std::string& classname) 60 117 { 61 118 std::list<std::pair<std::string, std::string> > configvalues; … … 71 128 } 72 129 73 ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(configvalue)(const std::string& varname, const std::string& classname)130 ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(configvalue)(const std::string& fragment, const std::string& varname, const std::string& classname) 74 131 { 75 132 std::list<std::pair<std::string, std::string> > oldvalue;
Note: See TracChangeset
for help on using the changeset viewer.