]> git.mxchange.org Git - flightgear.git/blob - src/Main/bootstrap.cxx
Reorganization of main.cxx
[flightgear.git] / src / Main / bootstrap.cxx
1 // bootstrap.cxx -- bootstrap routines: main()
2 //
3 // Written by Curtis Olson, started May 1997.
4 //
5 // Copyright (C) 1997 - 2002  Curtis L. Olson  - curt@flightgear.org
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22
23
24 #ifdef HAVE_CONFIG_H
25 #  include <config.h>
26 #endif
27
28 #if defined(__linux__) && defined(__i386__)
29 #  include <fpu_control.h>
30 #  include <signal.h>
31 #endif
32
33 #include <stdlib.h>
34
35 #include <simgear/compiler.h>
36 #include <simgear/misc/exception.hxx>
37
38 #include STL_IOSTREAM
39 SG_USING_STD(cerr);
40 SG_USING_STD(endl);
41
42 #include "main.hxx"
43
44
45 #ifdef HAVE_WINDOWS_H
46 #  include <windows.h>
47 #  include <float.h>
48 #endif
49
50 #include GLUT_H
51
52 #ifdef macintosh
53 #  include <console.h>          // -dw- for command line dialog
54 #endif
55
56
57 #if defined(__linux__) && defined(__i386__)
58
59 static void handleFPE (int);
60
61 static void
62 initFPE ()
63 {
64     fpu_control_t fpe_flags = 0;
65     _FPU_GETCW(fpe_flags);
66 //     fpe_flags &= ~_FPU_MASK_IM;      // invalid operation
67 //     fpe_flags &= ~_FPU_MASK_DM;      // denormalized operand
68 //     fpe_flags &= ~_FPU_MASK_ZM;      // zero-divide
69 //     fpe_flags &= ~_FPU_MASK_OM;      // overflow
70 //     fpe_flags &= ~_FPU_MASK_UM;      // underflow
71 //     fpe_flags &= ~_FPU_MASK_PM;      // precision (inexact result)
72     _FPU_SETCW(fpe_flags);
73     signal(SIGFPE, handleFPE);
74 }
75
76 static void
77 handleFPE (int num)
78 {
79   initFPE();
80   SG_LOG(SG_GENERAL, SG_ALERT, "Floating point interrupt (SIGFPE)");
81 }
82 #endif
83
84 #ifdef __APPLE__
85
86 typedef struct
87 {
88   int  lo;
89   int  hi;
90 } PSN;
91
92 extern "C" {
93   short CPSGetCurrentProcess(PSN *psn);
94   short CPSSetProcessName (PSN *psn, char *processname);
95   short CPSEnableForegroundOperation(PSN *psn, int _arg2, int _arg3, int _arg4, int _arg5);
96   short CPSSetFrontProcess(PSN *psn);
97 };
98
99 #define CPSEnableFG(psn) CPSEnableForegroundOperation(psn,0x03,0x3C,0x2C,0x1103)
100
101 #endif
102
103 // Main entry point; catch any exceptions that have made it this far.
104 int main ( int argc, char **argv ) {
105
106     // Enable floating-point exceptions for Linux/x86
107 #if defined(__linux__) && defined(__i386__)
108     initFPE();
109 #endif
110
111     // Enable floating-point exceptions for Windows
112 #if defined( _MSC_VER ) && defined( DEBUG )
113     // Christian, we should document what this does
114     _control87( _EM_INEXACT, _MCW_EM );
115 #endif
116
117 #if defined( HAVE_BC5PLUS )
118     _control87(MCW_EM, MCW_EM);  /* defined in float.h */
119 #endif
120
121     // Keyboard focus hack
122 #ifdef __APPLE__
123     {
124       PSN psn;
125
126       glutInit (&argc, argv);
127
128       CPSGetCurrentProcess(&psn);
129       CPSSetProcessName(&psn, "FlightGear");
130       CPSEnableFG(&psn);
131       CPSSetFrontProcess(&psn);
132     }
133 #endif
134
135     // FIXME: add other, more specific
136     // exceptions.
137     try {
138         fgMainInit(argc, argv);
139     } catch (sg_throwable &t) {
140                             // We must use cerr rather than
141                             // logging, since logging may be
142                             // disabled.
143         cerr << "Fatal error: " << t.getFormattedMessage()
144              << "\n (received from " << t.getOrigin() << ')' << endl;
145         exit(1);
146     }
147
148     return 0;
149 }
150
151