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