GitHub Actions: Try MSVC builds with /std:c++17 and 20
[ACE_TAO.git] / ACE / ace / OS_main.cpp
blob74b917da9f78d695d2da12ffa3648c72ed586de0
1 #include "ace/OS_main.h"
3 #if !defined (ACE_DOESNT_DEFINE_MAIN)
5 #if defined (ACE_HAS_NONSTATIC_OBJECT_MANAGER) && !defined (ACE_DOESNT_INSTANTIATE_NONSTATIC_OBJECT_MANAGER)
7 #include "ace/Init_ACE.h"
9 # if !defined (ACE_HAS_MINIMAL_ACE_OS)
10 # include "ace/Object_Manager.h"
11 # endif /* ! ACE_HAS_MINIMAL_ACE_OS */
13 // Rename "main ()" on platforms that don't allow it to be called "main ()".
15 // Also, create ACE_Object_Manager static instance(s) in "main ()".
16 // ACE_MAIN_OBJECT_MANAGER defines the ACE_Object_Manager(s) that will
17 // be instantiated on the stack of main (). Note that it is only used
18 // when compiling main (): its value does not affect the contents of
19 // ace/OS.o.
20 # if !defined (ACE_MAIN_OBJECT_MANAGER)
21 # define ACE_MAIN_OBJECT_MANAGER \
22 ACE_OS_Object_Manager ace_os_object_manager; \
23 ACE_Object_Manager ace_object_manager;
24 # endif /* ! ACE_MAIN_OBJECT_MANAGER */
26 # if !defined (ACE_WIN32)
28 # if !(defined (ACE_VXWORKS) && !defined (__RTP__))
29 /* forward declaration */
30 extern int ace_main_i (int, char *[]);
31 # endif
33 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
35 # if defined (ACE_VXWORKS) && !defined (__RTP__)
36 ace_main_proc_ptr vx_ace_main_i_ptr = 0;
38 int ace_os_main_i (int argc, char *argv[]) /* user's entry point, e.g., main */
40 ACE_MAIN_OBJECT_MANAGER
41 return vx_ace_main_i_ptr ? (*vx_ace_main_i_ptr) (argc, argv) : (-1); /* what the user calls "main" */
43 # else /* !ACE_VXWORKS && !__RTP__ */
44 ACE_Export int
45 ace_os_main_i (int argc, char *argv[]) /* user's entry point, e.g., main */
47 ACE_MAIN_OBJECT_MANAGER
48 return ace_main_i (argc, argv); /* what the user calls "main" */
50 # endif
52 ACE_END_VERSIONED_NAMESPACE_DECL
54 # elif !defined (ACE_HAS_WINCE)
56 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
58 # if defined (ACE_WIN32) && defined (ACE_USES_WCHAR)
59 int ACE_Main_Base::run (int argc, ACE_TCHAR *argv[])
61 return this->run_i (argc, argv);
64 ACE_Export int
65 ace_os_wmain_i (ACE_Main_Base &mbase, int argc, ACE_TCHAR *argv[]) /* user's entry point, e.g., main */
67 ACE_MAIN_OBJECT_MANAGER
68 return mbase.run (argc, argv); /* what the user calls "main" */
70 # else /* ! (ACE_WIN32 && ACE_USES_WCHAR) */
72 ACE_Main_Base::ACE_Main_Base ()
74 ACE::init ();
77 ACE_Main_Base::~ACE_Main_Base ()
79 ACE::fini ();
82 int ACE_Main_Base::run (int argc, char *argv[])
84 return this->run_i (argc, argv);
87 ACE_Export int
88 ace_os_main_i (ACE_Main_Base &mbase, int argc, char *argv[]) /* user's entry point, e.g., main */
90 ACE_MAIN_OBJECT_MANAGER
91 return mbase.run (argc, argv); /* what the user calls "main" */
93 # endif /* ACE_WIN32 && ACE_USES_WCHAR */
95 ACE_END_VERSIONED_NAMESPACE_DECL
97 # else /* ACE_HAS_WINCE */
99 // CE only gets a command line string; no argv. So we need to convert it
100 // when the main entrypoint expects argc/argv. ACE_ARGV supports this.
101 # include "ace/OS_NS_string.h"
102 # include "ace/OS_NS_ctype.h"
103 # include "ace/ACE.h"
104 # include "ace/ARGV.h"
106 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
108 ACE_Main_Base::~ACE_Main_Base ()
112 int ACE_Main_Base::run (HINSTANCE,
113 HINSTANCE,
114 LPWSTR lpCmdLine,
115 int)
117 ACE_TCHAR cmdline[1024];
118 ACE_TCHAR msg_file [MAXPATHLEN];
119 if (ACE_TEXT_GetModuleFileName (0, msg_file, MAXPATHLEN))
121 bool quote = false;
122 for (size_t i(0); !quote && msg_file[i]; ++i)
124 if (ACE_OS::ace_isspace (msg_file[i])) quote = true;
126 ACE_TCHAR *cmd_iter = cmdline;
127 if (quote)
129 *cmd_iter++ = ACE_TEXT ('"');
131 ACE_OS::strcpy (cmd_iter, msg_file);
132 ACE_OS::strcat (cmd_iter, quote ? ACE_TEXT ("\" ") : ACE_TEXT (" "));
134 else
136 ACE_OS::strcpy (cmdline, ACE_TEXT ("program "));
138 ACE_OS::strcat (cmdline, ACE_TEXT_WCHAR_TO_TCHAR (lpCmdLine));
139 ACE_ARGV ce_argv (cmdline);
140 ACE::init ();
141 ACE_MAIN_OBJECT_MANAGER
142 int const i = this->run_i (ce_argv.argc (), ce_argv.argv ());
143 ACE::fini ();
144 return i;
146 ACE_END_VERSIONED_NAMESPACE_DECL
148 # endif /* !ACE_HAS_WINCE */
150 #endif /* ACE_HAS_NONSTATIC_OBJECT_MANAGER && !ACE_HAS_WINCE && !ACE_DOESNT_INSTANTIATE_NONSTATIC_OBJECT_MANAGER */
152 #endif /* ACE_DOESNT_DEFINE_MAIN */