]> git.mxchange.org Git - flightgear.git/blob - src/Main/options.cxx
cosmetic changes *only*:
[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  - http://www.flightgear.org/~curt
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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21 // $Id$
22
23
24 #ifdef HAVE_CONFIG_H
25 #  include <config.h>
26 #endif
27
28 #include <simgear/compiler.h>
29 #include <simgear/structure/exception.hxx>
30 #include <simgear/debug/logstream.hxx>
31
32 #include <math.h>               // rint()
33 #include <stdio.h>
34 #include <stdlib.h>             // atof(), atoi()
35 #include <string.h>             // strcmp()
36 #include <algorithm>
37
38 #include STL_STRING
39
40 #include <plib/ul.h>
41
42 #include <simgear/math/sg_random.h>
43 #include <simgear/misc/sgstream.hxx>
44 #include <simgear/misc/sg_path.hxx>
45 #include <simgear/scene/material/mat.hxx>
46
47 // #include <Include/general.hxx>
48 // #include <Airports/simple.hxx>
49 // #include <Cockpit/cockpit.hxx>
50 // #include <FDM/flight.hxx>
51
52 #include <Autopilot/route_mgr.hxx>
53 #include <GUI/gui.h>
54
55 #include "globals.hxx"
56 #include "fg_init.hxx"
57 #include "fg_props.hxx"
58 #include "options.hxx"
59 #include "util.hxx"
60 #include "viewmgr.hxx"
61
62
63 SG_USING_STD(string);
64 SG_USING_STD(sort);
65 SG_USING_NAMESPACE(std);
66
67 #ifndef VERSION
68 #define VERSION "CVS "__DATE__
69 #endif
70
71 #define NEW_DEFAULT_MODEL_HZ 120
72
73 enum
74 {
75     FG_OPTIONS_OK = 0,
76     FG_OPTIONS_HELP = 1,
77     FG_OPTIONS_ERROR = 2,
78     FG_OPTIONS_EXIT = 3,
79     FG_OPTIONS_VERBOSE_HELP = 4,
80     FG_OPTIONS_SHOW_AIRCRAFT = 5
81 };
82
83 static double
84 atof( const string& str )
85 {
86
87 #ifdef __MWERKS__
88     // -dw- if ::atof is called, then we get an infinite loop
89     return std::atof( str.c_str() );
90 #else
91     return ::atof( str.c_str() );
92 #endif
93 }
94
95 static int
96 atoi( const string& str )
97 {
98 #ifdef __MWERKS__
99     // -dw- if ::atoi is called, then we get an infinite loop
100     return std::atoi( str.c_str() );
101 #else
102     return ::atoi( str.c_str() );
103 #endif
104 }
105
106 /**
107  * Set a few fail-safe default property values.
108  *
109  * These should all be set in $FG_ROOT/preferences.xml, but just
110  * in case, we provide some initial sane values here. This method
111  * should be invoked *before* reading any init files.
112  */
113 void
114 fgSetDefaults ()
115 {
116     // set a possibly independent location for scenery data
117     char *envp = ::getenv( "FG_SCENERY" );
118
119     if ( envp != NULL ) {
120         // fg_root could be anywhere, so default to environmental
121         // variable $FG_ROOT if it is set.
122         globals->set_fg_scenery(envp);
123     } else {
124         // Otherwise, default to Scenery being in $FG_ROOT/Scenery
125         globals->set_fg_scenery("");
126     }
127                                 // Position (deliberately out of range)
128     fgSetDouble("/position/longitude-deg", 9999.0);
129     fgSetDouble("/position/latitude-deg", 9999.0);
130     fgSetDouble("/position/altitude-ft", -9999.0);
131
132                                 // Orientation
133     fgSetDouble("/orientation/heading-deg", 9999.0);
134     fgSetDouble("/orientation/roll-deg", 0.0);
135     fgSetDouble("/orientation/pitch-deg", 0.424);
136
137                                 // Velocities
138     fgSetDouble("/velocities/uBody-fps", 0.0);
139     fgSetDouble("/velocities/vBody-fps", 0.0);
140     fgSetDouble("/velocities/wBody-fps", 0.0);
141     fgSetDouble("/velocities/speed-north-fps", 0.0);
142     fgSetDouble("/velocities/speed-east-fps", 0.0);
143     fgSetDouble("/velocities/speed-down-fps", 0.0);
144     fgSetDouble("/velocities/airspeed-kt", 0.0);
145     fgSetDouble("/velocities/mach", 0.0);
146
147                                 // Presets
148     fgSetDouble("/sim/presets/longitude-deg", 9999.0);
149     fgSetDouble("/sim/presets/latitude-deg", 9999.0);
150     fgSetDouble("/sim/presets/altitude-ft", -9999.0);
151
152     fgSetDouble("/sim/presets/heading-deg", 9999.0);
153     fgSetDouble("/sim/presets/roll-deg", 0.0);
154     fgSetDouble("/sim/presets/pitch-deg", 0.424);
155
156     fgSetString("/sim/presets/speed-set", "knots");
157     fgSetDouble("/sim/presets/airspeed-kt", 0.0);
158     fgSetDouble("/sim/presets/mach", 0.0);
159     fgSetDouble("/sim/presets/uBody-fps", 0.0);
160     fgSetDouble("/sim/presets/vBody-fps", 0.0);
161     fgSetDouble("/sim/presets/wBody-fps", 0.0);
162     fgSetDouble("/sim/presets/speed-north-fps", 0.0);
163     fgSetDouble("/sim/presets/speed-east-fps", 0.0);
164     fgSetDouble("/sim/presets/speed-down-fps", 0.0);
165
166     fgSetBool("/sim/presets/onground", true);
167     fgSetBool("/sim/presets/trim", false);
168
169                                 // Miscellaneous
170     fgSetBool("/sim/startup/game-mode", false);
171     fgSetBool("/sim/startup/splash-screen", true);
172     fgSetBool("/sim/startup/intro-music", true);
173     // we want mouse-pointer to have an undefined value if nothing is
174     // specified so we can do the right thing for voodoo-1/2 cards.
175     // fgSetString("/sim/startup/mouse-pointer", "disabled");
176     fgSetString("/sim/control-mode", "joystick");
177     fgSetBool("/sim/auto-coordination", false);
178 #if defined(WIN32)
179     fgSetString("/sim/startup/browser-app", "webrun.bat");
180 #elif defined(__APPLE__)
181     fgSetString("/sim/startup/browser-app", "open");
182 #elif defined(sgi)
183     fgSetString("/sim/startup/browser-app", "launchWebJumper");
184 #else
185     envp = ::getenv( "WEBBROWSER" );
186     if (!envp) envp = "netscape";
187     fgSetString("/sim/startup/browser-app", envp);
188 #endif
189     fgSetString("/sim/logging/priority", "alert");
190
191                                 // Features
192     fgSetBool("/sim/hud/color/antialiased", false);
193     fgSetBool("/sim/hud/enable3d", true);
194     fgSetBool("/sim/hud/visibility", false);
195     fgSetBool("/sim/panel/visibility", true);
196     fgSetBool("/sim/sound/pause", false);
197
198                                 // Flight Model options
199     fgSetString("/sim/flight-model", "jsb");
200     fgSetString("/sim/aero", "c172");
201     fgSetInt("/sim/model-hz", NEW_DEFAULT_MODEL_HZ);
202     fgSetInt("/sim/speed-up", 1);
203
204                                 // Rendering options
205     fgSetString("/sim/rendering/fog", "nicest");
206     fgSetBool("/environment/clouds/status", true);
207     fgSetBool("/sim/startup/fullscreen", false);
208     fgSetBool("/sim/rendering/shading", true);
209     fgSetBool("/sim/rendering/skyblend", true);
210     fgSetBool("/sim/rendering/textures", true);
211         fgTie( "/sim/rendering/filtering", SGGetTextureFilter, SGSetTextureFilter, false);
212     fgSetInt("/sim/rendering/filtering", 1);
213     fgSetBool("/sim/rendering/wireframe", false);
214     fgSetBool("/sim/rendering/horizon-effect", false);
215     fgSetBool("/sim/rendering/enhanced-lighting", false);
216     fgSetBool("/sim/rendering/distance-attenuation", false);
217     fgSetBool("/sim/rendering/specular-highlight", true);
218     fgSetInt("/sim/startup/xsize", 800);
219     fgSetInt("/sim/startup/ysize", 600);
220     fgSetInt("/sim/rendering/bits-per-pixel", 16);
221     fgSetString("/sim/view-mode", "pilot");
222     fgSetDouble("/sim/current-view/heading-offset-deg", 0);
223
224                                 // HUD options
225     fgSetString("/sim/startup/units", "feet");
226     fgSetString("/sim/hud/frame-stat-type", "tris");
227         
228                                 // Time options
229     fgSetInt("/sim/startup/time-offset", 0);
230     fgSetString("/sim/startup/time-offset-type", "system-offset");
231     fgSetLong("/sim/time/cur-time-override", 0);
232
233                                 // Freeze options
234     fgSetBool("/sim/freeze/master", false);
235     fgSetBool("/sim/freeze/position", false);
236     fgSetBool("/sim/freeze/clock", false);
237     fgSetBool("/sim/freeze/fuel", false);
238
239     fgSetString("/sim/multiplay/callsign", "callsign");
240     fgSetString("/sim/multiplay/rxhost", "0");
241     fgSetString("/sim/multiplay/txhost", "0");
242     fgSetInt("/sim/multiplay/rxport", 0);
243     fgSetInt("/sim/multiplay/txport", 0);
244 }
245
246 static bool
247 parse_wind (const string &wind, double * min_hdg, double * max_hdg,
248             double * speed, double * gust)
249 {
250   string::size_type pos = wind.find('@');
251   if (pos == string::npos)
252     return false;
253   string dir = wind.substr(0, pos);
254   string spd = wind.substr(pos+1);
255   pos = dir.find(':');
256   if (pos == string::npos) {
257     *min_hdg = *max_hdg = atof(dir.c_str());
258   } else {
259     *min_hdg = atof(dir.substr(0,pos).c_str());
260     *max_hdg = atof(dir.substr(pos+1).c_str());
261   }
262   pos = spd.find(':');
263   if (pos == string::npos) {
264     *speed = *gust = atof(spd.c_str());
265   } else {
266     *speed = atof(spd.substr(0,pos).c_str());
267     *gust = atof(spd.substr(pos+1).c_str());
268   }
269   return true;
270 }
271
272 // parse a time string ([+/-]%f[:%f[:%f]]) into hours
273 static double
274 parse_time(const string& time_in) {
275     char *time_str, num[256];
276     double hours, minutes, seconds;
277     double result = 0.0;
278     int sign = 1;
279     int i;
280
281     time_str = (char *)time_in.c_str();
282
283     // printf("parse_time(): %s\n", time_str);
284
285     // check for sign
286     if ( strlen(time_str) ) {
287         if ( time_str[0] == '+' ) {
288             sign = 1;
289             time_str++;
290         } else if ( time_str[0] == '-' ) {
291             sign = -1;
292             time_str++;
293         }
294     }
295     // printf("sign = %d\n", sign);
296
297     // get hours
298     if ( strlen(time_str) ) {
299         i = 0;
300         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
301             num[i] = time_str[0];
302             time_str++;
303             i++;
304         }
305         if ( time_str[0] == ':' ) {
306             time_str++;
307         }
308         num[i] = '\0';
309         hours = atof(num);
310         // printf("hours = %.2lf\n", hours);
311
312         result += hours;
313     }
314
315     // get minutes
316     if ( strlen(time_str) ) {
317         i = 0;
318         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
319             num[i] = time_str[0];
320             time_str++;
321             i++;
322         }
323         if ( time_str[0] == ':' ) {
324             time_str++;
325         }
326         num[i] = '\0';
327         minutes = atof(num);
328         // printf("minutes = %.2lf\n", minutes);
329
330         result += minutes / 60.0;
331     }
332
333     // get seconds
334     if ( strlen(time_str) ) {
335         i = 0;
336         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
337             num[i] = time_str[0];
338             time_str++;
339             i++;
340         }
341         num[i] = '\0';
342         seconds = atof(num);
343         // printf("seconds = %.2lf\n", seconds);
344
345         result += seconds / 3600.0;
346     }
347
348     SG_LOG( SG_GENERAL, SG_INFO, " parse_time() = " << sign * result );
349
350     return(sign * result);
351 }
352
353
354 // parse a date string (yyyy:mm:dd:hh:mm:ss) into a time_t (seconds)
355 static long int 
356 parse_date( const string& date)
357 {
358     struct tm gmt;
359     char * date_str, num[256];
360     int i;
361     // initialize to zero
362     gmt.tm_sec = 0;
363     gmt.tm_min = 0;
364     gmt.tm_hour = 0;
365     gmt.tm_mday = 0;
366     gmt.tm_mon = 0;
367     gmt.tm_year = 0;
368     gmt.tm_isdst = 0; // ignore daylight savings time for the moment
369     date_str = (char *)date.c_str();
370     // get year
371     if ( strlen(date_str) ) {
372         i = 0;
373         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
374             num[i] = date_str[0];
375             date_str++;
376             i++;
377         }
378         if ( date_str[0] == ':' ) {
379             date_str++;
380         }
381         num[i] = '\0';
382         gmt.tm_year = atoi(num) - 1900;
383     }
384     // get month
385     if ( strlen(date_str) ) {
386         i = 0;
387         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
388             num[i] = date_str[0];
389             date_str++;
390             i++;
391         }
392         if ( date_str[0] == ':' ) {
393             date_str++;
394         }
395         num[i] = '\0';
396         gmt.tm_mon = atoi(num) -1;
397     }
398     // get day
399     if ( strlen(date_str) ) {
400         i = 0;
401         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
402             num[i] = date_str[0];
403             date_str++;
404             i++;
405         }
406         if ( date_str[0] == ':' ) {
407             date_str++;
408         }
409         num[i] = '\0';
410         gmt.tm_mday = atoi(num);
411     }
412     // get hour
413     if ( strlen(date_str) ) {
414         i = 0;
415         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
416             num[i] = date_str[0];
417             date_str++;
418             i++;
419         }
420         if ( date_str[0] == ':' ) {
421             date_str++;
422         }
423         num[i] = '\0';
424         gmt.tm_hour = atoi(num);
425     }
426     // get minute
427     if ( strlen(date_str) ) {
428         i = 0;
429         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
430             num[i] = date_str[0];
431             date_str++;
432             i++;
433         }
434         if ( date_str[0] == ':' ) {
435             date_str++;
436         }
437         num[i] = '\0';
438         gmt.tm_min = atoi(num);
439     }
440     // get second
441     if ( strlen(date_str) ) {
442         i = 0;
443         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
444             num[i] = date_str[0];
445             date_str++;
446             i++;
447         }
448         if ( date_str[0] == ':' ) {
449             date_str++;
450         }
451         num[i] = '\0';
452         gmt.tm_sec = atoi(num);
453     }
454     time_t theTime = sgTimeGetGMT( gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
455                                    gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
456     //printf ("Date is %s\n", ctime(&theTime));
457     //printf ("in seconds that is %d\n", theTime);
458     //exit(1);
459     return (theTime);
460 }
461
462
463 // parse angle in the form of [+/-]ddd:mm:ss into degrees
464 static double
465 parse_degree( const string& degree_str) {
466     double result = parse_time( degree_str );
467
468     // printf("Degree = %.4f\n", result);
469
470     return(result);
471 }
472
473
474 // parse time offset string into seconds
475 static int
476 parse_time_offset( const string& time_str) {
477     int result;
478
479     // printf("time offset = %s\n", time_str);
480
481 #ifdef HAVE_RINT
482     result = (int)rint(parse_time(time_str) * 3600.0);
483 #else
484     result = (int)(parse_time(time_str) * 3600.0);
485 #endif
486
487     // printf("parse_time_offset(): %d\n", result);
488
489     return( result );
490 }
491
492
493 // Parse --fov=x.xx type option 
494 static double
495 parse_fov( const string& arg ) {
496     double fov = atof(arg);
497
498     if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
499     if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
500
501     fgSetDouble("/sim/view[0]/config/default-field-of-view-deg", fov);
502
503     // printf("parse_fov(): result = %.4f\n", fov);
504
505     return fov;
506 }
507
508
509 // Parse I/O channel option
510 //
511 // Format is "--protocol=medium,direction,hz,medium_options,..."
512 //
513 //   protocol = { native, nmea, garmin, AV400, fgfs, rul, pve, etc. }
514 //   medium = { serial, socket, file, etc. }
515 //   direction = { in, out, bi }
516 //   hz = number of times to process channel per second (floating
517 //        point values are ok.
518 //
519 // Serial example "--nmea=serial,dir,hz,device,baud" where
520 // 
521 //  device = OS device name of serial line to be open()'ed
522 //  baud = {300, 1200, 2400, ..., 230400}
523 //
524 // Socket exacmple "--native=socket,dir,hz,machine,port,style" where
525 //
526 //  machine = machine name or ip address if client (leave empty if server)
527 //  port = port, leave empty to let system choose
528 //  style = tcp or udp
529 //
530 // File example "--garmin=file,dir,hz,filename" where
531 //
532 //  filename = file system file name
533
534 static bool
535 add_channel( const string& type, const string& channel_str ) {
536     SG_LOG(SG_GENERAL, SG_INFO, "Channel string = " << channel_str );
537     globals->get_channel_options_list()->push_back( type + "," + channel_str );
538     return true;
539 }
540
541
542 // The parse wp and parse flight-plan options don't work anymore, because
543 // the route manager and the airport subsystems have not yet been initialized
544 // at this stage.
545
546 // Parse --wp=ID[@alt]
547 static void
548 parse_wp( const string& arg ) {
549     string_list *waypoints = globals->get_initial_waypoints();
550     if (!waypoints) {
551         waypoints = new string_list;
552         globals->set_initial_waypoints(waypoints);
553     }
554     waypoints->push_back(arg);
555 }
556
557
558 // Parse --flight-plan=[file]
559 static bool
560 parse_flightplan(const string& arg)
561 {
562     string_list *waypoints = globals->get_initial_waypoints();
563     if (!waypoints) {
564         waypoints = new string_list;
565         globals->set_initial_waypoints(waypoints);
566     }
567
568     sg_gzifstream in(arg.c_str());
569     if ( !in.is_open() )
570         return false;
571
572     while ( true ) {
573         string line;
574
575 #if defined( macintosh )
576         getline( in, line, '\r' );
577 #else
578         getline( in, line, '\n' );
579 #endif
580         // catch extraneous (DOS) line ending character
581         if ( line[line.length() - 1] < 32 )
582             line = line.substr( 0, line.length()-1 );
583
584         if ( in.eof() )
585             break;
586
587         waypoints->push_back(line);
588     }
589     return true;
590 }
591
592
593 static int
594 fgOptLanguage( const char *arg )
595 {
596     globals->set_locale( fgInitLocale( arg ) );
597     return FG_OPTIONS_OK;
598 }
599
600 static void
601 clearLocation ()
602 {
603     fgSetString("/sim/presets/airport-id", "");
604     fgSetString("/sim/presets/vor-id", "");
605     fgSetString("/sim/presets/ndb-id", "");
606     fgSetString("/sim/presets/carrier", "");
607     fgSetString("/sim/presets/parkpos", "");
608     fgSetString("/sim/presets/fix", "");
609 }
610
611 static int
612 fgOptVOR( const char * arg )
613 {
614     clearLocation();
615     fgSetString("/sim/presets/vor-id", arg);
616     return FG_OPTIONS_OK;
617 }
618
619 static int
620 fgOptNDB( const char * arg )
621 {
622     clearLocation();
623     fgSetString("/sim/presets/ndb-id", arg);
624     return FG_OPTIONS_OK;
625 }
626
627 static int
628 fgOptCarrier( const char * arg )
629 {
630     clearLocation();
631     fgSetString("/sim/presets/carrier", arg);
632     return FG_OPTIONS_OK;
633 }
634
635 static int
636 fgOptParkpos( const char * arg )
637 {
638     fgSetString("/sim/presets/parkpos", arg);
639     return FG_OPTIONS_OK;
640 }
641
642 static int
643 fgOptFIX( const char * arg )
644 {
645     clearLocation();
646     fgSetString("/sim/presets/fix", arg);
647     return FG_OPTIONS_OK;
648 }
649
650 static int
651 fgOptLon( const char *arg )
652 {
653     clearLocation();
654     fgSetDouble("/sim/presets/longitude-deg", parse_degree( arg ));
655     fgSetDouble("/position/longitude-deg", parse_degree( arg ));
656     return FG_OPTIONS_OK;
657 }
658
659 static int
660 fgOptLat( const char *arg )
661 {
662     clearLocation();
663     fgSetDouble("/sim/presets/latitude-deg", parse_degree( arg ));
664     fgSetDouble("/position/latitude-deg", parse_degree( arg ));
665     return FG_OPTIONS_OK;
666 }
667
668 static int
669 fgOptAltitude( const char *arg )
670 {
671     fgSetBool("/sim/presets/onground", false);
672     if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
673         fgSetDouble("/sim/presets/altitude-ft", atof( arg ));
674     else
675         fgSetDouble("/sim/presets/altitude-ft",
676                     atof( arg ) * SG_METER_TO_FEET);
677     return FG_OPTIONS_OK;
678 }
679
680 static int
681 fgOptUBody( const char *arg )
682 {
683     fgSetString("/sim/presets/speed-set", "UVW");
684     if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
685         fgSetDouble("/sim/presets/uBody-fps", atof( arg ));
686     else
687         fgSetDouble("/sim/presets/uBody-fps",
688                     atof( arg ) * SG_METER_TO_FEET);
689     return FG_OPTIONS_OK;
690 }
691
692 static int
693 fgOptVBody( const char *arg )
694 {
695     fgSetString("/sim/presets/speed-set", "UVW");
696     if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
697         fgSetDouble("/sim/presets/vBody-fps", atof( arg ));
698     else
699         fgSetDouble("/sim/presets/vBody-fps",
700                             atof( arg ) * SG_METER_TO_FEET);
701     return FG_OPTIONS_OK;
702 }
703
704 static int
705 fgOptWBody( const char *arg )
706 {
707     fgSetString("/sim/presets/speed-set", "UVW");
708     if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
709         fgSetDouble("/sim/presets/wBody-fps", atof(arg));
710     else
711         fgSetDouble("/sim/presets/wBody-fps",
712                             atof(arg) * SG_METER_TO_FEET);
713     return FG_OPTIONS_OK;
714 }
715
716 static int
717 fgOptVNorth( const char *arg )
718 {
719     fgSetString("/sim/presets/speed-set", "NED");
720     if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
721         fgSetDouble("/sim/presets/speed-north-fps", atof( arg ));
722     else
723         fgSetDouble("/sim/presets/speed-north-fps",
724                             atof( arg ) * SG_METER_TO_FEET);
725     return FG_OPTIONS_OK;
726 }
727
728 static int
729 fgOptVEast( const char *arg )
730 {
731     fgSetString("/sim/presets/speed-set", "NED");
732     if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
733         fgSetDouble("/sim/presets/speed-east-fps", atof(arg));
734     else
735         fgSetDouble("/sim/presets/speed-east-fps",
736                     atof(arg) * SG_METER_TO_FEET);
737     return FG_OPTIONS_OK;
738 }
739
740 static int
741 fgOptVDown( const char *arg )
742 {
743     fgSetString("/sim/presets/speed-set", "NED");
744     if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
745         fgSetDouble("/sim/presets/speed-down-fps", atof(arg));
746     else
747         fgSetDouble("/sim/presets/speed-down-fps",
748                             atof(arg) * SG_METER_TO_FEET);
749     return FG_OPTIONS_OK;
750 }
751
752 static int
753 fgOptVc( const char *arg )
754 {
755     // fgSetString("/sim/presets/speed-set", "knots");
756     // fgSetDouble("/velocities/airspeed-kt", atof(arg.substr(5)));
757     fgSetString("/sim/presets/speed-set", "knots");
758     fgSetDouble("/sim/presets/airspeed-kt", atof(arg));
759     return FG_OPTIONS_OK;
760 }
761
762 static int
763 fgOptMach( const char *arg )
764 {
765     fgSetString("/sim/presets/speed-set", "mach");
766     fgSetDouble("/sim/presets/mach", atof(arg));
767     return FG_OPTIONS_OK;
768 }
769
770 static int
771 fgOptRoc( const char *arg )
772 {
773     fgSetDouble("/velocities/vertical-speed-fps", atof(arg)/60);
774     return FG_OPTIONS_OK;
775 }
776
777 static int
778 fgOptFgRoot( const char *arg )
779 {
780     globals->set_fg_root(arg);
781     return FG_OPTIONS_OK;
782 }
783
784 static int
785 fgOptFgScenery( const char *arg )
786 {
787     globals->set_fg_scenery(arg);
788     return FG_OPTIONS_OK;
789 }
790
791 static int
792 fgOptFov( const char *arg )
793 {
794     parse_fov( arg );
795     return FG_OPTIONS_OK;
796 }
797
798 static int
799 fgOptGeometry( const char *arg )
800 {
801     bool geometry_ok = true;
802     int xsize = 0, ysize = 0;
803     string geometry = arg;
804     string::size_type i = geometry.find('x');
805
806     if (i != string::npos) {
807         xsize = atoi(geometry.substr(0, i));
808         ysize = atoi(geometry.substr(i+1));
809     } else {
810         geometry_ok = false;
811     }
812
813     if ( xsize <= 0 || ysize <= 0 ) {
814         xsize = 640;
815         ysize = 480;
816         geometry_ok = false;
817     }
818
819     if ( !geometry_ok ) {
820         SG_LOG( SG_GENERAL, SG_ALERT, "Unknown geometry: " << geometry );
821         SG_LOG( SG_GENERAL, SG_ALERT,
822                 "Setting geometry to " << xsize << 'x' << ysize << '\n');
823     } else {
824         SG_LOG( SG_GENERAL, SG_INFO,
825                 "Setting geometry to " << xsize << 'x' << ysize << '\n');
826         fgSetInt("/sim/startup/xsize", xsize);
827         fgSetInt("/sim/startup/ysize", ysize);
828     }
829     return FG_OPTIONS_OK;
830 }
831
832 static int
833 fgOptBpp( const char *arg )
834 {
835     string bits_per_pix = arg;
836     if ( bits_per_pix == "16" ) {
837         fgSetInt("/sim/rendering/bits-per-pixel", 16);
838     } else if ( bits_per_pix == "24" ) {
839         fgSetInt("/sim/rendering/bits-per-pixel", 24);
840     } else if ( bits_per_pix == "32" ) {
841         fgSetInt("/sim/rendering/bits-per-pixel", 32);
842     } else {
843         SG_LOG(SG_GENERAL, SG_ALERT, "Unsupported bpp " << bits_per_pix);
844     }
845     return FG_OPTIONS_OK;
846 }
847
848 static int
849 fgOptTimeOffset( const char *arg )
850 {
851     fgSetInt("/sim/startup/time-offset",
852                 parse_time_offset( arg ));
853     fgSetString("/sim/startup/time-offset-type", "system-offset");
854     return FG_OPTIONS_OK;
855 }
856
857 static int
858 fgOptStartDateSys( const char *arg )
859 {
860     fgSetInt("/sim/startup/time-offset", parse_date( arg ) );
861     fgSetString("/sim/startup/time-offset-type", "system");
862     return FG_OPTIONS_OK;
863 }
864
865 static int
866 fgOptStartDateLat( const char *arg )
867 {
868     fgSetInt("/sim/startup/time-offset", parse_date( arg ) );
869     fgSetString("/sim/startup/time-offset-type", "latitude");
870     return FG_OPTIONS_OK;
871 }
872
873 static int
874 fgOptStartDateGmt( const char *arg )
875 {
876     fgSetInt("/sim/startup/time-offset", parse_date( arg ) );
877     fgSetString("/sim/startup/time-offset-type", "gmt");
878     return FG_OPTIONS_OK;
879 }
880
881 static int
882 fgSetupProxy( const char *arg )
883 {
884     string options = arg;
885     string host, port, auth;
886     string::size_type pos;
887
888     host = port = auth = "";
889     if ((pos = options.find("@")) != string::npos) 
890         auth = options.substr(0, pos++);
891     else
892         pos = 0;
893
894     host = options.substr(pos, options.size());
895     if ((pos = host.find(":")) != string::npos) {
896         port = host.substr(++pos, host.size());
897         host.erase(--pos, host.size());
898     }
899
900     fgSetString("/sim/presets/proxy/host", host.c_str());
901     fgSetString("/sim/presets/proxy/port", port.c_str());
902     fgSetString("/sim/presets/proxy/authentication", auth.c_str());
903
904     return FG_OPTIONS_OK;
905 }
906
907 static int
908 fgOptTraceRead( const char *arg )
909 {
910     string name = arg;
911     SG_LOG(SG_GENERAL, SG_INFO, "Tracing reads for property " << name);
912     fgGetNode(name.c_str(), true)
913         ->setAttribute(SGPropertyNode::TRACE_READ, true);
914     return FG_OPTIONS_OK;
915 }
916
917 static int
918 fgOptLogLevel( const char *arg )
919 {
920     fgSetString("/sim/logging/classes", "all");
921     fgSetString("/sim/logging/priority", arg);
922
923     string priority = arg;
924     logbuf::set_log_classes(SG_ALL);
925     if (priority == "bulk") {
926       logbuf::set_log_priority(SG_BULK);
927     } else if (priority == "debug") {
928       logbuf::set_log_priority(SG_DEBUG);
929     } else if (priority == "info") {
930       logbuf::set_log_priority(SG_INFO);
931     } else if (priority == "warn") {
932       logbuf::set_log_priority(SG_WARN);
933     } else if (priority == "alert") {
934       logbuf::set_log_priority(SG_ALERT);
935     } else {
936       SG_LOG(SG_GENERAL, SG_WARN, "Unknown logging priority " << priority);
937     }
938     SG_LOG(SG_GENERAL, SG_DEBUG, "Logging priority is " << priority);
939
940     return FG_OPTIONS_OK;
941 }
942
943
944 static int
945 fgOptTraceWrite( const char *arg )
946 {
947     string name = arg;
948     SG_LOG(SG_GENERAL, SG_INFO, "Tracing writes for property " << name);
949     fgGetNode(name.c_str(), true)
950         ->setAttribute(SGPropertyNode::TRACE_WRITE, true);
951     return FG_OPTIONS_OK;
952 }
953
954 static int
955 fgOptViewOffset( const char *arg )
956 {
957     // $$$ begin - added VS Renganathan, 14 Oct 2K
958     // for multi-window outside window imagery
959     string woffset = arg;
960     double default_view_offset = 0.0;
961     if ( woffset == "LEFT" ) {
962             default_view_offset = SGD_PI * 0.25;
963     } else if ( woffset == "RIGHT" ) {
964         default_view_offset = SGD_PI * 1.75;
965     } else if ( woffset == "CENTER" ) {
966         default_view_offset = 0.00;
967     } else {
968         default_view_offset = atof( woffset.c_str() ) * SGD_DEGREES_TO_RADIANS;
969     }
970     /* apparently not used (CLO, 11 Jun 2002) 
971         FGViewer *pilot_view =
972             (FGViewer *)globals->get_viewmgr()->get_view( 0 ); */
973     // this will work without calls to the viewer...
974     fgSetDouble( "/sim/current-view/heading-offset-deg",
975                     default_view_offset  * SGD_RADIANS_TO_DEGREES );
976     // $$$ end - added VS Renganathan, 14 Oct 2K
977     return FG_OPTIONS_OK;
978 }
979
980 static int
981 fgOptVisibilityMeters( const char *arg )
982 {
983     double visibility = atof( arg );
984     fgDefaultWeatherValue("visibility-m", visibility);
985     return FG_OPTIONS_OK;
986 }
987
988 static int
989 fgOptVisibilityMiles( const char *arg )
990 {
991     double visibility = atof( arg ) * 5280.0 * SG_FEET_TO_METER;
992     fgDefaultWeatherValue("visibility-m", visibility);
993     return FG_OPTIONS_OK;
994 }
995
996 static int
997 fgOptRandomWind( const char *arg )
998 {
999     double min_hdg = sg_random() * 360.0;
1000     double max_hdg = min_hdg + (20 - sqrt(sg_random() * 400));
1001     double speed = sg_random() * sg_random() * 40;
1002     double gust = speed + (10 - sqrt(sg_random() * 100));
1003     fgSetupWind(min_hdg, max_hdg, speed, gust);
1004     return FG_OPTIONS_OK;
1005 }
1006
1007 static int
1008 fgOptWind( const char *arg )
1009 {
1010     double min_hdg, max_hdg, speed, gust;
1011     if (!parse_wind( arg, &min_hdg, &max_hdg, &speed, &gust)) {
1012         SG_LOG( SG_GENERAL, SG_ALERT, "bad wind value " << arg );
1013         return FG_OPTIONS_ERROR;
1014     }
1015     fgSetupWind(min_hdg, max_hdg, speed, gust);
1016     return FG_OPTIONS_OK;
1017 }
1018
1019 static int
1020 fgOptTurbulence( const char *arg )
1021 {
1022     fgDefaultWeatherValue("turbulence/magnitude-norm", atof(arg));
1023     return FG_OPTIONS_OK;
1024 }
1025
1026 static int
1027 fgOptCeiling( const char *arg )
1028 {
1029     double elevation, thickness;
1030     string spec = arg;
1031     string::size_type pos = spec.find(':');
1032     if (pos == string::npos) {
1033         elevation = atof(spec.c_str());
1034         thickness = 2000;
1035     } else {
1036         elevation = atof(spec.substr(0, pos).c_str());
1037         thickness = atof(spec.substr(pos + 1).c_str());
1038     }
1039     fgSetDouble("/environment/clouds/layer[0]/elevation-ft", elevation);
1040     fgSetDouble("/environment/clouds/layer[0]/thickness-ft", thickness);
1041     fgSetString("/environment/clouds/layer[0]/coverage", "overcast");
1042     return FG_OPTIONS_OK;
1043 }
1044
1045 static int
1046 fgOptWp( const char *arg )
1047 {
1048     parse_wp( arg );
1049     return FG_OPTIONS_OK;
1050 }
1051
1052 static int
1053 fgOptFlightPlan( const char *arg )
1054 {
1055     parse_flightplan ( arg );
1056     return FG_OPTIONS_OK;
1057 }
1058
1059 static int
1060 fgOptConfig( const char *arg )
1061 {
1062     string file = arg;
1063     try {
1064         readProperties(file, globals->get_props());
1065     } catch (const sg_exception &e) {
1066         string message = "Error loading config file: ";
1067         message += e.getFormattedMessage() + e.getOrigin();
1068         SG_LOG(SG_INPUT, SG_ALERT, message);
1069         exit(2);
1070     }
1071     return FG_OPTIONS_OK;
1072 }
1073
1074 static bool
1075 parse_colon (const string &s, double * val1, double * val2)
1076 {
1077     string::size_type pos = s.find(':');
1078     if (pos == string::npos) {
1079         *val2 = atof(s);
1080         return false;
1081     } else {
1082         *val1 = atof(s.substr(0, pos).c_str());
1083         *val2 = atof(s.substr(pos+1).c_str());
1084         return true;
1085     }
1086 }
1087
1088
1089 static int
1090 fgOptFailure( const char * arg )
1091 {
1092     string a = arg;
1093     if (a == "pitot") {
1094         fgSetBool("/systems/pitot/serviceable", false);
1095     } else if (a == "static") {
1096         fgSetBool("/systems/static/serviceable", false);
1097     } else if (a == "vacuum") {
1098         fgSetBool("/systems/vacuum/serviceable", false);
1099     } else if (a == "electrical") {
1100         fgSetBool("/systems/electrical/serviceable", false);
1101     } else {
1102         SG_LOG(SG_INPUT, SG_ALERT, "Unknown failure mode: " << a);
1103         return FG_OPTIONS_ERROR;
1104     }
1105
1106     return FG_OPTIONS_OK;
1107 }
1108
1109
1110 static int
1111 fgOptNAV1( const char * arg )
1112 {
1113     double radial, freq;
1114     if (parse_colon(arg, &radial, &freq))
1115         fgSetDouble("/instrumentation/nav[0]/radials/selected-deg", radial);
1116     fgSetDouble("/instrumentation/nav[0]/frequencies/selected-mhz", freq);
1117     return FG_OPTIONS_OK;
1118 }
1119
1120 static int
1121 fgOptNAV2( const char * arg )
1122 {
1123     double radial, freq;
1124     if (parse_colon(arg, &radial, &freq))
1125         fgSetDouble("/instrumentation/nav[1]/radials/selected-deg", radial);
1126     fgSetDouble("/instrumentation/nav[1]/frequencies/selected-mhz", freq);
1127     return FG_OPTIONS_OK;
1128 }
1129
1130 static int
1131 fgOptADF( const char * arg )
1132 {
1133     double rot, freq;
1134     if (parse_colon(arg, &rot, &freq))
1135         fgSetDouble("/instrumentation/adf/rotation-deg", rot);
1136     fgSetDouble("/instrumentation/adf/frequencies/selected-khz", freq);
1137     return FG_OPTIONS_OK;
1138 }
1139
1140 static int
1141 fgOptDME( const char *arg )
1142 {
1143     string opt = arg;
1144     if (opt == "nav1") {
1145         fgSetInt("/instrumentation/dme/switch-position", 1);
1146         fgSetString("/instrumentation/dme/frequencies/source",
1147                     "/instrumentation/nav[0]/frequencies/selected-mhz");
1148     } else if (opt == "nav2") {
1149         fgSetInt("/instrumentation/dme/switch-position", 3);
1150         fgSetString("/instrumentation/dme/frequencies/source",
1151                     "/instrumentation/nav[1]/frequencies/selected-mhz");
1152     } else {
1153         fgSetInt("/instrumentation/dme/switch-position", 2);
1154         fgSetString("/instrumentation/dme/frequencies/source",
1155                     "/instrumentation/dme/frequencies/selected-mhz");
1156         fgSetString("/instrumentation/dme/frequencies/selected-mhz", arg);
1157     }
1158     return FG_OPTIONS_OK;
1159 }
1160
1161 static int
1162 fgOptLivery( const char *arg )
1163 {
1164     string opt = arg;
1165     string livery_path = "livery/" + opt;
1166     fgSetString("/sim/model/texture-path", livery_path.c_str() );
1167     return FG_OPTIONS_OK;
1168 }
1169
1170 static int
1171 fgOptScenario( const char *arg )
1172 {
1173     SGPropertyNode_ptr ai_node = fgGetNode( "/sim/ai", true );
1174     vector<SGPropertyNode_ptr> scenarii = ai_node->getChildren( "scenario" );
1175     int index = -1;
1176     for ( size_t i = 0; i < scenarii.size(); ++i ) {
1177         int ind = scenarii[i]->getIndex();
1178         if ( index < ind ) {
1179             index = ind;
1180         }
1181     }
1182     SGPropertyNode_ptr scenario = ai_node->getNode( "scenario", index + 1, true );
1183     scenario->setStringValue( arg );
1184     ai_node->setBoolValue( "enabled", true );
1185     return FG_OPTIONS_OK;
1186 }
1187
1188 static int
1189 fgOptRunway( const char *arg )
1190 {
1191     fgSetString("/sim/presets/runway", arg );
1192     fgSetBool("/sim/presets/runway-requested", true );
1193     return FG_OPTIONS_OK;
1194 }
1195
1196 static int
1197 fgOptParking( const char *arg )
1198 {
1199     cerr << "Processing argument " << arg << endl;
1200     fgSetString("/sim/presets/parking", arg );
1201     fgSetBool  ("/sim/presets/parking-requested", true );
1202     return FG_OPTIONS_OK;
1203 }
1204
1205 static int
1206 fgOptVersion( const char *arg )
1207 {
1208     cerr << VERSION << endl;
1209     cerr << "FG_ROOT=" << globals->get_fg_root() << endl;
1210     cerr << "FG_HOME=" << fgGetString("/sim/fg-home") << endl;
1211     return FG_OPTIONS_EXIT;
1212 }
1213
1214 static map<string,size_t> fgOptionMap;
1215
1216 /*
1217    option       has_param type        property         b_param s_param  func
1218
1219 where:
1220  option    : name of the option
1221  has_param : option is --name=value if true or --name if false
1222  type      : OPTION_BOOL    - property is a boolean
1223              OPTION_STRING  - property is a string
1224              OPTION_DOUBLE  - property is a double
1225              OPTION_INT     - property is an integer
1226              OPTION_CHANNEL - name of option is the name of a channel
1227              OPTION_FUNC    - the option trigger a function
1228  b_param   : if type==OPTION_BOOL,
1229              value set to the property (has_param is false for boolean)
1230  s_param   : if type==OPTION_STRING,
1231              value set to the property if has_param is false
1232  func      : function called if type==OPTION_FUNC. if has_param is true,
1233              the value is passed to the function as a string, otherwise,
1234              0 is passed. 
1235
1236     For OPTION_DOUBLE and OPTION_INT, the parameter value is converted into a
1237     double or an integer and set to the property.
1238
1239     For OPTION_CHANNEL, add_channel is called with the parameter value as the
1240     argument.
1241 */
1242
1243 enum OptionType { OPTION_BOOL, OPTION_STRING, OPTION_DOUBLE, OPTION_INT, OPTION_CHANNEL, OPTION_FUNC };
1244 struct OptionDesc {
1245     char *option;
1246     bool has_param;
1247     enum OptionType type;
1248     char *property;
1249     bool b_param;
1250     char *s_param;
1251     int (*func)( const char * );
1252     } fgOptionArray[] = {
1253        
1254     {"language",                     true,  OPTION_FUNC,   "", false, "", fgOptLanguage },
1255     {"disable-game-mode",            false, OPTION_BOOL,   "/sim/startup/game-mode", false, "", 0 },
1256     {"enable-game-mode",             false, OPTION_BOOL,   "/sim/startup/game-mode", true, "", 0 },
1257     {"disable-splash-screen",        false, OPTION_BOOL,   "/sim/startup/splash-screen", false, "", 0 },
1258     {"enable-splash-screen",         false, OPTION_BOOL,   "/sim/startup/splash-screen", true, "", 0 },
1259     {"disable-intro-music",          false, OPTION_BOOL,   "/sim/startup/intro-music", false, "", 0 },
1260     {"enable-intro-music",           false, OPTION_BOOL,   "/sim/startup/intro-music", true, "", 0 },
1261     {"disable-mouse-pointer",        false, OPTION_STRING, "/sim/startup/mouse-pointer", false, "disabled", 0 },
1262     {"enable-mouse-pointer",         false, OPTION_STRING, "/sim/startup/mouse-pointer", false, "enabled", 0 },
1263     {"disable-random-objects",       false, OPTION_BOOL,   "/sim/rendering/random-objects", false, "", 0 },
1264     {"enable-random-objects",        false, OPTION_BOOL,   "/sim/rendering/random-objects", true, "", 0 },
1265     {"disable-real-weather-fetch",   false, OPTION_BOOL,   "/environment/params/real-world-weather-fetch", false, "", 0 },
1266     {"enable-real-weather-fetch",    false, OPTION_BOOL,   "/environment/params/real-world-weather-fetch", true, "", 0 },
1267     {"disable-ai-models",            false, OPTION_BOOL,   "/sim/ai/enabled", false, "", 0 },
1268     {"enable-ai-models",             false, OPTION_BOOL,   "/sim/ai/enabled", true, "", 0 },
1269     {"disable-freeze",               false, OPTION_BOOL,   "/sim/freeze/master", false, "", 0 },
1270     {"enable-freeze",                false, OPTION_BOOL,   "/sim/freeze/master", true, "", 0 },
1271     {"disable-fuel-freeze",          false, OPTION_BOOL,   "/sim/freeze/fuel", false, "", 0 },
1272     {"enable-fuel-freeze",           false, OPTION_BOOL,   "/sim/freeze/fuel", true, "", 0 },
1273     {"disable-clock-freeze",         false, OPTION_BOOL,   "/sim/freeze/clock", false, "", 0 },
1274     {"enable-clock-freeze",          false, OPTION_BOOL,   "/sim/freeze/clock", true, "", 0 },
1275     {"disable-hud-3d",               false, OPTION_BOOL,   "/sim/hud/enable3d", false, "", 0 },
1276     {"enable-hud-3d",                false, OPTION_BOOL,   "/sim/hud/enable3d", true, "", 0 },
1277     {"disable-anti-alias-hud",       false, OPTION_BOOL,   "/sim/hud/color/antialiased", false, "", 0 },
1278     {"enable-anti-alias-hud",        false, OPTION_BOOL,   "/sim/hud/color/antialiased", true, "", 0 },
1279     {"control",                      true,  OPTION_STRING, "/sim/control-mode", false, "", 0 },
1280     {"disable-auto-coordination",    false, OPTION_BOOL,   "/sim/auto-coordination", false, "", 0 },
1281     {"enable-auto-coordination",     false, OPTION_BOOL,   "/sim/auto-coordination", true, "", 0 },
1282     {"browser-app",                  true,  OPTION_STRING, "/sim/startup/browser-app", false, "", 0 },
1283     {"disable-hud",                  false, OPTION_BOOL,   "/sim/hud/visibility", false, "", 0 },
1284     {"enable-hud",                   false, OPTION_BOOL,   "/sim/hud/visibility", true, "", 0 },
1285     {"disable-panel",                false, OPTION_BOOL,   "/sim/panel/visibility", false, "", 0 },
1286     {"enable-panel",                 false, OPTION_BOOL,   "/sim/panel/visibility", true, "", 0 },
1287     {"disable-sound",                false, OPTION_BOOL,   "/sim/sound/pause", true, "", 0 },
1288     {"enable-sound",                 false, OPTION_BOOL,   "/sim/sound/pause", false, "", 0 },
1289     {"airport",                      true,  OPTION_STRING, "/sim/presets/airport-id", false, "", 0 },
1290     {"runway",                       true,  OPTION_FUNC,   "", false, "", fgOptRunway },
1291     {"vor",                          true,  OPTION_FUNC,   "", false, "", fgOptVOR },
1292     {"ndb",                          true,  OPTION_FUNC,   "", false, "", fgOptNDB },
1293     {"carrier",                      true,  OPTION_FUNC,   "", false, "", fgOptCarrier },
1294     {"parkpos",                      true,  OPTION_FUNC,   "", false, "", fgOptParkpos },
1295     {"fix",                          true,  OPTION_FUNC,   "", false, "", fgOptFIX },
1296     {"offset-distance",              true,  OPTION_DOUBLE, "/sim/presets/offset-distance-nm", false, "", 0 },
1297     {"offset-azimuth",               true,  OPTION_DOUBLE, "/sim/presets/offset-azimuth-deg", false, "", 0 },
1298     {"lon",                          true,  OPTION_FUNC,   "", false, "", fgOptLon },
1299     {"lat",                          true,  OPTION_FUNC,   "", false, "", fgOptLat },
1300     {"altitude",                     true,  OPTION_FUNC,   "", false, "", fgOptAltitude },
1301     {"uBody",                        true,  OPTION_FUNC,   "", false, "", fgOptUBody },
1302     {"vBody",                        true,  OPTION_FUNC,   "", false, "", fgOptVBody },
1303     {"wBody",                        true,  OPTION_FUNC,   "", false, "", fgOptWBody },
1304     {"vNorth",                       true,  OPTION_FUNC,   "", false, "", fgOptVNorth },
1305     {"vEast",                        true,  OPTION_FUNC,   "", false, "", fgOptVEast },
1306     {"vDown",                        true,  OPTION_FUNC,   "", false, "", fgOptVDown },
1307     {"vc",                           true,  OPTION_FUNC,   "", false, "", fgOptVc },
1308     {"mach",                         true,  OPTION_FUNC,   "", false, "", fgOptMach },
1309     {"heading",                      true,  OPTION_DOUBLE, "/sim/presets/heading-deg", false, "", 0 },
1310     {"roll",                         true,  OPTION_DOUBLE, "/sim/presets/roll-deg", false, "", 0 },
1311     {"pitch",                        true,  OPTION_DOUBLE, "/sim/presets/pitch-deg", false, "", 0 },
1312     {"glideslope",                   true,  OPTION_DOUBLE, "/sim/presets/glideslope-deg", false, "", 0 },
1313     {"roc",                          true,  OPTION_FUNC,   "", false, "", fgOptRoc },
1314     {"fg-root",                      true,  OPTION_FUNC,   "", false, "", fgOptFgRoot },
1315     {"fg-scenery",                   true,  OPTION_FUNC,   "", false, "", fgOptFgScenery },
1316     {"fdm",                          true,  OPTION_STRING, "/sim/flight-model", false, "", 0 },
1317     {"aero",                         true,  OPTION_STRING, "/sim/aero", false, "", 0 },
1318     {"aircraft-dir",                 true,  OPTION_STRING, "/sim/aircraft-dir", false, "", 0 },
1319     {"model-hz",                     true,  OPTION_INT,    "/sim/model-hz", false, "", 0 },
1320     {"speed",                        true,  OPTION_INT,    "/sim/speed-up", false, "", 0 },
1321     {"trim",                         false, OPTION_BOOL,   "/sim/presets/trim", true, "", 0 },
1322     {"notrim",                       false, OPTION_BOOL,   "/sim/presets/trim", false, "", 0 },
1323     {"on-ground",                    false, OPTION_BOOL,   "/sim/presets/onground", true, "", 0 },
1324     {"in-air",                       false, OPTION_BOOL,   "/sim/presets/onground", false, "", 0 },
1325     {"fog-disable",                  false, OPTION_STRING, "/sim/rendering/fog", false, "disabled", 0 },
1326     {"fog-fastest",                  false, OPTION_STRING, "/sim/rendering/fog", false, "fastest", 0 },
1327     {"fog-nicest",                   false, OPTION_STRING, "/sim/rendering/fog", false, "nicest", 0 },
1328     {"disable-horizon-effect",       false, OPTION_BOOL,   "/sim/rendering/horizon-effect", false, "", 0 },
1329     {"enable-horizon-effect",        false, OPTION_BOOL,   "/sim/rendering/horizon-effect", true, "", 0 },
1330     {"disable-enhanced-lighting",    false, OPTION_BOOL,   "/sim/rendering/enhanced-lighting", false, "", 0 },
1331     {"enable-enhanced-lighting",     false, OPTION_BOOL,   "/sim/rendering/enhanced-lighting", true, "", 0 },
1332     {"disable-distance-attenuation", false, OPTION_BOOL,   "/sim/rendering/distance-attenuation", false, "", 0 },
1333     {"enable-distance-attenuation",  false, OPTION_BOOL,   "/sim/rendering/distance-attenuation", true, "", 0 },
1334     {"disable-specular-highlight",   false, OPTION_BOOL,   "/sim/rendering/specular-highlight", false, "", 0 },
1335     {"enable-specular-highlight",    false, OPTION_BOOL,   "/sim/rendering/specular-highlight", true, "", 0 },
1336     {"disable-clouds",               false, OPTION_BOOL,   "/environment/clouds/status", false, "", 0 },
1337     {"enable-clouds",                false, OPTION_BOOL,   "/environment/clouds/status", true, "", 0 },
1338     {"disable-clouds3d",             false, OPTION_BOOL,   "/sim/rendering/clouds3d-enable", false, "", 0 },
1339     {"enable-clouds3d",              false, OPTION_BOOL,   "/sim/rendering/clouds3d-enable", true, "", 0 },
1340     {"fov",                          true,  OPTION_FUNC,   "", false, "", fgOptFov },
1341     {"aspect-ratio-multiplier",      true,  OPTION_DOUBLE, "/sim/current-view/aspect-ratio-multiplier", false, "", 0 },
1342     {"disable-fullscreen",           false, OPTION_BOOL,   "/sim/startup/fullscreen", false, "", 0 },
1343     {"enable-fullscreen",            false, OPTION_BOOL,   "/sim/startup/fullscreen", true, "", 0 },
1344     {"disable-save-on-exit",         false, OPTION_BOOL,   "/sim/startup/save-on-exit", false, "", 0 },
1345     {"enable-save-on-exit",          false, OPTION_BOOL,   "/sim/startup/save-on-exit", true, "", 0 },
1346     {"shading-flat",                 false, OPTION_BOOL,   "/sim/rendering/shading", false, "", 0 },
1347     {"shading-smooth",               false, OPTION_BOOL,   "/sim/rendering/shading", true, "", 0 },
1348     {"disable-skyblend",             false, OPTION_BOOL,   "/sim/rendering/skyblend", false, "", 0 },
1349     {"enable-skyblend",              false, OPTION_BOOL,   "/sim/rendering/skyblend", true, "", 0 },
1350     {"disable-textures",             false, OPTION_BOOL,   "/sim/rendering/textures", false, "", 0 },
1351     {"enable-textures",              false, OPTION_BOOL,   "/sim/rendering/textures", true, "", 0 },
1352     {"texture-filtering",            false, OPTION_INT,    "/sim/rendering/filtering", 1, "", 0 },
1353     {"disable-wireframe",            false, OPTION_BOOL,   "/sim/rendering/wireframe", false, "", 0 },
1354     {"enable-wireframe",             false, OPTION_BOOL,   "/sim/rendering/wireframe", true, "", 0 },
1355     {"geometry",                     true,  OPTION_FUNC,   "", false, "", fgOptGeometry },
1356     {"bpp",                          true,  OPTION_FUNC,   "", false, "", fgOptBpp },
1357     {"units-feet",                   false, OPTION_STRING, "/sim/startup/units", false, "feet", 0 },
1358     {"units-meters",                 false, OPTION_STRING, "/sim/startup/units", false, "meters", 0 },
1359     {"timeofday",                    true,  OPTION_STRING, "/sim/startup/time-offset-type", false, "noon", 0 },
1360     {"season",                       true,  OPTION_STRING, "/sim/startup/season", false, "summer", 0 },
1361     {"time-offset",                  true,  OPTION_FUNC,   "", false, "", fgOptTimeOffset },
1362     {"time-match-real",              false, OPTION_STRING, "/sim/startup/time-offset-type", false, "system-offset", 0 },
1363     {"time-match-local",             false, OPTION_STRING, "/sim/startup/time-offset-type", false, "latitude-offset", 0 },
1364     {"start-date-sys",               true,  OPTION_FUNC,   "", false, "", fgOptStartDateSys },
1365     {"start-date-lat",               true,  OPTION_FUNC,   "", false, "", fgOptStartDateLat },
1366     {"start-date-gmt",               true,  OPTION_FUNC,   "", false, "", fgOptStartDateGmt },
1367     {"hud-tris",                     false, OPTION_STRING, "/sim/hud/frame-stat-type", false, "tris", 0 },
1368     {"hud-culled",                   false, OPTION_STRING, "/sim/hud/frame-stat-type", false, "culled", 0 },
1369     {"atcsim",                       true,  OPTION_CHANNEL, "", false, "dummy", 0 },
1370     {"atlas",                        true,  OPTION_CHANNEL, "", false, "", 0 },
1371     {"httpd",                        true,  OPTION_CHANNEL, "", false, "", 0 },
1372 #ifdef FG_JPEG_SERVER
1373     {"jpg-httpd",                    true,  OPTION_CHANNEL, "", false, "", 0 },
1374 #endif
1375     {"native",                       true,  OPTION_CHANNEL, "", false, "", 0 },
1376     {"native-ctrls",                 true,  OPTION_CHANNEL, "", false, "", 0 },
1377     {"native-fdm",                   true,  OPTION_CHANNEL, "", false, "", 0 },
1378     {"native-gui",                   true,  OPTION_CHANNEL, "", false, "", 0 },
1379     {"opengc",                       true,  OPTION_CHANNEL, "", false, "", 0 },
1380     {"AV400",                        true,  OPTION_CHANNEL, "", false, "", 0 },
1381     {"garmin",                       true,  OPTION_CHANNEL, "", false, "", 0 },
1382     {"nmea",                         true,  OPTION_CHANNEL, "", false, "", 0 },
1383     {"generic",                      true,  OPTION_CHANNEL, "", false, "", 0 },
1384     {"props",                        true,  OPTION_CHANNEL, "", false, "", 0 },
1385     {"telnet",                       true,  OPTION_CHANNEL, "", false, "", 0 },
1386     {"pve",                          true,  OPTION_CHANNEL, "", false, "", 0 },
1387     {"ray",                          true,  OPTION_CHANNEL, "", false, "", 0 },
1388     {"rul",                          true,  OPTION_CHANNEL, "", false, "", 0 },
1389     {"joyclient",                    true,  OPTION_CHANNEL, "", false, "", 0 },
1390     {"jsclient",                     true,  OPTION_CHANNEL, "", false, "", 0 },
1391     {"proxy",                        true,  OPTION_FUNC,    "", false, "", fgSetupProxy },
1392     {"callsign",                     true, OPTION_STRING,  "sim/multiplay/callsign", false, "", 0 },
1393     {"multiplay",                    true,  OPTION_CHANNEL, "", false, "", 0 },
1394     {"trace-read",                   true,  OPTION_FUNC,   "", false, "", fgOptTraceRead },
1395     {"trace-write",                  true,  OPTION_FUNC,   "", false, "", fgOptTraceWrite },
1396     {"log-level",                    true,  OPTION_FUNC,   "", false, "", fgOptLogLevel },
1397     {"view-offset",                  true,  OPTION_FUNC,   "", false, "", fgOptViewOffset },
1398     {"visibility",                   true,  OPTION_FUNC,   "", false, "", fgOptVisibilityMeters },
1399     {"visibility-miles",             true,  OPTION_FUNC,   "", false, "", fgOptVisibilityMiles },
1400     {"random-wind",                  false, OPTION_FUNC,   "", false, "", fgOptRandomWind },
1401     {"wind",                         true,  OPTION_FUNC,   "", false, "", fgOptWind },
1402     {"turbulence",                   true,  OPTION_FUNC,   "", false, "", fgOptTurbulence },
1403     {"ceiling",                      true,  OPTION_FUNC,   "", false, "", fgOptCeiling },
1404     {"wp",                           true,  OPTION_FUNC,   "", false, "", fgOptWp },
1405     {"flight-plan",                  true,  OPTION_FUNC,   "", false, "", fgOptFlightPlan },
1406     {"config",                       true,  OPTION_FUNC,   "", false, "", fgOptConfig },
1407     {"aircraft",                     true,  OPTION_STRING, "/sim/aircraft", false, "", 0 },
1408     {"vehicle",                      true,  OPTION_STRING, "/sim/aircraft", false, "", 0 },
1409     {"failure",                      true,  OPTION_FUNC,   "", false, "", fgOptFailure },
1410     {"com1",                         true,  OPTION_DOUBLE, "/instrumentation/comm[0]/frequencies/selected-mhz", false, "", 0 },
1411     {"com2",                         true,  OPTION_DOUBLE, "/instrumentation/comm[1]/frequencies/selected-mhz", false, "", 0 },
1412     {"nav1",                         true,  OPTION_FUNC,   "", false, "", fgOptNAV1 },
1413     {"nav2",                         true,  OPTION_FUNC,   "", false, "", fgOptNAV2 },
1414     {"adf",                          true,  OPTION_FUNC,   "", false, "", fgOptADF },
1415     {"dme",                          true,  OPTION_FUNC,   "", false, "", fgOptDME },
1416     {"min-status",                   true,  OPTION_STRING,  "/sim/aircraft-min-status", false, "all", 0 },
1417     {"livery",                       true,  OPTION_FUNC,   "", false, "", fgOptLivery },
1418     {"ai-scenario",                  true,  OPTION_FUNC,   "", false, "", fgOptScenario },
1419     {"parking-id",                   true,  OPTION_FUNC,   "", false, "", fgOptParking  },
1420     {"version",                      false, OPTION_FUNC,   "", false, "", fgOptVersion },
1421     {0}
1422 };
1423
1424
1425 // Set a property for the --prop: option. Syntax: --prop:[<type>:]<name>=<value>
1426 // <type> can be "double" etc. but also only the first letter "d".
1427 // Examples:  --prop:alpha=1  --prop:bool:beta=true  --prop:d:gamma=0.123
1428 static bool
1429 set_property(const string& arg)
1430 {
1431     string::size_type pos = arg.find('=');
1432     if (pos == arg.npos || pos == 0 || pos + 1 == arg.size())
1433         return false;
1434
1435     string name = arg.substr(0, pos);
1436     string value = arg.substr(pos + 1);
1437     string type;
1438     pos = name.find(':');
1439
1440     if (pos != name.npos && pos != 0 && pos + 1 != name.size()) {
1441         type = name.substr(0, pos);
1442         name = name.substr(pos + 1);
1443     }
1444     SGPropertyNode *n = fgGetNode(name.c_str(), true);
1445
1446     if (type.empty())
1447         return n->setUnspecifiedValue(value.c_str());
1448     else if (type == "s" || type == "string")
1449         return n->setStringValue(value.c_str());
1450     else if (type == "d" || type == "double")
1451         return n->setDoubleValue(strtod(value.c_str(), 0));
1452     else if (type == "f" || type == "float")
1453         return n->setFloatValue(atof(value.c_str()));
1454     else if (type == "l" || type == "long")
1455         return n->setLongValue(strtol(value.c_str(), 0, 0));
1456     else if (type == "i" || type == "int")
1457         return n->setIntValue(atoi(value.c_str()));
1458     else if (type == "b" || type == "bool")
1459         return n->setBoolValue(value == "true" || atoi(value.c_str()) != 0);
1460
1461     return false;
1462 }
1463
1464
1465 // Parse a single option
1466 static int
1467 parse_option (const string& arg)
1468 {
1469     if ( fgOptionMap.size() == 0 ) {
1470         size_t i = 0;
1471         OptionDesc *pt = &fgOptionArray[ 0 ];
1472         while ( pt->option != 0 ) {
1473             fgOptionMap[ pt->option ] = i;
1474             i += 1;
1475             pt += 1;
1476         }
1477     }
1478
1479     // General Options
1480     if ( (arg == "--help") || (arg == "-h") ) {
1481         // help/usage request
1482         return(FG_OPTIONS_HELP);
1483     } else if ( (arg == "--verbose") || (arg == "-v") ) {
1484         // verbose help/usage request
1485         return(FG_OPTIONS_VERBOSE_HELP);
1486     } else if ( arg.find( "--show-aircraft") == 0) {
1487         return(FG_OPTIONS_SHOW_AIRCRAFT);
1488     } else if ( arg.find( "--prop:" ) == 0 ) {
1489         if (!set_property(arg.substr(7))) {
1490             SG_LOG( SG_GENERAL, SG_ALERT, "Bad property assignment: " << arg );
1491             return FG_OPTIONS_ERROR;
1492         }
1493     } else if ( arg.find( "--" ) == 0 ) {
1494         size_t pos = arg.find( '=' );
1495         string arg_name, arg_value;
1496         if ( pos == string::npos ) {
1497             arg_name = arg.substr( 2 );
1498         } else {
1499             arg_name = arg.substr( 2, pos - 2 );
1500             arg_value = arg.substr( pos + 1);
1501         }
1502         map<string,size_t>::iterator it = fgOptionMap.find( arg_name );
1503         if ( it != fgOptionMap.end() ) {
1504             OptionDesc *pt = &fgOptionArray[ it->second ];
1505             switch ( pt->type ) {
1506                 case OPTION_BOOL:
1507                     fgSetBool( pt->property, pt->b_param );
1508                     break;
1509                 case OPTION_STRING:
1510                     if ( pt->has_param && !arg_value.empty() ) {
1511                         fgSetString( pt->property, arg_value.c_str() );
1512                     } else if ( !pt->has_param && arg_value.empty() ) {
1513                         fgSetString( pt->property, pt->s_param );
1514                     } else if ( pt->has_param ) {
1515                         SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1516                         return FG_OPTIONS_ERROR;
1517                     } else {
1518                         SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' does not have a parameter" );
1519                         return FG_OPTIONS_ERROR;
1520                     }
1521                     break;
1522                 case OPTION_DOUBLE:
1523                     if ( !arg_value.empty() ) {
1524                         fgSetDouble( pt->property, atof( arg_value ) );
1525                     } else {
1526                         SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1527                         return FG_OPTIONS_ERROR;
1528                     }
1529                     break;
1530                 case OPTION_INT:
1531                     if ( !arg_value.empty() ) {
1532                         fgSetInt( pt->property, atoi( arg_value ) );
1533                     } else {
1534                         SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1535                         return FG_OPTIONS_ERROR;
1536                     }
1537                     break;
1538                 case OPTION_CHANNEL:
1539                     if ( pt->has_param && !arg_value.empty() ) {
1540                         add_channel( pt->option, arg_value );
1541                     } else if ( !pt->has_param && arg_value.empty() ) {
1542                         add_channel( pt->option, pt->s_param );
1543                     } else if ( pt->has_param ) {
1544                         SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1545                         return FG_OPTIONS_ERROR;
1546                     } else {
1547                         SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' does not have a parameter" );
1548                         return FG_OPTIONS_ERROR;
1549                     }
1550                     break;
1551                 case OPTION_FUNC:
1552                     if ( pt->has_param && !arg_value.empty() ) {
1553                         return pt->func( arg_value.c_str() );
1554                     } else if ( !pt->has_param && arg_value.empty() ) {
1555                         return pt->func( 0 );
1556                     } else if ( pt->has_param ) {
1557                         SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1558                         return FG_OPTIONS_ERROR;
1559                     } else {
1560                         SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' does not have a parameter" );
1561                         return FG_OPTIONS_ERROR;
1562                     }
1563                     break;
1564             }
1565         } else {
1566             SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" );
1567             return FG_OPTIONS_ERROR;
1568         }
1569     } else {
1570         SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" );
1571         return FG_OPTIONS_ERROR;
1572     }
1573
1574     return FG_OPTIONS_OK;
1575 }
1576
1577
1578 // Parse the command line options
1579 void
1580 fgParseArgs (int argc, char **argv)
1581 {
1582     bool in_options = true;
1583     bool verbose = false;
1584     bool help = false;
1585
1586     SG_LOG(SG_GENERAL, SG_INFO, "Processing command line arguments");
1587
1588     for (int i = 1; i < argc; i++) {
1589         string arg = argv[i];
1590
1591         if (in_options && (arg.find('-') == 0)) {
1592           if (arg == "--") {
1593             in_options = false;
1594           } else {
1595             int result = parse_option(arg);
1596             if ((result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR))
1597               help = true;
1598
1599             else if (result == FG_OPTIONS_VERBOSE_HELP)
1600               verbose = true;
1601
1602             else if (result == FG_OPTIONS_SHOW_AIRCRAFT) {
1603                fgOptLogLevel( "alert" );
1604                SGPath path( globals->get_fg_root() );
1605                path.append("Aircraft");
1606                fgShowAircraft(path, true);
1607                exit(0);
1608             }
1609
1610             else if (result == FG_OPTIONS_EXIT)
1611                exit(0);
1612           }
1613         } else {
1614           in_options = false;
1615           SG_LOG(SG_GENERAL, SG_INFO,
1616                  "Reading command-line property file " << arg);
1617           readProperties(arg, globals->get_props());
1618         }
1619     }
1620
1621     if (help) {
1622        fgOptLogLevel( "alert" );
1623        fgUsage(verbose);
1624        exit(0);
1625     }
1626
1627     SG_LOG(SG_GENERAL, SG_INFO, "Finished command line arguments");
1628 }
1629
1630
1631 // Parse config file options
1632 void
1633 fgParseOptions (const string& path) {
1634     sg_gzifstream in( path );
1635     if ( !in.is_open() ) {
1636         return;
1637     }
1638
1639     SG_LOG( SG_GENERAL, SG_INFO, "Processing config file: " << path );
1640
1641     in >> skipcomment;
1642 #ifndef __MWERKS__
1643     while ( ! in.eof() ) {
1644 #else
1645     char c = '\0';
1646     while ( in.get(c) && c != '\0' ) {
1647         in.putback(c);
1648 #endif
1649         string line;
1650
1651 #if defined( macintosh )
1652         getline( in, line, '\r' );
1653 #else
1654         getline( in, line, '\n' );
1655 #endif
1656
1657         // catch extraneous (DOS) line ending character
1658         int i;
1659         for (i = line.length(); i > 0; i--)
1660             if (line[i - 1] > 32)
1661                 break;
1662         line = line.substr( 0, i );
1663
1664         if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
1665             cerr << endl << "Config file parse error: " << path << " '" 
1666                     << line << "'" << endl;
1667             fgUsage();
1668             exit(-1);
1669         }
1670         in >> skipcomment;
1671     }
1672 }
1673
1674
1675 // Print usage message
1676 void 
1677 fgUsage (bool verbose)
1678 {
1679     SGPropertyNode *locale = globals->get_locale();
1680
1681     SGPropertyNode options_root;
1682
1683     SG_LOG( SG_GENERAL, SG_ALERT, "" ); // To popup the console on Windows
1684     cout << endl;
1685
1686     try {
1687         fgLoadProps("options.xml", &options_root);
1688     } catch (const sg_exception &) {
1689         cout << "Unable to read the help file." << endl;
1690         cout << "Make sure the file options.xml is located in the FlightGear base directory," << endl;
1691         cout << "and the location of the base directory is specified by setting $FG_ROOT or" << endl;
1692         cout << "by adding --fg-root=path as a program argument." << endl;
1693         
1694         exit(-1);
1695     }
1696
1697     SGPropertyNode *options = options_root.getNode("options");
1698     if (!options) {
1699         SG_LOG( SG_GENERAL, SG_ALERT,
1700                 "Error reading options.xml: <options> directive not found." );
1701         exit(-1);
1702     }
1703
1704     SGPropertyNode *usage = locale->getNode(options->getStringValue("usage"));
1705     if (usage) {
1706         cout << "Usage: " << usage->getStringValue() << endl;
1707     }
1708
1709     vector<SGPropertyNode_ptr>section = options->getChildren("section");
1710     for (unsigned int j = 0; j < section.size(); j++) {
1711         string msg = "";
1712
1713         vector<SGPropertyNode_ptr>option = section[j]->getChildren("option");
1714         for (unsigned int k = 0; k < option.size(); k++) {
1715
1716             SGPropertyNode *name = option[k]->getNode("name");
1717             SGPropertyNode *short_name = option[k]->getNode("short");
1718             SGPropertyNode *key = option[k]->getNode("key");
1719             SGPropertyNode *arg = option[k]->getNode("arg");
1720             bool brief = option[k]->getNode("brief") != 0;
1721
1722             if ((brief || verbose) && name) {
1723                 string tmp = name->getStringValue();
1724
1725                 if (key){
1726                     tmp.append(":");
1727                     tmp.append(key->getStringValue());
1728                 }
1729                 if (arg) {
1730                     tmp.append("=");
1731                     tmp.append(arg->getStringValue());
1732                 }
1733                 if (short_name) {
1734                     tmp.append(", -");
1735                     tmp.append(short_name->getStringValue());
1736                 }
1737                                 
1738                 if (tmp.size() <= 25) {
1739                     msg+= "   --";
1740                     msg += tmp;
1741                     msg.append( 27-tmp.size(), ' ');
1742                 } else {
1743                     msg += "\n   --";
1744                     msg += tmp + '\n';
1745                     msg.append(32, ' ');
1746                 }
1747                 // There may be more than one <description> tag assosiated
1748                 // with one option
1749
1750                 vector<SGPropertyNode_ptr> desc;
1751                 desc = option[k]->getChildren("description");
1752                 if (desc.size() > 0) {
1753                    for ( unsigned int l = 0; l < desc.size(); l++) {
1754
1755                       // There may be more than one translation line.
1756
1757                       string t = desc[l]->getStringValue();
1758                       SGPropertyNode *n = locale->getNode("strings");
1759                       vector<SGPropertyNode_ptr>trans_desc =
1760                                n->getChildren(t.substr(8).c_str());
1761
1762                       for ( unsigned int m = 0; m < trans_desc.size(); m++ ) {
1763                          string t_str = trans_desc[m]->getStringValue();
1764
1765                          if ((m > 0) || ((l > 0) && m == 0)) {
1766                             msg.append( 32, ' ');
1767                          }
1768
1769                          // If the string is too large to fit on the screen,
1770                          // then split it up in several pieces.
1771
1772                          while ( t_str.size() > 47 ) {
1773
1774                             unsigned int m = t_str.rfind(' ', 47);
1775                             msg += t_str.substr(0, m) + '\n';
1776                             msg.append( 32, ' ');
1777
1778                             t_str.erase(t_str.begin(), t_str.begin() + m + 1);
1779                         }
1780                         msg += t_str + '\n';
1781                      }
1782                   }
1783                }
1784             }
1785         }
1786
1787         SGPropertyNode *name;
1788         name = locale->getNode(section[j]->getStringValue("name"));
1789
1790         if (!msg.empty() && name) {
1791            cout << endl << name->getStringValue() << ":" << endl;
1792            cout << msg;
1793            msg.erase();
1794         }
1795     }
1796
1797     if ( !verbose ) {
1798         cout << endl;
1799         cout << "For a complete list of options use --help --verbose" << endl;
1800     }
1801 #ifdef _MSC_VER
1802     cout << "Hit a key to continue..." << endl;
1803     cin.get();
1804 #endif
1805 }
1806
1807 // A simple function to return an integer depending on the position
1808 // of the status string within the array in order to determine the hierarchy.
1809 unsigned int getNumMaturity(const char * str) 
1810 {
1811   // changes should also be reflected in $FG_ROOT/data/options.xml & 
1812   // $FG_ROOT/data/Translations/string-default.xml
1813   const char levels[][20]= {"alpha","beta","early-production","production",0}; 
1814
1815   for (unsigned int i=0; i<(sizeof(levels)/sizeof(levels[0])-1);i++) 
1816     if (strcmp(str,levels[i])==0)
1817       return i;
1818
1819   return 0;
1820 };
1821
1822
1823 static void fgSearchAircraft(const SGPath &path, string_list &aircraft,
1824                              bool recursive)
1825 {   
1826    
1827    ulDirEnt* dire;
1828    ulDir *dirp = ulOpenDir(path.str().c_str());
1829    if (dirp == NULL) {
1830       cerr << "Unable to open aircraft directory '" << path.str() << '\'' << endl;
1831       exit(-1);
1832    }
1833
1834    while ((dire = ulReadDir(dirp)) != NULL) {
1835       char *ptr;
1836
1837       if (dire->d_isdir) {
1838           if (recursive && strcmp("CVS", dire->d_name)
1839               && strcmp(".", dire->d_name) && strcmp("..", dire->d_name))
1840           {
1841               SGPath next = path;
1842               next.append(dire->d_name);
1843
1844               fgSearchAircraft(next, aircraft, true);
1845           }
1846       } else if ((ptr = strstr(dire->d_name, "-set.xml")) && (ptr[8] == '\0')) {
1847
1848           SGPath afile = path;
1849           afile.append(dire->d_name);
1850
1851           *ptr = '\0';
1852
1853           SGPropertyNode root;
1854           try {
1855              readProperties(afile.str(), &root);
1856           } catch (...) {
1857              continue;
1858           }
1859
1860           SGPropertyNode *desc = NULL;
1861           SGPropertyNode *status = NULL;
1862           
1863           SGPropertyNode *node = root.getNode("sim");
1864           if (node) {
1865              desc = node->getNode("description");
1866              // if a status tag is found, read it in
1867              if (node->hasValue("status"))
1868                 status = node->getNode("status");
1869           }
1870
1871           //additionally display status information where it is available
1872
1873           string descStr("   ");
1874           descStr += dire->d_name;
1875           if (desc) {
1876               if (descStr.size() <= 27+3) {
1877                 descStr.append(29+3-descStr.size(), ' ');
1878               } else {
1879                 descStr += '\n';
1880                 descStr.append( 32, ' ');
1881               }
1882               descStr += desc->getStringValue();
1883           }
1884   
1885           SGPropertyNode * required_status
1886                              = fgGetNode ("/sim/aircraft-min-status", true);
1887           
1888           // If the node holds the value "all", then there wasn't any status 
1889           // level specified, so we simply go ahead and output ALL aircraft
1890           if (strcmp(required_status->getStringValue(),"all")==0) {        
1891                   aircraft.push_back(descStr);
1892                   }
1893           else
1894           {
1895           // If the node doesn't hold "all" as its value, then we are supposed
1896           // to show only aircraft meeting specific status (development status)
1897           // requirements:
1898  
1899      if (node->hasValue("status"))     {
1900           //Compare (minimally) required status level with actual aircraft status:
1901            if ( getNumMaturity(status->getStringValue() ) >= 
1902                 getNumMaturity(required_status->getStringValue() ) )
1903                                   aircraft.push_back(descStr); }
1904                                                   
1905           }
1906       
1907    
1908    }
1909    }
1910
1911    ulCloseDir(dirp);
1912 }
1913
1914 /*
1915  * Search in the current directory, and in on directory deeper
1916  * for <aircraft>-set.xml configuration files and show the aircaft name
1917  * and the contents of the<description> tag in a sorted manner.
1918  *
1919  * @parampath the directory to search for configuration files
1920  * @param recursive defines whether the directory should be searched recursively
1921  */
1922 void fgShowAircraft(const SGPath &path, bool recursive) {
1923     string_list aircraft;
1924
1925     fgSearchAircraft( path, aircraft, recursive );
1926
1927     sort(aircraft.begin(), aircraft.end());
1928     SG_LOG( SG_GENERAL, SG_ALERT, "" ); // To popup the console on Windows
1929     cout << "Available aircraft:" << endl;
1930     for ( unsigned int i = 0; i < aircraft.size(); i++ ) {
1931         cout << aircraft[i] << endl;
1932     }
1933 #ifdef _MSC_VER
1934     cout << "Hit a key to continue..." << endl;
1935     cin.get();
1936 #endif
1937 }