Codechange: move main function(s) to separate files

This commit is contained in:
Rubidium
2023-04-10 17:33:18 +02:00
committed by rubidium42
parent 7b0797d1cd
commit 9e89eb5726
11 changed files with 209 additions and 128 deletions

View File

@@ -1,5 +1,6 @@
add_files(
crashlog_unix.cpp
unix_main.cpp
CONDITION UNIX AND NOT APPLE AND NOT OPTION_OS2
)

View File

@@ -9,9 +9,6 @@
#include "../../stdafx.h"
#include "../../textbuf_gui.h"
#include "../../openttd.h"
#include "../../crashlog.h"
#include "../../core/random_func.hpp"
#include "../../debug.h"
#include "../../string_func.h"
#include "../../fios.h"
@@ -55,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
@@ -235,39 +227,6 @@ void ShowOSErrorBox(const char *buf, bool system)
}
#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
bool GetClipboardContents(char *buffer, const char *last)
{

33
src/os/unix/unix_main.cpp Normal file
View File

@@ -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);
}