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