diff options
author | Ryan Pavlik <rpavlik@iastate.edu> | 2011-10-31 15:29:42 (GMT) |
---|---|---|
committer | Ryan Pavlik <rpavlik@iastate.edu> | 2011-10-31 15:54:33 (GMT) |
commit | ea5f7b56ecceaa638133f406a954d324f8e720c6 (patch) | |
tree | 7ce81ee1ffc937665bef7edeeca571b9a3b94e9c | |
parent | 65cb53b68551fde7dafe97f08c90b69f972f93ef (diff) | |
download | fluxbox-ea5f7b56ecceaa638133f406a954d324f8e720c6.zip fluxbox-ea5f7b56ecceaa638133f406a954d324f8e720c6.tar.bz2 |
src/Makefile.am,FbTk/StringUtil.cc: Search relative to the executable.
On Windows, prepend /DUMMYPREFIX to default paths, and replace it at
runtime with the prefix relative to the exe directory.
-rw-r--r-- | src/FbTk/StringUtil.cc | 65 | ||||
-rw-r--r-- | src/Makefile.am | 20 |
2 files changed, 78 insertions, 7 deletions
diff --git a/src/FbTk/StringUtil.cc b/src/FbTk/StringUtil.cc index ad9739e..2cc47fd 100644 --- a/src/FbTk/StringUtil.cc +++ b/src/FbTk/StringUtil.cc | |||
@@ -21,6 +21,7 @@ | |||
21 | 21 | ||
22 | #include "StringUtil.hh" | 22 | #include "StringUtil.hh" |
23 | 23 | ||
24 | #include "../defaults.hh" | ||
24 | 25 | ||
25 | #ifdef HAVE_CSTDIO | 26 | #ifdef HAVE_CSTDIO |
26 | #include <cstdio> | 27 | #include <cstdio> |
@@ -57,6 +58,7 @@ | |||
57 | #include <memory> | 58 | #include <memory> |
58 | #include <algorithm> | 59 | #include <algorithm> |
59 | #include <string> | 60 | #include <string> |
61 | #include <iostream> | ||
60 | 62 | ||
61 | using std::string; | 63 | using std::string; |
62 | using std::transform; | 64 | using std::transform; |
@@ -167,8 +169,64 @@ const char *strcasestr(const char *str, const char *ptn) { | |||
167 | return 0; | 169 | return 0; |
168 | } | 170 | } |
169 | 171 | ||
172 | |||
173 | #ifdef _WIN32 | ||
174 | |||
175 | #include <string> | ||
176 | #define WIN32_LEAN_AND_MEAN 1 | ||
177 | #define NOMINMAX | ||
178 | #include <windows.h> | ||
179 | |||
180 | static void removeTrailingPathSeparators(std::string & path) { | ||
181 | // Remove any trailing path separators | ||
182 | size_t beforeLastPathSep = path.find_last_not_of("/\\"); | ||
183 | if (beforeLastPathSep != path.size() - 1) { | ||
184 | path.erase(beforeLastPathSep + 1); | ||
185 | } | ||
186 | } | ||
187 | |||
188 | static std::string getFluxboxPrefix() { | ||
189 | static std::string ret; | ||
190 | static bool init = false; | ||
191 | if (!init) { | ||
192 | char buffer[1024]; | ||
193 | HMODULE module = GetModuleHandle(NULL); | ||
194 | DWORD size = GetModuleFileName(module, buffer, sizeof(buffer)); | ||
195 | if (sizeof(buffer) > 0) | ||
196 | { | ||
197 | buffer[sizeof(buffer) - 1] = 0; | ||
198 | } | ||
199 | static const char slash = '/'; | ||
200 | static const char backslash = '\\'; | ||
201 | char * lastslash = std::find_end(buffer, buffer+size, &slash, &slash + 1); | ||
202 | char * lastbackslash = std::find_end(buffer, buffer+size, &backslash, &backslash + 1); | ||
203 | ret.assign(buffer); | ||
204 | |||
205 | // Remove the filename | ||
206 | size_t lastPathSep = ret.find_last_of("/\\"); | ||
207 | if (lastPathSep != std::string::npos) { | ||
208 | ret.erase(lastPathSep); | ||
209 | } | ||
210 | |||
211 | removeTrailingPathSeparators(ret); | ||
212 | |||
213 | // If the last directory is bin, remove that too. | ||
214 | lastPathSep = ret.find_last_of("/\\"); | ||
215 | if (lastPathSep != std::string::npos && ret.substr(lastPathSep + 1) == "bin") { | ||
216 | ret.erase(lastPathSep); | ||
217 | } | ||
218 | |||
219 | removeTrailingPathSeparators(ret); | ||
220 | } | ||
221 | return ret; | ||
222 | } | ||
223 | |||
224 | #endif // _WIN32 | ||
225 | |||
170 | /** | 226 | /** |
171 | if ~ then expand it to home of user | 227 | if ~ then expand it to home of user |
228 | if /DUMMYPREFIX on Windows then expand it to the prefix relative to the | ||
229 | executable on Windows. | ||
172 | returns expanded filename | 230 | returns expanded filename |
173 | */ | 231 | */ |
174 | string expandFilename(const string &filename) { | 232 | string expandFilename(const string &filename) { |
@@ -188,6 +246,13 @@ string expandFilename(const string &filename) { | |||
188 | retval = filename; //return unmodified value | 246 | retval = filename; //return unmodified value |
189 | } | 247 | } |
190 | 248 | ||
249 | #if defined(_WIN32) && defined(DUMMYPREFIX) | ||
250 | if (retval.find(DUMMYPREFIX) == 0) { | ||
251 | static const std::string dummyPrefix = DUMMYPREFIX; | ||
252 | retval.replace(0, dummyPrefix.size(), getFluxboxPrefix()); | ||
253 | } | ||
254 | #endif | ||
255 | |||
191 | return retval; | 256 | return retval; |
192 | } | 257 | } |
193 | 258 | ||
diff --git a/src/Makefile.am b/src/Makefile.am index 1a04e4e..9a84897 100644 --- a/src/Makefile.am +++ b/src/Makefile.am | |||
@@ -48,13 +48,19 @@ defaults.hh: Makefile | |||
48 | echo '// This file is generated from Makefile. Do not edit!'; \ | 48 | echo '// This file is generated from Makefile. Do not edit!'; \ |
49 | echo '#include <string>'; \ | 49 | echo '#include <string>'; \ |
50 | echo ''; \ | 50 | echo ''; \ |
51 | echo '#define DEFAULTMENU "$(DEFAULT_MENU)"'; \ | 51 | echo '#ifdef _WIN32'; \ |
52 | echo '#define DEFAULTSTYLE "$(DEFAULT_STYLE)"'; \ | 52 | echo '#define DUMMYPREFIX "/DUMMYPREFIX"'; \ |
53 | echo '#define DEFAULTKEYSFILE "$(DEFAULT_KEYSFILE)"'; \ | 53 | echo '#define PATHPREFIX DUMMYPREFIX'; \ |
54 | echo '#define DEFAULT_APPSFILE "$(DEFAULT_APPSFILE)"'; \ | 54 | echo '#else'; \ |
55 | echo '#define DEFAULT_OVERLAY "$(DEFAULT_OVERLAY)"'; \ | 55 | echo '#define PATHPREFIX'; \ |
56 | echo '#define DEFAULT_INITFILE "$(DEFAULT_INITFILE)"'; \ | 56 | echo '#endif'; \ |
57 | echo '#define DEFAULT_WINDOWMENU "$(DEFAULT_WINDOWMENU)"'; \ | 57 | echo '#define DEFAULTMENU PATHPREFIX "$(DEFAULT_MENU)"'; \ |
58 | echo '#define DEFAULTSTYLE PATHPREFIX "$(DEFAULT_STYLE)"'; \ | ||
59 | echo '#define DEFAULTKEYSFILE PATHPREFIX "$(DEFAULT_KEYSFILE)"'; \ | ||
60 | echo '#define DEFAULT_APPSFILE PATHPREFIX "$(DEFAULT_APPSFILE)"'; \ | ||
61 | echo '#define DEFAULT_OVERLAY PATHPREFIX "$(DEFAULT_OVERLAY)"'; \ | ||
62 | echo '#define DEFAULT_INITFILE PATHPREFIX "$(DEFAULT_INITFILE)"'; \ | ||
63 | echo '#define DEFAULT_WINDOWMENU PATHPREFIX "$(DEFAULT_WINDOWMENU)"'; \ | ||
58 | echo '#define PROGRAM_PREFIX "$(PROGRAM_PREFIX:NONE=)"'; \ | 64 | echo '#define PROGRAM_PREFIX "$(PROGRAM_PREFIX:NONE=)"'; \ |
59 | echo '#define PROGRAM_SUFFIX "$(PROGRAM_SUFFIX:NONE=)"'; \ | 65 | echo '#define PROGRAM_SUFFIX "$(PROGRAM_SUFFIX:NONE=)"'; \ |
60 | echo 'std::string realProgramName(const std::string& name);'; \ | 66 | echo 'std::string realProgramName(const std::string& name);'; \ |