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