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