xref: /aoo41x/main/sal/inc/sal/main.h (revision fac87513)
19eab2a37SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
39eab2a37SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
49eab2a37SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
59eab2a37SAndrew Rist  * distributed with this work for additional information
69eab2a37SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
79eab2a37SAndrew Rist  * to you under the Apache License, Version 2.0 (the
89eab2a37SAndrew Rist  * "License"); you may not use this file except in compliance
99eab2a37SAndrew Rist  * with the License.  You may obtain a copy of the License at
109eab2a37SAndrew Rist  *
119eab2a37SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
129eab2a37SAndrew Rist  *
139eab2a37SAndrew Rist  * Unless required by applicable law or agreed to in writing,
149eab2a37SAndrew Rist  * software distributed under the License is distributed on an
159eab2a37SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
169eab2a37SAndrew Rist  * KIND, either express or implied.  See the License for the
179eab2a37SAndrew Rist  * specific language governing permissions and limitations
189eab2a37SAndrew Rist  * under the License.
199eab2a37SAndrew Rist  *
209eab2a37SAndrew Rist  *************************************************************/
219eab2a37SAndrew Rist 
229eab2a37SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _SAL_MAIN_H_
25cdf0e10cSrcweir #define _SAL_MAIN_H_
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <sal/types.h>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #ifdef __cplusplus
30cdf0e10cSrcweir extern "C" {
31cdf0e10cSrcweir #endif
32cdf0e10cSrcweir 
33cdf0e10cSrcweir void SAL_CALL sal_detail_initialize(int argc, char ** argv);
34cdf0e10cSrcweir void SAL_CALL sal_detail_deinitialize();
35cdf0e10cSrcweir 
36c99cd5fcSYuri Dario #ifdef SAL_OS2
37c99cd5fcSYuri Dario #include <string.h>
38c99cd5fcSYuri Dario 
39c99cd5fcSYuri Dario #define INCL_DOSPROCESS
40c99cd5fcSYuri Dario #define INCL_DOSEXCEPTIONS
41c99cd5fcSYuri Dario #define INCL_DOSMODULEMGR
42c99cd5fcSYuri Dario #include <os2.h>
43c99cd5fcSYuri Dario #define INCL_LOADEXCEPTQ
44c99cd5fcSYuri Dario #include <exceptq.h>
45c99cd5fcSYuri Dario 
46*fac87513SYuri Dario #include <osl/process.h>
47*fac87513SYuri Dario 
48c99cd5fcSYuri Dario #define sal_detail_initialize(a,b) \
49c99cd5fcSYuri Dario 	EXCEPTIONREGISTRATIONRECORD exRegRec = {0}; \
50c99cd5fcSYuri Dario 	LoadExceptq(&exRegRec, NULL, NULL); \
51c99cd5fcSYuri Dario 	osl_setCommandArgs(argc, argv);
52c99cd5fcSYuri Dario #define sal_detail_deinitialize() \
53c99cd5fcSYuri Dario 	UninstallExceptq(&exRegRec);
54c99cd5fcSYuri Dario #endif // SAL_OS2
55c99cd5fcSYuri Dario 
56cdf0e10cSrcweir #define SAL_MAIN_WITH_ARGS_IMPL \
57cdf0e10cSrcweir int SAL_CALL main(int argc, char ** argv) \
58cdf0e10cSrcweir { \
59cdf0e10cSrcweir 	int ret; \
60cdf0e10cSrcweir 	sal_detail_initialize(argc, argv);   \
61cdf0e10cSrcweir 	ret = sal_main_with_args(argc, argv); \
62cdf0e10cSrcweir 	sal_detail_deinitialize(); \
63cdf0e10cSrcweir 	return ret; \
64cdf0e10cSrcweir }
65cdf0e10cSrcweir 
66cdf0e10cSrcweir #define SAL_MAIN_IMPL \
67cdf0e10cSrcweir int SAL_CALL main(int argc, char ** argv) \
68cdf0e10cSrcweir { \
69cdf0e10cSrcweir 	int ret; \
70cdf0e10cSrcweir 	sal_detail_initialize(argc, argv); \
71cdf0e10cSrcweir 	ret = sal_main(); \
72cdf0e10cSrcweir 	sal_detail_deinitialize(); \
73cdf0e10cSrcweir 	return ret; \
74cdf0e10cSrcweir }
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 
77cdf0e10cSrcweir /* Definition macros for CRT entries */
78cdf0e10cSrcweir 
79cdf0e10cSrcweir #ifdef SAL_W32
80cdf0e10cSrcweir 
81cdf0e10cSrcweir #ifndef INCLUDED_STDLIB_H
82cdf0e10cSrcweir #include <stdlib.h>
83cdf0e10cSrcweir #define INCLUDED_STDLIB_H
84cdf0e10cSrcweir #endif
85cdf0e10cSrcweir 
86cdf0e10cSrcweir /* Sorry but this is neccessary cause HINSTANCE is a typedef that differs (C++ causes an error) */
87cdf0e10cSrcweir 
88cdf0e10cSrcweir #if 0
89cdf0e10cSrcweir 
90cdf0e10cSrcweir #ifndef _WINDOWS_
91cdf0e10cSrcweir #include <windows.h>
92cdf0e10cSrcweir #endif
93cdf0e10cSrcweir 
94cdf0e10cSrcweir #else /* Simulated what windows.h does */
95cdf0e10cSrcweir 
96cdf0e10cSrcweir #ifndef WINAPI
97cdf0e10cSrcweir #	define WINAPI	__stdcall
98cdf0e10cSrcweir #endif
99cdf0e10cSrcweir 
100cdf0e10cSrcweir #if !defined(DECLARE_HANDLE)
101cdf0e10cSrcweir #	ifdef STRICT
102cdf0e10cSrcweir 		typedef void *HANDLE;
103cdf0e10cSrcweir #		define DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name
104cdf0e10cSrcweir #	else
105cdf0e10cSrcweir 		typedef void *PVOID;
106cdf0e10cSrcweir 		typedef PVOID HANDLE;
107cdf0e10cSrcweir #		define DECLARE_HANDLE(name) typedef HANDLE name
108cdf0e10cSrcweir #	endif
109cdf0e10cSrcweir DECLARE_HANDLE(HINSTANCE);
110cdf0e10cSrcweir #endif
111cdf0e10cSrcweir 
112cdf0e10cSrcweir #endif
113cdf0e10cSrcweir 
114cdf0e10cSrcweir #define SAL_WIN_WinMain \
115cdf0e10cSrcweir int WINAPI WinMain( HINSTANCE _hinst, HINSTANCE _dummy, char* _cmdline, int _nshow ) \
116cdf0e10cSrcweir { \
117cdf0e10cSrcweir 	int argc = __argc; char ** argv = __argv; \
118cdf0e10cSrcweir     (void) _hinst; (void) _dummy; (void) _cmdline; (void) _nshow; /* unused */ \
119cdf0e10cSrcweir 	return main(argc, argv); \
120cdf0e10cSrcweir }
121cdf0e10cSrcweir 
122cdf0e10cSrcweir #else	/* ! SAL_W32 */
123cdf0e10cSrcweir 
124cdf0e10cSrcweir # define SAL_WIN_WinMain
125cdf0e10cSrcweir 
126cdf0e10cSrcweir #endif /* ! SAL_W32 */
127cdf0e10cSrcweir 
128cdf0e10cSrcweir /* Implementation macro */
129cdf0e10cSrcweir 
130cdf0e10cSrcweir #define SAL_IMPLEMENT_MAIN_WITH_ARGS(_argc_, _argv_) \
131cdf0e10cSrcweir     static int  SAL_CALL sal_main_with_args (int _argc_, char ** _argv_); \
132cdf0e10cSrcweir     SAL_MAIN_WITH_ARGS_IMPL \
133cdf0e10cSrcweir     SAL_WIN_WinMain \
134cdf0e10cSrcweir 	static int SAL_CALL sal_main_with_args(int _argc_, char ** _argv_)
135cdf0e10cSrcweir 
136cdf0e10cSrcweir #define SAL_IMPLEMENT_MAIN() \
137cdf0e10cSrcweir     static int  SAL_CALL sal_main(void); \
138cdf0e10cSrcweir     SAL_MAIN_IMPL \
139cdf0e10cSrcweir     SAL_WIN_WinMain \
140cdf0e10cSrcweir 	static int SAL_CALL sal_main(void)
141cdf0e10cSrcweir 
142cdf0e10cSrcweir /*
143cdf0e10cSrcweir 	"How to use" Examples:
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 	#include <sal/main.h>
146cdf0e10cSrcweir 
147cdf0e10cSrcweir 	SAL_IMPLEMENT_MAIN()
148cdf0e10cSrcweir 	{
149cdf0e10cSrcweir 		DoSomething();
150cdf0e10cSrcweir 
151cdf0e10cSrcweir 		return 0;
152cdf0e10cSrcweir 	}
153cdf0e10cSrcweir 
154cdf0e10cSrcweir 	SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
155cdf0e10cSrcweir 	{
156cdf0e10cSrcweir 		DoSomethingWithArgs(argc, argv);
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 		return 0;
159cdf0e10cSrcweir 	}
160cdf0e10cSrcweir 
161cdf0e10cSrcweir */
162cdf0e10cSrcweir 
163cdf0e10cSrcweir #ifdef __cplusplus
164cdf0e10cSrcweir }	/* extern "C" */
165cdf0e10cSrcweir #endif
166cdf0e10cSrcweir 
167cdf0e10cSrcweir #endif	/* _SAL_MAIN_H_ */
168cdf0e10cSrcweir 
169