3 Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 Random portability stuff
23 See comments in porting.h
34 Signal handler (grabs Ctrl-C on POSIX systems)
37 bool g_killed = false;
39 bool * signal_handler_killstatus(void)
44 #if !defined(_WIN32) // POSIX
47 void sigint_handler(int sig)
51 dstream<<DTIME<<"INFO: sigint_handler(): "
52 <<"Ctrl-C pressed, shutting down."<<std::endl;
54 dstream<<DTIME<<"INFO: sigint_handler(): "
55 <<"Printing debug stacks"<<std::endl;
62 (void)signal(SIGINT, SIG_DFL);
66 void signal_handler_init(void)
68 dstream<<"signal_handler_init()"<<std::endl;
69 (void)signal(SIGINT, sigint_handler);
74 void signal_handler_init(void)
85 std::string path_data = "../data";
86 std::string path_userdata = "../";
88 void pathRemoveFile(char *path, char delim)
90 // Remove filename and path delimiter
92 for(i = strlen(path)-1; i>=0; i--)
100 void initializePaths()
104 Use relative paths if RUN_IN_PLACE
107 dstream<<"Using relative paths (RUN_IN_PLACE)"<<std::endl;
115 const DWORD buflen = 1000;
119 // Find path of executable and set path_data relative to it
120 len = GetModuleFileName(GetModuleHandle(NULL), buf, buflen);
121 assert(len < buflen);
122 pathRemoveFile(buf, '\\');
124 // Use "./bin/../data"
125 path_data = std::string(buf) + "/../data";
128 path_userdata = std::string(buf) + "/../";
137 memset(buf, 0, BUFSIZ);
138 // Get path to executable
139 assert(readlink("/proc/self/exe", buf, BUFSIZ-1) != -1);
141 pathRemoveFile(buf, '/');
143 // Use "./bin/../data"
144 path_data = std::string(buf) + "/../data";
147 path_userdata = std::string(buf) + "/../";
152 #elif defined(__APPLE__)
154 //TODO: Get path of executable. This assumes working directory is bin/
155 dstream<<"WARNING: Relative path not properly supported on OS X"
157 path_data = std::string("../data");
158 path_userdata = std::string("../");
162 #else // RUN_IN_PLACE
165 Use platform-specific paths otherwise
168 dstream<<"Using system-wide paths (NOT RUN_IN_PLACE)"<<std::endl;
176 const DWORD buflen = 1000;
180 // Find path of executable and set path_data relative to it
181 len = GetModuleFileName(GetModuleHandle(NULL), buf, buflen);
182 assert(len < buflen);
183 pathRemoveFile(buf, '\\');
185 // Use "./bin/../data"
186 path_data = std::string(buf) + "/../data";
187 //path_data = std::string(buf) + "/../share/" + APPNAME;
189 // Use "C:\Documents and Settings\user\Application Data\<APPNAME>"
190 len = GetEnvironmentVariable("APPDATA", buf, buflen);
191 assert(len < buflen);
192 path_userdata = std::string(buf) + "/" + APPNAME;
201 memset(buf, 0, BUFSIZ);
202 // Get path to executable
203 assert(readlink("/proc/self/exe", buf, BUFSIZ-1) != -1);
205 pathRemoveFile(buf, '/');
207 path_data = std::string(buf) + "/../share/" + APPNAME;
208 //path_data = std::string(INSTALL_PREFIX) + "/share/" + APPNAME;
210 path_userdata = std::string(getenv("HOME")) + "/." + APPNAME;
215 #elif defined(__APPLE__)
218 path_userdata = std::string(getenv("HOME")) + "/Library/Application Support/" + APPNAME;
219 path_data = std::string("minetest-mac.app/Contents/Resources/data/");
223 #endif // RUN_IN_PLACE
225 dstream<<"path_data = "<<path_data<<std::endl;
226 dstream<<"path_userdata = "<<path_userdata<<std::endl;
229 } //namespace porting