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