HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_Main.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_Main.h (UT Library, C++)
7  *
8  * COMMENTS: Platform-independent helper for main function
9  */
10 
11 #ifndef __UT_MAIN_H_INCLUDED__
12 #define __UT_MAIN_H_INCLUDED__
13 
14 #include <UT/UT_Exit.h>
15 
16 /// @def UT_MAIN(theMain)
17 /// Provides platform independent main() wrapper for UTF-8 command line args
18 ///
19 /// Example usage:
20 /// @code
21 /// static inline int
22 /// int theMain(int argc, const char *argv[])
23 /// {
24 /// ...etc...
25 /// }
26 /// UT_MAIN(theMain)
27 /// @endcode
28 
29 #include "UT_SubSystem.h"
30 
31 #ifdef _WIN32
32 
33 #define UT_MAIN(THE_MAIN) \
34  int wmain(int w_argc, wchar_t *w_argv[]) \
35  { \
36  UT_WorkArgs args; \
37  UTmainConvertArgs(args, w_argc, w_argv); \
38  UT_Exit::exitWithSpecificCode( \
39  THE_MAIN(args.getArgc(), \
40  const_cast<char**>(args.getArgv())) \
41  ); \
42  } \
43  /**/
44 
45 #include <UT/UT_Unicode.h>
46 #include <UT/UT_WorkBuffer.h>
47 #include <UT/UT_WorkArgs.h>
48 #include <string.h>
49 
50 static inline void
51 UTmainConvertArgs(UT_WorkArgs &args, int w_argc, const wchar_t *const w_argv[])
52 {
53  for (int i = 0; i < w_argc; ++i)
54  {
55  args.appendArg(strdup(
56  UT_WorkBuffer::narrow((const utf16*)w_argv[i]).buffer()));
57  }
58 }
59 
60 #else
61 
62 #define UT_MAIN(THE_MAIN) \
63  int main(int argc, char *argv[]) \
64  { \
65  UT_Exit::exitWithSpecificCode(THE_MAIN(argc, argv)); \
66  } \
67  /**/
68 
69 #endif // _WIN32
70 
71 #endif // __UT_MAIN_H_INCLUDED__
unsigned short utf16
Definition: SYS_Types.h:56
GLuint buffer
Definition: glcorearb.h:660
static SYS_FORCE_INLINE UT_WorkBuffer narrow(const utf16 *str)
void appendArg(const char *text)
Definition: UT_WorkArgs.h:30
**If you just want to fire and args
Definition: thread.h:609