make it possible to override CXX from the command line
[rofl0r-df-libgraphics.git] / g_src / find_files_posix.cpp
blobbda787b5890f27a9f05e1b8aa1a0a62448f78634
1 #include "platform.h"
2 #include <cerrno>
3 #include <string>
4 #include <cstring>
5 #include <cmath>
6 #include <iostream>
7 #include <sstream>
8 #include <fstream>
9 #include <algorithm>
10 #include <map>
11 #include <set>
13 extern "C" {
14 #include <zlib.h>
15 #ifndef WIN32
16 # include <sys/types.h>
17 # include <sys/stat.h>
18 # include <sys/time.h>
19 # include <signal.h>
20 #endif
22 #include "svector.h"
23 #include "random.h"
25 using std::string;
27 #include "basics.h"
28 #include "endian.h"
29 #include "files.h"
30 #include "enabler.h"
31 #include "find_files.h"
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include <unistd.h>
36 #include <glob.h>
37 #include <string.h>
39 void find_files_by_pattern(const char* pattern, svector<char *>& filenames)
41 glob_t g;
42 if (!glob(pattern, 0, NULL, &g))
44 for (int i = 0; i < g.gl_pathc; ++i)
46 struct stat cstat;
47 stat(g.gl_pathv[i],&cstat);
48 if(!S_ISREG(cstat.st_mode))continue;
50 // don't include the path
51 char* src = strrchr(g.gl_pathv[i], '/');
52 if (src)
54 int len = strlen(++src);
55 char* c = new char[len + 1]; // caller will free this
56 strcpy(c, src);
57 filenames.push_back(c);
61 globfree(&g);
64 void find_files_by_pattern_with_exception(const char* pattern, svector<char *>& filenames,const char *exception)
66 glob_t g;
67 if (!glob(pattern, 0, NULL, &g))
69 for (int i = 0; i < g.gl_pathc; ++i)
71 struct stat cstat;
72 stat(g.gl_pathv[i],&cstat);
73 if(!S_ISREG(cstat.st_mode))continue;
75 // don't include the path
76 char* src = strrchr(g.gl_pathv[i], '/');
77 if (src)
79 int len = strlen(++src);
80 if(!strcmp(src,exception))continue;
82 char* c = new char[len + 1]; // caller will free this
83 strcpy(c, src);
84 filenames.push_back(c);
88 globfree(&g);
91 void find_files_by_pattern(const char* pattern, stringvectst& filenames)
93 glob_t g;
94 if (!glob(pattern, 0, NULL, &g))
96 for (int i = 0; i < g.gl_pathc; ++i)
98 struct stat cstat;
99 stat(g.gl_pathv[i],&cstat);
100 if(!S_ISREG(cstat.st_mode))continue;
102 // don't include the path
103 char* src = strrchr(g.gl_pathv[i], '/');
104 if (src)
106 ++src;
107 filenames.add_string(src);
111 globfree(&g);
114 void find_files_by_pattern_with_exception(const char* pattern, stringvectst& filenames,const char *exception)
116 glob_t g;
117 if (!glob(pattern, 0, NULL, &g))
119 for (int i = 0; i < g.gl_pathc; ++i)
121 struct stat cstat;
122 stat(g.gl_pathv[i],&cstat);
123 if(!S_ISREG(cstat.st_mode))continue;
125 // don't include the path
126 char* src = strrchr(g.gl_pathv[i], '/');
127 if (src)
129 ++src;
130 if(!strcmp(src,exception))continue;
132 filenames.add_string(src);
136 globfree(&g);
139 void find_directories_by_pattern(const char* pattern, stringvectst &filenames)
141 glob_t g;
142 if (!glob(pattern, 0, NULL, &g))
144 for (int i = 0; i < g.gl_pathc; ++i)
146 struct stat cstat;
147 stat(g.gl_pathv[i],&cstat);
148 if(!S_ISDIR(cstat.st_mode))continue;
150 // don't include the path
151 char* src = strrchr(g.gl_pathv[i], '/');
152 if (src)
154 ++src;
155 filenames.add_string(src);
159 globfree(&g);
162 void find_directories_by_pattern_with_exception(const char* pattern, stringvectst &filenames,const char *exception)
164 glob_t g;
165 if (!glob(pattern, 0, NULL, &g))
167 for (int i = 0; i < g.gl_pathc; ++i)
169 struct stat cstat;
170 stat(g.gl_pathv[i],&cstat);
171 if(!S_ISDIR(cstat.st_mode))continue;
173 // don't include the path
174 char* src = strrchr(g.gl_pathv[i], '/');
175 if (src)
177 ++src;
178 if(!strcmp(src,exception))continue;
180 filenames.add_string(src);
184 globfree(&g);