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