OpenTTD Source: src/os/windows/win32_main.cpp Source File

OpenTTD Source 14.0-beta3

win32_main.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
7
10 #include "../../stdafx.h"
11 #include <windows.h>
12 #include <mmsystem.h>
13 #include "../../openttd.h"
14 #include "../../core/random_func.hpp"
15 #include "../../string_func.h"
16 #include "../../crashlog.h"
17 #include "../../debug.h"
18
19 #include "../../safeguards.h"
20
21 static int ParseCommandLine(char *line, char **argv, int max_argc)
22 {
23 int n = 0;
24
25 do {
26 /* skip whitespace */
27 while (*line == ' ' || *line == '\t') line++;
28
29 /* end? */
30 if (*line == '\0') break;
31
32 /* special handling when quoted */
33 if (*line == '"') {
34 argv[n++] = ++line;
35 while (*line != '"') {
36 if (*line == '\0') return n;
37 line++;
38 }
39 } else {
40 argv[n++] = line;
41 while (*line != ' ' && *line != '\t') {
42 if (*line == '\0') return n;
43 line++;
44 }
45 }
46 *line++ = '\0';
47 } while (n != max_argc);
48
49 return n;
50 }
51
52 void CreateConsole();
53
54 int APIENTRY WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
55 {
56 /* Set system timer resolution to 1ms. */
57 timeBeginPeriod(1);
58
59 CrashLog::InitialiseCrashLog();
60
61 /* Convert the command line to UTF-8. */
62 std::string cmdline = FS2OTTD(GetCommandLine());
63
64 /* Set the console codepage to UTF-8. */
65 SetConsoleOutputCP(CP_UTF8);
66
67 #if defined(_DEBUG)
68 CreateConsole();
69 #endif
70
71 _set_error_mode(_OUT_TO_MSGBOX); // force assertion output to messagebox
72
73 /* setup random seed to something quite random */
74 SetRandomSeed(GetTickCount());
75
76 char *argv[64]; // max 64 command line arguments
77 int argc = ParseCommandLine(cmdline.data(), argv, lengthof(argv));
78
79 /* Make sure our arguments contain only valid UTF-8 characters. */
80 for (int i = 0; i < argc; i++) StrMakeValidInPlace(argv[i]);
81
82 int ret = openttd_main(argc, argv);
83
84 /* Restore system timer resolution. */
85 timeEndPeriod(1);
86
87 return ret;
88 }
openttd_main
int openttd_main(int argc, char *argv[])
Main entry point for this lovely game.
Definition: openttd.cpp:518
FS2OTTD
std::string FS2OTTD(const std::wstring &name)
Convert to OpenTTD's encoding from a wide string.
Definition: win32.cpp:462
StrMakeValidInPlace
void StrMakeValidInPlace(char *str, const char *last, StringValidationSettings settings)
Scans the string for invalid characters and replaces then with a question mark '?' (if not ignored).
Definition: string.cpp:185
SetRandomSeed
void SetRandomSeed(uint32_t seed)
(Re)set the state of the random number generators.
Definition: random_func.cpp:77
CrashLog::InitialiseCrashLog
static void InitialiseCrashLog()
Initialiser for crash logs; do the appropriate things so crashes are handled by our crash handler ins...
Definition: crashlog_osx.cpp:233
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:300