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