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