Test: Add upstream tests
This commit is contained in:
		| @@ -11,3 +11,7 @@ add_files( | ||||
|     survey_osx.cpp | ||||
|     CONDITION APPLE | ||||
| ) | ||||
|  | ||||
| if(APPLE) | ||||
|     target_sources(openttd PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/osx_main.cpp) | ||||
| endif() | ||||
|   | ||||
							
								
								
									
										51
									
								
								src/os/macosx/osx_main.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								src/os/macosx/osx_main.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,51 @@ | ||||
| /* | ||||
|  * This file is part of OpenTTD. | ||||
|  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. | ||||
|  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||||
|  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| /** @file unix_main.cpp Main entry for Mac OSX. */ | ||||
|  | ||||
| #include "../../stdafx.h" | ||||
| #include "../../openttd.h" | ||||
| #include "../../crashlog.h" | ||||
| #include "../../core/random_func.hpp" | ||||
| #include "../../string_func.h" | ||||
| #include "../../thread.h" | ||||
|  | ||||
| #include <time.h> | ||||
| #include <signal.h> | ||||
|  | ||||
| #include "macos.h" | ||||
|  | ||||
| #include "../../safeguards.h" | ||||
|  | ||||
| void CocoaSetupAutoreleasePool(); | ||||
| void CocoaReleaseAutoreleasePool(); | ||||
|  | ||||
| int CDECL main(int argc, char *argv[]) | ||||
| { | ||||
| 	/* Make sure our arguments contain only valid UTF-8 characters. */ | ||||
| 	for (int i = 0; i < argc; i++) StrMakeValidInPlace(argv[i]); | ||||
|  | ||||
| 	CocoaSetupAutoreleasePool(); | ||||
| 	/* This is passed if we are launched by double-clicking */ | ||||
| 	if (argc >= 2 && strncmp(argv[1], "-psn", 4) == 0) { | ||||
| 		argv[1] = nullptr; | ||||
| 		argc = 1; | ||||
| 	} | ||||
|  | ||||
| 	PerThreadSetupInit(); | ||||
| 	CrashLog::InitialiseCrashLog(); | ||||
|  | ||||
| 	SetRandomSeed(time(nullptr)); | ||||
|  | ||||
| 	signal(SIGPIPE, SIG_IGN); | ||||
|  | ||||
| 	int ret = openttd_main(argc, argv); | ||||
|  | ||||
| 	CocoaReleaseAutoreleasePool(); | ||||
|  | ||||
| 	return ret; | ||||
| } | ||||
| @@ -13,3 +13,7 @@ add_files( | ||||
|     font_unix.cpp | ||||
|     CONDITION Fontconfig_FOUND | ||||
| ) | ||||
|  | ||||
| if(UNIX AND NOT APPLE) | ||||
|     target_sources(openttd PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/unix_main.cpp) | ||||
| endif() | ||||
|   | ||||
| @@ -52,11 +52,6 @@ | ||||
| #endif | ||||
|  | ||||
| #if defined(__APPLE__) | ||||
| #	if defined(WITH_SDL) | ||||
| 		/* the mac implementation needs this file included in the same file as main() */ | ||||
| #		include <SDL.h> | ||||
| #	endif | ||||
|  | ||||
| #	include "../macosx/macos.h" | ||||
| #endif | ||||
|  | ||||
| @@ -229,40 +224,6 @@ void NORETURN DoOSAbort() | ||||
| } | ||||
| #endif | ||||
|  | ||||
| #ifdef WITH_COCOA | ||||
| void CocoaSetupAutoreleasePool(); | ||||
| void CocoaReleaseAutoreleasePool(); | ||||
| #endif | ||||
|  | ||||
| int CDECL main(int argc, char *argv[]) | ||||
| { | ||||
| 	/* Make sure our arguments contain only valid UTF-8 characters. */ | ||||
| 	for (int i = 0; i < argc; i++) StrMakeValidInPlace(argv[i]); | ||||
|  | ||||
| #ifdef WITH_COCOA | ||||
| 	CocoaSetupAutoreleasePool(); | ||||
| 	/* This is passed if we are launched by double-clicking */ | ||||
| 	if (argc >= 2 && strncmp(argv[1], "-psn", 4) == 0) { | ||||
| 		argv[1] = nullptr; | ||||
| 		argc = 1; | ||||
| 	} | ||||
| #endif | ||||
| 	PerThreadSetupInit(); | ||||
| 	CrashLog::InitialiseCrashLog(); | ||||
|  | ||||
| 	SetRandomSeed(time(nullptr)); | ||||
|  | ||||
| 	signal(SIGPIPE, SIG_IGN); | ||||
|  | ||||
| 	int ret = openttd_main(argc, argv); | ||||
|  | ||||
| #ifdef WITH_COCOA | ||||
| 	CocoaReleaseAutoreleasePool(); | ||||
| #endif | ||||
|  | ||||
| 	return ret; | ||||
| } | ||||
|  | ||||
| #ifndef WITH_COCOA | ||||
| std::optional<std::string> GetClipboardContents() | ||||
| { | ||||
|   | ||||
							
								
								
									
										35
									
								
								src/os/unix/unix_main.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								src/os/unix/unix_main.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,35 @@ | ||||
| /* | ||||
|  * This file is part of OpenTTD. | ||||
|  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. | ||||
|  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||||
|  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| /** @file unix_main.cpp Main entry for Unix. */ | ||||
|  | ||||
| #include "../../stdafx.h" | ||||
| #include "../../openttd.h" | ||||
| #include "../../crashlog.h" | ||||
| #include "../../core/random_func.hpp" | ||||
| #include "../../string_func.h" | ||||
| #include "../../thread.h" | ||||
|  | ||||
| #include <time.h> | ||||
| #include <signal.h> | ||||
|  | ||||
| #include "../../safeguards.h" | ||||
|  | ||||
| int CDECL main(int argc, char *argv[]) | ||||
| { | ||||
| 	/* Make sure our arguments contain only valid UTF-8 characters. */ | ||||
| 	for (int i = 0; i < argc; i++) StrMakeValidInPlace(argv[i]); | ||||
|  | ||||
| 	PerThreadSetupInit(); | ||||
| 	CrashLog::InitialiseCrashLog(); | ||||
|  | ||||
| 	SetRandomSeed(time(nullptr)); | ||||
|  | ||||
| 	signal(SIGPIPE, SIG_IGN); | ||||
|  | ||||
| 	return openttd_main(argc, argv); | ||||
| } | ||||
| @@ -9,3 +9,7 @@ add_files( | ||||
|     win32.h | ||||
|     CONDITION WIN32 | ||||
| ) | ||||
|  | ||||
| if(WIN32) | ||||
|     target_sources(openttd PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/win32_main.cpp) | ||||
| endif() | ||||
|   | ||||
| @@ -270,37 +270,6 @@ std::optional<uint64_t> FiosGetDiskFreeSpace(const std::string &path) | ||||
| 	return std::nullopt; | ||||
| } | ||||
|  | ||||
| static int ParseCommandLine(char *line, char **argv, int max_argc) | ||||
| { | ||||
| 	int n = 0; | ||||
|  | ||||
| 	do { | ||||
| 		/* skip whitespace */ | ||||
| 		while (*line == ' ' || *line == '\t') line++; | ||||
|  | ||||
| 		/* end? */ | ||||
| 		if (*line == '\0') break; | ||||
|  | ||||
| 		/* special handling when quoted */ | ||||
| 		if (*line == '"') { | ||||
| 			argv[n++] = ++line; | ||||
| 			while (*line != '"') { | ||||
| 				if (*line == '\0') return n; | ||||
| 				line++; | ||||
| 			} | ||||
| 		} else { | ||||
| 			argv[n++] = line; | ||||
| 			while (*line != ' ' && *line != '\t') { | ||||
| 				if (*line == '\0') return n; | ||||
| 				line++; | ||||
| 			} | ||||
| 		} | ||||
| 		*line++ = '\0'; | ||||
| 	} while (n != max_argc); | ||||
|  | ||||
| 	return n; | ||||
| } | ||||
|  | ||||
| void CreateConsole() | ||||
| { | ||||
| 	HANDLE hand; | ||||
| @@ -419,45 +388,6 @@ void ShowInfo(const char *str) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) | ||||
| { | ||||
| 	int argc; | ||||
| 	char *argv[64]; // max 64 command line arguments | ||||
|  | ||||
| 	/* Set system timer resolution to 1ms. */ | ||||
| 	timeBeginPeriod(1); | ||||
|  | ||||
| 	PerThreadSetupInit(); | ||||
| 	CrashLog::InitialiseCrashLog(); | ||||
|  | ||||
| 	/* Convert the command line to UTF-8. */ | ||||
| 	std::string cmdline = FS2OTTD(GetCommandLine()); | ||||
|  | ||||
| 	/* Set the console codepage to UTF-8. */ | ||||
| 	SetConsoleOutputCP(CP_UTF8); | ||||
|  | ||||
| #if defined(_DEBUG) | ||||
| 	CreateConsole(); | ||||
| #endif | ||||
|  | ||||
| 	_set_error_mode(_OUT_TO_MSGBOX); // force assertion output to messagebox | ||||
|  | ||||
| 	/* setup random seed to something quite random */ | ||||
| 	SetRandomSeed(GetTickCount()); | ||||
|  | ||||
| 	argc = ParseCommandLine(cmdline.data(), argv, lengthof(argv)); | ||||
|  | ||||
| 	/* Make sure our arguments contain only valid UTF-8 characters. */ | ||||
| 	for (int i = 0; i < argc; i++) StrMakeValidInPlace(argv[i]); | ||||
|  | ||||
| 	openttd_main(argc, argv); | ||||
|  | ||||
| 	/* Restore system timer resolution. */ | ||||
| 	timeEndPeriod(1); | ||||
|  | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| char *getcwd(char *buf, size_t size) | ||||
| { | ||||
| 	wchar_t path[MAX_PATH]; | ||||
|   | ||||
							
								
								
									
										92
									
								
								src/os/windows/win32_main.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										92
									
								
								src/os/windows/win32_main.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,92 @@ | ||||
| /* | ||||
|  * This file is part of OpenTTD. | ||||
|  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. | ||||
|  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||||
|  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| /** @file win32_main.cpp Implementation main for Windows. */ | ||||
|  | ||||
| #include "../../stdafx.h" | ||||
| #include <windows.h> | ||||
| #include <mmsystem.h> | ||||
| #include "../../openttd.h" | ||||
| #include "../../core/random_func.hpp" | ||||
| #include "../../string_func.h" | ||||
| #include "../../crashlog.h" | ||||
| #include "../../debug.h" | ||||
| #include "../../thread.h" | ||||
|  | ||||
| #include "../../safeguards.h" | ||||
|  | ||||
| static int ParseCommandLine(char *line, char **argv, int max_argc) | ||||
| { | ||||
| 	int n = 0; | ||||
|  | ||||
| 	do { | ||||
| 		/* skip whitespace */ | ||||
| 		while (*line == ' ' || *line == '\t') line++; | ||||
|  | ||||
| 		/* end? */ | ||||
| 		if (*line == '\0') break; | ||||
|  | ||||
| 		/* special handling when quoted */ | ||||
| 		if (*line == '"') { | ||||
| 			argv[n++] = ++line; | ||||
| 			while (*line != '"') { | ||||
| 				if (*line == '\0') return n; | ||||
| 				line++; | ||||
| 			} | ||||
| 		} else { | ||||
| 			argv[n++] = line; | ||||
| 			while (*line != ' ' && *line != '\t') { | ||||
| 				if (*line == '\0') return n; | ||||
| 				line++; | ||||
| 			} | ||||
| 		} | ||||
| 		*line++ = '\0'; | ||||
| 	} while (n != max_argc); | ||||
|  | ||||
| 	return n; | ||||
| } | ||||
|  | ||||
| void CreateConsole(); | ||||
|  | ||||
| int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) | ||||
| { | ||||
| 	int argc; | ||||
| 	char *argv[64]; // max 64 command line arguments | ||||
|  | ||||
| 	/* Set system timer resolution to 1ms. */ | ||||
| 	timeBeginPeriod(1); | ||||
|  | ||||
| 	PerThreadSetupInit(); | ||||
| 	CrashLog::InitialiseCrashLog(); | ||||
|  | ||||
| 	/* Convert the command line to UTF-8. */ | ||||
| 	std::string cmdline = FS2OTTD(GetCommandLine()); | ||||
|  | ||||
| 	/* Set the console codepage to UTF-8. */ | ||||
| 	SetConsoleOutputCP(CP_UTF8); | ||||
|  | ||||
| #if defined(_DEBUG) | ||||
| 	CreateConsole(); | ||||
| #endif | ||||
|  | ||||
| 	_set_error_mode(_OUT_TO_MSGBOX); // force assertion output to messagebox | ||||
|  | ||||
| 	/* setup random seed to something quite random */ | ||||
| 	SetRandomSeed(GetTickCount()); | ||||
|  | ||||
| 	argc = ParseCommandLine(cmdline.data(), argv, lengthof(argv)); | ||||
|  | ||||
| 	/* Make sure our arguments contain only valid UTF-8 characters. */ | ||||
| 	for (int i = 0; i < argc; i++) StrMakeValidInPlace(argv[i]); | ||||
|  | ||||
| 	openttd_main(argc, argv); | ||||
|  | ||||
| 	/* Restore system timer resolution. */ | ||||
| 	timeEndPeriod(1); | ||||
|  | ||||
| 	return 0; | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Jonathan G Rennison
					Jonathan G Rennison