]> git.mxchange.org Git - flightgear.git/blob - src/Main/options.cxx
Code reorganization.
[flightgear.git] / src / Main / options.cxx
1 // options.cxx -- class to handle command line options
2 //
3 // Written by Curtis Olson, started April 1998.
4 //
5 // Copyright (C) 1998  Curtis L. Olson  - curt@me.umn.edu
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(FX) && defined(XMESA)
29 bool global_fullscreen = true;
30 #endif
31
32 #include <simgear/compiler.h>
33
34 #include <math.h>            // rint()
35 #include <stdio.h>
36 #include <stdlib.h>          // atof(), atoi()
37 #include <string.h>
38
39 #include STL_STRING
40
41 #include <simgear/logstream.hxx>
42 #include <simgear/fgstream.hxx>
43 #include <simgear/constants.h>
44
45 #include <Include/general.hxx>
46 #include <Cockpit/cockpit.hxx>
47 #include <FDM/flight.hxx>
48 #ifdef FG_NETWORK_OLK
49 #  include <NetworkOLK/network.h>
50 #endif
51 #include <Time/fg_time.hxx>
52
53 #include "views.hxx"
54 #include "options.hxx"
55
56 FG_USING_STD(string);
57 FG_USING_NAMESPACE(std);
58
59 // from GLUTmain.cxx
60 extern void fgReshape( int width, int height );
61
62 inline double
63 atof( const string& str )
64 {
65
66 #ifdef __MWERKS__ 
67     // -dw- if ::atof is called, then we get an infinite loop
68     return std::atof( str.c_str() );
69 #else
70     return ::atof( str.c_str() );
71 #endif
72 }
73
74 inline int
75 atoi( const string& str )
76 {
77 #ifdef __MWERKS__ 
78     // -dw- if ::atoi is called, then we get an infinite loop
79     return std::atoi( str.c_str() );
80 #else
81     return ::atoi( str.c_str() );
82 #endif
83 }
84
85 // Defined the shared options class here
86 fgOPTIONS current_options;
87
88
89 // Constructor
90 fgOPTIONS::fgOPTIONS() :
91     // starting longitude in degrees (west = -)
92     // starting latitude in degrees (south = -)
93
94     // Default initial position is Globe, AZ (P13)
95     lon(-110.6642444),
96     lat(  33.3528917),
97
98     // North of the city of Globe
99     // lon(-110.7),
100     // lat(  33.4),
101
102     // North of the city of Globe
103     // lon(-110.742578),
104     // lat(  33.507122),
105
106     // Near where I used to live in Globe, AZ
107     // lon(-110.766000),
108     // lat(  33.377778),
109
110     // 10125 Jewell St. NE
111     // lon(-93.15),
112     // lat( 45.15),
113
114     // Near KHSP (Hot Springs, VA)
115     // lon(-79.8338964 + 0.01),
116     // lat( 37.9514564 + 0.008),
117
118     // (SEZ) SEDONA airport
119     // lon(-111.7884614 + 0.01),
120     // lat(  34.8486289 - 0.015),
121
122     // Jim Brennon's Kingmont Observatory
123     // lon(-121.1131667),
124     // lat(  38.8293917),
125
126     // Huaras, Peru (S09d 31.871'  W077d 31.498')
127     // lon(-77.5249667),
128     // lat( -9.5311833),
129  
130     // Eclipse Watching w73.5 n10 (approx) 18:00 UT
131     // lon(-73.5),
132     // lat( 10.0),
133
134     // Timms Hill (WI)
135     // lon(-90.1953055556),
136     // lat( 45.4511388889),
137
138     // starting altitude in meters (this will be reset to ground level
139     // if it is lower than the terrain
140     altitude(-9999.0),
141
142     // Initial Orientation
143     heading(270.0),      // heading (yaw) angle in degress (Psi)
144     roll(0.0),           // roll angle in degrees (Phi)
145     pitch(0.424),        // pitch angle in degrees (Theta)
146
147     // Initialize current options velocities to 0.0
148     uBody(0.0), vBody(0.0), wBody(0.0),
149
150     // Miscellaneous
151     game_mode(0),
152     splash_screen(1),
153     intro_music(1),
154     mouse_pointer(0),
155     pause(0),
156     control_mode(FG_JOYSTICK),
157     auto_coordination(FG_AUTO_COORD_NOT_SPECIFIED),
158
159     // Features
160     hud_status(1),
161     panel_status(0),
162     sound(1),
163
164     // Flight Model options
165     flight_model( FGInterface::FG_LARCSIM ),
166     aircraft( "c172" ),
167     model_hz( NEW_DEFAULT_MODEL_HZ ),
168     speed_up( 1 ),
169
170     // Rendering options
171     fog(FG_FOG_NICEST),  // nicest
172     clouds(true),
173     clouds_asl(5000*FEET_TO_METER),
174     fov(55.0),
175     fullscreen(0),
176     shading(1),
177     skyblend(1),
178     textures(1),
179     wireframe(0),
180     xsize(640),
181     ysize(480),
182     view_mode(FG_VIEW_PILOT),
183
184     // Scenery options
185     tile_diameter(5),
186
187     // HUD options
188     units(FG_UNITS_FEET),
189     tris_or_culled(0),
190         
191     // Time options
192     time_offset(0)
193 {
194     // set initial values/defaults
195     time_offset_type=FG_TIME_SYS_OFFSET;
196     char* envp = ::getenv( "FG_ROOT" );
197
198     if ( envp != NULL ) {
199         // fg_root could be anywhere, so default to environmental
200         // variable $FG_ROOT if it is set.
201         fg_root = envp;
202     } else {
203         // Otherwise, default to a random compiled in location if
204         // $FG_ROOT is not set.  This can still be overridden from the
205         // command line or a config file.
206
207 #if defined( WIN32 )
208         fg_root = "\\FlightGear";
209 #elif defined( MACOS )
210         fg_root = "";
211 #else
212         fg_root = PKGLIBDIR;
213 #endif
214     }
215
216     airport_id = "";            // default airport id
217     net_id = "Johnney";         // default pilot's name
218
219     // initialize port config string list
220     channel_options_list.clear();
221 }
222
223 void 
224 fgOPTIONS::toggle_panel() {
225     
226     FGTime *t = FGTime::cur_time_params;
227     
228     int toggle_pause = t->getPause();
229     
230     if( !toggle_pause )
231         t->togglePauseMode();
232     
233     if( panel_status ) {
234         panel_status = false;
235     } else {
236         panel_status = true;
237     }
238     if ( panel_status ) {
239         if( FGPanel::OurPanel == 0)
240             new FGPanel;
241         fov *= 0.4232;
242     } else {
243         fov *= (1.0 / 0.4232);
244     }
245     fgReshape( xsize, ysize);
246     
247     if( !toggle_pause )
248         t->togglePauseMode();
249 }
250
251 double
252 fgOPTIONS::parse_time(const string& time_in) {
253     char *time_str, num[256];
254     double hours, minutes, seconds;
255     double result = 0.0;
256     int sign = 1;
257     int i;
258
259     time_str = (char *)time_in.c_str();
260
261     // printf("parse_time(): %s\n", time_str);
262
263     // check for sign
264     if ( strlen(time_str) ) {
265         if ( time_str[0] == '+' ) {
266             sign = 1;
267             time_str++;
268         } else if ( time_str[0] == '-' ) {
269             sign = -1;
270             time_str++;
271         }
272     }
273     // printf("sign = %d\n", sign);
274
275     // get hours
276     if ( strlen(time_str) ) {
277         i = 0;
278         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
279             num[i] = time_str[0];
280             time_str++;
281             i++;
282         }
283         if ( time_str[0] == ':' ) {
284             time_str++;
285         }
286         num[i] = '\0';
287         hours = atof(num);
288         // printf("hours = %.2lf\n", hours);
289
290         result += hours;
291     }
292
293     // get minutes
294     if ( strlen(time_str) ) {
295         i = 0;
296         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
297             num[i] = time_str[0];
298             time_str++;
299             i++;
300         }
301         if ( time_str[0] == ':' ) {
302             time_str++;
303         }
304         num[i] = '\0';
305         minutes = atof(num);
306         // printf("minutes = %.2lf\n", minutes);
307
308         result += minutes / 60.0;
309     }
310
311     // get seconds
312     if ( strlen(time_str) ) {
313         i = 0;
314         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
315             num[i] = time_str[0];
316             time_str++;
317             i++;
318         }
319         num[i] = '\0';
320         seconds = atof(num);
321         // printf("seconds = %.2lf\n", seconds);
322
323         result += seconds / 3600.0;
324     }
325
326     return(sign * result);
327 }
328
329
330 long int fgOPTIONS::parse_date( const string& date)
331 {
332     struct tm gmt;
333     char * date_str, num[256];
334     int i;
335     // initialize to zero
336     gmt.tm_sec = 0;
337     gmt.tm_min = 0;
338     gmt.tm_hour = 0;
339     gmt.tm_mday = 0;
340     gmt.tm_mon = 0;
341     gmt.tm_year = 0;
342     gmt.tm_isdst = 0; // ignore daylight savings time for the moment
343     date_str = (char *)date.c_str();
344     // get year
345     if ( strlen(date_str) ) {
346         i = 0;
347         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
348             num[i] = date_str[0];
349             date_str++;
350             i++;
351         }
352         if ( date_str[0] == ':' ) {
353             date_str++;
354         }
355         num[i] = '\0';
356         gmt.tm_year = atoi(num) - 1900;
357     }
358     // get month
359     if ( strlen(date_str) ) {
360         i = 0;
361         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
362             num[i] = date_str[0];
363             date_str++;
364             i++;
365         }
366         if ( date_str[0] == ':' ) {
367             date_str++;
368         }
369         num[i] = '\0';
370         gmt.tm_mon = atoi(num) -1;
371     }
372     // get day
373     if ( strlen(date_str) ) {
374         i = 0;
375         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
376             num[i] = date_str[0];
377             date_str++;
378             i++;
379         }
380         if ( date_str[0] == ':' ) {
381             date_str++;
382         }
383         num[i] = '\0';
384         gmt.tm_mday = atoi(num);
385     }
386     // get hour
387     if ( strlen(date_str) ) {
388         i = 0;
389         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
390             num[i] = date_str[0];
391             date_str++;
392             i++;
393         }
394         if ( date_str[0] == ':' ) {
395             date_str++;
396         }
397         num[i] = '\0';
398         gmt.tm_hour = atoi(num);
399     }
400     // get minute
401     if ( strlen(date_str) ) {
402         i = 0;
403         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
404             num[i] = date_str[0];
405             date_str++;
406             i++;
407         }
408         if ( date_str[0] == ':' ) {
409             date_str++;
410         }
411         num[i] = '\0';
412         gmt.tm_min = atoi(num);
413     }
414     // get second
415     if ( strlen(date_str) ) {
416         i = 0;
417         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
418             num[i] = date_str[0];
419             date_str++;
420             i++;
421         }
422         if ( date_str[0] == ':' ) {
423             date_str++;
424         }
425         num[i] = '\0';
426         gmt.tm_sec = atoi(num);
427     }
428     time_t theTime = FGTime::cur_time_params->get_gmt(gmt.tm_year,
429                                                       gmt.tm_mon,
430                                                       gmt.tm_mday,
431                                                       gmt.tm_hour,
432                                                       gmt.tm_min,
433                                                       gmt.tm_sec);
434     //printf ("Date is %s\n", ctime(&theTime));
435     //printf ("in seconds that is %d\n", theTime);
436     //exit(1);
437     return (theTime);
438 }
439
440
441 // parse degree in the form of [+/-]hhh:mm:ss
442 void fgOPTIONS::parse_control( const string& mode ) {
443     if ( mode == "joystick" ) {
444         control_mode = FG_JOYSTICK;
445     } else if ( mode == "mouse" ) {
446         control_mode = FG_MOUSE;
447     } else {
448         control_mode = FG_KEYBOARD;
449     }
450 }
451
452
453 /// parse degree in the form of [+/-]hhh:mm:ss
454 double
455 fgOPTIONS::parse_degree( const string& degree_str) {
456     double result = parse_time( degree_str );
457
458     // printf("Degree = %.4f\n", result);
459
460     return(result);
461 }
462
463
464 // parse time offset command line option
465 int
466 fgOPTIONS::parse_time_offset( const string& time_str) {
467     int result;
468
469     // printf("time offset = %s\n", time_str);
470
471 #ifdef HAVE_RINT
472     result = (int)rint(parse_time(time_str) * 3600.0);
473 #else
474     result = (int)(parse_time(time_str) * 3600.0);
475 #endif
476
477     // printf("parse_time_offset(): %d\n", result);
478
479     return( result );
480 }
481
482
483 // Parse --tile-diameter=n type option 
484
485 int
486 fgOPTIONS::parse_tile_radius( const string& arg ) {
487     int radius = atoi( arg );
488
489     if ( radius < FG_RADIUS_MIN ) { radius = FG_RADIUS_MIN; }
490     if ( radius > FG_RADIUS_MAX ) { radius = FG_RADIUS_MAX; }
491
492     // printf("parse_tile_radius(): radius = %d\n", radius);
493
494     return(radius);
495 }
496
497
498 // Parse --fdm=abcdefg type option 
499 int
500 fgOPTIONS::parse_fdm( const string& fm ) {
501     // cout << "fdm = " << fm << endl;
502
503     if ( fm == "balloon" ) {
504         return FGInterface::FG_BALLOONSIM;
505     } else if ( fm == "external" ) {
506         return FGInterface::FG_EXTERNAL;
507     } else if ( fm == "jsb" ) {
508         return FGInterface::FG_JSBSIM;
509     } else if ( (fm == "larcsim") || (fm == "LaRCsim") ) {
510         return FGInterface::FG_LARCSIM;
511     } else if ( fm == "magic" ) {
512         return FGInterface::FG_MAGICCARPET;
513     } else {
514         FG_LOG( FG_GENERAL, FG_ALERT, "Unknown fdm = " << fm );
515         exit(-1);
516     }
517
518     // we'll never get here, but it makes the compiler happy.
519     return -1;
520 }
521
522
523 // Parse --fov=x.xx type option 
524 double
525 fgOPTIONS::parse_fov( const string& arg ) {
526     double fov = atof(arg);
527
528     if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
529     if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
530
531     // printf("parse_fov(): result = %.4f\n", fov);
532
533     return(fov);
534 }
535
536
537 // Parse I/O channel option
538 //
539 // Format is "--protocol=medium,direction,hz,medium_options,..."
540 //
541 //   protocol = { native, nmea, garmin, fgfs, rul, pve, etc. }
542 //   medium = { serial, socket, file, etc. }
543 //   direction = { in, out, bi }
544 //   hz = number of times to process channel per second (floating
545 //        point values are ok.
546 //
547 // Serial example "--nmea=serial,dir,hz,device,baud" where
548 // 
549 //  device = OS device name of serial line to be open()'ed
550 //  baud = {300, 1200, 2400, ..., 230400}
551 //
552 // Socket exacmple "--native=socket,dir,hz,machine,port" where
553 // 
554 //  machine = machine name or ip address if client (leave empty if server)
555 //  port = port, leave empty to let system choose
556 //
557 // File example "--garmin=file,dir,hz,filename" where
558 // 
559 //  filename = file system file name
560
561 bool 
562 fgOPTIONS::parse_channel( const string& type, const string& channel_str ) {
563     // cout << "Channel string = " << channel_str << endl;
564
565     channel_options_list.push_back( type + "," + channel_str );
566
567     return true;
568 }
569
570
571 // Parse a single option
572 int fgOPTIONS::parse_option( const string& arg ) {
573     // General Options
574     if ( (arg == "--help") || (arg == "-h") ) {
575         // help/usage request
576         return(FG_OPTIONS_HELP);
577     } else if ( arg == "--disable-game-mode") {
578         game_mode = false;
579     } else if ( arg == "--enable-game-mode" ) {
580         game_mode = true;
581     } else if ( arg == "--disable-splash-screen" ) {
582         splash_screen = false;
583     } else if ( arg == "--enable-splash-screen" ) {
584         splash_screen = true;
585     } else if ( arg == "--disable-intro-music" ) {
586         intro_music = false;
587     } else if ( arg == "--enable-intro-music" ) {
588         intro_music = true;
589     } else if ( arg == "--disable-mouse-pointer" ) {
590         mouse_pointer = 1;
591     } else if ( arg == "--enable-mouse-pointer" ) {
592         mouse_pointer = 2;
593     } else if ( arg == "--disable-pause" ) {
594         pause = false;  
595     } else if ( arg == "--enable-pause" ) {
596         pause = true;   
597     } else if ( arg.find( "--control=") != string::npos ) {
598         parse_control( arg.substr(10) );
599     } else if ( arg == "--disable-auto-coordination" ) {
600         auto_coordination = FG_AUTO_COORD_DISABLED;     
601     } else if ( arg == "--enable-auto-coordination" ) {
602         auto_coordination = FG_AUTO_COORD_ENABLED;      
603     } else if ( arg == "--disable-hud" ) {
604         hud_status = false;     
605     } else if ( arg == "--enable-hud" ) {
606         hud_status = true;      
607     } else if ( arg == "--disable-panel" ) {
608         panel_status = false;
609     } else if ( arg == "--enable-panel" ) {
610         panel_status = true;
611         fov *= 0.4232;
612     } else if ( arg == "--disable-sound" ) {
613         sound = false;
614     } else if ( arg == "--enable-sound" ) {
615         sound = true;
616     } else if ( arg.find( "--airport-id=") != string::npos ) {
617         airport_id = arg.substr( 13 );
618     } else if ( arg.find( "--lon=" ) != string::npos ) {
619         lon = parse_degree( arg.substr(6) );
620     } else if ( arg.find( "--lat=" ) != string::npos ) {
621         lat = parse_degree( arg.substr(6) );
622     } else if ( arg.find( "--altitude=" ) != string::npos ) {
623         if ( units == FG_UNITS_FEET ) {
624             altitude = atof( arg.substr(11) ) * FEET_TO_METER;
625         } else {
626             altitude = atof( arg.substr(11) );
627         }
628     } else if ( arg.find( "--uBody=" ) != string::npos ) {
629         if ( units == FG_UNITS_FEET ) {
630             uBody = atof( arg.substr(8) );
631         } else {
632             uBody = atof( arg.substr(8) ) * FEET_TO_METER;
633         }
634     } else if ( arg.find( "--vBody=" ) != string::npos ) {
635         if ( units == FG_UNITS_FEET ) {
636             vBody = atof( arg.substr(8) );
637         } else {
638             vBody = atof( arg.substr(8) ) * FEET_TO_METER;
639         }
640     } else if ( arg.find( "--wBody=" ) != string::npos ) {
641         if ( units == FG_UNITS_FEET ) {
642             wBody = atof( arg.substr(8) );
643         } else {
644             wBody = atof( arg.substr(8) ) * FEET_TO_METER;
645         }
646     } else if ( arg.find( "--heading=" ) != string::npos ) {
647         heading = atof( arg.substr(10) );
648     } else if ( arg.find( "--roll=" ) != string::npos ) {
649         roll = atof( arg.substr(7) );
650     } else if ( arg.find( "--pitch=" ) != string::npos ) {
651         pitch = atof( arg.substr(8) );
652     } else if ( arg.find( "--fg-root=" ) != string::npos ) {
653         fg_root = arg.substr( 10 );
654     } else if ( arg.find( "--fdm=" ) != string::npos ) {
655         flight_model = parse_fdm( arg.substr(6) );
656     } else if ( arg.find( "--aircraft=" ) != string::npos ) {
657         aircraft = arg.substr(11);
658     } else if ( arg.find( "--model-hz=" ) != string::npos ) {
659         model_hz = atoi( arg.substr(11) );
660     } else if ( arg.find( "--speed=" ) != string::npos ) {
661         speed_up = atoi( arg.substr(8) );
662     } else if ( arg == "--fog-disable" ) {
663         fog = FG_FOG_DISABLED;  
664     } else if ( arg == "--fog-fastest" ) {
665         fog = FG_FOG_FASTEST;   
666     } else if ( arg == "--fog-nicest" ) {
667         fog = FG_FOG_NICEST;    
668     } else if ( arg == "--disable-clouds" ) {
669         clouds = false; 
670     } else if ( arg == "--enable-clouds" ) {
671         clouds = true;  
672     } else if ( arg.find( "--clouds-asl=" ) != string::npos ) {
673         if ( units == FG_UNITS_FEET ) {
674             clouds_asl = atof( arg.substr(13) ) * FEET_TO_METER;
675         } else {
676             clouds_asl = atof( arg.substr(13) );
677         }
678     } else if ( arg.find( "--fov=" ) != string::npos ) {
679         fov = parse_fov( arg.substr(6) );
680     } else if ( arg == "--disable-fullscreen" ) {
681         fullscreen = false;     
682     } else if ( arg== "--enable-fullscreen") {
683         fullscreen = true;      
684     } else if ( arg == "--shading-flat") {
685         shading = 0;    
686     } else if ( arg == "--shading-smooth") {
687         shading = 1;    
688     } else if ( arg == "--disable-skyblend") {
689         skyblend = false;       
690     } else if ( arg== "--enable-skyblend" ) {
691         skyblend = true;        
692     } else if ( arg == "--disable-textures" ) {
693         textures = false;       
694     } else if ( arg == "--enable-textures" ) {
695         textures = true;
696     } else if ( arg == "--disable-wireframe" ) {
697         wireframe = false;      
698     } else if ( arg == "--enable-wireframe" ) {
699         wireframe = true;
700     } else if ( arg.find( "--geometry=" ) != string::npos ) {
701         bool geometry_ok = true;
702         string geometry = arg.substr( 11 );
703         string::size_type i = geometry.find('x');
704
705         if (i != string::npos) {
706             xsize = atoi(geometry.substr(0, i));
707             ysize = atoi(geometry.substr(i+1));
708             // cout << "Geometry is " << xsize << 'x' << ysize << '\n';
709         } else {
710             geometry_ok = false;
711         }
712
713         if ( xsize <= 0 || ysize <= 0 ) {
714             xsize = 640;
715             ysize = 480;
716             geometry_ok = false;
717         }
718
719         if ( !geometry_ok ) {
720             FG_LOG( FG_GENERAL, FG_ALERT, "Unknown geometry: " << geometry );
721             FG_LOG( FG_GENERAL, FG_ALERT,
722                     "Setting geometry to " << xsize << 'x' << ysize << '\n');
723         }
724     } else if ( arg == "--units-feet" ) {
725         units = FG_UNITS_FEET;  
726     } else if ( arg == "--units-meters" ) {
727         units = FG_UNITS_METERS;        
728     } else if ( arg.find( "--tile-radius=" ) != string::npos ) {
729         tile_radius = parse_tile_radius( arg.substr(14) );
730         tile_diameter = tile_radius * 2 + 1;
731     } else if ( arg.find( "--time-offset" ) != string::npos ) {
732         time_offset = parse_time_offset( (arg.substr(14)) );
733         //time_offset_type = FG_TIME_SYS_OFFSET;
734     } else if ( arg.find( "--time-match-real") != string::npos ) {
735       //time_offset = parse_time_offset(arg.substr(18));
736         time_offset_type = FG_TIME_SYS_OFFSET;
737     } else if ( arg.find( "--time-match-local") != string::npos ) {
738       //time_offset = parse_time_offset(arg.substr(18));
739         time_offset_type = FG_TIME_LAT_OFFSET;
740     } else if ( arg.find( "--start-date-sys=") != string::npos ) {
741         time_offset = parse_date( (arg.substr(17)) );
742         time_offset_type = FG_TIME_SYS_ABSOLUTE;
743     } else if ( arg.find( "--start-date-lat=") != string::npos ) {
744         time_offset = parse_date( (arg.substr(17)) );
745         time_offset_type = FG_TIME_LAT_ABSOLUTE;
746     } else if ( arg.find( "--start-date-gmt=") != string::npos ) {
747         time_offset = parse_date( (arg.substr(17)) );
748         time_offset_type = FG_TIME_GMT_ABSOLUTE;
749
750     } else if ( arg == "--hud-tris" ) {
751         tris_or_culled = 0;     
752     } else if ( arg == "--hud-culled" ) {
753         tris_or_culled = 1;
754     } else if ( arg.find( "--native=" ) != string::npos ) {
755         parse_channel( "native", arg.substr(9) );
756     } else if ( arg.find( "--garmin=" ) != string::npos ) {
757         parse_channel( "garmin", arg.substr(9) );
758     } else if ( arg.find( "--nmea=" ) != string::npos ) {
759         parse_channel( "nmea", arg.substr(7) );
760     } else if ( arg.find( "--pve=" ) != string::npos ) {
761         parse_channel( "pve", arg.substr(6) );
762     } else if ( arg.find( "--rul=" ) != string::npos ) {
763         parse_channel( "rul", arg.substr(6) );
764 #ifdef FG_NETWORK_OLK
765     } else if ( arg == "--net-hud" ) {
766         net_hud_display = 1;    
767     } else if ( arg.find( "--net-id=") != string::npos ) {
768         net_id = arg.substr( 9 );
769 #endif
770     } else {
771         FG_LOG( FG_GENERAL, FG_ALERT, "Unknown option '" << arg << "'" );
772         return FG_OPTIONS_ERROR;
773     }
774     
775     return FG_OPTIONS_OK;
776 }
777
778
779 // Parse the command line options
780 int fgOPTIONS::parse_command_line( int argc, char **argv ) {
781     int i = 1;
782     int result;
783
784     FG_LOG(FG_GENERAL, FG_INFO, "Processing command line arguments");
785
786     while ( i < argc ) {
787         FG_LOG( FG_GENERAL, FG_DEBUG, "argv[" << i << "] = " << argv[i] );
788
789         result = parse_option(argv[i]);
790         if ( (result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR) ) {
791             return(result);
792         }
793
794         i++;
795     }
796     
797     return(FG_OPTIONS_OK);
798 }
799
800
801 // Parse config file options
802 int fgOPTIONS::parse_config_file( const string& path ) {
803     fg_gzifstream in( path );
804     if ( !in.is_open() )
805         return(FG_OPTIONS_ERROR);
806
807     FG_LOG( FG_GENERAL, FG_INFO, "Processing config file: " << path );
808
809     in >> skipcomment;
810 #ifndef __MWERKS__
811     while ( ! in.eof() ) {
812 #else
813     char c = '\0';
814     while ( in.get(c) && c != '\0' ) {
815         in.putback(c);
816 #endif
817         string line;
818
819 #ifdef GETLINE_NEEDS_TERMINATOR
820         getline( in, line, '\n' );
821 #elif defined (MACOS)
822         getline( in, line, '\r' );
823 #else
824         getline( in, line );
825 #endif
826
827         if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
828             FG_LOG( FG_GENERAL, FG_ALERT, 
829                     "Config file parse error: " << path << " '" 
830                     << line << "'" );
831             exit(-1);
832         }
833         in >> skipcomment;
834     }
835
836     return FG_OPTIONS_OK;
837 }
838
839
840 // Print usage message
841 void fgOPTIONS::usage ( void ) {
842     cout << "Usage: fg [ options ... ]" << endl;
843     cout << endl;
844
845     cout << "General Options:" << endl;
846     cout << "\t--help -h:  print usage" << endl;
847     cout << "\t--fg-root=path:  specify the root path for all the data files"
848          << endl;
849     cout << "\t--disable-game-mode:  disable full-screen game mode" << endl;
850     cout << "\t--enable-game-mode:  enable full-screen game mode" << endl;
851     cout << "\t--disable-splash-screen:  disable splash screen" << endl;
852     cout << "\t--enable-splash-screen:  enable splash screen" << endl;
853     cout << "\t--disable-intro-music:  disable introduction music" << endl;
854     cout << "\t--enable-intro-music:  enable introduction music" << endl;
855     cout << "\t--disable-mouse-pointer:  disable extra mouse pointer" << endl;
856     cout << "\t--enable-mouse-pointer:  enable extra mouse pointer (i.e. for"
857          << endl;
858     cout << "\t\tfull screen voodoo/voodoo-II based cards.)" << endl;
859     cout << "\t--disable-pause:  start out in an active state" << endl;
860     cout << "\t--enable-pause:  start out in a paused state" << endl;
861     cout << "\t--control=mode:  primary control mode " 
862          << "(joystick, keyboard, mouse)" << endl;
863     cout << endl;
864
865     cout << "Features:" << endl;
866     cout << "\t--disable-hud:  disable heads up display" << endl;
867     cout << "\t--enable-hud:  enable heads up display" << endl;
868     cout << "\t--disable-panel:  disable instrument panel" << endl;
869     cout << "\t--enable-panel:  enable instrumetn panel" << endl;
870     cout << "\t--disable-sound:  disable sound effects" << endl;
871     cout << "\t--enable-sound:  enable sound effects" << endl;
872     cout << endl;
873  
874     cout << "Flight Model:" << endl;
875     cout << "\t--fdm=abcd:  selects the core flight model code." << endl;
876     cout << "\t\tcan be one of jsb, larcsim, magic, or external" << endl;
877     cout << "\t--aircraft=abcd:  aircraft model to load" << endl;
878     cout << "\t--model-hz=n:  run the FDM this rate (iterations per second)" 
879          << endl;
880     cout << "\t--speed=n:  run the FDM this much faster than real time" << endl;
881     cout << endl;
882
883     cout << "Initial Position and Orientation:" << endl;
884     cout << "\t--airport-id=ABCD:  specify starting postion by airport id" 
885          << endl;
886     cout << "\t--lon=degrees:  starting longitude in degrees (west = -)" 
887          << endl;
888     cout << "\t--lat=degrees:  starting latitude in degrees (south = -)"
889          << endl;
890     cout << "\t--altitude=feet:  starting altitude in feet" << endl;
891     cout << "\t\t(unless --units-meters specified" << endl;
892     cout << "\t--heading=degrees:  heading (yaw) angle in degress (Psi)"
893          << endl;
894     cout << "\t--roll=degrees:  roll angle in degrees (Phi)" << endl;
895     cout << "\t--pitch=degrees:  pitch angle in degrees (Theta)" << endl;
896     cout << "\t--uBody=feet per second:  velocity along the body X axis"
897          << endl;
898     cout << "\t--vBody=feet per second:  velocity along the body Y axis"
899          << endl;
900     cout << "\t--wBody=feet per second:  velocity along the body Z axis"
901          << endl;
902     cout << "\t\t(unless --units-meters specified" << endl;
903     cout << endl;
904
905     cout << "Rendering Options:" << endl;
906     cout << "\t--fog-disable:  disable fog/haze" << endl;
907     cout << "\t--fog-fastest:  enable fastest fog/haze" << endl;
908     cout << "\t--fog-nicest:  enable nicest fog/haze" << endl;
909     cout << "\t--enable-clouds:  enable demo cloud layer" << endl;
910     cout << "\t--disable-clouds:  disable demo cloud layer" << endl;
911     cout << "\t--clouds-asl=xxx:  specify altitude of cloud layer above sea level" << endl;
912     cout << "\t--fov=xx.x:  specify initial field of view angle in degrees"
913          << endl;
914     cout << "\t--disable-fullscreen:  disable fullscreen mode" << endl;
915     cout << "\t--enable-fullscreen:  enable fullscreen mode" << endl;
916     cout << "\t--shading-flat:  enable flat shading" << endl;
917     cout << "\t--shading-smooth:  enable smooth shading" << endl;
918     cout << "\t--disable-skyblend:  disable sky blending" << endl;
919     cout << "\t--enable-skyblend:  enable sky blending" << endl;
920     cout << "\t--disable-textures:  disable textures" << endl;
921     cout << "\t--enable-textures:  enable textures" << endl;
922     cout << "\t--disable-wireframe:  disable wireframe drawing mode" << endl;
923     cout << "\t--enable-wireframe:  enable wireframe drawing mode" << endl;
924     cout << "\t--geometry=WWWxHHH:  window geometry: 640x480, 800x600, etc."
925          << endl;
926     cout << endl;
927
928     cout << "Scenery Options:" << endl;
929     cout << "\t--tile-radius=n:  specify tile radius, must be 1 - 4" << endl;
930     cout << endl;
931
932     cout << "Hud Options:" << endl;
933     cout << "\t--units-feet:  Hud displays units in feet" << endl;
934     cout << "\t--units-meters:  Hud displays units in meters" << endl;
935     cout << "\t--hud-tris:  Hud displays number of triangles rendered" << endl;
936     cout << "\t--hud-culled:  Hud displays percentage of triangles culled"
937          << endl;
938     cout << endl;
939         
940     cout << "Time Options:" << endl;
941     cout << "\t--time-offset=[+-]hh:mm:ss: add this time offset" << endl;
942     cout << "\t--time-match-real: Synchronize real-world and FlightGear" << endl
943          << "\t\ttime. Can be used in combination with --time-offset." << endl;
944     cout << "\t--time-match-local:Synchronize local real-world and " << endl
945          << "\t\tFlightGear time" << endl;   
946     cout << "\t--start-date-sys=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
947          << "\t\tdate/time. Uses your system time " << endl;
948     cout << "\t--start-date-gmt=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
949          << "\t\tdate/time. Uses Greenwich Mean Time" << endl;
950     cout << "\t--start-date-lat=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
951          << "\t\tdate/time. Uses Local Aircraft Time" << endl;
952 #ifdef FG_NETWORK_OLK
953     cout << "" << endl;
954
955     cout << "Network Options:" << endl;
956     cout << "\t--net-hud:  Hud displays network info" << endl;
957     cout << "\t--net-id=name:  specify your own callsign" << endl;
958 #endif
959 }
960
961
962 // Destructor
963 fgOPTIONS::~fgOPTIONS( void ) {
964 }