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