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