1// LAF OS Library
2// Copyright (C) 2021 Igara Studio S.A.
3// Copyright (C) 2012-2018 David Capello
4//
5// This file is released under the terms of the MIT license.
6// Read LICENSE.txt for more information.
7
8#ifdef HAVE_CONFIG_H
9#include "config.h"
10#endif
11
12#include "base/memory.h"
13#include "base/string.h"
14
15#if LAF_WINDOWS
16 #include <windows.h>
17#elif LAF_MACOS
18 #include "os/osx/app.h"
19#elif LAF_LINUX
20 #include "os/x11/x11.h"
21#endif
22
23extern int app_main(int argc, char* argv[]);
24
25#if LAF_WINDOWS
26int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
27 PWSTR lpCmdLine, int nCmdShow) {
28 int argc = __argc;
29 char** argv;
30 if (__wargv && argc > 0) {
31 argv = new char*[argc];
32 for (int i=0; i<argc; ++i)
33 argv[i] = base_strdup(base::to_utf8(std::wstring(__wargv[i])).c_str());
34 }
35 else {
36 argv = new char*[1];
37 argv[0] = base_strdup("");
38 argc = 1;
39 }
40 return app_main(argc, argv);
41}
42
43int wmain(int argc, wchar_t* wargv[], wchar_t* envp[]) {
44 char** argv;
45 if (wargv && argc > 0) {
46 argv = new char*[argc];
47 for (int i=0; i<argc; ++i)
48 argv[i] = base_strdup(base::to_utf8(std::wstring(wargv[i])).c_str());
49 }
50 else {
51 argv = new char*[1];
52 argv[0] = base_strdup("");
53 argc = 1;
54 }
55 return app_main(argc, argv);
56}
57#endif
58
59int main(int argc, char* argv[]) {
60#if LAF_MACOS
61 os::AppOSX app;
62 if (!app.init())
63 return 1;
64#elif LAF_LINUX
65 os::X11 x11;
66#endif
67 return app_main(argc, argv);
68}
69