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