aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk
diff options
context:
space:
mode:
authorRyan Pavlik <rpavlik@iastate.edu>2011-10-31 15:29:42 (GMT)
committerRyan Pavlik <rpavlik@iastate.edu>2011-10-31 15:54:33 (GMT)
commitea5f7b56ecceaa638133f406a954d324f8e720c6 (patch)
tree7ce81ee1ffc937665bef7edeeca571b9a3b94e9c /src/FbTk
parent65cb53b68551fde7dafe97f08c90b69f972f93ef (diff)
downloadfluxbox-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.
Diffstat (limited to 'src/FbTk')
-rw-r--r--src/FbTk/StringUtil.cc65
1 files changed, 65 insertions, 0 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
61using std::string; 63using std::string;
62using std::transform; 64using 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
180static 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
188static 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*/
174string expandFilename(const string &filename) { 232string 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