]> git.mxchange.org Git - flightgear.git/blob - src/Main/options.cxx
e904e2747084ab77d41bd026144167189f0aa00b
[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 <Include/fg_constants.h>
42 #include <Include/general.hxx>
43 #include <Cockpit/cockpit.hxx>
44 #include <Debug/logstream.hxx>
45 #include <FDM/flight.hxx>
46 #include <Misc/fgstream.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     fov(55.0),
171     fullscreen(0),
172     shading(1),
173     skyblend(1),
174     textures(1),
175     wireframe(0),
176     xsize(640),
177     ysize(480),
178     view_mode(FG_VIEW_FIRST_PERSON),
179
180     // Scenery options
181     tile_diameter(5),
182
183     // HUD options
184     units(FG_UNITS_FEET),
185     tris_or_culled(0),
186         
187     // Time options
188     time_offset(0)
189 {
190     // set initial values/defaults
191     time_offset_type=FG_TIME_SYS_OFFSET;
192     char* envp = ::getenv( "FG_ROOT" );
193
194     if ( envp != NULL ) {
195         // fg_root could be anywhere, so default to environmental
196         // variable $FG_ROOT if it is set.
197         fg_root = envp;
198     } else {
199         // Otherwise, default to a random compiled in location if
200         // $FG_ROOT is not set.  This can still be overridden from the
201         // command line or a config file.
202
203 #if defined( WIN32 )
204         fg_root = "\\FlightGear";
205 #elif defined( MACOS )
206         fg_root = "";
207 #else
208         fg_root = PKGLIBDIR;
209 #endif
210     }
211
212     airport_id = "";            // default airport id
213     net_id = "Johnney";         // default pilot's name
214
215     // initialize port config string list
216     port_options_list.erase ( port_options_list.begin(), 
217                               port_options_list.end() );
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 == "slew" ) {
501         return FGInterface::FG_SLEW;
502     } else if ( fm == "jsb" ) {
503         return FGInterface::FG_JSBSIM;
504     } else if ( (fm == "larcsim") || (fm == "LaRCsim") ) {
505         return FGInterface::FG_LARCSIM;
506     } else if ( fm == "external" ) {
507         return FGInterface::FG_EXTERNAL;
508     } else {
509         FG_LOG( FG_GENERAL, FG_ALERT, "Unknown fdm = " << fm );
510         exit(-1);
511     }
512
513     // we'll never get here, but it makes the compiler happy.
514     return -1;
515 }
516
517
518 // Parse --fov=x.xx type option 
519 double
520 fgOPTIONS::parse_fov( const string& arg ) {
521     double fov = atof(arg);
522
523     if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
524     if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
525
526     // printf("parse_fov(): result = %.4f\n", fov);
527
528     return(fov);
529 }
530
531
532 // Parse serial port option --serial=/dev/ttyS1,nmea,4800,out
533 //
534 // Format is "--serial=device,format,baud,direction" where
535 // 
536 //  device = OS device name to be open()'ed
537 //  format = {nmea, garmin,fgfs,rul,pve}
538 //  baud = {300, 1200, 2400, ..., 230400}
539 //  direction = {in, out, bi}
540
541 bool 
542 fgOPTIONS::parse_serial( const string& serial_str ) {
543     string::size_type pos;
544
545     // cout << "Serial string = " << serial_str << endl;
546
547     // a flailing attempt to see if the port config string has a
548     // chance at being valid
549     pos = serial_str.find(",");
550     if ( pos == string::npos ) {
551         FG_LOG( FG_GENERAL, FG_ALERT, 
552                 "Malformed serial port configure string" );
553         return false;
554     }
555     
556     port_options_list.push_back( serial_str );
557
558     return true;
559 }
560
561
562 // Parse a single option
563 int fgOPTIONS::parse_option( const string& arg ) {
564     // General Options
565     if ( (arg == "--help") || (arg == "-h") ) {
566         // help/usage request
567         return(FG_OPTIONS_HELP);
568     } else if ( arg == "--disable-game-mode") {
569         game_mode = false;
570     } else if ( arg == "--enable-game-mode" ) {
571         game_mode = true;
572     } else if ( arg == "--disable-splash-screen" ) {
573         splash_screen = false;
574     } else if ( arg == "--enable-splash-screen" ) {
575         splash_screen = true;
576     } else if ( arg == "--disable-intro-music" ) {
577         intro_music = false;
578     } else if ( arg == "--enable-intro-music" ) {
579         intro_music = true;
580     } else if ( arg == "--disable-mouse-pointer" ) {
581         mouse_pointer = 1;
582     } else if ( arg == "--enable-mouse-pointer" ) {
583         mouse_pointer = 2;
584     } else if ( arg == "--disable-pause" ) {
585         pause = false;  
586     } else if ( arg == "--enable-pause" ) {
587         pause = true;   
588     } else if ( arg.find( "--control=") != string::npos ) {
589         parse_control( arg.substr(10) );
590     } else if ( arg == "--disable-auto-coordination" ) {
591         auto_coordination = FG_AUTO_COORD_DISABLED;     
592     } else if ( arg == "--enable-auto-coordination" ) {
593         auto_coordination = FG_AUTO_COORD_ENABLED;      
594     } else if ( arg == "--disable-hud" ) {
595         hud_status = false;     
596     } else if ( arg == "--enable-hud" ) {
597         hud_status = true;      
598     } else if ( arg == "--disable-panel" ) {
599         panel_status = false;
600     } else if ( arg == "--enable-panel" ) {
601         panel_status = true;
602         fov *= 0.4232;
603     } else if ( arg == "--disable-sound" ) {
604         sound = false;
605     } else if ( arg == "--enable-sound" ) {
606         sound = true;
607     } else if ( arg.find( "--airport-id=") != string::npos ) {
608         airport_id = arg.substr( 13 );
609     } else if ( arg.find( "--lon=" ) != string::npos ) {
610         lon = parse_degree( arg.substr(6) );
611     } else if ( arg.find( "--lat=" ) != string::npos ) {
612         lat = parse_degree( arg.substr(6) );
613     } else if ( arg.find( "--altitude=" ) != string::npos ) {
614         if ( units == FG_UNITS_FEET ) {
615             altitude = atof( arg.substr(11) ) * FEET_TO_METER;
616         } else {
617             altitude = atof( arg.substr(11) );
618         }
619     } else if ( arg.find( "--uBody=" ) != string::npos ) {
620         if ( units == FG_UNITS_FEET ) {
621             uBody = atof( arg.substr(8) ) * FEET_TO_METER;
622         } else {
623             uBody = atof( arg.substr(8) );
624         }
625     } else if ( arg.find( "--vBody=" ) != string::npos ) {
626         if ( units == FG_UNITS_FEET ) {
627             vBody = atof( arg.substr(8) ) * FEET_TO_METER;
628         } else {
629             vBody = atof( arg.substr(8) );
630         }
631     } else if ( arg.find( "--wBody=" ) != string::npos ) {
632         if ( units == FG_UNITS_FEET ) {
633             wBody = atof( arg.substr(8) ) * FEET_TO_METER;
634         } else {
635             wBody = atof( arg.substr(8) );
636         }
637     } else if ( arg.find( "--heading=" ) != string::npos ) {
638         heading = atof( arg.substr(10) );
639     } else if ( arg.find( "--roll=" ) != string::npos ) {
640         roll = atof( arg.substr(7) );
641     } else if ( arg.find( "--pitch=" ) != string::npos ) {
642         pitch = atof( arg.substr(8) );
643     } else if ( arg.find( "--fg-root=" ) != string::npos ) {
644         fg_root = arg.substr( 10 );
645     } else if ( arg.find( "--fdm=" ) != string::npos ) {
646         flight_model = parse_fdm( arg.substr(6) );
647     } else if ( arg.find( "--model-hz=" ) != string::npos ) {
648         model_hz = atoi( arg.substr(11) );
649     } else if ( arg.find( "--speed=" ) != string::npos ) {
650         speed_up = atoi( arg.substr(8) );
651     } else if ( arg == "--fog-disable" ) {
652         fog = FG_FOG_DISABLED;  
653     } else if ( arg == "--fog-fastest" ) {
654         fog = FG_FOG_FASTEST;   
655     } else if ( arg == "--fog-nicest" ) {
656         fog = FG_FOG_NICEST;    
657     } else if ( arg.find( "--fov=" ) != string::npos ) {
658         fov = parse_fov( arg.substr(6) );
659     } else if ( arg == "--disable-fullscreen" ) {
660         fullscreen = false;     
661     } else if ( arg== "--enable-fullscreen") {
662         fullscreen = true;      
663     } else if ( arg == "--shading-flat") {
664         shading = 0;    
665     } else if ( arg == "--shading-smooth") {
666         shading = 1;    
667     } else if ( arg == "--disable-skyblend") {
668         skyblend = false;       
669     } else if ( arg== "--enable-skyblend" ) {
670         skyblend = true;        
671     } else if ( arg == "--disable-textures" ) {
672         textures = false;       
673     } else if ( arg == "--enable-textures" ) {
674         textures = true;
675     } else if ( arg == "--disable-wireframe" ) {
676         wireframe = false;      
677     } else if ( arg == "--enable-wireframe" ) {
678         wireframe = true;
679     } else if ( arg.find( "--geometry=" ) != string::npos ) {
680         bool geometry_ok = true;
681         string geometry = arg.substr( 11 );
682         string::size_type i = geometry.find('x');
683
684         if (i != string::npos) {
685             xsize = atoi(geometry.substr(0, i));
686             ysize = atoi(geometry.substr(i+1));
687             // cout << "Geometry is " << xsize << 'x' << ysize << '\n';
688         } else {
689             geometry_ok = false;
690         }
691
692         if ( xsize <= 0 || ysize <= 0 ) {
693             xsize = 640;
694             ysize = 480;
695             geometry_ok = false;
696         }
697
698         if ( !geometry_ok ) {
699             FG_LOG( FG_GENERAL, FG_ALERT, "Unknown geometry: " << geometry );
700             FG_LOG( FG_GENERAL, FG_ALERT,
701                     "Setting geometry to " << xsize << 'x' << ysize << '\n');
702         }
703     } else if ( arg == "--units-feet" ) {
704         units = FG_UNITS_FEET;  
705     } else if ( arg == "--units-meters" ) {
706         units = FG_UNITS_METERS;        
707     } else if ( arg.find( "--tile-radius=" ) != string::npos ) {
708         tile_radius = parse_tile_radius( arg.substr(14) );
709         tile_diameter = tile_radius * 2 + 1;
710     } else if ( arg.find( "--time-offset-sys=" ) != string::npos ) {
711         time_offset = parse_time_offset( (arg.substr(18)) );
712         time_offset_type = FG_TIME_SYS_OFFSET;
713     } else if ( arg.find( "--time-offset-lat=") != string::npos ) {
714         time_offset = parse_time_offset(arg.substr(18));
715         time_offset_type = FG_TIME_LAT_OFFSET;
716     } else if ( arg.find( "--time-offset-gmt=") != string::npos ) {
717         time_offset = parse_time_offset(arg.substr(18));
718         time_offset_type = FG_TIME_GMT_OFFSET;
719     } else if ( arg.find( "--start-date-sys=") != string::npos ) {
720         time_offset = parse_date( (arg.substr(17)) );
721         time_offset_type = FG_TIME_SYS_ABSOLUTE;
722     } else if ( arg.find( "--start-date-lat=") != string::npos ) {
723         time_offset = parse_date( (arg.substr(17)) );
724         time_offset_type = FG_TIME_LAT_ABSOLUTE;
725     } else if ( arg.find( "--start-date-gmt=") != string::npos ) {
726         time_offset = parse_date( (arg.substr(17)) );
727         time_offset_type = FG_TIME_GMT_ABSOLUTE;
728
729     } else if ( arg == "--hud-tris" ) {
730         tris_or_culled = 0;     
731     } else if ( arg == "--hud-culled" ) {
732         tris_or_culled = 1;
733     } else if ( arg.find( "--serial=" ) != string::npos ) {
734         parse_serial( arg.substr(9) );
735 #ifdef FG_NETWORK_OLK
736     } else if ( arg == "--net-hud" ) {
737         net_hud_display = 1;    
738     } else if ( arg.find( "--net-id=") != string::npos ) {
739         net_id = arg.substr( 9 );
740 #endif
741     } else {
742         FG_LOG( FG_GENERAL, FG_ALERT, "Unknown option '" << arg << "'" );
743         return FG_OPTIONS_ERROR;
744     }
745     
746     return FG_OPTIONS_OK;
747 }
748
749
750 // Parse the command line options
751 int fgOPTIONS::parse_command_line( int argc, char **argv ) {
752     int i = 1;
753     int result;
754
755     FG_LOG(FG_GENERAL, FG_INFO, "Processing command line arguments");
756
757     while ( i < argc ) {
758         FG_LOG( FG_GENERAL, FG_DEBUG, "argv[" << i << "] = " << argv[i] );
759
760         result = parse_option(argv[i]);
761         if ( (result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR) ) {
762             return(result);
763         }
764
765         i++;
766     }
767     
768     return(FG_OPTIONS_OK);
769 }
770
771
772 // Parse config file options
773 int fgOPTIONS::parse_config_file( const string& path ) {
774     fg_gzifstream in( path );
775     if ( !in.is_open() )
776         return(FG_OPTIONS_ERROR);
777
778     FG_LOG( FG_GENERAL, FG_INFO, "Processing config file: " << path );
779
780     in >> skipcomment;
781 #ifndef __MWERKS__
782     while ( ! in.eof() ) {
783 #else
784     char c = '\0';
785     while ( in.get(c) && c != '\0' ) {
786         in.putback(c);
787 #endif
788         string line;
789
790 #ifdef GETLINE_NEEDS_TERMINATOR
791         getline( in, line, '\n' );
792 #else
793         getline( in, line );
794 #endif
795
796         if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
797             FG_LOG( FG_GENERAL, FG_ALERT, 
798                     "Config file parse error: " << path << " '" 
799                     << line << "'" );
800             exit(-1);
801         }
802         in >> skipcomment;
803     }
804
805     return FG_OPTIONS_OK;
806 }
807
808
809 // Print usage message
810 void fgOPTIONS::usage ( void ) {
811     cout << "Usage: fg [ options ... ]" << endl;
812     cout << endl;
813
814     cout << "General Options:" << endl;
815     cout << "\t--help -h:  print usage" << endl;
816     cout << "\t--fg-root=path:  specify the root path for all the data files"
817          << endl;
818     cout << "\t--disable-game-mode:  disable full-screen game mode" << endl;
819     cout << "\t--enable-game-mode:  enable full-screen game mode" << endl;
820     cout << "\t--disable-splash-screen:  disable splash screen" << endl;
821     cout << "\t--enable-splash-screen:  enable splash screen" << endl;
822     cout << "\t--disable-intro-music:  disable introduction music" << endl;
823     cout << "\t--enable-intro-music:  enable introduction music" << endl;
824     cout << "\t--disable-mouse-pointer:  disable extra mouse pointer" << endl;
825     cout << "\t--enable-mouse-pointer:  enable extra mouse pointer (i.e. for"
826          << endl;
827     cout << "\t\tfull screen voodoo/voodoo-II based cards.)" << endl;
828     cout << "\t--disable-pause:  start out in an active state" << endl;
829     cout << "\t--enable-pause:  start out in a paused state" << endl;
830     cout << "\t--control=mode:  primary control mode " 
831          << "(joystick, keyboard, mouse)" << endl;
832     cout << endl;
833
834     cout << "Features:" << endl;
835     cout << "\t--disable-hud:  disable heads up display" << endl;
836     cout << "\t--enable-hud:  enable heads up display" << endl;
837     cout << "\t--disable-panel:  disable instrument panel" << endl;
838     cout << "\t--enable-panel:  enable instrumetn panel" << endl;
839     cout << "\t--disable-sound:  disable sound effects" << endl;
840     cout << "\t--enable-sound:  enable sound effects" << endl;
841     cout << endl;
842  
843     cout << "Flight Model:" << endl;
844     cout << "\t--fdm=abcd:  one of slew, jsb, larcsim, or external" << endl;
845     cout << "\t--model-hz=n:  run the FDM this rate (iterations per second)" 
846          << endl;
847     cout << "\t--speed=n:  run the FDM this much faster than real time" << endl;
848     cout << endl;
849
850     cout << "Initial Position and Orientation:" << endl;
851     cout << "\t--airport-id=ABCD:  specify starting postion by airport id" 
852          << endl;
853     cout << "\t--lon=degrees:  starting longitude in degrees (west = -)" 
854          << endl;
855     cout << "\t--lat=degrees:  starting latitude in degrees (south = -)"
856          << endl;
857     cout << "\t--altitude=feet:  starting altitude in feet" << endl;
858     cout << "\t\t(unless --units-meters specified" << endl;
859     cout << "\t--heading=degrees:  heading (yaw) angle in degress (Psi)"
860          << endl;
861     cout << "\t--roll=degrees:  roll angle in degrees (Phi)" << endl;
862     cout << "\t--pitch=degrees:  pitch angle in degrees (Theta)" << endl;
863     cout << "\t--uBody=feet per second:  velocity along the body X axis"
864          << endl;
865     cout << "\t--vBody=feet per second:  velocity along the body Y axis"
866          << endl;
867     cout << "\t--wBody=feet per second:  velocity along the body Z axis"
868          << endl;
869     cout << "\t\t(unless --units-meters specified" << endl;
870     cout << endl;
871
872     cout << "Rendering Options:" << endl;
873     cout << "\t--fog-disable:  disable fog/haze" << endl;
874     cout << "\t--fog-fastest:  enable fastest fog/haze" << endl;
875     cout << "\t--fog-nicest:  enable nicest fog/haze" << endl;
876     cout << "\t--fov=xx.x:  specify initial field of view angle in degrees"
877          << endl;
878     cout << "\t--disable-fullscreen:  disable fullscreen mode" << endl;
879     cout << "\t--enable-fullscreen:  enable fullscreen mode" << endl;
880     cout << "\t--shading-flat:  enable flat shading" << endl;
881     cout << "\t--shading-smooth:  enable smooth shading" << endl;
882     cout << "\t--disable-skyblend:  disable sky blending" << endl;
883     cout << "\t--enable-skyblend:  enable sky blending" << endl;
884     cout << "\t--disable-textures:  disable textures" << endl;
885     cout << "\t--enable-textures:  enable textures" << endl;
886     cout << "\t--disable-wireframe:  disable wireframe drawing mode" << endl;
887     cout << "\t--enable-wireframe:  enable wireframe drawing mode" << endl;
888     cout << "\t--geometry=WWWxHHH:  window geometry: 640x480, 800x600, etc."
889          << endl;
890     cout << endl;
891
892     cout << "Scenery Options:" << endl;
893     cout << "\t--tile-radius=n:  specify tile radius, must be 1 - 4" << endl;
894     cout << endl;
895
896     cout << "Hud Options:" << endl;
897     cout << "\t--units-feet:  Hud displays units in feet" << endl;
898     cout << "\t--units-meters:  Hud displays units in meters" << endl;
899     cout << "\t--hud-tris:  Hud displays number of triangles rendered" << endl;
900     cout << "\t--hud-culled:  Hud displays percentage of triangles culled"
901          << endl;
902     cout << endl;
903         
904     cout << "Time Options:" << endl;
905     cout << "\t--time-offset-sys=[+-]hh:mm:ss: add this time offset to" << endl
906          << "\t\tyour system time" << endl;
907     cout << "\t--time-offset-gmt:[+-]hh:mm:ss: add this time offset to" << endl
908          << "\t\tGreenwich Mean Time (GMT)" << endl;
909     cout << "\t--time-offset-lat:[+-]hh:mm:ss: add this time offset to" << endl
910          << "\t\tLocal Aircraft Time (LAT)" << endl;   
911     cout << "\t--start-date-sys=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
912          << "\t\tdate/time. Uses your system time " << endl;
913     cout << "\t--start-date-gmt=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
914          << "\t\tdate/time. Uses Greenwich Mean Time" << endl;
915     cout << "\t--start-date-lat=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
916          << "\t\tdate/time. Uses Local Aircraft Time" << endl;
917 #ifdef FG_NETWORK_OLK
918     cout << "" << endl;
919
920     cout << "Network Options:" << endl;
921     cout << "\t--net-hud:  Hud displays network info" << endl;
922     cout << "\t--net-id=name:  specify your own callsign" << endl;
923 #endif
924 }
925
926
927 // Destructor
928 fgOPTIONS::~fgOPTIONS( void ) {
929 }