]> git.mxchange.org Git - flightgear.git/blob - src/Main/options.cxx
Erik Hofman:
[flightgear.git] / src / Main / options.cxx
1 // options.cxx -- class to handle command line options
2 //
3 // Written by Curtis Olson, started April 1998.
4 //
5 // Copyright (C) 1998  Curtis L. Olson  - curt@me.umn.edu
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22
23
24 #ifdef HAVE_CONFIG_H
25 #  include <config.h>
26 #endif
27
28 #include <simgear/compiler.h>
29 #include <simgear/misc/exception.hxx>
30
31 #include <math.h>               // rint()
32 #include <stdio.h>
33 #include <stdlib.h>             // atof(), atoi()
34 #include <string.h>             // strcmp()
35
36 #include STL_STRING
37
38 #include <plib/ul.h>
39
40 #include <simgear/math/sg_random.h>
41 #include <simgear/misc/sgstream.hxx>
42 #include <simgear/misc/sg_path.hxx>
43 #include <simgear/route/route.hxx>
44 #include <simgear/route/waypoint.hxx>
45
46 // #include <Include/general.hxx>
47 // #include <Airports/simple.hxx>
48 // #include <Cockpit/cockpit.hxx>
49 // #include <FDM/flight.hxx>
50 // #include <FDM/UIUCModel/uiuc_aircraftdir.h>
51 #ifdef FG_NETWORK_OLK
52 #  include <NetworkOLK/network.h>
53 #endif
54
55 #include <GUI/gui.h>
56
57 #include "globals.hxx"
58 #include "fg_init.hxx"
59 #include "fg_props.hxx"
60 #include "options.hxx"
61 #include "viewmgr.hxx"
62
63 // Hack: from main.cxx
64 extern SGPropertyNode *fgInitLocale(const char *);
65
66 SG_USING_STD(string);
67 SG_USING_NAMESPACE(std);
68
69
70 #define NEW_DEFAULT_MODEL_HZ 120
71
72 enum
73 {
74     FG_OPTIONS_OK = 0,
75     FG_OPTIONS_HELP = 1,
76     FG_OPTIONS_ERROR = 2,
77     FG_OPTIONS_VERBOSE_HELP = 3,
78     FG_OPTIONS_SHOW_AIRCRAFT = 4
79 };
80
81 static double
82 atof( const string& str )
83 {
84
85 #ifdef __MWERKS__ 
86     // -dw- if ::atof is called, then we get an infinite loop
87     return std::atof( str.c_str() );
88 #else
89     return ::atof( str.c_str() );
90 #endif
91 }
92
93 static int
94 atoi( const string& str )
95 {
96 #ifdef __MWERKS__ 
97     // -dw- if ::atoi is called, then we get an infinite loop
98     return std::atoi( str.c_str() );
99 #else
100     return ::atoi( str.c_str() );
101 #endif
102 }
103
104
105 /**
106  * Set a few fail-safe default property values.
107  *
108  * These should all be set in $FG_ROOT/preferences.xml, but just
109  * in case, we provide some initial sane values here. This method 
110  * should be invoked *before* reading any init files.
111  */
112 void
113 fgSetDefaults ()
114 {
115     // set a possibly independent location for scenery data
116     char *envp = ::getenv( "FG_SCENERY" );
117
118     if ( envp != NULL ) {
119         // fg_root could be anywhere, so default to environmental
120         // variable $FG_ROOT if it is set.
121         globals->set_fg_scenery(envp);
122     } else {
123         // Otherwise, default to Scenery being in $FG_ROOT/Scenery
124         globals->set_fg_scenery("");
125     }
126                                 // Position (deliberately out of range)
127     fgSetDouble("/position/longitude-deg", 9999.0);
128     fgSetDouble("/position/latitude-deg", 9999.0);
129     fgSetDouble("/position/altitude-ft", -9999.0);
130
131                                 // Orientation
132     fgSetDouble("/orientation/heading-deg", 270);
133     fgSetDouble("/orientation/roll-deg", 0);
134     fgSetDouble("/orientation/pitch-deg", 0.424);
135
136                                 // Velocities
137     fgSetString("/sim/startup/speed-set", "knots");
138     fgSetDouble("/velocities/uBody-fps", 0.0);
139     fgSetDouble("/velocities/vBody-fps", 0.0);
140     fgSetDouble("/velocities/wBody-fps", 0.0);
141     fgSetDouble("/velocities/speed-north-fps", 0.0);
142     fgSetDouble("/velocities/speed-east-fps", 0.0);
143     fgSetDouble("/velocities/speed-down-fps", 0.0);
144     fgSetDouble("/velocities/airspeed-kt", 0.0);
145     fgSetDouble("/velocities/mach", 0.0);
146
147                                 // Miscellaneous
148     fgSetBool("/sim/startup/game-mode", false);
149     fgSetBool("/sim/startup/splash-screen", true);
150     fgSetBool("/sim/startup/intro-music", true);
151     // we want mouse-pointer to have an undefined value if nothing is
152     // specified so we can do the right thing for voodoo-1/2 cards.
153     // fgSetString("/sim/startup/mouse-pointer", "disabled");
154     fgSetString("/sim/control-mode", "joystick");
155     fgSetBool("/sim/auto-coordination", false);
156 #if !defined(WIN32)
157     fgSetString("/sim/startup/browser-app", "netscape");
158 #else
159     fgSetString("/sim/startup/browser-app", "webrun.bat");
160 #endif
161                                 // Features
162     fgSetBool("/sim/hud/visibility", false);
163     fgSetBool("/sim/panel/visibility", true);
164     fgSetBool("/sim/sound/audible", true);
165     fgSetBool("/sim/hud/antialiased", false);
166
167                                 // Flight Model options
168     fgSetString("/sim/flight-model", "jsb");
169     fgSetString("/sim/aero", "c172");
170     fgSetInt("/sim/model-hz", NEW_DEFAULT_MODEL_HZ);
171     fgSetInt("/sim/speed-up", 1);
172     fgSetBool("/sim/startup/trim", false);
173     fgSetBool("/sim/startup/onground", true);
174
175                                 // Rendering options
176     fgSetString("/sim/rendering/fog", "nicest");
177     fgSetBool("/environment/clouds/status", true);
178     fgSetBool("/sim/startup/fullscreen", false);
179     fgSetBool("/sim/rendering/shading", true);
180     fgSetBool("/sim/rendering/skyblend", true);
181     fgSetBool("/sim/rendering/textures", true);
182     fgSetBool("/sim/rendering/wireframe", false);
183     fgSetInt("/sim/startup/xsize", 800);
184     fgSetInt("/sim/startup/ysize", 600);
185     fgSetInt("/sim/rendering/bits-per-pixel", 16);
186     fgSetString("/sim/view-mode", "pilot");
187     fgSetDouble("/sim/current-view/heading-offset-deg", 0);
188     fgSetDouble("/environment/visibility-m", 20000);
189
190                                 // HUD options
191     fgSetString("/sim/startup/units", "feet");
192     fgSetString("/sim/hud/frame-stat-type", "tris");
193         
194                                 // Time options
195     fgSetInt("/sim/startup/time-offset", 0);
196     fgSetString("/sim/startup/time-offset-type", "system-offset");
197     fgSetLong("/sim/time/cur-time-override", 0);
198
199     fgSetBool("/sim/networking/network-olk", false);
200     fgSetString("/sim/networking/call-sign", "Johnny");
201
202                                 // Freeze options
203     fgSetBool("/sim/freeze/master", false);
204     fgSetBool("/sim/freeze/position", false);
205     fgSetBool("/sim/freeze/clock", false);
206     fgSetBool("/sim/freeze/fuel", false);
207 }
208
209
210 static bool
211 parse_wind (const string &wind, double * min_hdg, double * max_hdg,
212             double * speed, double * gust)
213 {
214   string::size_type pos = wind.find('@');
215   if (pos == string::npos)
216     return false;
217   string dir = wind.substr(0, pos);
218   string spd = wind.substr(pos+1);
219   pos = dir.find(':');
220   if (pos == string::npos) {
221     *min_hdg = *max_hdg = atof(dir.c_str());
222   } else {
223     *min_hdg = atof(dir.substr(0,pos).c_str());
224     *max_hdg = atof(dir.substr(pos+1).c_str());
225   }
226   pos = spd.find(':');
227   if (pos == string::npos) {
228     *speed = *gust = atof(spd.c_str());
229   } else {
230     *speed = atof(spd.substr(0,pos).c_str());
231     *gust = atof(spd.substr(pos+1).c_str());
232   }
233   return true;
234 }
235
236 // parse a time string ([+/-]%f[:%f[:%f]]) into hours
237 static double
238 parse_time(const string& time_in) {
239     char *time_str, num[256];
240     double hours, minutes, seconds;
241     double result = 0.0;
242     int sign = 1;
243     int i;
244
245     time_str = (char *)time_in.c_str();
246
247     // printf("parse_time(): %s\n", time_str);
248
249     // check for sign
250     if ( strlen(time_str) ) {
251         if ( time_str[0] == '+' ) {
252             sign = 1;
253             time_str++;
254         } else if ( time_str[0] == '-' ) {
255             sign = -1;
256             time_str++;
257         }
258     }
259     // printf("sign = %d\n", sign);
260
261     // get hours
262     if ( strlen(time_str) ) {
263         i = 0;
264         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
265             num[i] = time_str[0];
266             time_str++;
267             i++;
268         }
269         if ( time_str[0] == ':' ) {
270             time_str++;
271         }
272         num[i] = '\0';
273         hours = atof(num);
274         // printf("hours = %.2lf\n", hours);
275
276         result += hours;
277     }
278
279     // get minutes
280     if ( strlen(time_str) ) {
281         i = 0;
282         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
283             num[i] = time_str[0];
284             time_str++;
285             i++;
286         }
287         if ( time_str[0] == ':' ) {
288             time_str++;
289         }
290         num[i] = '\0';
291         minutes = atof(num);
292         // printf("minutes = %.2lf\n", minutes);
293
294         result += minutes / 60.0;
295     }
296
297     // get seconds
298     if ( strlen(time_str) ) {
299         i = 0;
300         while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
301             num[i] = time_str[0];
302             time_str++;
303             i++;
304         }
305         num[i] = '\0';
306         seconds = atof(num);
307         // printf("seconds = %.2lf\n", seconds);
308
309         result += seconds / 3600.0;
310     }
311
312     return(sign * result);
313 }
314
315
316 // parse a date string (yyyy:mm:dd:hh:mm:ss) into a time_t (seconds)
317 static long int 
318 parse_date( const string& date)
319 {
320     struct tm gmt;
321     char * date_str, num[256];
322     int i;
323     // initialize to zero
324     gmt.tm_sec = 0;
325     gmt.tm_min = 0;
326     gmt.tm_hour = 0;
327     gmt.tm_mday = 0;
328     gmt.tm_mon = 0;
329     gmt.tm_year = 0;
330     gmt.tm_isdst = 0; // ignore daylight savings time for the moment
331     date_str = (char *)date.c_str();
332     // get year
333     if ( strlen(date_str) ) {
334         i = 0;
335         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
336             num[i] = date_str[0];
337             date_str++;
338             i++;
339         }
340         if ( date_str[0] == ':' ) {
341             date_str++;
342         }
343         num[i] = '\0';
344         gmt.tm_year = atoi(num) - 1900;
345     }
346     // get month
347     if ( strlen(date_str) ) {
348         i = 0;
349         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
350             num[i] = date_str[0];
351             date_str++;
352             i++;
353         }
354         if ( date_str[0] == ':' ) {
355             date_str++;
356         }
357         num[i] = '\0';
358         gmt.tm_mon = atoi(num) -1;
359     }
360     // get day
361     if ( strlen(date_str) ) {
362         i = 0;
363         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
364             num[i] = date_str[0];
365             date_str++;
366             i++;
367         }
368         if ( date_str[0] == ':' ) {
369             date_str++;
370         }
371         num[i] = '\0';
372         gmt.tm_mday = atoi(num);
373     }
374     // get hour
375     if ( strlen(date_str) ) {
376         i = 0;
377         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
378             num[i] = date_str[0];
379             date_str++;
380             i++;
381         }
382         if ( date_str[0] == ':' ) {
383             date_str++;
384         }
385         num[i] = '\0';
386         gmt.tm_hour = atoi(num);
387     }
388     // get minute
389     if ( strlen(date_str) ) {
390         i = 0;
391         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
392             num[i] = date_str[0];
393             date_str++;
394             i++;
395         }
396         if ( date_str[0] == ':' ) {
397             date_str++;
398         }
399         num[i] = '\0';
400         gmt.tm_min = atoi(num);
401     }
402     // get second
403     if ( strlen(date_str) ) {
404         i = 0;
405         while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
406             num[i] = date_str[0];
407             date_str++;
408             i++;
409         }
410         if ( date_str[0] == ':' ) {
411             date_str++;
412         }
413         num[i] = '\0';
414         gmt.tm_sec = atoi(num);
415     }
416     time_t theTime = sgTimeGetGMT( gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
417                                    gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
418     //printf ("Date is %s\n", ctime(&theTime));
419     //printf ("in seconds that is %d\n", theTime);
420     //exit(1);
421     return (theTime);
422 }
423
424
425 // parse angle in the form of [+/-]ddd:mm:ss into degrees
426 static double
427 parse_degree( const string& degree_str) {
428     double result = parse_time( degree_str );
429
430     // printf("Degree = %.4f\n", result);
431
432     return(result);
433 }
434
435
436 // parse time offset string into seconds
437 static int
438 parse_time_offset( const string& time_str) {
439     int result;
440
441     // printf("time offset = %s\n", time_str);
442
443 #ifdef HAVE_RINT
444     result = (int)rint(parse_time(time_str) * 3600.0);
445 #else
446     result = (int)(parse_time(time_str) * 3600.0);
447 #endif
448
449     // printf("parse_time_offset(): %d\n", result);
450
451     return( result );
452 }
453
454
455 // Parse --fov=x.xx type option 
456 static double
457 parse_fov( const string& arg ) {
458     double fov = atof(arg);
459
460     if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
461     if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
462
463     fgSetDouble("/sim/current-view/field-of-view", fov);
464
465     // printf("parse_fov(): result = %.4f\n", fov);
466
467     return fov;
468 }
469
470
471 // Parse I/O channel option
472 //
473 // Format is "--protocol=medium,direction,hz,medium_options,..."
474 //
475 //   protocol = { native, nmea, garmin, fgfs, rul, pve, etc. }
476 //   medium = { serial, socket, file, etc. }
477 //   direction = { in, out, bi }
478 //   hz = number of times to process channel per second (floating
479 //        point values are ok.
480 //
481 // Serial example "--nmea=serial,dir,hz,device,baud" where
482 // 
483 //  device = OS device name of serial line to be open()'ed
484 //  baud = {300, 1200, 2400, ..., 230400}
485 //
486 // Socket exacmple "--native=socket,dir,hz,machine,port,style" where
487 // 
488 //  machine = machine name or ip address if client (leave empty if server)
489 //  port = port, leave empty to let system choose
490 //  style = tcp or udp
491 //
492 // File example "--garmin=file,dir,hz,filename" where
493 // 
494 //  filename = file system file name
495
496 static bool 
497 add_channel( const string& type, const string& channel_str ) {
498     // cout << "Channel string = " << channel_str << endl;
499
500     globals->get_channel_options_list()->push_back( type + "," + channel_str );
501
502     return true;
503 }
504
505
506 static void
507 setup_wind (double min_hdg, double max_hdg, double speed, double gust)
508 {
509   fgSetDouble("/environment/wind-from-heading-deg", min_hdg);
510   fgSetDouble("/environment/params/min-wind-from-heading-deg", min_hdg);
511   fgSetDouble("/environment/params/max-wind-from-heading-deg", max_hdg);
512   fgSetDouble("/environment/wind-speed-kt", speed);
513   fgSetDouble("/environment/params/base-wind-speed-kt", speed);
514   fgSetDouble("/environment/params/gust-wind-speed-kt", gust);
515
516   SG_LOG(SG_GENERAL, SG_INFO, "WIND: " << min_hdg << '@' << 
517          speed << " knots" << endl);
518
519 #ifdef FG_WEATHERCM
520   // convert to fps
521   speed *= SG_NM_TO_METER * SG_METER_TO_FEET * (1.0/3600);
522   while (min_hdg > 360)
523     min_hdg -= 360;
524   while (min_hdg <= 0)
525     min_hdg += 360;
526   min_hdg *= SGD_DEGREES_TO_RADIANS;
527   fgSetDouble("/environment/wind-from-north-fps", speed * cos(dir));
528   fgSetDouble("/environment/wind-from-east-fps", speed * sin(dir));
529 #endif // FG_WEATHERCM
530 }
531
532
533 // Parse --wp=ID[@alt]
534 static bool 
535 parse_wp( const string& arg ) {
536     string id, alt_str;
537     double alt = 0.0;
538
539     string::size_type pos = arg.find( "@" );
540     if ( pos != string::npos ) {
541         id = arg.substr( 0, pos );
542         alt_str = arg.substr( pos + 1 );
543         // cout << "id str = " << id << "  alt str = " << alt_str << endl;
544         alt = atof( alt_str.c_str() );
545         if ( !strcmp(fgGetString("/sim/startup/units"), "feet") ) {
546             alt *= SG_FEET_TO_METER;
547         }
548     } else {
549         id = arg;
550     }
551
552     FGAirport a;
553     if ( fgFindAirportID( id, &a ) ) {
554         SGWayPoint wp( a.longitude, a.latitude, alt, SGWayPoint::WGS84, id );
555         globals->get_route()->add_waypoint( wp );
556
557         return true;
558     } else {
559         return false;
560     }
561 }
562
563
564 // Parse --flight-plan=[file]
565 static bool 
566 parse_flightplan(const string& arg)
567 {
568     sg_gzifstream in(arg.c_str());
569     if ( !in.is_open() ) {
570         return false;
571     }
572     while ( true ) {
573         string line;
574
575 #if defined( macintosh )
576         getline( in, line, '\r' );
577 #else
578         getline( in, line, '\n' );
579 #endif
580
581         // catch extraneous (DOS) line ending character
582         if ( line[line.length() - 1] < 32 ) {
583             line = line.substr( 0, line.length()-1 );
584         }
585
586         if ( in.eof() ) {
587             break;
588         }
589         parse_wp(line);
590     }
591
592     return true;
593 }
594
595
596 // Parse a single option
597 static int 
598 parse_option (const string& arg) 
599 {
600     // General Options
601     if ( (arg == "--help") || (arg == "-h") ) {
602         // help/usage request
603         return(FG_OPTIONS_HELP);
604     } else if ( (arg == "--verbose") || (arg == "-v") ) {
605         // verbose help/usage request
606         return(FG_OPTIONS_VERBOSE_HELP);
607     } else if ( arg.find( "--language=") == 0 ) {
608         globals->set_locale( fgInitLocale( arg.substr( 11 ).c_str() ) );
609     } else if ( arg == "--disable-game-mode") {
610         fgSetBool("/sim/startup/game-mode", false);
611     } else if ( arg == "--enable-game-mode" ) {
612         fgSetBool("/sim/startup/game-mode", true);
613     } else if ( arg == "--disable-splash-screen" ) {
614         fgSetBool("/sim/startup/splash-screen", false); 
615     } else if ( arg == "--enable-splash-screen" ) {
616         fgSetBool("/sim/startup/splash-screen", true);
617     } else if ( arg == "--disable-intro-music" ) {
618         fgSetBool("/sim/startup/intro-music", false);
619     } else if ( arg == "--enable-intro-music" ) {
620         fgSetBool("/sim/startup/intro-music", true);
621     } else if ( arg == "--disable-mouse-pointer" ) {
622         fgSetString("/sim/startup/mouse-pointer", "disabled");
623     } else if ( arg == "--enable-mouse-pointer" ) {
624         fgSetString("/sim/startup/mouse-pointer", "enabled");
625     } else if ( arg == "--disable-random-objects" ) {
626         fgSetBool("/sim/rendering/random-objects", false);
627     } else if ( arg == "--enable-random-objects" ) {
628         fgSetBool("/sim/rendering/random-objects", true);
629     } else if ( arg == "--disable-freeze" ) {
630         fgSetBool("/sim/freeze/master", false);
631     } else if ( arg == "--enable-freeze" ) {
632         fgSetBool("/sim/freeze/master", true);
633     } else if ( arg == "--disable-fuel-freeze" ) {
634         fgSetBool("/sim/freeze/fuel", false);
635     } else if ( arg == "--enable-fuel-freeze" ) {
636         fgSetBool("/sim/freeze/fuel", true);
637     } else if ( arg == "--disable-clock-freeze" ) {
638         fgSetBool("/sim/freeze/clock", false);
639     } else if ( arg == "--enable-clock-freeze" ) {
640         fgSetBool("/sim/freeze/clock", true);
641     } else if ( arg == "--disable-anti-alias-hud" ) {
642         fgSetBool("/sim/hud/antialiased", false);
643     } else if ( arg == "--enable-anti-alias-hud" ) {
644         fgSetBool("/sim/hud/antialiased", true);
645     } else if ( arg.find( "--control=") == 0 ) {
646         fgSetString("/sim/control-mode", arg.substr(10).c_str());
647     } else if ( arg == "--disable-auto-coordination" ) {
648         fgSetBool("/sim/auto-coordination", false);
649     } else if ( arg == "--enable-auto-coordination" ) {
650         fgSetBool("/sim/auto-coordination", true);
651     } else if ( arg.find( "--browser-app=") == 0 ) {
652         fgSetString("/sim/startup/browser-app", arg.substr(14).c_str());
653     } else if ( arg == "--disable-hud" ) {
654         fgSetBool("/sim/hud/visibility", false);
655     } else if ( arg == "--enable-hud" ) {
656         fgSetBool("/sim/hud/visibility", true);
657     } else if ( arg == "--disable-panel" ) {
658         fgSetBool("/sim/panel/visibility", false);
659     } else if ( arg == "--enable-panel" ) {
660         fgSetBool("/sim/panel/visibility", true);
661     } else if ( arg == "--disable-sound" ) {
662         fgSetBool("/sim/sound/audible", false);
663     } else if ( arg == "--enable-sound" ) {
664         fgSetBool("/sim/sound/audible", true);
665     } else if ( arg.find( "--airport-id=") == 0 ) {
666                                 // NB: changed property name!!!
667         fgSetString("/sim/startup/airport-id", arg.substr(13).c_str());
668     } else if ( arg.find( "--offset-distance=") == 0 ) {
669         fgSetDouble("/sim/startup/offset-distance", atof(arg.substr(18)));
670     } else if ( arg.find( "--offset-azimuth=") == 0 ) {
671         fgSetDouble("/sim/startup/offset-azimuth", atof(arg.substr(17))); 
672     } else if ( arg.find( "--lon=" ) == 0 ) {
673         fgSetDouble("/position/longitude-deg",
674                               parse_degree(arg.substr(6)));
675         fgSetString("/sim/startup/airport-id", "");
676     } else if ( arg.find( "--lat=" ) == 0 ) {
677         fgSetDouble("/position/latitude-deg",
678                               parse_degree(arg.substr(6)));
679         fgSetString("/sim/startup/airport-id", "");
680     } else if ( arg.find( "--altitude=" ) == 0 ) {
681         fgSetBool("/sim/startup/onground", false);
682         if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
683             fgSetDouble("/position/altitude-ft", atof(arg.substr(11)));
684         else
685             fgSetDouble("/position/altitude-ft",
686                         atof(arg.substr(11)) * SG_METER_TO_FEET);
687     } else if ( arg.find( "--uBody=" ) == 0 ) {
688         fgSetString("/sim/startup/speed-set", "UVW");
689         if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
690           fgSetDouble("/velocities/uBody-fps", atof(arg.substr(8)));
691         else
692           fgSetDouble("/velocities/uBody-fps",
693                                atof(arg.substr(8)) * SG_METER_TO_FEET);
694     } else if ( arg.find( "--vBody=" ) == 0 ) {
695         fgSetString("/sim/startup/speed-set", "UVW");
696         if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
697           fgSetDouble("/velocities/vBody-fps", atof(arg.substr(8)));
698         else
699           fgSetDouble("/velocities/vBody-fps",
700                                atof(arg.substr(8)) * SG_METER_TO_FEET);
701     } else if ( arg.find( "--wBody=" ) == 0 ) {
702         fgSetString("/sim/startup/speed-set", "UVW");
703         if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
704           fgSetDouble("/velocities/wBody-fps", atof(arg.substr(8)));
705         else
706           fgSetDouble("/velocities/wBody-fps",
707                                atof(arg.substr(8)) * SG_METER_TO_FEET);
708     } else if ( arg.find( "--vNorth=" ) == 0 ) {
709         fgSetString("/sim/startup/speed-set", "NED");
710         if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
711           fgSetDouble("/velocities/speed-north-fps", atof(arg.substr(9)));
712         else
713           fgSetDouble("/velocities/speed-north-fps",
714                                atof(arg.substr(9)) * SG_METER_TO_FEET);
715     } else if ( arg.find( "--vEast=" ) == 0 ) {
716         fgSetString("/sim/startup/speed-set", "NED");
717         if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
718           fgSetDouble("/velocities/speed-east-fps", atof(arg.substr(8)));
719         else
720           fgSetDouble("/velocities/speed-east-fps",
721                       atof(arg.substr(8)) * SG_METER_TO_FEET);
722     } else if ( arg.find( "--vDown=" ) == 0 ) {
723         fgSetString("/sim/startup/speed-set", "NED");
724         if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
725           fgSetDouble("/velocities/speed-down-fps", atof(arg.substr(8)));
726         else
727           fgSetDouble("/velocities/speed-down-fps",
728                                atof(arg.substr(8)) * SG_METER_TO_FEET);
729     } else if ( arg.find( "--vc=" ) == 0) {
730         fgSetString("/sim/startup/speed-set", "knots");
731         fgSetDouble("/velocities/airspeed-kt", atof(arg.substr(5)));
732     } else if ( arg.find( "--mach=" ) == 0) {
733         fgSetString("/sim/startup/speed-set", "mach");
734         fgSetDouble("/velocities/mach", atof(arg.substr(7)));
735     } else if ( arg.find( "--heading=" ) == 0 ) {
736         fgSetDouble("/orientation/heading-deg", atof(arg.substr(10)));
737     } else if ( arg.find( "--roll=" ) == 0 ) {
738         fgSetDouble("/orientation/roll-deg", atof(arg.substr(7)));
739     } else if ( arg.find( "--pitch=" ) == 0 ) {
740         fgSetDouble("/orientation/pitch-deg", atof(arg.substr(8)));
741     } else if ( arg.find( "--glideslope=" ) == 0 ) {
742         fgSetDouble("/velocities/glideslope", atof(arg.substr(13))
743                                           *SG_DEGREES_TO_RADIANS);
744     }  else if ( arg.find( "--roc=" ) == 0 ) {
745         fgSetDouble("/velocities/vertical-speed-fps", atof(arg.substr(6))/60);
746     } else if ( arg.find( "--fg-root=" ) == 0 ) {
747         globals->set_fg_root(arg.substr( 10 ));
748     } else if ( arg.find( "--fg-scenery=" ) == 0 ) {
749         globals->set_fg_scenery(arg.substr( 13 ));
750     } else if ( arg.find( "--fdm=" ) == 0 ) {
751         fgSetString("/sim/flight-model", arg.substr(6).c_str());
752     } else if ( arg.find( "--aero=" ) == 0 ) {
753         fgSetString("/sim/aero", arg.substr(7).c_str());
754     } else if ( arg.find( "--aircraft-dir=" ) == 0 ) {
755         fgSetString("/sim/aircraft-dir", arg.substr(15).c_str());
756     } else if ( arg.find( "--show-aircraft") == 0) {
757         return(FG_OPTIONS_SHOW_AIRCRAFT);
758     } else if ( arg.find( "--model-hz=" ) == 0 ) {
759         fgSetInt("/sim/model-hz", atoi(arg.substr(11)));
760     } else if ( arg.find( "--speed=" ) == 0 ) {
761         fgSetInt("/sim/speed-up", atoi(arg.substr(8)));
762     } else if ( arg.find( "--trim") == 0) {
763         fgSetBool("/sim/startup/trim", true);
764     } else if ( arg.find( "--notrim") == 0) {
765         fgSetBool("/sim/startup/trim", false);
766     } else if ( arg.find( "--on-ground") == 0) {
767         fgSetBool("/sim/startup/onground", true);
768     } else if ( arg.find( "--in-air") == 0) {
769         fgSetBool("/sim/startup/onground", false);
770     } else if ( arg == "--fog-disable" ) {
771         fgSetString("/sim/rendering/fog", "disabled");
772     } else if ( arg == "--fog-fastest" ) {
773         fgSetString("/sim/rendering/fog", "fastest");
774     } else if ( arg == "--fog-nicest" ) {
775         fgSetString("/sim/fog", "nicest");
776     } else if ( arg == "--disable-clouds" ) {
777         fgSetBool("/environment/clouds/status", false);
778     } else if ( arg == "--enable-clouds" ) {
779         fgSetBool("/environment/clouds/status", true);
780     } else if ( arg == "--disable-clouds3d" ) {
781         fgSetBool("/sim/rendering/clouds3d", false);
782     } else if ( arg == "--enable-clouds3d" ) {
783         fgSetBool("/sim/rendering/clouds3d", true);
784     } else if ( arg.find( "--fov=" ) == 0 ) {
785         parse_fov( arg.substr(6) );
786     } else if ( arg == "--disable-fullscreen" ) {
787         fgSetBool("/sim/startup/fullscreen", false);
788     } else if ( arg== "--enable-fullscreen") {
789         fgSetBool("/sim/startup/fullscreen", true);
790     } else if ( arg == "--shading-flat") {
791         fgSetBool("/sim/rendering/shading", false);
792     } else if ( arg == "--shading-smooth") {
793         fgSetBool("/sim/rendering/shading", true);
794     } else if ( arg == "--disable-skyblend") {
795         fgSetBool("/sim/rendering/skyblend", false);
796     } else if ( arg== "--enable-skyblend" ) {
797         fgSetBool("/sim/rendering/skyblend", true);
798     } else if ( arg == "--disable-textures" ) {
799         fgSetBool("/sim/rendering/textures", false);
800     } else if ( arg == "--enable-textures" ) {
801         fgSetBool("/sim/rendering/textures", true);
802     } else if ( arg == "--disable-wireframe" ) {
803         fgSetBool("/sim/rendering/wireframe", false);
804     } else if ( arg == "--enable-wireframe" ) {
805         fgSetBool("/sim/rendering/wireframe", true);
806     } else if ( arg.find( "--geometry=" ) == 0 ) {
807         bool geometry_ok = true;
808         int xsize = 0, ysize = 0;
809         string geometry = arg.substr( 11 );
810         string::size_type i = geometry.find('x');
811
812         if (i != string::npos) {
813             xsize = atoi(geometry.substr(0, i));
814             ysize = atoi(geometry.substr(i+1));
815         } else {
816             geometry_ok = false;
817         }
818
819         if ( xsize <= 0 || ysize <= 0 ) {
820             xsize = 640;
821             ysize = 480;
822             geometry_ok = false;
823         }
824
825         if ( !geometry_ok ) {
826             SG_LOG( SG_GENERAL, SG_ALERT, "Unknown geometry: " << geometry );
827             SG_LOG( SG_GENERAL, SG_ALERT,
828                     "Setting geometry to " << xsize << 'x' << ysize << '\n');
829         } else {
830           SG_LOG( SG_GENERAL, SG_INFO,
831                   "Setting geometry to " << xsize << 'x' << ysize << '\n');
832           fgSetInt("/sim/startup/xsize", xsize);
833           fgSetInt("/sim/startup/ysize", ysize);
834         }
835     } else if ( arg.find( "--bpp=" ) == 0 ) {
836         string bits_per_pix = arg.substr( 6 );
837         if ( bits_per_pix == "16" ) {
838             fgSetInt("/sim/rendering/bits-per-pixel", 16);
839         } else if ( bits_per_pix == "24" ) {
840             fgSetInt("/sim/rendering/bits-per-pixel", 24);
841         } else if ( bits_per_pix == "32" ) {
842             fgSetInt("/sim/rendering/bits-per-pixel", 32);
843         } else {
844           SG_LOG(SG_GENERAL, SG_ALERT, "Unsupported bpp " << bits_per_pix);
845         }
846     } else if ( arg == "--units-feet" ) {
847         fgSetString("/sim/startup/units", "feet");
848     } else if ( arg == "--units-meters" ) {
849         fgSetString("/sim/startup/units", "meters");
850     } else if ( arg.find( "--time-offset" ) == 0 ) {
851         fgSetInt("/sim/startup/time-offset",
852                  parse_time_offset( (arg.substr(14)) ));
853         fgSetString("/sim/startup/time-offset-type", "system-offset");
854     } else if ( arg.find( "--time-match-real") == 0 ) {
855         fgSetString("/sim/startup/time-offset-type", "system-offset");
856     } else if ( arg.find( "--time-match-local") == 0 ) {
857         fgSetString("/sim/startup/time-offset-type", "latitude-offset");
858     } else if ( arg.find( "--start-date-sys=") == 0 ) {
859         fgSetInt("/sim/startup/time-offset", parse_date((arg.substr(17))));
860         fgSetString("/sim/startup/time-offset-type", "system");
861     } else if ( arg.find( "--start-date-lat=") == 0 ) {
862         fgSetInt("/sim/startup/time-offset", parse_date((arg.substr(17))));
863         fgSetString("/sim/startup/time-offset-type", "latitude");
864     } else if ( arg.find( "--start-date-gmt=") == 0 ) {
865         fgSetInt("/sim/startup/time-offset", parse_date((arg.substr(17))));
866         fgSetString("/sim/startup/time-offset-type", "gmt");
867     } else if ( arg == "--hud-tris" ) {
868         fgSetString("/sim/hud/frame-stat-type", "tris");
869     } else if ( arg == "--hud-culled" ) {
870         fgSetString("/sim/hud/frame-stat-type", "culled");
871     } else if ( arg.find( "--atc610x" ) == 0 ) {
872         add_channel( "atc610x", "dummy" );
873     } else if ( arg.find( "--atlas=" ) == 0 ) {
874         add_channel( "atlas", arg.substr(8) );
875     } else if ( arg.find( "--httpd=" ) == 0 ) {
876         add_channel( "httpd", arg.substr(8) );
877 #ifdef FG_JPEG_SERVER
878     } else if ( arg.find( "--jpg-httpd=" ) == 0 ) {
879         add_channel( "jpg-httpd", arg.substr(12) );
880 #endif
881     } else if ( arg.find( "--native=" ) == 0 ) {
882         add_channel( "native", arg.substr(9) );
883     } else if ( arg.find( "--native-ctrls=" ) == 0 ) {
884         add_channel( "native_ctrls", arg.substr(15) );
885     } else if ( arg.find( "--native-fdm=" ) == 0 ) {
886         add_channel( "native_fdm", arg.substr(13) );
887     } else if ( arg.find( "--opengc=" ) == 0 ) {
888         // char stop;
889         // cout << "Adding channel for OpenGC Display" << endl; cin >> stop;
890         add_channel( "opengc", arg.substr(9) );
891     } else if ( arg.find( "--garmin=" ) == 0 ) {
892         add_channel( "garmin", arg.substr(9) );
893     } else if ( arg.find( "--nmea=" ) == 0 ) {
894         add_channel( "nmea", arg.substr(7) );
895     } else if ( arg.find( "--props=" ) == 0 ) {
896         add_channel( "props", arg.substr(8) );
897     } else if ( arg.find( "--telnet=" ) == 0 ) {
898         add_channel( "telnet", arg.substr(9) );
899     } else if ( arg.find( "--pve=" ) == 0 ) {
900         add_channel( "pve", arg.substr(6) );
901     } else if ( arg.find( "--ray=" ) == 0 ) {
902         add_channel( "ray", arg.substr(6) );
903     } else if ( arg.find( "--rul=" ) == 0 ) {
904         add_channel( "rul", arg.substr(6) );
905     } else if ( arg.find( "--joyclient=" ) == 0 ) {
906         add_channel( "joyclient", arg.substr(12) );
907 #ifdef FG_NETWORK_OLK
908     } else if ( arg == "--disable-network-olk" ) {
909         fgSetBool("/sim/networking/olk", false);
910     } else if ( arg== "--enable-network-olk") {
911         fgSetBool("/sim/networking/olk", true);
912     } else if ( arg == "--net-hud" ) {
913         fgSetBool("/sim/hud/net-display", true);
914         net_hud_display = 1;    // FIXME
915     } else if ( arg.find( "--net-id=") == 0 ) {
916         fgSetString("sim/networking/call-sign", arg.substr(9).c_str());
917 #endif
918     } else if ( arg.find( "--prop:" ) == 0 ) {
919         string assign = arg.substr(7);
920         string::size_type pos = assign.find('=');
921         if ( pos == arg.npos || pos == 0 ) {
922             SG_LOG( SG_GENERAL, SG_ALERT, "Bad property assignment: " << arg );
923             return FG_OPTIONS_ERROR;
924         }
925         string name = assign.substr(0, pos);
926         string value = assign.substr(pos + 1);
927         fgSetString(name.c_str(), value.c_str());
928         // SG_LOG(SG_GENERAL, SG_INFO, "Setting default value of property "
929         //        << name << " to \"" << value << '"');
930     } else if ( arg.find("--trace-read=") == 0) {
931         string name = arg.substr(13);
932         SG_LOG(SG_GENERAL, SG_INFO, "Tracing reads for property " << name);
933         fgGetNode(name.c_str(), true)
934           ->setAttribute(SGPropertyNode::TRACE_READ, true);
935     } else if ( arg.find("--trace-write=") == 0) {
936         string name = arg.substr(14);
937         SG_LOG(SG_GENERAL, SG_INFO, "Tracing writes for property " << name);
938         fgGetNode(name.c_str(), true)
939           ->setAttribute(SGPropertyNode::TRACE_WRITE, true);
940     } else if ( arg.find( "--view-offset=" ) == 0 ) {
941         // $$$ begin - added VS Renganathan, 14 Oct 2K
942         // for multi-window outside window imagery
943         string woffset = arg.substr( 14 );
944         double default_view_offset = 0.0;
945         if ( woffset == "LEFT" ) {
946                default_view_offset = SGD_PI * 0.25;
947         } else if ( woffset == "RIGHT" ) {
948             default_view_offset = SGD_PI * 1.75;
949         } else if ( woffset == "CENTER" ) {
950             default_view_offset = 0.00;
951         } else {
952             default_view_offset = atof( woffset.c_str() ) * SGD_DEGREES_TO_RADIANS;
953         }
954         /* apparently not used (CLO, 11 Jun 2002) 
955            FGViewer *pilot_view =
956               (FGViewer *)globals->get_viewmgr()->get_view( 0 ); */
957         // this will work without calls to the viewer...
958         fgSetDouble( "/sim/current-view/heading-offset-deg",
959                      default_view_offset  * SGD_RADIANS_TO_DEGREES );
960     // $$$ end - added VS Renganathan, 14 Oct 2K
961     } else if ( arg.find( "--visibility=" ) == 0 ) {
962         fgSetDouble("/environment/visibility-m", atof(arg.substr(13)));
963     } else if ( arg.find( "--visibility-miles=" ) == 0 ) {
964         double visibility = atof(arg.substr(19)) * 5280.0 * SG_FEET_TO_METER;
965         fgSetDouble("/environment/visibility-m", visibility);
966     } else if ( arg.find( "--random-wind" ) == 0 ) {
967         double min_hdg = sg_random() * 360.0;
968         double max_hdg = min_hdg + (20 - sqrt(sg_random() * 400));
969         double speed = 40 - sqrt(sg_random() * 1600.0);
970         double gust = speed + (10 - sqrt(sg_random() * 100));
971         setup_wind(min_hdg, max_hdg, speed, gust);
972     } else if ( arg.find( "--wind=" ) == 0 ) {
973         double min_hdg, max_hdg, speed, gust;
974         if (!parse_wind(arg.substr(7), &min_hdg, &max_hdg, &speed, &gust)) {
975           SG_LOG( SG_GENERAL, SG_ALERT, "bad wind value " << arg.substr(7) );
976           return FG_OPTIONS_ERROR;
977         }
978         setup_wind(min_hdg, max_hdg, speed, gust);
979     } else if ( arg.find( "--wp=" ) == 0 ) {
980         parse_wp( arg.substr( 5 ) );
981     } else if ( arg.find( "--flight-plan=") == 0) {
982         parse_flightplan ( arg.substr (14) );
983     } else if ( arg.find( "--config=" ) == 0 ) {
984         string file = arg.substr(9);
985         try {
986           readProperties(file, globals->get_props());
987         } catch (const sg_exception &e) {
988           string message = "Error loading config file: ";
989           message += e.getFormattedMessage();
990           SG_LOG(SG_INPUT, SG_ALERT, message);
991           exit(2);
992         }
993     } else if ( arg.find( "--aircraft=" ) == 0 ) {
994         // read in the top level aircraft definition file
995         SGPath apath( globals->get_fg_root() );
996         apath.append( "Aircraft" );
997         apath.append( arg.substr(11) );
998         apath.concat( "-set.xml" );
999         SG_LOG(SG_INPUT, SG_INFO, "Reading aircraft: " << arg.substr(11)
1000             << " from " << apath.str());
1001         readProperties( apath.str(), globals->get_props() );
1002     } else {
1003         SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" );
1004         return FG_OPTIONS_ERROR;
1005     }
1006     
1007     return FG_OPTIONS_OK;
1008 }
1009
1010
1011 // Scan the command line options for an fg_root definition and set
1012 // just that.
1013 string
1014 fgScanForRoot (int argc, char **argv) 
1015 {
1016     int i = 1;
1017
1018     SG_LOG(SG_GENERAL, SG_INFO, "Scanning for root: command line");
1019
1020     while ( i < argc ) {
1021         SG_LOG( SG_GENERAL, SG_DEBUG, "argv[" << i << "] = " << argv[i] );
1022
1023         string arg = argv[i];
1024         if ( arg.find( "--fg-root=" ) == 0 ) {
1025             return arg.substr( 10 );
1026         }
1027
1028         i++;
1029     }
1030
1031     return "";
1032 }
1033
1034
1035 // Scan the config file for an fg_root definition and set just that.
1036 string
1037 fgScanForRoot (const string& path)
1038 {
1039     sg_gzifstream in( path );
1040     if ( !in.is_open() )
1041       return "";
1042
1043     SG_LOG( SG_GENERAL, SG_INFO, "Scanning for root: " << path );
1044
1045     in >> skipcomment;
1046 #ifndef __MWERKS__
1047     while ( ! in.eof() ) {
1048 #else
1049     char c = '\0';
1050     while ( in.get(c) && c != '\0' ) {
1051         in.putback(c);
1052 #endif
1053         string line;
1054
1055 #if defined( macintosh )
1056         getline( in, line, '\r' );
1057 #else
1058         getline( in, line, '\n' );
1059 #endif
1060
1061         // catch extraneous (DOS) line ending character
1062         if ( line[line.length() - 1] < 32 ) {
1063             line = line.substr( 0, line.length()-1 );
1064         }
1065
1066         if ( line.find( "--fg-root=" ) == 0 ) {
1067             return line.substr( 10 );
1068         }
1069
1070         in >> skipcomment;
1071     }
1072
1073     return "";
1074 }
1075
1076
1077 // Parse the command line options
1078 void
1079 fgParseArgs (int argc, char **argv)
1080 {
1081     bool in_options = true;
1082     bool verbose = false;
1083     bool help = false;
1084
1085     SG_LOG(SG_GENERAL, SG_INFO, "Processing command line arguments");
1086
1087     for (int i = 1; i < argc; i++) {
1088         string arg = argv[i];
1089
1090         if (in_options && (arg.find('-') == 0)) {
1091           if (arg == "--") {
1092             in_options = false;
1093           } else {
1094             int result = parse_option(arg);
1095             if ((result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR))
1096               help = true;
1097
1098             else if (result == FG_OPTIONS_VERBOSE_HELP)
1099               verbose = true;
1100
1101             else if (result == FG_OPTIONS_SHOW_AIRCRAFT) {
1102                fgShowAircraft();
1103                exit(0);
1104             }
1105           }
1106         } else {
1107           in_options = false;
1108           SG_LOG(SG_GENERAL, SG_INFO,
1109                  "Reading command-line property file " << arg);
1110           readProperties(arg, globals->get_props());
1111         }
1112     }
1113
1114     if (help) {
1115        fgUsage(verbose);
1116        exit(0);
1117     }
1118
1119     SG_LOG(SG_GENERAL, SG_INFO, "Finished command line arguments");
1120 }
1121
1122
1123 // Parse config file options
1124 void
1125 fgParseOptions (const string& path) {
1126     sg_gzifstream in( path );
1127     if ( !in.is_open() ) {
1128         return;
1129     }
1130
1131     SG_LOG( SG_GENERAL, SG_INFO, "Processing config file: " << path );
1132
1133     in >> skipcomment;
1134 #ifndef __MWERKS__
1135     while ( ! in.eof() ) {
1136 #else
1137     char c = '\0';
1138     while ( in.get(c) && c != '\0' ) {
1139         in.putback(c);
1140 #endif
1141         string line;
1142
1143 #if defined( macintosh )
1144         getline( in, line, '\r' );
1145 #else
1146         getline( in, line, '\n' );
1147 #endif
1148
1149         // catch extraneous (DOS) line ending character
1150         if ( line[line.length() - 1] < 32 ) {
1151             line = line.substr( 0, line.length()-1 );
1152         }
1153
1154         if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
1155             cerr << endl << "Config file parse error: " << path << " '" 
1156                     << line << "'" << endl;
1157             fgUsage();
1158             exit(-1);
1159         }
1160         in >> skipcomment;
1161     }
1162 }
1163
1164
1165 // Print usage message
1166 void 
1167 fgUsage (bool verbose)
1168 {
1169     SGPropertyNode options_root;
1170     SGPath opath( globals->get_fg_root() );
1171     opath.append( "options.xml" );
1172
1173     cout << "" << endl;
1174
1175     try {
1176         readProperties(opath.c_str(), &options_root);
1177     } catch (const sg_exception &ex) {
1178         cout << "Unable to read the help file." << endl;
1179         cout << "Make sure the file options.xml is located in the FlightGear base directory," << endl;
1180         cout << "and the location of the base directory is specified by setting $FG_ROOT or" << endl;
1181         cout << "by adding --fg-root=path as a program argument." << endl;
1182         
1183         exit(-1);
1184     }
1185
1186     SGPropertyNode *options = options_root.getNode("options");
1187     if (!options) {
1188         SG_LOG( SG_GENERAL, SG_ALERT,
1189                 "Error reading options.xml: <options> directive not found." );
1190         exit(-1);
1191     }
1192
1193     SGPropertyNode *usage = options->getNode("usage");
1194     if (usage) {
1195         cout << "Usage: " << usage->getStringValue() << endl;
1196     }
1197
1198     vector<SGPropertyNode_ptr>section = options->getChildren("section");
1199     for (unsigned int j = 0; j < section.size(); j++) {
1200         string msg = "";
1201
1202         vector<SGPropertyNode_ptr>option = section[j]->getChildren("option");
1203         for (unsigned int k = 0; k < option.size(); k++) {
1204
1205             SGPropertyNode *name = option[k]->getNode("name");
1206             SGPropertyNode *short_name = option[k]->getNode("short");
1207             SGPropertyNode *key = option[k]->getNode("key");
1208             SGPropertyNode *arg = option[k]->getNode("arg");
1209             bool brief = option[k]->getNode("brief");
1210
1211             if ((brief || verbose) && name) {
1212                 string tmp = name->getStringValue();
1213
1214                 if (key){
1215                     tmp.append(":");
1216                     tmp.append(key->getStringValue());
1217                 }
1218                 if (arg) {
1219                     tmp.append("=");
1220                     tmp.append(arg->getStringValue());
1221                 }
1222                 if (short_name) {
1223                     tmp.append(", -");
1224                     tmp.append(short_name->getStringValue());
1225                 }
1226
1227                 char cstr[96];
1228                 if (tmp.size() <= 25) {
1229                     snprintf(cstr, 96, "   --%-27s", tmp.c_str());
1230                 } else {
1231                     snprintf(cstr, 96, "\n   --%s\n%32c", tmp.c_str(), ' ');
1232                 }
1233
1234                 msg += cstr;
1235                 SGPropertyNode *desc = option[k]->getNode("description");
1236                 if (desc) {
1237                     msg += desc->getStringValue();
1238
1239                     for ( unsigned int l = 1;
1240                           (desc = option[k]->getNode("description", l, false));
1241                           l++ )
1242                     {
1243                         snprintf(cstr, 96, "\n%32c%s", ' ',
1244                                  desc->getStringValue());
1245                         msg += cstr;
1246                     }
1247                     msg += '\n';
1248                 }
1249             }
1250         }
1251
1252         SGPropertyNode *name = section[j]->getNode("name");
1253         if (!msg.empty() && name) {
1254            cout << endl << name->getStringValue() << ":" << endl;
1255            cout << msg;
1256            msg.erase();
1257         }
1258     }
1259
1260     if ( !verbose ) {
1261         cout << endl;
1262         cout << "For a complete list of options use --help --verbose" << endl;
1263     }
1264 }
1265
1266 // Show available aircraft types
1267 void fgShowAircraft(void) {
1268    SGPath path( globals->get_fg_root() );
1269    path.append("Aircraft");
1270
1271    ulDirEnt* dire;
1272    ulDir *dirp;
1273
1274    dirp = ulOpenDir(path.c_str());
1275    if (dirp == NULL) {
1276       cerr << "Unable to open aircraft directory." << endl;
1277       exit(-1);
1278    }
1279
1280    cout << "Available aircraft:" << endl;
1281    while ((dire = ulReadDir(dirp)) != NULL) {
1282       char *ptr;
1283
1284       if ((ptr = strstr(dire->d_name, "-set.xml")) && ptr[8] == '\0' ) {
1285           SGPath afile = path;
1286           afile.append(dire->d_name);
1287
1288           *ptr = '\0';
1289
1290           SGPropertyNode root;
1291           try {
1292              readProperties(afile.str(), &root);
1293           } catch (...) {
1294              continue;
1295           }
1296
1297           SGPropertyNode *desc, *node = root.getNode("sim");
1298           if (node)
1299              desc = node->getNode("description");
1300
1301           char cstr[96];
1302           if (strlen(dire->d_name) <= 27)
1303              snprintf(cstr, 96, "   %-27s  %s", dire->d_name,
1304                       (desc) ? desc->getStringValue() : "" );
1305
1306           else
1307              snprintf(cstr, 96, "   %-27s\n%32c%s", dire->d_name, ' ',
1308                       (desc) ? desc->getStringValue() : "" );
1309
1310           cout << cstr << endl;
1311       }
1312    }
1313
1314    ulCloseDir(dirp);
1315 }