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