Branch libreoffice-5-0-4
[LibreOffice.git] / include / sal / main.h
blob7c79fad5f0f9b8a06dce6ae20f918c97c03d9a24
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SAL_MAIN_H
21 #define INCLUDED_SAL_MAIN_H
23 #include <sal/config.h>
25 #include <sal/saldllapi.h>
26 #include <sal/types.h>
28 #if defined AIX
29 #include <unistd.h>
30 #endif
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
36 SAL_DLLPUBLIC void SAL_CALL sal_detail_initialize(int argc, char ** argv);
37 SAL_DLLPUBLIC void SAL_CALL sal_detail_deinitialize(void);
39 #if defined IOS || defined ANDROID
41 #error No code that includes this should be built for iOS or Android
43 #else
45 #define SAL_MAIN_WITH_ARGS_IMPL \
46 int SAL_DLLPUBLIC_EXPORT SAL_CALL main(int argc, char ** argv) \
47 { \
48 int ret; \
49 sal_detail_initialize(argc, argv); \
50 ret = sal_main_with_args(argc, argv); \
51 sal_detail_deinitialize(); \
52 return ret; \
55 #define SAL_MAIN_IMPL \
56 int SAL_DLLPUBLIC_EXPORT SAL_CALL main(int argc, char ** argv) \
57 { \
58 int ret; \
59 sal_detail_initialize(argc, argv); \
60 ret = sal_main(); \
61 sal_detail_deinitialize(); \
62 return ret; \
65 #endif
68 /* Definition macros for CRT entries */
70 #ifdef SAL_W32
72 #include <stdlib.h>
74 /* Sorry but this is necessary cause HINSTANCE is a typedef that differs (C++ causes an error) */
76 #ifndef WINAPI
77 # define WINAPI __stdcall
78 #endif
80 #if !defined(DECLARE_HANDLE)
81 # ifdef STRICT
82 typedef void *HANDLE;
83 # define DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name
84 # else
85 typedef void *PVOID;
86 typedef PVOID HANDLE;
87 # define DECLARE_HANDLE(name) typedef HANDLE name
88 # endif
89 DECLARE_HANDLE(HINSTANCE);
90 #endif
94 #define SAL_WIN_WinMain \
95 int WINAPI WinMain( HINSTANCE _hinst, HINSTANCE _dummy, char* _cmdline, int _nshow ) \
96 { \
97 int argc = __argc; char ** argv = __argv; \
98 (void) _hinst; (void) _dummy; (void) _cmdline; (void) _nshow; /* unused */ \
99 return main(argc, argv); \
102 #else /* ! SAL_W32 */
104 # define SAL_WIN_WinMain
106 #endif /* ! SAL_W32 */
108 /* Implementation macro */
110 #define SAL_IMPLEMENT_MAIN_WITH_ARGS(_argc_, _argv_) \
111 static int SAL_CALL sal_main_with_args (int _argc_, char ** _argv_); \
112 SAL_MAIN_WITH_ARGS_IMPL \
113 SAL_WIN_WinMain \
114 static int SAL_CALL sal_main_with_args(int _argc_, char ** _argv_)
116 #define SAL_IMPLEMENT_MAIN() \
117 static int SAL_CALL sal_main(void); \
118 SAL_MAIN_IMPL \
119 SAL_WIN_WinMain \
120 static int SAL_CALL sal_main(void)
123 "How to use" Examples:
125 #include <sal/main.h>
127 SAL_IMPLEMENT_MAIN()
129 DoSomething();
131 return 0;
134 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
136 DoSomethingWithArgs(argc, argv);
138 return 0;
143 #ifdef __cplusplus
144 } /* extern "C" */
145 #endif
147 #endif // INCLUDED_SAL_MAIN_H
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */