]> git.mxchange.org Git - flightgear.git/blob - src/Main/options.cxx
Fixed --enable-freeze.
[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 #include <simgear/compiler.h>
29
30 #include <math.h>            // rint()
31 #include <stdio.h>
32 #include <stdlib.h>          // atof(), atoi()
33 #include <string.h>
34
35 #include STL_STRING
36
37 #include <simgear/misc/fgstream.hxx>
38
39 // #include <Include/general.hxx>
40 // #include <Airports/simple.hxx>
41 // #include <Cockpit/cockpit.hxx>
42 // #include <FDM/flight.hxx>
43 // #include <FDM/UIUCModel/uiuc_aircraftdir.h>
44 #ifdef FG_NETWORK_OLK
45 #  include <NetworkOLK/network.h>
46 #endif
47
48 #include "globals.hxx"
49 #include "fg_init.hxx"
50 #include "fg_props.hxx"
51 #include "options.hxx"
52
53 FG_USING_STD(string);
54 FG_USING_NAMESPACE(std);
55
56
57 #define NEW_DEFAULT_MODEL_HZ 120
58
59 enum
60 {
61     FG_OPTIONS_OK = 0,
62     FG_OPTIONS_HELP = 1,
63     FG_OPTIONS_ERROR = 2
64 };
65
66 static double
67 atof( const string& str )
68 {
69
70 #ifdef __MWERKS__ 
71     // -dw- if ::atof is called, then we get an infinite loop
72     return std::atof( str.c_str() );
73 #else
74     return ::atof( str.c_str() );
75 #endif
76 }
77
78 static int
79 atoi( const string& str )
80 {
81 #ifdef __MWERKS__ 
82     // -dw- if ::atoi is called, then we get an infinite loop
83     return std::atoi( str.c_str() );
84 #else
85     return ::atoi( str.c_str() );
86 #endif
87 }
88
89
90 /**
91  * Set a few fail-safe default property values.
92  *
93  * These should all be set in $FG_ROOT/preferences.xml, but just
94  * in case, we provide some initial sane values here. This method 
95  * should be invoked *before* reading any init files.
96  */
97 void
98 fgSetDefaults ()
99 {
100     // set a possibly independent location for scenery data
101     char *envp = ::getenv( "FG_SCENERY" );
102
103     if ( envp != NULL ) {
104         // fg_root could be anywhere, so default to environmental
105         // variable $FG_ROOT if it is set.
106         globals->set_fg_scenery(envp);
107     } else {
108         // Otherwise, default to Scenery being in $FG_ROOT/Scenery
109         globals->set_fg_scenery("");
110     }
111                                 // Position (Globe, AZ)
112     fgSetDouble("/position/longitude", -110.6642444);
113     fgSetDouble("/position/latitude", 33.3528917);
114     fgSetDouble("/position/altitude", -9999.0);
115
116                                 // Orientation
117     fgSetDouble("/orientation/heading", 270);
118     fgSetDouble("/orientation/roll", 0);
119     fgSetDouble("/orientation/pitch", 0.424);
120
121                                 // Velocities
122     fgSetString("/sim/startup/speed-set", "knots");
123     fgSetDouble("/velocities/uBody", 0.0);
124     fgSetDouble("/velocities/vBody", 0.0);
125     fgSetDouble("/velocities/wBody", 0.0);
126     fgSetDouble("/velocities/speed-north", 0.0);
127     fgSetDouble("/velocities/speed-east", 0.0);
128     fgSetDouble("/velocities/speed-down", 0.0);
129     fgSetDouble("/velocities/airspeed", 0.0);
130     fgSetDouble("/velocities/mach", 0.0);
131
132                                 // Miscellaneous
133     fgSetBool("/sim/startup/game-mode", false);
134     fgSetBool("/sim/startup/splash-screen", true);
135     fgSetBool("/sim/startup/intro-music", true);
136     fgSetString("/sim/startup/mouse-pointer", "disabled");
137     fgSetString("/sim/control-mode", "joystick");
138     fgSetBool("/sim/auto-coordination", false);
139
140                                 // Features
141     fgSetBool("/sim/hud/visibility", false);
142     fgSetBool("/sim/panel/visibility", true);
143     fgSetBool("/sim/sound", true);
144     fgSetBool("/sim/hud/antialiased", false);
145
146                                 // Flight Model options
147     fgSetString("/sim/flight-model", "larcsim");
148     fgSetString("/sim/aircraft", "c172");
149     fgSetInt("/sim/model-hz", NEW_DEFAULT_MODEL_HZ);
150     fgSetInt("/sim/speed-up", 1);
151     fgSetBool("/sim/startup/trim", false);
152     fgSetBool("/sim/startup/onground", true);
153
154                                 // Rendering options
155     fgSetString("/sim/rendering/fog", "nicest");
156     fgSetBool("/environment/clouds/status", true);
157     fgSetDouble("/environment/clouds/altitude", 5000);
158     fgSetBool("/sim/startup/fullscreen", false);
159     fgSetBool("/sim/rendering/shading", true);
160     fgSetBool("/sim/rendering/skyblend", true);
161     fgSetBool("/sim/rendering/textures", true);
162     fgSetBool("/sim/rendering/wireframe", false);
163     fgSetInt("/sim/startup/xsize", 800);
164     fgSetInt("/sim/startup/ysize", 600);
165     fgSetInt("/sim/rendering/bits-per-pixel", 16);
166     fgSetString("/sim/view-mode", "pilot");
167     fgSetDouble("/sim/startup/view-offset", 0);
168     fgSetDouble("/environment/visibility", 20000);
169
170                                 // HUD options
171     fgSetString("/sim/startup/units", "feet");
172     fgSetString("/sim/hud/frame-stat-type", "tris");
173         
174                                 // Time options
175     fgSetInt("/sim/startup/time-offset", 0);
176     fgSetString("/sim/startup/time-offset-type", "system-offset");
177
178     fgSetBool("/sim/networking/network-olk", false);
179     fgSetString("/sim/networking/call-sign", "Johnny");
180 }
181
182 static double
183 parse_time(const string& time_in) {
184     char *time_str, num[256];
185     double hours, minutes, seconds;
186     double result = 0.0;
187     int sign = 1;
188     int i;
189
190     time_str = (char *)time_in.c_str();
191
192     // printf("parse_time(): %s\n", time_str);
193
194     // check for sign
195     if ( strlen(time_str) ) {
196         if ( time_str[0] == '+' ) {
197             sign = 1;
198             time_str++;
199         } else if ( time_str[0] == '-' ) {
200             sign = -1;
201             time_str++;
202         }
203     }
204     // printf("sign = %d\n", sign);
205
206     // get hours
207     if ( strlen(time_str) ) {
208         i = 0;
209         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
210             num[i] = time_str[0];
211             time_str++;
212             i++;
213         }
214         if ( time_str[0] == ':' ) {
215             time_str++;
216         }
217         num[i] = '\0';
218         hours = atof(num);
219         // printf("hours = %.2lf\n", hours);
220
221         result += hours;
222     }
223
224     // get minutes
225     if ( strlen(time_str) ) {
226         i = 0;
227         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
228             num[i] = time_str[0];
229             time_str++;
230             i++;
231         }
232         if ( time_str[0] == ':' ) {
233             time_str++;
234         }
235         num[i] = '\0';
236         minutes = atof(num);
237         // printf("minutes = %.2lf\n", minutes);
238
239         result += minutes / 60.0;
240     }
241
242     // get seconds
243     if ( strlen(time_str) ) {
244         i = 0;
245         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
246             num[i] = time_str[0];
247             time_str++;
248             i++;
249         }
250         num[i] = '\0';
251         seconds = atof(num);
252         // printf("seconds = %.2lf\n", seconds);
253
254         result += seconds / 3600.0;
255     }
256
257     return(sign * result);
258 }
259
260
261 static long int 
262 parse_date( const string& date)
263 {
264     struct tm gmt;
265     char * date_str, num[256];
266     int i;
267     // initialize to zero
268     gmt.tm_sec = 0;
269     gmt.tm_min = 0;
270     gmt.tm_hour = 0;
271     gmt.tm_mday = 0;
272     gmt.tm_mon = 0;
273     gmt.tm_year = 0;
274     gmt.tm_isdst = 0; // ignore daylight savings time for the moment
275     date_str = (char *)date.c_str();
276     // get year
277     if ( strlen(date_str) ) {
278         i = 0;
279         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
280             num[i] = date_str[0];
281             date_str++;
282             i++;
283         }
284         if ( date_str[0] == ':' ) {
285             date_str++;
286         }
287         num[i] = '\0';
288         gmt.tm_year = atoi(num) - 1900;
289     }
290     // get month
291     if ( strlen(date_str) ) {
292         i = 0;
293         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
294             num[i] = date_str[0];
295             date_str++;
296             i++;
297         }
298         if ( date_str[0] == ':' ) {
299             date_str++;
300         }
301         num[i] = '\0';
302         gmt.tm_mon = atoi(num) -1;
303     }
304     // get day
305     if ( strlen(date_str) ) {
306         i = 0;
307         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
308             num[i] = date_str[0];
309             date_str++;
310             i++;
311         }
312         if ( date_str[0] == ':' ) {
313             date_str++;
314         }
315         num[i] = '\0';
316         gmt.tm_mday = atoi(num);
317     }
318     // get hour
319     if ( strlen(date_str) ) {
320         i = 0;
321         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
322             num[i] = date_str[0];
323             date_str++;
324             i++;
325         }
326         if ( date_str[0] == ':' ) {
327             date_str++;
328         }
329         num[i] = '\0';
330         gmt.tm_hour = atoi(num);
331     }
332     // get minute
333     if ( strlen(date_str) ) {
334         i = 0;
335         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
336             num[i] = date_str[0];
337             date_str++;
338             i++;
339         }
340         if ( date_str[0] == ':' ) {
341             date_str++;
342         }
343         num[i] = '\0';
344         gmt.tm_min = atoi(num);
345     }
346     // get second
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_sec = atoi(num);
359     }
360     time_t theTime = sgTimeGetGMT( gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
361                                    gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
362     //printf ("Date is %s\n", ctime(&theTime));
363     //printf ("in seconds that is %d\n", theTime);
364     //exit(1);
365     return (theTime);
366 }
367
368
369 /// parse degree in the form of [+/-]hhh:mm:ss
370 static double
371 parse_degree( const string& degree_str) {
372     double result = parse_time( degree_str );
373
374     // printf("Degree = %.4f\n", result);
375
376     return(result);
377 }
378
379
380 // parse time offset command line option
381 static int
382 parse_time_offset( const string& time_str) {
383     int result;
384
385     // printf("time offset = %s\n", time_str);
386
387 #ifdef HAVE_RINT
388     result = (int)rint(parse_time(time_str) * 3600.0);
389 #else
390     result = (int)(parse_time(time_str) * 3600.0);
391 #endif
392
393     // printf("parse_time_offset(): %d\n", result);
394
395     return( result );
396 }
397
398
399 // Parse --fov=x.xx type option 
400 static double
401 parse_fov( const string& arg ) {
402     double fov = atof(arg);
403
404     if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
405     if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
406
407     fgSetDouble("/sim/field-of-view", fov);
408
409     // printf("parse_fov(): result = %.4f\n", fov);
410
411     return fov;
412 }
413
414
415 // Parse I/O channel option
416 //
417 // Format is "--protocol=medium,direction,hz,medium_options,..."
418 //
419 //   protocol = { native, nmea, garmin, fgfs, rul, pve, etc. }
420 //   medium = { serial, socket, file, etc. }
421 //   direction = { in, out, bi }
422 //   hz = number of times to process channel per second (floating
423 //        point values are ok.
424 //
425 // Serial example "--nmea=serial,dir,hz,device,baud" where
426 // 
427 //  device = OS device name of serial line to be open()'ed
428 //  baud = {300, 1200, 2400, ..., 230400}
429 //
430 // Socket exacmple "--native=socket,dir,hz,machine,port,style" where
431 // 
432 //  machine = machine name or ip address if client (leave empty if server)
433 //  port = port, leave empty to let system choose
434 //  style = tcp or udp
435 //
436 // File example "--garmin=file,dir,hz,filename" where
437 // 
438 //  filename = file system file name
439
440 static bool 
441 parse_channel( const string& type, const string& channel_str ) {
442     // cout << "Channel string = " << channel_str << endl;
443
444     globals->get_channel_options_list()->push_back( type + "," + channel_str );
445
446     return true;
447 }
448
449
450 // Parse --wp=ID[,alt]
451 static bool 
452 parse_wp( const string& arg ) {
453     string id, alt_str;
454     double alt = 0.0;
455
456     int pos = arg.find( "@" );
457     if ( pos != string::npos ) {
458         id = arg.substr( 0, pos );
459         alt_str = arg.substr( pos + 1 );
460         // cout << "id str = " << id << "  alt str = " << alt_str << endl;
461         alt = atof( alt_str.c_str() );
462         if ( fgGetString("/sim/startup/units") == "feet" ) {
463             alt *= FEET_TO_METER;
464         }
465     } else {
466         id = arg;
467     }
468
469     FGAirport a;
470     if ( fgFindAirportID( id, &a ) ) {
471         SGWayPoint wp( a.longitude, a.latitude, alt, SGWayPoint::WGS84, id );
472         globals->get_route()->add_waypoint( wp );
473
474         return true;
475     } else {
476         return false;
477     }
478 }
479
480
481 // Parse --flight-plan=[file]
482 static bool 
483 parse_flightplan(const string& arg)
484 {
485     fg_gzifstream infile(arg.c_str());
486     if (!infile) {
487         return false;
488     }
489     while ( true ) {
490         string line;
491 #ifdef GETLINE_NEEDS_TERMINATOR
492         getline( infile, line, '\n' );
493 #elif defined( macintosh )
494         getline( infile, line, '\r' );
495 #else
496         getline( infile, line );
497 #endif
498         if ( infile.eof() ) {
499             break;
500         }
501         parse_wp(line);
502     }
503
504     return true;
505 }
506
507
508 // Parse a single option
509 static int 
510 parse_option (const string& arg) 
511 {
512     // General Options
513     if ( (arg == "--help") || (arg == "-h") ) {
514         // help/usage request
515         return(FG_OPTIONS_HELP);
516     } else if ( arg == "--disable-game-mode") {
517         fgSetBool("/sim/startup/game-mode", false);
518     } else if ( arg == "--enable-game-mode" ) {
519         fgSetBool("/sim/startup/game-mode", true);
520     } else if ( arg == "--disable-splash-screen" ) {
521         fgSetBool("/sim/startup/splash-screen", false); 
522     } else if ( arg == "--enable-splash-screen" ) {
523         fgSetBool("/sim/startup/splash-screen", true);
524     } else if ( arg == "--disable-intro-music" ) {
525         fgSetBool("/sim/startup/intro-music", false);
526     } else if ( arg == "--enable-intro-music" ) {
527         fgSetBool("/sim/startup/intro-music", true);
528     } else if ( arg == "--disable-mouse-pointer" ) {
529         fgSetString("/sim/startup/mouse-pointer", "disabled");
530     } else if ( arg == "--enable-mouse-pointer" ) {
531         fgSetString("/sim/startup/mouse-pointer", "enabled");
532     } else if ( arg == "--disable-freeze" ) {
533         globals->set_freeze(false);
534     } else if ( arg == "--enable-freeze" ) {
535         globals->set_freeze(true);
536     } else if ( arg == "--disable-anti-alias-hud" ) {
537         fgSetBool("/sim/hud/antialiased", false);
538     } else if ( arg == "--enable-anti-alias-hud" ) {
539         fgSetBool("/sim/hud/antialiased", true);
540     } else if ( arg.find( "--control=") != string::npos ) {
541         fgSetString("/sim/control-mode", arg.substr(10));
542     } else if ( arg == "--disable-auto-coordination" ) {
543         fgSetBool("/sim/auto-coordination", false);
544     } else if ( arg == "--enable-auto-coordination" ) {
545         fgSetBool("/sim/auto-coordination", true);
546     } else if ( arg == "--disable-hud" ) {
547         fgSetBool("/sim/hud/visibility", false);
548     } else if ( arg == "--enable-hud" ) {
549         fgSetBool("/sim/hud/visibility", true);
550     } else if ( arg == "--disable-panel" ) {
551         fgSetBool("/sim/panel/visibility", false);
552     } else if ( arg == "--enable-panel" ) {
553         fgSetBool("/sim/panel/visibility", true);
554     } else if ( arg == "--disable-sound" ) {
555         fgSetBool("/sim/sound", false);
556     } else if ( arg == "--enable-sound" ) {
557         fgSetBool("/sim/sound", true);
558     } else if ( arg.find( "--airport-id=") != string::npos ) {
559                                 // NB: changed property name!!!
560         fgSetString("/sim/startup/airport-id", arg.substr(13));
561     } else if ( arg.find( "--lon=" ) != string::npos ) {
562         fgSetDouble("/position/longitude",
563                               parse_degree(arg.substr(6)));
564         fgSetString("/sim/startup/airport-id", "");
565     } else if ( arg.find( "--lat=" ) != string::npos ) {
566         fgSetDouble("/position/latitude",
567                               parse_degree(arg.substr(6)));
568         fgSetString("/sim/startup/airport-id", "");
569     } else if ( arg.find( "--altitude=" ) != string::npos ) {
570         fgSetBool("/sim/startup/onground", false);
571         if ( fgGetString("/sim/startup/units") == "feet" )
572             fgSetDouble("/position/altitude", atof(arg.substr(11)));
573         else
574             fgSetDouble("/position/altitude",
575                         atof(arg.substr(11)) * METER_TO_FEET);
576     } else if ( arg.find( "--uBody=" ) != string::npos ) {
577         fgSetString("/sim/startup/speed-set", "UVW");
578                                 // FIXME: the units are totally confused here
579         if ( fgGetString("/sim/startup/units") == "feet" )
580           fgSetDouble("/velocities/uBody", atof(arg.substr(8)));
581         else
582           fgSetDouble("/velocities/uBody",
583                                atof(arg.substr(8)) * FEET_TO_METER);
584     } else if ( arg.find( "--vBody=" ) != string::npos ) {
585         fgSetString("/sim/startup/speed-set", "UVW");
586                                 // FIXME: the units are totally confused here
587         if ( fgGetString("/sim/startup/units") == "feet" )
588           fgSetDouble("/velocities/vBody", atof(arg.substr(8)));
589         else
590           fgSetDouble("/velocities/vBody",
591                                atof(arg.substr(8)) * FEET_TO_METER);
592     } else if ( arg.find( "--wBody=" ) != string::npos ) {
593         fgSetString("/sim/startup/speed-set", "UVW");
594                                 // FIXME: the units are totally confused here
595         if ( fgGetString("/sim/startup/units") == "feet" )
596           fgSetDouble("/velocities/wBody", atof(arg.substr(8)));
597         else
598           fgSetDouble("/velocities/wBody",
599                                atof(arg.substr(8)) * FEET_TO_METER);
600     } else if ( arg.find( "--vNorth=" ) != string::npos ) {
601         fgSetString("/sim/startup/speed-set", "NED");
602                                 // FIXME: the units are totally confused here
603         if ( fgGetString("/sim/startup/units") == "feet" )
604           fgSetDouble("/velocities/speed-north", atof(arg.substr(8)));
605         else
606           fgSetDouble("/velocities/speed-north",
607                                atof(arg.substr(8)) * FEET_TO_METER);
608     } else if ( arg.find( "--vEast=" ) != string::npos ) {
609         fgSetString("/sim/startup/speed-set", "NED");
610                                 // FIXME: the units are totally confused here
611         if ( fgGetString("/sim/startup/units") == "feet" )
612           fgSetDouble("/velocities/speed-east", atof(arg.substr(8)));
613         else
614           fgSetDouble("/velocities/speed-east",
615                                atof(arg.substr(8)) * FEET_TO_METER);
616     } else if ( arg.find( "--vDown=" ) != string::npos ) {
617         fgSetString("/sim/startup/speed-set", "NED");
618                                 // FIXME: the units are totally confused here
619         if ( fgGetString("/sim/startup/units") == "feet" )
620           fgSetDouble("/velocities/speed-down", atof(arg.substr(8)));
621         else
622           fgSetDouble("/velocities/speed-down",
623                                atof(arg.substr(8)) * FEET_TO_METER);
624     } else if ( arg.find( "--vc=" ) != string::npos) {
625         fgSetString("/sim/startup/speed-set", "knots");
626         fgSetDouble("/velocities/airspeed", atof(arg.substr(5)));
627     } else if ( arg.find( "--mach=" ) != string::npos) {
628         fgSetString("/sim/startup/speed-set", "mach");
629         fgSetDouble("/velocities/mach", atof(arg.substr(7)));
630     } else if ( arg.find( "--heading=" ) != string::npos ) {
631         fgSetDouble("/orientation/heading", atof(arg.substr(10)));
632     } else if ( arg.find( "--roll=" ) != string::npos ) {
633         fgSetDouble("/orientation/roll", atof(arg.substr(7)));
634     } else if ( arg.find( "--pitch=" ) != string::npos ) {
635         fgSetDouble("/orientation/pitch", atof(arg.substr(8)));
636     } else if ( arg.find( "--fg-root=" ) != string::npos ) {
637         globals->set_fg_root(arg.substr( 10 ));
638     } else if ( arg.find( "--fg-scenery=" ) != string::npos ) {
639         globals->set_fg_scenery(arg.substr( 13 ));
640     } else if ( arg.find( "--fdm=" ) != string::npos ) {
641         fgSetString("/sim/flight-model", arg.substr(6));
642     } else if ( arg.find( "--aircraft=" ) != string::npos ) {
643         fgSetString("/sim/aircraft", arg.substr(11));
644     } else if ( arg.find( "--aircraft-dir=" ) != string::npos ) {
645         fgSetString("/sim/aircraft-dir", arg.substr(15));
646     } else if ( arg.find( "--model-hz=" ) != string::npos ) {
647         fgSetInt("/sim/model-hz", atoi(arg.substr(11)));
648     } else if ( arg.find( "--speed=" ) != string::npos ) {
649         fgSetInt("/sim/speed-up", atoi(arg.substr(8)));
650     } else if ( arg.find( "--trim") != string::npos) {
651         fgSetBool("/sim/startup/trim", true);
652     } else if ( arg.find( "--notrim") != string::npos) {
653         fgSetBool("/sim/startup/trim", false);
654     } else if ( arg.find( "--on-ground") != string::npos) {
655         fgSetBool("/sim/startup/onground", true);
656     } else if ( arg.find( "--in-air") != string::npos) {
657         fgSetBool("/sim/startup/onground", false);
658     } else if ( arg == "--fog-disable" ) {
659         fgSetString("/sim/rendering/fog", "disabled");
660     } else if ( arg == "--fog-fastest" ) {
661         fgSetString("/sim/rendering/fog", "fastest");
662     } else if ( arg == "--fog-nicest" ) {
663         fgSetString("/sim/fog", "nicest");
664     } else if ( arg == "--disable-clouds" ) {
665         fgSetBool("/environment/clouds/status", false);
666     } else if ( arg == "--enable-clouds" ) {
667         fgSetBool("/environment/clouds/status", true);
668     } else if ( arg.find( "--clouds-asl=" ) != string::npos ) {
669                                 // FIXME: check units
670         if ( fgGetString("/sim/startup/units") == "feet" )
671           fgSetDouble("/environment/clouds/altitude",
672                                 atof(arg.substr(13)) * FEET_TO_METER);
673         else
674           fgSetDouble("/environment/clouds/altitude",
675                                 atof(arg.substr(13)));
676     } else if ( arg.find( "--fov=" ) != string::npos ) {
677         parse_fov( arg.substr(6) );
678     } else if ( arg == "--disable-fullscreen" ) {
679         fgSetBool("/sim/startup/fullscreen", false);
680     } else if ( arg== "--enable-fullscreen") {
681         fgSetBool("/sim/startup/fullscreen", true);
682     } else if ( arg == "--shading-flat") {
683         fgSetBool("/sim/rendering/shading", false);
684     } else if ( arg == "--shading-smooth") {
685         fgSetBool("/sim/rendering/shading", true);
686     } else if ( arg == "--disable-skyblend") {
687         fgSetBool("/sim/rendering/skyblend", false);
688     } else if ( arg== "--enable-skyblend" ) {
689         fgSetBool("/sim/rendering/skyblend", true);
690     } else if ( arg == "--disable-textures" ) {
691         fgSetBool("/sim/rendering/textures", false);
692     } else if ( arg == "--enable-textures" ) {
693         fgSetBool("/sim/rendering/textures", true);
694     } else if ( arg == "--disable-wireframe" ) {
695         fgSetBool("/sim/rendering/wireframe", false);
696     } else if ( arg == "--enable-wireframe" ) {
697         fgSetBool("/sim/rendering/wireframe", true);
698     } else if ( arg.find( "--geometry=" ) != string::npos ) {
699         bool geometry_ok = true;
700         int xsize = 0, ysize = 0;
701         string geometry = arg.substr( 11 );
702         string::size_type i = geometry.find('x');
703
704         if (i != string::npos) {
705             xsize = atoi(geometry.substr(0, i));
706             ysize = atoi(geometry.substr(i+1));
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         } else {
722           FG_LOG( FG_GENERAL, FG_INFO,
723                   "Setting geometry to " << xsize << 'x' << ysize << '\n');
724           fgSetInt("/sim/startup/xsize", xsize);
725           fgSetInt("/sim/startup/ysize", ysize);
726         }
727     } else if ( arg.find( "--bpp=" ) != string::npos ) {
728         string bits_per_pix = arg.substr( 6 );
729         if ( bits_per_pix == "16" ) {
730             fgSetInt("/sim/rendering/bits-per-pixel", 16);
731         } else if ( bits_per_pix == "24" ) {
732             fgSetInt("/sim/rendering/bits-per-pixel", 24);
733         } else if ( bits_per_pix == "32" ) {
734             fgSetInt("/sim/rendering/bits-per-pixel", 32);
735         } else {
736           FG_LOG(FG_GENERAL, FG_ALERT, "Unsupported bpp " << bits_per_pix);
737         }
738     } else if ( arg == "--units-feet" ) {
739         fgSetString("/sim/startup/units", "feet");
740     } else if ( arg == "--units-meters" ) {
741         fgSetString("/sim/startup/units", "meters");
742     } else if ( arg.find( "--time-offset" ) != string::npos ) {
743         fgSetInt("/sim/startup/time-offset",
744                            parse_time_offset( (arg.substr(14)) ));
745     } else if ( arg.find( "--time-match-real") != string::npos ) {
746         fgSetString("/sim/startup/time-offset_type",
747                               "system-offset");
748     } else if ( arg.find( "--time-match-local") != string::npos ) {
749         fgSetString("/sim/startup/time-offset_type",
750                               "latitude-offset");
751     } else if ( arg.find( "--start-date-sys=") != string::npos ) {
752         fgSetInt("/sim/startup/time-offset",
753                            parse_date((arg.substr(17))));
754         fgSetString("/sim/startup/time-offset-type", "system");
755     } else if ( arg.find( "--start-date-lat=") != string::npos ) {
756         fgSetInt("/sim/startup/time-offset",
757                            parse_date((arg.substr(17))));
758         fgSetString("/sim/startup/time-offset-type",
759                            "latitude");
760     } else if ( arg.find( "--start-date-gmt=") != string::npos ) {
761         fgSetInt("/sim/startup/time-offset",
762                            parse_date((arg.substr(17))));
763         fgSetString("/sim/startup/time-offset-type", "gmt");
764     } else if ( arg == "--hud-tris" ) {
765         fgSetString("/sim/hud/frame-stat-type", "tris");
766     } else if ( arg == "--hud-culled" ) {
767         fgSetString("/sim/hud/frame-stat-type", "culled");
768     } else if ( arg.find( "--native=" ) != string::npos ) {
769         parse_channel( "native", arg.substr(9) );
770     } else if ( arg.find( "--garmin=" ) != string::npos ) {
771         parse_channel( "garmin", arg.substr(9) );
772     } else if ( arg.find( "--nmea=" ) != string::npos ) {
773         parse_channel( "nmea", arg.substr(7) );
774     } else if ( arg.find( "--props=" ) != string::npos ) {
775         parse_channel( "props", arg.substr(8) );
776     } else if ( arg.find( "--pve=" ) != string::npos ) {
777         parse_channel( "pve", arg.substr(6) );
778     } else if ( arg.find( "--ray=" ) != string::npos ) {
779         parse_channel( "ray", arg.substr(6) );
780     } else if ( arg.find( "--rul=" ) != string::npos ) {
781         parse_channel( "rul", arg.substr(6) );
782     } else if ( arg.find( "--joyclient=" ) != string::npos ) {
783         parse_channel( "joyclient", arg.substr(12) );
784 #ifdef FG_NETWORK_OLK
785     } else if ( arg == "--disable-network-olk" ) {
786         fgSetBool("/sim/networking/olk", false);
787     } else if ( arg== "--enable-network-olk") {
788         fgSetBool("/sim/networking/olk", true);
789     } else if ( arg == "--net-hud" ) {
790         fgSetBool("/sim/hud/net-display", true);
791         net_hud_display = 1;    // FIXME
792     } else if ( arg.find( "--net-id=") != string::npos ) {
793         fgSetString("sim/networking/call-sign", arg.substr(9));
794 #endif
795     } else if ( arg.find( "--prop:" ) == 0 ) {
796         string assign = arg.substr(7);
797         int pos = assign.find('=');
798         if (pos == arg.npos || pos == 0) {
799             FG_LOG(FG_GENERAL, FG_ALERT, "Bad property assignment: " << arg);
800             return FG_OPTIONS_ERROR;
801         }
802         string name = assign.substr(0, pos);
803         string value = assign.substr(pos + 1);
804         fgSetString(name.c_str(), value);
805         // FG_LOG(FG_GENERAL, FG_INFO, "Setting default value of property "
806         //        << name << " to \"" << value << '"');
807     // $$$ begin - added VS Renganathan, 14 Oct 2K
808     // for multi-window outside window imagery
809     } else if ( arg.find( "--view-offset=" ) != string::npos ) {
810         string woffset = arg.substr( 14 );
811         double default_view_offset = 0.0;
812         if ( woffset == "LEFT" ) {
813                default_view_offset = FG_PI * 0.25;
814         } else if ( woffset == "RIGHT" ) {
815             default_view_offset = FG_PI * 1.75;
816         } else if ( woffset == "CENTER" ) {
817             default_view_offset = 0.00;
818         } else {
819             default_view_offset = atof( woffset.c_str() ) * DEG_TO_RAD;
820         }
821         FGViewerRPH *pilot_view =
822             (FGViewerRPH *)globals->get_viewmgr()->get_view( 0 );
823         pilot_view->set_view_offset( default_view_offset );
824         pilot_view->set_goal_view_offset( default_view_offset );
825         fgSetDouble("/sim/startup/view-offset", default_view_offset);
826     // $$$ end - added VS Renganathan, 14 Oct 2K
827     } else if ( arg.find( "--visibility=" ) != string::npos ) {
828         fgSetDouble("/environment/visibility", atof(arg.substr(13)));
829     } else if ( arg.find( "--visibility-miles=" ) != string::npos ) {
830         double visibility = atof(arg.substr(19)) * 5280.0 * FEET_TO_METER;
831         fgSetDouble("/environment/visibility", visibility);
832     } else if ( arg.find( "--wind=" ) == 0 ) {
833         string val = arg.substr(7);
834         int pos = val.find('@');
835         if (pos == string::npos) {
836           FG_LOG(FG_GENERAL, FG_ALERT, "bad wind value " << val);
837           return FG_OPTIONS_ERROR;
838         }
839         double dir = atof(val.substr(0,pos).c_str());
840         double speed = atof(val.substr(pos+1).c_str());
841         FG_LOG(FG_GENERAL, FG_INFO, "WIND: " << dir << '@' << 
842                speed << " knots" << endl);
843                                 // convert to fps
844         speed *= NM_TO_METER * METER_TO_FEET * (1.0/3600);
845         dir += 180;
846         if (dir >= 360)
847           dir -= 360;
848         dir *= DEG_TO_RAD;
849         fgSetDouble("/environment/wind-north",
850                                              speed * cos(dir));
851         fgSetDouble("/environment/wind-east",
852                                              speed * sin(dir));
853     } else if ( arg.find( "--wp=" ) != string::npos ) {
854         parse_wp( arg.substr( 5 ) );
855     } else if ( arg.find( "--flight-plan=") != string::npos) {
856         parse_flightplan ( arg.substr (14) );
857     } else {
858         FG_LOG( FG_GENERAL, FG_ALERT, "Unknown option '" << arg << "'" );
859         return FG_OPTIONS_ERROR;
860     }
861     
862     return FG_OPTIONS_OK;
863 }
864
865
866 // Scan the command line options for an fg_root definition and set
867 // just that.
868 string
869 fgScanForRoot (int argc, char **argv) 
870 {
871     int i = 1;
872
873     FG_LOG(FG_GENERAL, FG_INFO, "Scanning for root: command line");
874
875     while ( i < argc ) {
876         FG_LOG( FG_GENERAL, FG_DEBUG, "argv[" << i << "] = " << argv[i] );
877
878         string arg = argv[i];
879         if ( arg.find( "--fg-root=" ) != string::npos ) {
880             return arg.substr( 10 );
881         }
882
883         i++;
884     }
885
886     return "";
887 }
888
889
890 // Scan the config file for an fg_root definition and set just that.
891 string
892 fgScanForRoot (const string& path)
893 {
894     fg_gzifstream in( path );
895     if ( !in.is_open() )
896       return "";
897
898     FG_LOG( FG_GENERAL, FG_INFO, "Scanning for root: " << path );
899
900     in >> skipcomment;
901 #ifndef __MWERKS__
902     while ( ! in.eof() ) {
903 #else
904     char c = '\0';
905     while ( in.get(c) && c != '\0' ) {
906         in.putback(c);
907 #endif
908         string line;
909
910 #ifdef GETLINE_NEEDS_TERMINATOR
911         getline( in, line, '\n' );
912 #elif defined( macintosh )
913         getline( in, line, '\r' );
914 #else
915         getline( in, line );
916 #endif
917
918         if ( line.find( "--fg-root=" ) != string::npos ) {
919             return line.substr( 10 );
920         }
921
922         in >> skipcomment;
923     }
924
925     return "";
926 }
927
928
929 // Parse the command line options
930 void
931 fgParseOptions (int argc, char **argv) {
932     int i = 1;
933     int result;
934
935     FG_LOG(FG_GENERAL, FG_INFO, "Processing command line arguments");
936
937     while ( i < argc ) {
938         FG_LOG( FG_GENERAL, FG_DEBUG, "argv[" << i << "] = " << argv[i] );
939
940         result = parse_option(argv[i]);
941         if ( (result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR) ) {
942             fgUsage();
943             exit(-1);
944         }
945
946         i++;
947     }
948 }
949
950
951 // Parse config file options
952 void
953 fgParseOptions (const string& path) {
954     fg_gzifstream in( path );
955     if ( !in.is_open() )
956       return;
957
958     FG_LOG( FG_GENERAL, FG_INFO, "Processing config file: " << path );
959
960     in >> skipcomment;
961 #ifndef __MWERKS__
962     while ( ! in.eof() ) {
963 #else
964     char c = '\0';
965     while ( in.get(c) && c != '\0' ) {
966         in.putback(c);
967 #endif
968         string line;
969
970 #ifdef GETLINE_NEEDS_TERMINATOR
971         getline( in, line, '\n' );
972 #elif defined( macintosh )
973         getline( in, line, '\r' );
974 #else
975         getline( in, line );
976 #endif
977
978         if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
979             FG_LOG( FG_GENERAL, FG_ALERT, 
980                     "Config file parse error: " << path << " '" 
981                     << line << "'" );
982             fgUsage();
983             exit(-1);
984         }
985         in >> skipcomment;
986     }
987 }
988
989
990 // Print usage message
991 void 
992 fgUsage ()
993 {
994     cout << "Usage: fg [ options ... ]" << endl;
995     cout << endl;
996
997     cout << "General Options:" << endl;
998     cout << "\t--help -h:  print usage" << endl;
999     cout << "\t--fg-root=path:  specify the root path for all the data files"
1000          << endl;
1001     cout << "\t--fg-scenery=path:  specify the base path for all the scenery"
1002          << " data." << endl
1003          << "\t\tdefaults to $FG_ROOT/Scenery" << endl;
1004     cout << "\t--disable-game-mode:  disable full-screen game mode" << endl;
1005     cout << "\t--enable-game-mode:  enable full-screen game mode" << endl;
1006     cout << "\t--disable-splash-screen:  disable splash screen" << endl;
1007     cout << "\t--enable-splash-screen:  enable splash screen" << endl;
1008     cout << "\t--disable-intro-music:  disable introduction music" << endl;
1009     cout << "\t--enable-intro-music:  enable introduction music" << endl;
1010     cout << "\t--disable-mouse-pointer:  disable extra mouse pointer" << endl;
1011     cout << "\t--enable-mouse-pointer:  enable extra mouse pointer (i.e. for"
1012          << endl;
1013     cout << "\t\tfull screen voodoo/voodoo-II based cards.)" << endl;
1014     cout << "\t--disable-freeze:  start out in an running state" << endl;
1015     cout << "\t--enable-freeze:  start out in a frozen state" << endl;
1016     cout << "\t--control=mode:  primary control mode " 
1017          << "(joystick, keyboard, mouse)" << endl;
1018     cout << endl;
1019
1020     cout << "Features:" << endl;
1021     cout << "\t--disable-hud:  disable heads up display" << endl;
1022     cout << "\t--enable-hud:  enable heads up display" << endl;
1023     cout << "\t--disable-panel:  disable instrument panel" << endl;
1024     cout << "\t--enable-panel:  enable instrumetn panel" << endl;
1025     cout << "\t--disable-sound:  disable sound effects" << endl;
1026     cout << "\t--enable-sound:  enable sound effects" << endl;
1027     cout << "\t--disable-anti-alias-hud:  disable anti aliased hud" << endl;
1028     cout << "\t--enable-anti-alias-hud:  enable anti aliased hud" << endl;
1029     cout << endl;
1030  
1031     cout << "Flight Model:" << endl;
1032     cout << "\t--fdm=abcd:  selects the core flight model code." << endl;
1033     cout << "\t\tcan be one of jsb, larcsim, magic, external, balloon, or ada"
1034          << endl;
1035     cout << "\t--aircraft=abcd:  aircraft model to load" << endl;
1036     cout << "\t--model-hz=n:  run the FDM this rate (iterations per second)" 
1037          << endl;
1038     cout << "\t--speed=n:  run the FDM this much faster than real time" << endl;
1039     cout << "\t--notrim:  Do NOT attempt to trim the model when initializing JSBsim" << endl;
1040     cout << "\t--on-ground:  Start up at ground level (default)" << endl;
1041     cout << "\t--in-air:  Start up in air (implied by specifying an initial"
1042          << " altitude above ground level." << endl;
1043     cout << "\t--wind=DIR@SPEED: specify wind coming from DIR (degrees) at SPEED (knots)" << endl;
1044     cout << endl;
1045
1046     //(UIUC)
1047     cout <<"Aircraft model directory:" << endl;
1048     cout <<"\t--aircraft-dir=<path> path is relative to the path of the executable" << endl;
1049     cout << endl;
1050
1051     cout << "Initial Position and Orientation:" << endl;
1052     cout << "\t--airport-id=ABCD:  specify starting postion by airport id" 
1053          << endl;
1054     cout << "\t--lon=degrees:  starting longitude in degrees (west = -)" 
1055          << endl;
1056     cout << "\t--lat=degrees:  starting latitude in degrees (south = -)"
1057          << endl;
1058     cout << "\t--altitude=feet:  starting altitude in feet" << endl;
1059     cout << "\t\t(unless --units-meters specified" << endl;
1060     cout << "\t--heading=degrees:  heading (yaw) angle in degress (Psi)"
1061          << endl;
1062     cout << "\t--roll=degrees:  roll angle in degrees (Phi)" << endl;
1063     cout << "\t--pitch=degrees:  pitch angle in degrees (Theta)" << endl;
1064     cout << "\t--uBody=feet per second:  velocity along the body X axis"
1065          << endl;
1066     cout << "\t--vBody=feet per second:  velocity along the body Y axis"
1067          << endl;
1068     cout << "\t--wBody=feet per second:  velocity along the body Z axis"
1069          << endl;
1070     cout << "\t\t(unless --units-meters specified" << endl;
1071     cout << "\t--vc= initial airspeed in knots (--fdm=jsb only)" << endl;
1072     cout << "\t--mach= initial mach number (--fdm=jsb only)" << endl;
1073     cout << endl;
1074
1075     cout << "Rendering Options:" << endl;
1076     cout << "\t--fog-disable:  disable fog/haze" << endl;
1077     cout << "\t--fog-fastest:  enable fastest fog/haze" << endl;
1078     cout << "\t--fog-nicest:  enable nicest fog/haze" << endl;
1079     cout << "\t--enable-clouds:  enable demo cloud layer" << endl;
1080     cout << "\t--disable-clouds:  disable demo cloud layer" << endl;
1081     cout << "\t--clouds-asl=xxx:  specify altitude of cloud layer above sea level" << endl;
1082     cout << "\t--fov=xx.x:  specify initial field of view angle in degrees"
1083          << endl;
1084     cout << "\t--disable-fullscreen:  disable fullscreen mode" << endl;
1085     cout << "\t--enable-fullscreen:  enable fullscreen mode" << endl;
1086     cout << "\t--shading-flat:  enable flat shading" << endl;
1087     cout << "\t--shading-smooth:  enable smooth shading" << endl;
1088     cout << "\t--disable-skyblend:  disable sky blending" << endl;
1089     cout << "\t--enable-skyblend:  enable sky blending" << endl;
1090     cout << "\t--disable-textures:  disable textures" << endl;
1091     cout << "\t--enable-textures:  enable textures" << endl;
1092     cout << "\t--disable-wireframe:  disable wireframe drawing mode" << endl;
1093     cout << "\t--enable-wireframe:  enable wireframe drawing mode" << endl;
1094     cout << "\t--geometry=WWWxHHH:  window geometry: 640x480, 800x600, etc."
1095          << endl;
1096     cout << "\t--view-offset=xxx:  set the default forward view direction"
1097          << endl;
1098     cout << "\t\tas an offset from straight ahead.  Allowable values are"
1099          << endl;
1100     cout << "\t\tLEFT, RIGHT, CENTER, or a specific number of degrees" << endl;
1101     cout << "\t--visibility=xxx:  specify initial visibility in meters" << endl;
1102     cout << "\t--visibility-miles=xxx:  specify initial visibility in miles"
1103          << endl;
1104     cout << endl;
1105
1106     cout << "Scenery Options:" << endl;
1107     cout << "\t--tile-radius=n:  specify tile radius, must be 1 - 4" << endl;
1108     cout << endl;
1109
1110     cout << "Hud Options:" << endl;
1111     cout << "\t--units-feet:  Hud displays units in feet" << endl;
1112     cout << "\t--units-meters:  Hud displays units in meters" << endl;
1113     cout << "\t--hud-tris:  Hud displays number of triangles rendered" << endl;
1114     cout << "\t--hud-culled:  Hud displays percentage of triangles culled"
1115          << endl;
1116     cout << endl;
1117         
1118     cout << "Time Options:" << endl;
1119     cout << "\t--time-offset=[+-]hh:mm:ss: add this time offset" << endl;
1120     cout << "\t--time-match-real: Synchronize real-world and FlightGear" << endl
1121          << "\t\ttime. Can be used in combination with --time-offset." << endl;
1122     cout << "\t--time-match-local:Synchronize local real-world and " << endl
1123          << "\t\tFlightGear time" << endl;   
1124     cout << "\t--start-date-sys=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1125          << "\t\tdate/time. Uses your system time " << endl;
1126     cout << "\t--start-date-gmt=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1127          << "\t\tdate/time. Uses Greenwich Mean Time" << endl;
1128     cout << "\t--start-date-lat=yyyy:mm:dd:hh:mm:ss: specify a starting" << endl
1129          << "\t\tdate/time. Uses Local Aircraft Time" << endl;
1130 #ifdef FG_NETWORK_OLK
1131     cout << endl;
1132
1133     cout << "Network Options:" << endl;
1134     cout << "\t--enable-network-olk:  enable Multipilot mode" << endl;
1135     cout << "\t--disable-network-olk:  disable Multipilot mode (default)" << endl;
1136     cout << "\t--net-hud:  Hud displays network info" << endl;
1137     cout << "\t--net-id=name:  specify your own callsign" << endl;
1138 #endif
1139
1140     cout << endl;
1141     cout << "Route/Way Point Options:" << endl;
1142     cout << "\t--wp=ID[@alt]:  specify a waypoint for the GC autopilot" << endl;
1143     cout << "\t\tYou can specify multiple waypoints (a route) with multiple"
1144          << endl;
1145     cout << "\t\tinstances of --wp=" << endl;
1146     cout << "\t--flight-plan=[file]: Read all waypoints from [file]" <<endl;
1147 }