mirror of https://github.com/OpenTTD/OpenTTD
Codechange: move main function(s) to separate files
parent
7b0797d1cd
commit
9e89eb5726
|
@ -4,6 +4,7 @@ add_files(
|
||||||
font_osx.h
|
font_osx.h
|
||||||
macos.h
|
macos.h
|
||||||
macos.mm
|
macos.mm
|
||||||
|
osx_main.cpp
|
||||||
osx_stdafx.h
|
osx_stdafx.h
|
||||||
string_osx.cpp
|
string_osx.cpp
|
||||||
string_osx.h
|
string_osx.h
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
/*
|
||||||
|
* 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 <time.h>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
|
#if defined(WITH_SDL)
|
||||||
|
/* the mac implementation needs this file included in the same file as main() */
|
||||||
|
# include <SDL.h>
|
||||||
|
#endif
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
|
||||||
|
CrashLog::InitialiseCrashLog();
|
||||||
|
|
||||||
|
SetRandomSeed(time(nullptr));
|
||||||
|
|
||||||
|
signal(SIGPIPE, SIG_IGN);
|
||||||
|
|
||||||
|
int ret = openttd_main(argc, argv);
|
||||||
|
|
||||||
|
CocoaReleaseAutoreleasePool();
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
add_files(
|
add_files(
|
||||||
os2.cpp
|
os2.cpp
|
||||||
|
os2_main.cpp
|
||||||
CONDITION OPTION_OS2
|
CONDITION OPTION_OS2
|
||||||
)
|
)
|
||||||
|
|
|
@ -12,8 +12,6 @@
|
||||||
#include "../../gui.h"
|
#include "../../gui.h"
|
||||||
#include "../../fileio_func.h"
|
#include "../../fileio_func.h"
|
||||||
#include "../../fios.h"
|
#include "../../fios.h"
|
||||||
#include "../../openttd.h"
|
|
||||||
#include "../../core/random_func.hpp"
|
|
||||||
#include "../../string_func.h"
|
#include "../../string_func.h"
|
||||||
#include "../../textbuf_gui.h"
|
#include "../../textbuf_gui.h"
|
||||||
#include "../../thread.h"
|
#include "../../thread.h"
|
||||||
|
@ -169,16 +167,6 @@ void ShowOSErrorBox(const char *buf, bool system)
|
||||||
WinTerminate(hab);
|
WinTerminate(hab);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CDECL main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
SetRandomSeed(time(nullptr));
|
|
||||||
|
|
||||||
/* Make sure our arguments contain only valid UTF-8 characters. */
|
|
||||||
for (int i = 0; i < argc; i++) StrMakeValidInPlace(argv[i]);
|
|
||||||
|
|
||||||
return openttd_main(argc, argv);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GetClipboardContents(char *buffer, const char *last)
|
bool GetClipboardContents(char *buffer, const char *last)
|
||||||
{
|
{
|
||||||
/* XXX -- Currently no clipboard support implemented with GCC */
|
/* XXX -- Currently no clipboard support implemented with GCC */
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
/*
|
||||||
|
* 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 os2_main.cpp Main entry for OS/2. */
|
||||||
|
|
||||||
|
#include "../../stdafx.h"
|
||||||
|
#include "../../openttd.h"
|
||||||
|
#include "../../core/random_func.hpp"
|
||||||
|
#include "../../string_func.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "../../safeguards.h"
|
||||||
|
|
||||||
|
int CDECL main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
SetRandomSeed(time(nullptr));
|
||||||
|
|
||||||
|
/* Make sure our arguments contain only valid UTF-8 characters. */
|
||||||
|
for (int i = 0; i < argc; i++) StrMakeValidInPlace(argv[i]);
|
||||||
|
|
||||||
|
return openttd_main(argc, argv);
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
add_files(
|
add_files(
|
||||||
crashlog_unix.cpp
|
crashlog_unix.cpp
|
||||||
|
unix_main.cpp
|
||||||
CONDITION UNIX AND NOT APPLE AND NOT OPTION_OS2
|
CONDITION UNIX AND NOT APPLE AND NOT OPTION_OS2
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -9,9 +9,6 @@
|
||||||
|
|
||||||
#include "../../stdafx.h"
|
#include "../../stdafx.h"
|
||||||
#include "../../textbuf_gui.h"
|
#include "../../textbuf_gui.h"
|
||||||
#include "../../openttd.h"
|
|
||||||
#include "../../crashlog.h"
|
|
||||||
#include "../../core/random_func.hpp"
|
|
||||||
#include "../../debug.h"
|
#include "../../debug.h"
|
||||||
#include "../../string_func.h"
|
#include "../../string_func.h"
|
||||||
#include "../../fios.h"
|
#include "../../fios.h"
|
||||||
|
@ -55,11 +52,6 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__APPLE__)
|
#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"
|
# include "../macosx/macos.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -235,39 +227,6 @@ void ShowOSErrorBox(const char *buf, bool system)
|
||||||
}
|
}
|
||||||
#endif
|
#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
|
|
||||||
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
|
#ifndef WITH_COCOA
|
||||||
bool GetClipboardContents(char *buffer, const char *last)
|
bool GetClipboardContents(char *buffer, const char *last)
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
/*
|
||||||
|
* 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 <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]);
|
||||||
|
|
||||||
|
CrashLog::InitialiseCrashLog();
|
||||||
|
|
||||||
|
SetRandomSeed(time(nullptr));
|
||||||
|
|
||||||
|
signal(SIGPIPE, SIG_IGN);
|
||||||
|
|
||||||
|
return openttd_main(argc, argv);
|
||||||
|
}
|
|
@ -6,5 +6,6 @@ add_files(
|
||||||
string_uniscribe.h
|
string_uniscribe.h
|
||||||
win32.cpp
|
win32.cpp
|
||||||
win32.h
|
win32.h
|
||||||
|
win32_main.cpp
|
||||||
CONDITION WIN32
|
CONDITION WIN32
|
||||||
)
|
)
|
||||||
|
|
|
@ -22,10 +22,7 @@
|
||||||
#include "win32.h"
|
#include "win32.h"
|
||||||
#include "../../fios.h"
|
#include "../../fios.h"
|
||||||
#include "../../core/alloc_func.hpp"
|
#include "../../core/alloc_func.hpp"
|
||||||
#include "../../openttd.h"
|
|
||||||
#include "../../core/random_func.hpp"
|
|
||||||
#include "../../string_func.h"
|
#include "../../string_func.h"
|
||||||
#include "../../crashlog.h"
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include "../../language.h"
|
#include "../../language.h"
|
||||||
|
@ -229,37 +226,6 @@ bool FiosGetDiskFreeSpace(const char *path, uint64 *tot)
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
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()
|
void CreateConsole()
|
||||||
{
|
{
|
||||||
HANDLE hand;
|
HANDLE hand;
|
||||||
|
@ -378,47 +344,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);
|
|
||||||
|
|
||||||
CrashLog::InitialiseCrashLog();
|
|
||||||
|
|
||||||
/* Convert the command line to UTF-8. We need a dedicated buffer
|
|
||||||
* for this because argv[] points into this buffer and this needs to
|
|
||||||
* be available between subsequent calls to FS2OTTD(). */
|
|
||||||
char *cmdline = stredup(FS2OTTD(GetCommandLine()).c_str());
|
|
||||||
|
|
||||||
/* 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, 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);
|
|
||||||
|
|
||||||
free(cmdline);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *getcwd(char *buf, size_t size)
|
char *getcwd(char *buf, size_t size)
|
||||||
{
|
{
|
||||||
wchar_t path[MAX_PATH];
|
wchar_t path[MAX_PATH];
|
||||||
|
|
|
@ -0,0 +1,91 @@
|
||||||
|
/*
|
||||||
|
* 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 "../../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)
|
||||||
|
{
|
||||||
|
/* Set system timer resolution to 1ms. */
|
||||||
|
timeBeginPeriod(1);
|
||||||
|
|
||||||
|
CrashLog::InitialiseCrashLog();
|
||||||
|
|
||||||
|
/* Convert the command line to UTF-8. We need a dedicated buffer
|
||||||
|
* for this because argv[] points into this buffer and this needs to
|
||||||
|
* be available between subsequent calls to FS2OTTD(). */
|
||||||
|
char *cmdline = stredup(FS2OTTD(GetCommandLine()).c_str());
|
||||||
|
|
||||||
|
/* 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());
|
||||||
|
|
||||||
|
char *argv[64]; // max 64 command line arguments
|
||||||
|
int argc = ParseCommandLine(cmdline, argv, lengthof(argv));
|
||||||
|
|
||||||
|
/* Make sure our arguments contain only valid UTF-8 characters. */
|
||||||
|
for (int i = 0; i < argc; i++) StrMakeValidInPlace(argv[i]);
|
||||||
|
|
||||||
|
int ret = openttd_main(argc, argv);
|
||||||
|
|
||||||
|
/* Restore system timer resolution. */
|
||||||
|
timeEndPeriod(1);
|
||||||
|
|
||||||
|
free(cmdline);
|
||||||
|
return ret;
|
||||||
|
}
|
Loading…
Reference in New Issue