]> 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 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 == "--disable-clouds3d" ) {
776         fgSetBool("/sim/rendering/clouds3d", false);
777     } else if ( arg == "--enable-clouds3d" ) {
778         fgSetBool("/sim/rendering/clouds3d", true);
779     } else if ( arg.find( "--fov=" ) == 0 ) {
780         parse_fov( arg.substr(6) );
781     } else if ( arg == "--disable-fullscreen" ) {
782         fgSetBool("/sim/startup/fullscreen", false);
783     } else if ( arg== "--enable-fullscreen") {
784         fgSetBool("/sim/startup/fullscreen", true);
785     } else if ( arg == "--shading-flat") {
786         fgSetBool("/sim/rendering/shading", false);
787     } else if ( arg == "--shading-smooth") {
788         fgSetBool("/sim/rendering/shading", true);
789     } else if ( arg == "--disable-skyblend") {
790         fgSetBool("/sim/rendering/skyblend", false);
791     } else if ( arg== "--enable-skyblend" ) {
792         fgSetBool("/sim/rendering/skyblend", true);
793     } else if ( arg == "--disable-textures" ) {
794         fgSetBool("/sim/rendering/textures", false);
795     } else if ( arg == "--enable-textures" ) {
796         fgSetBool("/sim/rendering/textures", true);
797     } else if ( arg == "--disable-wireframe" ) {
798         fgSetBool("/sim/rendering/wireframe", false);
799     } else if ( arg == "--enable-wireframe" ) {
800         fgSetBool("/sim/rendering/wireframe", true);
801     } else if ( arg.find( "--geometry=" ) == 0 ) {
802         bool geometry_ok = true;
803         int xsize = 0, ysize = 0;
804         string geometry = arg.substr( 11 );
805         string::size_type i = geometry.find('x');
806
807         if (i != string::npos) {
808             xsize = atoi(geometry.substr(0, i));
809             ysize = atoi(geometry.substr(i+1));
810         } else {
811             geometry_ok = false;
812         }
813
814         if ( xsize <= 0 || ysize <= 0 ) {
815             xsize = 640;
816             ysize = 480;
817             geometry_ok = false;
818         }
819
820         if ( !geometry_ok ) {
821             SG_LOG( SG_GENERAL, SG_ALERT, "Unknown geometry: " << geometry );
822             SG_LOG( SG_GENERAL, SG_ALERT,
823                     "Setting geometry to " << xsize << 'x' << ysize << '\n');
824         } else {
825           SG_LOG( SG_GENERAL, SG_INFO,
826                   "Setting geometry to " << xsize << 'x' << ysize << '\n');
827           fgSetInt("/sim/startup/xsize", xsize);
828           fgSetInt("/sim/startup/ysize", ysize);
829         }
830     } else if ( arg.find( "--bpp=" ) == 0 ) {
831         string bits_per_pix = arg.substr( 6 );
832         if ( bits_per_pix == "16" ) {
833             fgSetInt("/sim/rendering/bits-per-pixel", 16);
834         } else if ( bits_per_pix == "24" ) {
835             fgSetInt("/sim/rendering/bits-per-pixel", 24);
836         } else if ( bits_per_pix == "32" ) {
837             fgSetInt("/sim/rendering/bits-per-pixel", 32);
838         } else {
839           SG_LOG(SG_GENERAL, SG_ALERT, "Unsupported bpp " << bits_per_pix);
840         }
841     } else if ( arg == "--units-feet" ) {
842         fgSetString("/sim/startup/units", "feet");
843     } else if ( arg == "--units-meters" ) {
844         fgSetString("/sim/startup/units", "meters");
845     } else if ( arg.find( "--time-offset" ) == 0 ) {
846         fgSetInt("/sim/startup/time-offset",
847                  parse_time_offset( (arg.substr(14)) ));
848         fgSetString("/sim/startup/time-offset-type", "system-offset");
849     } else if ( arg.find( "--time-match-real") == 0 ) {
850         fgSetString("/sim/startup/time-offset-type", "system-offset");
851     } else if ( arg.find( "--time-match-local") == 0 ) {
852         fgSetString("/sim/startup/time-offset-type", "latitude-offset");
853     } else if ( arg.find( "--start-date-sys=") == 0 ) {
854         fgSetInt("/sim/startup/time-offset", parse_date((arg.substr(17))));
855         fgSetString("/sim/startup/time-offset-type", "system");
856     } else if ( arg.find( "--start-date-lat=") == 0 ) {
857         fgSetInt("/sim/startup/time-offset", parse_date((arg.substr(17))));
858         fgSetString("/sim/startup/time-offset-type", "latitude");
859     } else if ( arg.find( "--start-date-gmt=") == 0 ) {
860         fgSetInt("/sim/startup/time-offset", parse_date((arg.substr(17))));
861         fgSetString("/sim/startup/time-offset-type", "gmt");
862     } else if ( arg == "--hud-tris" ) {
863         fgSetString("/sim/hud/frame-stat-type", "tris");
864     } else if ( arg == "--hud-culled" ) {
865         fgSetString("/sim/hud/frame-stat-type", "culled");
866     } else if ( arg.find( "--atc610x" ) == 0 ) {
867         add_channel( "atc610x", "dummy" );
868     } else if ( arg.find( "--atlas=" ) == 0 ) {
869         add_channel( "atlas", arg.substr(8) );
870     } else if ( arg.find( "--httpd=" ) == 0 ) {
871         add_channel( "httpd", arg.substr(8) );
872 #ifdef FG_JPEG_SERVER
873     } else if ( arg.find( "--jpg-httpd=" ) == 0 ) {
874         add_channel( "jpg-httpd", arg.substr(12) );
875 #endif
876     } else if ( arg.find( "--native=" ) == 0 ) {
877         add_channel( "native", arg.substr(9) );
878     } else if ( arg.find( "--native-ctrls=" ) == 0 ) {
879         add_channel( "native_ctrls", arg.substr(15) );
880     } else if ( arg.find( "--native-fdm=" ) == 0 ) {
881         add_channel( "native_fdm", arg.substr(13) );
882     } else if ( arg.find( "--opengc=" ) == 0 ) {
883         // char stop;
884         // cout << "Adding channel for OpenGC Display" << endl; cin >> stop;
885         add_channel( "opengc", arg.substr(9) );
886     } else if ( arg.find( "--garmin=" ) == 0 ) {
887         add_channel( "garmin", arg.substr(9) );
888     } else if ( arg.find( "--nmea=" ) == 0 ) {
889         add_channel( "nmea", arg.substr(7) );
890     } else if ( arg.find( "--props=" ) == 0 ) {
891         add_channel( "props", arg.substr(8) );
892     } else if ( arg.find( "--telnet=" ) == 0 ) {
893         add_channel( "telnet", arg.substr(9) );
894     } else if ( arg.find( "--pve=" ) == 0 ) {
895         add_channel( "pve", arg.substr(6) );
896     } else if ( arg.find( "--ray=" ) == 0 ) {
897         add_channel( "ray", arg.substr(6) );
898     } else if ( arg.find( "--rul=" ) == 0 ) {
899         add_channel( "rul", arg.substr(6) );
900     } else if ( arg.find( "--joyclient=" ) == 0 ) {
901         add_channel( "joyclient", arg.substr(12) );
902 #ifdef FG_NETWORK_OLK
903     } else if ( arg == "--disable-network-olk" ) {
904         fgSetBool("/sim/networking/olk", false);
905     } else if ( arg== "--enable-network-olk") {
906         fgSetBool("/sim/networking/olk", true);
907     } else if ( arg == "--net-hud" ) {
908         fgSetBool("/sim/hud/net-display", true);
909         net_hud_display = 1;    // FIXME
910     } else if ( arg.find( "--net-id=") == 0 ) {
911         fgSetString("sim/networking/call-sign", arg.substr(9).c_str());
912 #endif
913     } else if ( arg.find( "--prop:" ) == 0 ) {
914         string assign = arg.substr(7);
915         string::size_type pos = assign.find('=');
916         if ( pos == arg.npos || pos == 0 ) {
917             SG_LOG( SG_GENERAL, SG_ALERT, "Bad property assignment: " << arg );
918             return FG_OPTIONS_ERROR;
919         }
920         string name = assign.substr(0, pos);
921         string value = assign.substr(pos + 1);
922         fgSetString(name.c_str(), value.c_str());
923         // SG_LOG(SG_GENERAL, SG_INFO, "Setting default value of property "
924         //        << name << " to \"" << value << '"');
925     } else if ( arg.find("--trace-read=") == 0) {
926         string name = arg.substr(13);
927         SG_LOG(SG_GENERAL, SG_INFO, "Tracing reads for property " << name);
928         fgGetNode(name.c_str(), true)
929           ->setAttribute(SGPropertyNode::TRACE_READ, true);
930     } else if ( arg.find("--trace-write=") == 0) {
931         string name = arg.substr(14);
932         SG_LOG(SG_GENERAL, SG_INFO, "Tracing writes for property " << name);
933         fgGetNode(name.c_str(), true)
934           ->setAttribute(SGPropertyNode::TRACE_WRITE, true);
935     } else if ( arg.find( "--view-offset=" ) == 0 ) {
936         // $$$ begin - added VS Renganathan, 14 Oct 2K
937         // for multi-window outside window imagery
938         string woffset = arg.substr( 14 );
939         double default_view_offset = 0.0;
940         if ( woffset == "LEFT" ) {
941                default_view_offset = SGD_PI * 0.25;
942         } else if ( woffset == "RIGHT" ) {
943             default_view_offset = SGD_PI * 1.75;
944         } else if ( woffset == "CENTER" ) {
945             default_view_offset = 0.00;
946         } else {
947             default_view_offset = atof( woffset.c_str() ) * SGD_DEGREES_TO_RADIANS;
948         }
949         /* apparently not used (CLO, 11 Jun 2002) 
950            FGViewer *pilot_view =
951               (FGViewer *)globals->get_viewmgr()->get_view( 0 ); */
952         // this will work without calls to the viewer...
953         fgSetDouble( "/sim/current-view/heading-offset-deg",
954                      default_view_offset  * SGD_RADIANS_TO_DEGREES );
955     // $$$ end - added VS Renganathan, 14 Oct 2K
956     } else if ( arg.find( "--visibility=" ) == 0 ) {
957         fgSetDouble("/environment/visibility-m", atof(arg.substr(13)));
958     } else if ( arg.find( "--visibility-miles=" ) == 0 ) {
959         double visibility = atof(arg.substr(19)) * 5280.0 * SG_FEET_TO_METER;
960         fgSetDouble("/environment/visibility-m", visibility);
961     } else if ( arg.find( "--random-wind" ) == 0 ) {
962         double min_hdg = sg_random() * 360.0;
963         double max_hdg = min_hdg + (20 - sqrt(sg_random() * 400));
964         double speed = 40 - sqrt(sg_random() * 1600.0);
965         double gust = speed + (10 - sqrt(sg_random() * 100));
966         setup_wind(min_hdg, max_hdg, speed, gust);
967     } else if ( arg.find( "--wind=" ) == 0 ) {
968         double min_hdg, max_hdg, speed, gust;
969         if (!parse_wind(arg.substr(7), &min_hdg, &max_hdg, &speed, &gust)) {
970           SG_LOG( SG_GENERAL, SG_ALERT, "bad wind value " << arg.substr(7) );
971           return FG_OPTIONS_ERROR;
972         }
973         setup_wind(min_hdg, max_hdg, speed, gust);
974     } else if ( arg.find( "--wp=" ) == 0 ) {
975         parse_wp( arg.substr( 5 ) );
976     } else if ( arg.find( "--flight-plan=") == 0) {
977         parse_flightplan ( arg.substr (14) );
978     } else if ( arg.find( "--config=" ) == 0 ) {
979         string file = arg.substr(9);
980         try {
981           readProperties(file, globals->get_props());
982         } catch (const sg_exception &e) {
983           string message = "Error loading config file: ";
984           message += e.getFormattedMessage();
985           SG_LOG(SG_INPUT, SG_ALERT, message);
986           exit(2);
987         }
988     } else if ( arg.find( "--aircraft=" ) == 0 ) {
989         // read in the top level aircraft definition file
990         SGPath apath( globals->get_fg_root() );
991         apath.append( "Aircraft" );
992         apath.append( arg.substr(11) );
993         apath.concat( "-set.xml" );
994         SG_LOG(SG_INPUT, SG_INFO, "Reading aircraft: " << arg.substr(11)
995             << " from " << apath.str());
996         readProperties( apath.str(), globals->get_props() );
997     } else {
998         SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" );
999         return FG_OPTIONS_ERROR;
1000     }
1001     
1002     return FG_OPTIONS_OK;
1003 }
1004
1005
1006 // Scan the command line options for an fg_root definition and set
1007 // just that.
1008 string
1009 fgScanForRoot (int argc, char **argv) 
1010 {
1011     int i = 1;
1012
1013     SG_LOG(SG_GENERAL, SG_INFO, "Scanning for root: command line");
1014
1015     while ( i < argc ) {
1016         SG_LOG( SG_GENERAL, SG_DEBUG, "argv[" << i << "] = " << argv[i] );
1017
1018         string arg = argv[i];
1019         if ( arg.find( "--fg-root=" ) == 0 ) {
1020             return arg.substr( 10 );
1021         }
1022
1023         i++;
1024     }
1025
1026     return "";
1027 }
1028
1029
1030 // Scan the config file for an fg_root definition and set just that.
1031 string
1032 fgScanForRoot (const string& path)
1033 {
1034     sg_gzifstream in( path );
1035     if ( !in.is_open() )
1036       return "";
1037
1038     SG_LOG( SG_GENERAL, SG_INFO, "Scanning for root: " << path );
1039
1040     in >> skipcomment;
1041 #ifndef __MWERKS__
1042     while ( ! in.eof() ) {
1043 #else
1044     char c = '\0';
1045     while ( in.get(c) && c != '\0' ) {
1046         in.putback(c);
1047 #endif
1048         string line;
1049
1050 #if defined( macintosh )
1051         getline( in, line, '\r' );
1052 #else
1053         getline( in, line, '\n' );
1054 #endif
1055
1056         // catch extraneous (DOS) line ending character
1057         if ( line[line.length() - 1] < 32 ) {
1058             line = line.substr( 0, line.length()-1 );
1059         }
1060
1061         if ( line.find( "--fg-root=" ) == 0 ) {
1062             return line.substr( 10 );
1063         }
1064
1065         in >> skipcomment;
1066     }
1067
1068     return "";
1069 }
1070
1071
1072 // Parse the command line options
1073 void
1074 fgParseArgs (int argc, char **argv)
1075 {
1076     bool in_options = true;
1077     bool verbose = false;
1078     bool help = false;
1079
1080     SG_LOG(SG_GENERAL, SG_INFO, "Processing command line arguments");
1081
1082     for (int i = 1; i < argc; i++) {
1083         string arg = argv[i];
1084
1085         if (in_options && (arg.find('-') == 0)) {
1086           if (arg == "--") {
1087             in_options = false;
1088           } else {
1089             int result = parse_option(arg);
1090             if ((result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR))
1091               help = true;
1092
1093             else if (result == FG_OPTIONS_VERBOSE_HELP)
1094               verbose = true;
1095
1096             else if (result == FG_OPTIONS_SHOW_AIRCRAFT) {
1097                fgShowAircraft();
1098                exit(0);
1099             }
1100           }
1101         } else {
1102           in_options = false;
1103           SG_LOG(SG_GENERAL, SG_INFO,
1104                  "Reading command-line property file " << arg);
1105           readProperties(arg, globals->get_props());
1106         }
1107     }
1108
1109     if (help) {
1110        fgUsage(verbose);
1111        exit(0);
1112     }
1113
1114     SG_LOG(SG_GENERAL, SG_INFO, "Finished command line arguments");
1115 }
1116
1117
1118 // Parse config file options
1119 void
1120 fgParseOptions (const string& path) {
1121     sg_gzifstream in( path );
1122     if ( !in.is_open() ) {
1123         return;
1124     }
1125
1126     SG_LOG( SG_GENERAL, SG_INFO, "Processing config file: " << path );
1127
1128     in >> skipcomment;
1129 #ifndef __MWERKS__
1130     while ( ! in.eof() ) {
1131 #else
1132     char c = '\0';
1133     while ( in.get(c) && c != '\0' ) {
1134         in.putback(c);
1135 #endif
1136         string line;
1137
1138 #if defined( macintosh )
1139         getline( in, line, '\r' );
1140 #else
1141         getline( in, line, '\n' );
1142 #endif
1143
1144         // catch extraneous (DOS) line ending character
1145         if ( line[line.length() - 1] < 32 ) {
1146             line = line.substr( 0, line.length()-1 );
1147         }
1148
1149         if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
1150             cout << endl << "Config file parse error: " << path << " '" 
1151                     << line << "'" << endl;
1152             fgUsage();
1153             exit(-1);
1154         }
1155         in >> skipcomment;
1156     }
1157 }
1158
1159
1160 // Print usage message
1161 void 
1162 fgUsage (bool verbose)
1163 {
1164     SGPropertyNode options_root;
1165     SGPath opath( globals->get_fg_root() );
1166     opath.append( "options.xml" );
1167
1168     cout << "" << endl;
1169
1170     try {
1171         readProperties(opath.c_str(), &options_root);
1172     } catch (const sg_exception &ex) {
1173         cout << "Unable to read the help file." << endl;
1174         cout << "Make sure the file options.xml is located in the FlightGear base directory," << endl;
1175         cout << "and the location of the base directory is specified by setting $FG_ROOT or" << endl;
1176         cout << "by adding --fg-root=path as a program argument." << endl;
1177         
1178         exit(-1);
1179     }
1180
1181     SGPropertyNode *options = options_root.getNode("options");
1182     if (!options) {
1183         SG_LOG( SG_GENERAL, SG_ALERT,
1184                 "Error reading options.xml: <options> directive not found." );
1185         exit(-1);
1186     }
1187
1188     SGPropertyNode *usage = options->getNode("usage");
1189     if (usage) {
1190         cout << "Usage: " << usage->getStringValue() << endl;
1191     }
1192
1193     vector<SGPropertyNode_ptr>section = options->getChildren("section");
1194     for (unsigned int j = 0; j < section.size(); j++) {
1195         string msg = "";
1196
1197         vector<SGPropertyNode_ptr>option = section[j]->getChildren("option");
1198         for (unsigned int k = 0; k < option.size(); k++) {
1199
1200             SGPropertyNode *name = option[k]->getNode("name");
1201             SGPropertyNode *short_name = option[k]->getNode("short");
1202             SGPropertyNode *key = option[k]->getNode("key");
1203             SGPropertyNode *arg = option[k]->getNode("arg");
1204             bool brief = option[k]->getNode("brief");
1205
1206             if ((brief || verbose) && name) {
1207                 string tmp = name->getStringValue();
1208
1209                 if (key){
1210                     tmp.append(":");
1211                     tmp.append(key->getStringValue());
1212                 }
1213                 if (arg) {
1214                     tmp.append("=");
1215                     tmp.append(arg->getStringValue());
1216                 }
1217                 if (short_name) {
1218                     tmp.append(", -");
1219                     tmp.append(short_name->getStringValue());
1220                 }
1221
1222                 char cstr[96];
1223                 if (tmp.size() <= 25) {
1224                     snprintf(cstr, 96, "   --%-27s", tmp.c_str());
1225                 } else {
1226                     snprintf(cstr, 96, "\n   --%s\n%32c", tmp.c_str(), ' ');
1227                 }
1228
1229                 msg += cstr;
1230                 SGPropertyNode *desc = option[k]->getNode("description");
1231                 if (desc) {
1232                     msg += desc->getStringValue();
1233
1234                     for ( unsigned int l = 1;
1235                           (desc = option[k]->getNode("description", l, false));
1236                           l++ )
1237                     {
1238                         snprintf(cstr, 96, "\n%32c%s", ' ',
1239                                  desc->getStringValue());
1240                         msg += cstr;
1241                     }
1242                     msg += '\n';
1243                 }
1244             }
1245         }
1246
1247         SGPropertyNode *name = section[j]->getNode("name");
1248         if (!msg.empty() && name) {
1249            cout << endl << name->getStringValue() << ":" << endl;
1250            cout << msg;
1251            msg.erase();
1252         }
1253     }
1254
1255     if ( !verbose ) {
1256         cout << endl;
1257         cout << "For a complete list of options use --help --verbose" << endl;
1258     }
1259 }
1260
1261 // Show available aircraft types
1262 void fgShowAircraft(void) {
1263    SGPath path( globals->get_fg_root() );
1264    path.append("Aircraft");
1265
1266    ulDirEnt* dire;
1267    ulDir *dirp;
1268
1269    dirp = ulOpenDir(path.c_str());
1270    if (dirp == NULL) {
1271       cout << "Unable to open aircraft directory." << endl;
1272       exit(-1);
1273    }
1274
1275    cout << "Available aircraft:" << endl;
1276    while ((dire = ulReadDir(dirp)) != NULL) {
1277       char *ptr;
1278
1279       if ((ptr = strstr(dire->d_name, "-set.xml")) && ptr[8] == '\0' ) {
1280           SGPath afile = path;
1281           afile.append(dire->d_name);
1282
1283           *ptr = '\0';
1284
1285           SGPropertyNode root;
1286           try {
1287              readProperties(afile.str(), &root);
1288           } catch (...) {
1289              continue;
1290           }
1291
1292           SGPropertyNode *desc, *node = root.getNode("sim");
1293           if (node)
1294              desc = node->getNode("description");
1295
1296           char cstr[96];
1297           if (strlen(dire->d_name) <= 27)
1298              snprintf(cstr, 96, "   %-27s  %s", dire->d_name,
1299                       (desc) ? desc->getStringValue() : "" );
1300
1301           else
1302              snprintf(cstr, 96, "   %-27s\n%32c%s", dire->d_name, ' ',
1303                       (desc) ? desc->getStringValue() : "" );
1304
1305           cout << cstr << endl;
1306       }
1307    }
1308
1309    ulCloseDir(dirp);
1310 }