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