summaryrefslogtreecommitdiffstats
path: root/labb5/lib/StanfordCPPLib/private/main.h
blob: 43399156e798ca54c25fa3c03ebdda8b9312374e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
 * File: main.h
 * ------------
 * This file renames the <code>main</code> method in the client's
 * program to <code>Main</code>, thereby allowing a custom
 * <code>main</code> method in the libraries to take control
 * before passing control back to the client program.  The main macro
 * also defines a function getMainFlags that returns an int whose bits
 * indicate which of the various interfaces have been loaded by this
 * definition of main.
 *
 * Note: This file can be loaded more than once and must therefore
 * check to see what has already been defined.
 */

#ifdef main
#  undef main
#  undef CONSOLE_FLAG
#  undef GRAPHICS_FLAG
#else
#  define MAIN_USES_CONSOLE (1<<0)
#  define MAIN_USES_GRAPHICS (1<<1)
#endif

#ifdef _console_h
#  define CONSOLE_FLAG MAIN_USES_CONSOLE
#else
#  define CONSOLE_FLAG 0
#endif

#ifdef _gwindow_h
#  define GRAPHICS_FLAG MAIN_USES_GRAPHICS
#else
#  define GRAPHICS_FLAG 0
#endif

void __StanfordCPPLib_terminate_handler();
void __StanfordCPPLib_set_terminate();

#if CONSOLE_FLAG | GRAPHICS_FLAG

#define main main(int argc, char **argv) { \
                extern int _mainFlags; \
                _mainFlags = GRAPHICS_FLAG + CONSOLE_FLAG; \
                return startupMain(argc, argv); \
             } \
             int Main

extern int startupMain(int argc, char **argv);

#else

#define main main(int argc, char **argv) { \
                extern int _mainFlags; \
                _mainFlags = GRAPHICS_FLAG + CONSOLE_FLAG; \
                return mainWrapper(argc, argv); } \
             } \
             int Main

extern int mainWrapper(int argc, char **argv);

#endif