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