GCC Code Coverage Report


Directory: src/gate/
File: src/gate/gatemain.h
Date: 2026-09-21 06:26:40
Exec Total Coverage
Lines: 2 2 100.0%
Functions: 1 1 100.0%
Branches: 0 0 -%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright (c) 2018-2026, Stefan Meislinger <sm@opengate.at> |
4 | All rights reserved. |
5 | |
6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met:|
8 | |
9 | 1. Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. |
11 | 2. Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. |
14 | |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"|
16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
25 | THE POSSIBILITY OF SUCH DAMAGE. |
26 +----------------------------------------------------------------------------+
27 */
28
29 /** @file
30 * @brief Abstraction utilities for system specific component entrypoints
31 * @ingroup gatecore
32 */
33
34
35
36 /** @mainpage Introduction
37 *
38 * \section section_preamble Preamble
39 *
40 * The GATE project is a C based library framework that shall provide
41 * platform-independent implementations of lower-level auxiliary functions.
42 * While most C libraries are only targeting Windows and Linux platforms,
43 * GATE code is designed to run within other operating systems with no or
44 * limited C standard library implementation.
45 *
46 * The GATE C++ libraries are a thin layer of C++ classes around the C based
47 * implementation to simplify usage of lower-level C functions. Using a C
48 * API within C++ code allows code sharing of C++ logic between incompatible
49 * compilers (e.g. MSVC++ and g++).
50 *
51 * GATE is also an interface study where I add all kinds of features I was
52 * missing in Win32 or POSIX like:
53 *
54 * - C-based object interfaces
55 * - unified streaming
56 * - coroutines
57 * - delegates
58 * - data containers, fields and dictionaries
59 *
60 * \section section_platforms Supported platforms
61 *
62 * - Windows API beginning with NT4
63 * - Windows CE (CE 5+)
64 * - Windows RT (experimental)
65 * - POSIX
66 * - Linux (GLIBC, MUSL-LIBC)
67 * - BSD (NetBSD, FreeBSD, OpenBSD)
68 * - Android (experimental)
69 * - FreeRTOS (experimental)
70 * - UEFI Bootservices (experimental)
71 * - DOS (experimental)
72 * - WebAssembly-Emscripten (experimental)
73 *
74 * GATE libraries are designed with the concept of mandatory and optional
75 * features. Mandatory features are available on all platforms and are only
76 * depending on memory allocation support. Everything else that needs
77 * operating system support (or a native platform implementation) is only
78 * provided, if the platform supports it.
79 * GATE ensures that the entry points are available on all platforms, but
80 * they will return a NOT_IMPLEMENTED error at runtime when they are used.
81 * This allows application to compile function calls also on platform where
82 * they are not completely implemented.
83 *
84 * This feature was a main goal to overcome problems I found with other
85 * libraries that still could not be compiled on a target platform due to
86 * a single function that I never wanted to invoke.
87 *
88 * \section section_compilers Supported compilers
89 *
90 * - MSVC
91 * - GCC
92 * - CLANG
93 * - WATCOM
94 */
95
96 #ifndef GATE_MAIN_H_INCLUDED
97 #define GATE_MAIN_H_INCLUDED
98
99 #include "gate/gate_core_api.h"
100 #include "gate/gatemaindefs.h"
101
102
103 #if defined(__cplusplus)
104 # define GATE_MAIN_EXTERNC extern "C"
105 #else
106 # define GATE_MAIN_EXTERNC
107 #endif
108
109 GATE_MAIN_EXTERNC GATE_CORE_API int GATE_CALL gate_main_stdc_entry(gate_main_func main_func, int argc, char* argv[]);
110
111 #if defined(GATE_MAIN_WINAPI_IMPL)
112
113 #if defined(GATE_SYS_WINCE) || defined(GATE_SYS_WIN16)
114 # include <windows.h>
115 # define GATE_MAIN_NATIVE_HEADER_INCLUDED 1
116 #endif
117
118 #if !defined(GATE_COMPILER_WATCOM)
119 GATE_MAIN_EXTERNC GATE_CORE_API int GATE_CALL gate_main_wchar_entry(gate_main_func main_func, int argc, wchar_t* argv[], wchar_t* envp[]);
120 #endif
121 GATE_MAIN_EXTERNC GATE_CORE_API int GATE_CALL gate_main_winapi_entry(gate_main_func main_func, void* hInstance, void* hPrevInstance, void* lpCmdLine, int nShowCmd);
122
123 #if defined(GATE_MAIN_NATIVE_HEADER_INCLUDED)
124 # define GATE_WINMAIN_API WINAPI
125 #else
126 # if defined(GATE_SYS_WIN16)
127 # define GATE_WINMAIN_API __far __pascal
128 # else
129 # define GATE_WINMAIN_API __stdcall
130 # endif
131 #endif
132
133 #if defined(GATE_SYS_WINCE)
134 # if defined(GATE_MAIN_NATIVE_HEADER_INCLUDED)
135 # define WINMAIN_STR LPWSTR
136 # else
137 # define WINMAIN_STR wchar_t*
138 # endif
139 #else
140 # if defined(GATE_MAIN_NATIVE_HEADER_INCLUDED)
141 # define WINMAIN_STR LPSTR
142 # else
143 # define WINMAIN_STR char*
144 # endif
145 #endif
146
147 #if defined(GATE_APP_TYPE_UI) || defined(GATE_SYS_WIN16)
148 #if defined(GATE_MAIN_NATIVE_HEADER_INCLUDED)
149 int GATE_WINMAIN_API WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, WINMAIN_STR lpCmdLine, int nShowCmd)
150 #else
151 int GATE_WINMAIN_API WinMain(void* hInstance, void* hPrevInstance, void* lpCmdLine, int nShowCmd)
152 #endif
153 {
154 const gate_main_func main_func = &gate_main;
155 return gate_main_winapi_entry(main_func, (void*)hInstance, (void*)hPrevInstance, lpCmdLine, nShowCmd);
156 }
157 #endif
158
159 #if !defined(GATE_COMPILER_WATCOM) && !defined(GATE_COMPILER_TCC) && (!defined(GATE_APP_TYPE_UI) || defined(GATE_SYS_WINCE))
160 int wmain(int argc, wchar_t* argv[], wchar_t* envp[])
161 {
162 return gate_main_wchar_entry(&gate_main, argc, argv, envp);
163 }
164 #endif /* !GATE_COMPILER_WATCOM && !GATE_COMPILER_TCC && !GATE_APP_TYPE_UI */
165
166 #if defined(GATE_APP_TYPE_UI) && !defined(GATE_MAIN_NO_STDC_IMPL) && !defined(GATE_COMPILER_GCC)
167 # define GATE_MAIN_NO_STDC_IMPL 1
168 #endif
169
170
171 #endif /* GATE_MAIN_WINAPI_IMPL */
172
173
174 #if defined(GATE_MAIN_ANDROID_IMPL)
175 # include <android/native_activity.h>
176
177 GATE_MAIN_EXTERNC GATE_CORE_API void gate_main_android_entry(gate_main_func main_func, void* activity, void* savedState, size_t savedStateSize);
178
179 void ANativeActivity_onCreate(ANativeActivity* activity, void* savedState, size_t savedStateSize)
180 {
181 gate_main_android_entry(&gate_main, activity, savedState, savedStateSize);
182 }
183 #endif /* GATE_MAIN_ANDROID_IMPL */
184
185
186 #if defined(GATE_MAIN_ARDUINO_IMPL)
187
188 GATE_MAIN_EXTERNC GATE_CORE_API void gate_main_arduino_setup(void);
189 GATE_MAIN_EXTERNC GATE_CORE_API void gate_main_arduino_loop(void);
190
191 GATE_MAIN_EXTERNC void setup(void)
192 {
193 gate_main_arduino_setup();
194 }
195 GATE_MAIN_EXTERNC void loop(void)
196 {
197 gate_main_arduino_loop();
198 }
199
200 #endif /* GATE_MAIN_ARDUINO_IMPL */
201
202
203 #if !defined(GATE_MAIN_NO_STDC_IMPL)
204 40 int main(int argc, char* argv[], char* envp[])
205 {
206 (void)envp;
207 40 return gate_main_stdc_entry(&gate_main, argc, argv);
208 }
209
210 #endif /* GATE_MAIN_NO_STDC */
211
212 #endif /* GATE_MAIN_H_INCLUDED */
213