1 // options.cxx -- class to handle command line options
3 // Written by Curtis Olson, started April 1998.
5 // Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu
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.
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.
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.
28 #include <simgear/compiler.h>
29 #include <simgear/misc/exception.hxx>
31 #include <math.h> // rint()
33 #include <stdlib.h> // atof(), atoi()
34 #include <string.h> // strcmp()
41 #include <simgear/math/sg_random.h>
42 #include <simgear/misc/sgstream.hxx>
43 #include <simgear/misc/sg_path.hxx>
44 #include <simgear/route/route.hxx>
45 #include <simgear/route/waypoint.hxx>
47 // #include <Include/general.hxx>
48 // #include <Airports/simple.hxx>
49 // #include <Cockpit/cockpit.hxx>
50 // #include <FDM/flight.hxx>
51 // #include <FDM/UIUCModel/uiuc_aircraftdir.h>
53 # include <NetworkOLK/network.h>
58 #include "globals.hxx"
59 #include "fg_init.hxx"
60 #include "fg_props.hxx"
61 #include "options.hxx"
62 #include "viewmgr.hxx"
67 SG_USING_NAMESPACE(std);
70 #define NEW_DEFAULT_MODEL_HZ 120
77 FG_OPTIONS_VERBOSE_HELP = 3,
78 FG_OPTIONS_SHOW_AIRCRAFT = 4
82 atof( const string& str )
86 // -dw- if ::atof is called, then we get an infinite loop
87 return std::atof( str.c_str() );
89 return ::atof( str.c_str() );
94 atoi( const string& str )
97 // -dw- if ::atoi is called, then we get an infinite loop
98 return std::atoi( str.c_str() );
100 return ::atoi( str.c_str() );
106 * Set a few fail-safe default property values.
108 * These should all be set in $FG_ROOT/preferences.xml, but just
109 * in case, we provide some initial sane values here. This method
110 * should be invoked *before* reading any init files.
115 // set a possibly independent location for scenery data
116 char *envp = ::getenv( "FG_SCENERY" );
118 if ( envp != NULL ) {
119 // fg_root could be anywhere, so default to environmental
120 // variable $FG_ROOT if it is set.
121 globals->set_fg_scenery(envp);
123 // Otherwise, default to Scenery being in $FG_ROOT/Scenery
124 globals->set_fg_scenery("");
126 // Position (deliberately out of range)
127 fgSetDouble("/position/longitude-deg", 9999.0);
128 fgSetDouble("/position/latitude-deg", 9999.0);
129 fgSetDouble("/position/altitude-ft", -9999.0);
132 fgSetDouble("/orientation/heading-deg", 270);
133 fgSetDouble("/orientation/roll-deg", 0);
134 fgSetDouble("/orientation/pitch-deg", 0.424);
137 fgSetDouble("/velocities/uBody-fps", 0.0);
138 fgSetDouble("/velocities/vBody-fps", 0.0);
139 fgSetDouble("/velocities/wBody-fps", 0.0);
140 fgSetDouble("/velocities/speed-north-fps", 0.0);
141 fgSetDouble("/velocities/speed-east-fps", 0.0);
142 fgSetDouble("/velocities/speed-down-fps", 0.0);
143 fgSetDouble("/velocities/airspeed-kt", 0.0);
144 fgSetDouble("/velocities/mach", 0.0);
147 fgSetDouble("/sim/presets/longitude-deg", 9999.0);
148 fgSetDouble("/sim/presets/latitude-deg", 9999.0);
149 fgSetDouble("/sim/presets/altitude-ft", -9999.0);
151 fgSetDouble("/sim/presets/heading-deg", 270);
152 fgSetDouble("/sim/presets/roll-deg", 0);
153 fgSetDouble("/sim/presets/pitch-deg", 0.424);
155 fgSetString("/sim/presets/speed-set", "knots");
156 fgSetDouble("/sim/presets/airspeed-kt", 0.0);
157 fgSetDouble("/sim/presets/mach", 0.0);
158 fgSetDouble("/sim/presets/uBody-fps", 0.0);
159 fgSetDouble("/sim/presets/vBody-fps", 0.0);
160 fgSetDouble("/sim/presets/wBody-fps", 0.0);
161 fgSetDouble("/sim/presets/speed-north-fps", 0.0);
162 fgSetDouble("/sim/presets/speed-east-fps", 0.0);
163 fgSetDouble("/sim/presets/speed-down-fps", 0.0);
165 fgSetBool("/sim/presets/onground", true);
166 fgSetBool("/sim/presets/trim", false);
169 fgSetBool("/sim/startup/game-mode", false);
170 fgSetBool("/sim/startup/splash-screen", true);
171 fgSetBool("/sim/startup/intro-music", true);
172 // we want mouse-pointer to have an undefined value if nothing is
173 // specified so we can do the right thing for voodoo-1/2 cards.
174 // fgSetString("/sim/startup/mouse-pointer", "disabled");
175 fgSetString("/sim/control-mode", "joystick");
176 fgSetBool("/sim/auto-coordination", false);
178 fgSetString("/sim/startup/browser-app", "netscape");
180 fgSetString("/sim/startup/browser-app", "webrun.bat");
183 fgSetBool("/sim/hud/visibility", false);
184 fgSetBool("/sim/panel/visibility", true);
185 fgSetBool("/sim/sound/audible", true);
186 fgSetBool("/sim/hud/antialiased", false);
188 // Flight Model options
189 fgSetString("/sim/flight-model", "jsb");
190 fgSetString("/sim/aero", "c172");
191 fgSetInt("/sim/model-hz", NEW_DEFAULT_MODEL_HZ);
192 fgSetInt("/sim/speed-up", 1);
195 fgSetString("/sim/rendering/fog", "nicest");
196 fgSetBool("/environment/clouds/status", true);
197 fgSetBool("/sim/startup/fullscreen", false);
198 fgSetBool("/sim/rendering/shading", true);
199 fgSetBool("/sim/rendering/skyblend", true);
200 fgSetBool("/sim/rendering/textures", true);
201 fgSetBool("/sim/rendering/wireframe", false);
202 fgSetBool("/sim/rendering/distance-attenuation", false);
203 fgSetInt("/sim/startup/xsize", 800);
204 fgSetInt("/sim/startup/ysize", 600);
205 fgSetInt("/sim/rendering/bits-per-pixel", 16);
206 fgSetString("/sim/view-mode", "pilot");
207 fgSetDouble("/sim/current-view/heading-offset-deg", 0);
208 fgSetDouble("/environment/visibility-m", 20000);
211 fgSetString("/sim/startup/units", "feet");
212 fgSetString("/sim/hud/frame-stat-type", "tris");
215 fgSetInt("/sim/startup/time-offset", 0);
216 fgSetString("/sim/startup/time-offset-type", "system-offset");
217 fgSetLong("/sim/time/cur-time-override", 0);
219 fgSetBool("/sim/networking/network-olk", false);
220 fgSetString("/sim/networking/call-sign", "Johnny");
223 fgSetBool("/sim/freeze/master", false);
224 fgSetBool("/sim/freeze/position", false);
225 fgSetBool("/sim/freeze/clock", false);
226 fgSetBool("/sim/freeze/fuel", false);
229 fgSetString("/sim/multiplay/callsign", "callsign");
230 fgSetString("/sim/multiplay/rxhost", "0");
231 fgSetString("/sim/multiplay/txhost", "0");
232 fgSetInt("/sim/multiplay/rxport", 0);
233 fgSetInt("/sim/multiplay/txport", 0);
240 parse_wind (const string &wind, double * min_hdg, double * max_hdg,
241 double * speed, double * gust)
243 string::size_type pos = wind.find('@');
244 if (pos == string::npos)
246 string dir = wind.substr(0, pos);
247 string spd = wind.substr(pos+1);
249 if (pos == string::npos) {
250 *min_hdg = *max_hdg = atof(dir.c_str());
252 *min_hdg = atof(dir.substr(0,pos).c_str());
253 *max_hdg = atof(dir.substr(pos+1).c_str());
256 if (pos == string::npos) {
257 *speed = *gust = atof(spd.c_str());
259 *speed = atof(spd.substr(0,pos).c_str());
260 *gust = atof(spd.substr(pos+1).c_str());
265 // parse a time string ([+/-]%f[:%f[:%f]]) into hours
267 parse_time(const string& time_in) {
268 char *time_str, num[256];
269 double hours, minutes, seconds;
274 time_str = (char *)time_in.c_str();
276 // printf("parse_time(): %s\n", time_str);
279 if ( strlen(time_str) ) {
280 if ( time_str[0] == '+' ) {
283 } else if ( time_str[0] == '-' ) {
288 // printf("sign = %d\n", sign);
291 if ( strlen(time_str) ) {
293 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
294 num[i] = time_str[0];
298 if ( time_str[0] == ':' ) {
303 // printf("hours = %.2lf\n", hours);
309 if ( strlen(time_str) ) {
311 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
312 num[i] = time_str[0];
316 if ( time_str[0] == ':' ) {
321 // printf("minutes = %.2lf\n", minutes);
323 result += minutes / 60.0;
327 if ( strlen(time_str) ) {
329 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
330 num[i] = time_str[0];
336 // printf("seconds = %.2lf\n", seconds);
338 result += seconds / 3600.0;
341 SG_LOG( SG_GENERAL, SG_INFO, " parse_time() = " << sign * result );
343 return(sign * result);
347 // parse a date string (yyyy:mm:dd:hh:mm:ss) into a time_t (seconds)
349 parse_date( const string& date)
352 char * date_str, num[256];
354 // initialize to zero
361 gmt.tm_isdst = 0; // ignore daylight savings time for the moment
362 date_str = (char *)date.c_str();
364 if ( strlen(date_str) ) {
366 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
367 num[i] = date_str[0];
371 if ( date_str[0] == ':' ) {
375 gmt.tm_year = atoi(num) - 1900;
378 if ( strlen(date_str) ) {
380 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
381 num[i] = date_str[0];
385 if ( date_str[0] == ':' ) {
389 gmt.tm_mon = atoi(num) -1;
392 if ( strlen(date_str) ) {
394 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
395 num[i] = date_str[0];
399 if ( date_str[0] == ':' ) {
403 gmt.tm_mday = atoi(num);
406 if ( strlen(date_str) ) {
408 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
409 num[i] = date_str[0];
413 if ( date_str[0] == ':' ) {
417 gmt.tm_hour = atoi(num);
420 if ( strlen(date_str) ) {
422 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
423 num[i] = date_str[0];
427 if ( date_str[0] == ':' ) {
431 gmt.tm_min = atoi(num);
434 if ( strlen(date_str) ) {
436 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
437 num[i] = date_str[0];
441 if ( date_str[0] == ':' ) {
445 gmt.tm_sec = atoi(num);
447 time_t theTime = sgTimeGetGMT( gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
448 gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
449 //printf ("Date is %s\n", ctime(&theTime));
450 //printf ("in seconds that is %d\n", theTime);
456 // parse angle in the form of [+/-]ddd:mm:ss into degrees
458 parse_degree( const string& degree_str) {
459 double result = parse_time( degree_str );
461 // printf("Degree = %.4f\n", result);
467 // parse time offset string into seconds
469 parse_time_offset( const string& time_str) {
472 // printf("time offset = %s\n", time_str);
475 result = (int)rint(parse_time(time_str) * 3600.0);
477 result = (int)(parse_time(time_str) * 3600.0);
480 // printf("parse_time_offset(): %d\n", result);
486 // Parse --fov=x.xx type option
488 parse_fov( const string& arg ) {
489 double fov = atof(arg);
491 if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
492 if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
494 fgSetDouble("/sim/current-view/field-of-view", fov);
496 // printf("parse_fov(): result = %.4f\n", fov);
502 // Parse I/O channel option
504 // Format is "--protocol=medium,direction,hz,medium_options,..."
506 // protocol = { native, nmea, garmin, fgfs, rul, pve, etc. }
507 // medium = { serial, socket, file, etc. }
508 // direction = { in, out, bi }
509 // hz = number of times to process channel per second (floating
510 // point values are ok.
512 // Serial example "--nmea=serial,dir,hz,device,baud" where
514 // device = OS device name of serial line to be open()'ed
515 // baud = {300, 1200, 2400, ..., 230400}
517 // Socket exacmple "--native=socket,dir,hz,machine,port,style" where
519 // machine = machine name or ip address if client (leave empty if server)
520 // port = port, leave empty to let system choose
521 // style = tcp or udp
523 // File example "--garmin=file,dir,hz,filename" where
525 // filename = file system file name
528 add_channel( const string& type, const string& channel_str ) {
529 SG_LOG(SG_GENERAL, SG_INFO, "Channel string = " << channel_str );
531 globals->get_channel_options_list()->push_back( type + "," + channel_str );
533 // cout << "here" << endl;
540 setup_wind (double min_hdg, double max_hdg, double speed, double gust)
542 fgSetDouble("/environment/wind-from-heading-deg", min_hdg);
543 fgSetDouble("/environment/params/min-wind-from-heading-deg", min_hdg);
544 fgSetDouble("/environment/params/max-wind-from-heading-deg", max_hdg);
545 fgSetDouble("/environment/wind-speed-kt", speed);
546 fgSetDouble("/environment/params/base-wind-speed-kt", speed);
547 fgSetDouble("/environment/params/gust-wind-speed-kt", gust);
549 SG_LOG(SG_GENERAL, SG_INFO, "WIND: " << min_hdg << '@' <<
550 speed << " knots" << endl);
554 speed *= SG_NM_TO_METER * SG_METER_TO_FEET * (1.0/3600);
555 while (min_hdg > 360)
559 min_hdg *= SGD_DEGREES_TO_RADIANS;
560 fgSetDouble("/environment/wind-from-north-fps", speed * cos(dir));
561 fgSetDouble("/environment/wind-from-east-fps", speed * sin(dir));
562 #endif // FG_WEATHERCM
566 // Parse --wp=ID[@alt]
568 parse_wp( const string& arg ) {
572 string::size_type pos = arg.find( "@" );
573 if ( pos != string::npos ) {
574 id = arg.substr( 0, pos );
575 alt_str = arg.substr( pos + 1 );
576 // cout << "id str = " << id << " alt str = " << alt_str << endl;
577 alt = atof( alt_str.c_str() );
578 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") ) {
579 alt *= SG_FEET_TO_METER;
586 if ( fgFindAirportID( id, &a ) ) {
587 SGWayPoint wp( a.longitude, a.latitude, alt, SGWayPoint::WGS84, id );
588 globals->get_route()->add_waypoint( wp );
597 // Parse --flight-plan=[file]
599 parse_flightplan(const string& arg)
601 sg_gzifstream in(arg.c_str());
602 if ( !in.is_open() ) {
608 #if defined( macintosh )
609 getline( in, line, '\r' );
611 getline( in, line, '\n' );
614 // catch extraneous (DOS) line ending character
615 if ( line[line.length() - 1] < 32 ) {
616 line = line.substr( 0, line.length()-1 );
628 #define NEW_OPTION_PARSING 1
629 #ifdef NEW_OPTION_PARSING
631 fgOptLanguage( const char *arg )
633 globals->set_locale( fgInitLocale( arg ) );
634 return FG_OPTIONS_OK;
640 fgSetString("/sim/presets/airport-id", "");
641 fgSetString("/sim/presets/vor-id", "");
642 fgSetString("/sim/presets/ndb-id", "");
643 fgSetString("/sim/presets/fix", "");
647 fgOptVOR( const char * arg )
650 fgSetString("/sim/presets/vor-id", arg);
651 return FG_OPTIONS_OK;
655 fgOptNDB( const char * arg )
658 fgSetString("/sim/presets/ndb-id", arg);
659 return FG_OPTIONS_OK;
663 fgOptFIX( const char * arg )
666 fgSetString("/sim/presets/fix", arg);
667 return FG_OPTIONS_OK;
671 fgOptLon( const char *arg )
674 fgSetDouble("/sim/presets/longitude-deg", parse_degree( arg ));
675 fgSetDouble("/position/longitude-deg", parse_degree( arg ));
676 return FG_OPTIONS_OK;
680 fgOptLat( const char *arg )
683 fgSetDouble("/sim/presets/latitude-deg", parse_degree( arg ));
684 fgSetDouble("/position/latitude-deg", parse_degree( arg ));
685 return FG_OPTIONS_OK;
689 fgOptAltitude( const char *arg )
691 fgSetBool("/sim/presets/onground", false);
692 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
693 fgSetDouble("/sim/presets/altitude-ft", atof( arg ));
695 fgSetDouble("/sim/presets/altitude-ft",
696 atof( arg ) * SG_METER_TO_FEET);
697 return FG_OPTIONS_OK;
701 fgOptUBody( const char *arg )
703 fgSetString("/sim/presets/speed-set", "UVW");
704 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
705 fgSetDouble("/sim/presets/uBody-fps", atof( arg ));
707 fgSetDouble("/sim/presets/uBody-fps",
708 atof( arg ) * SG_METER_TO_FEET);
709 return FG_OPTIONS_OK;
713 fgOptVBody( const char *arg )
715 fgSetString("/sim/presets/speed-set", "UVW");
716 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
717 fgSetDouble("/sim/presets/vBody-fps", atof( arg ));
719 fgSetDouble("/sim/presets/vBody-fps",
720 atof( arg ) * SG_METER_TO_FEET);
721 return FG_OPTIONS_OK;
725 fgOptWBody( const char *arg )
727 fgSetString("/sim/presets/speed-set", "UVW");
728 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
729 fgSetDouble("/sim/presets/wBody-fps", atof(arg));
731 fgSetDouble("/sim/presets/wBody-fps",
732 atof(arg) * SG_METER_TO_FEET);
733 return FG_OPTIONS_OK;
737 fgOptVNorth( const char *arg )
739 fgSetString("/sim/presets/speed-set", "NED");
740 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
741 fgSetDouble("/sim/presets/speed-north-fps", atof( arg ));
743 fgSetDouble("/sim/presets/speed-north-fps",
744 atof( arg ) * SG_METER_TO_FEET);
745 return FG_OPTIONS_OK;
749 fgOptVEast( const char *arg )
751 fgSetString("/sim/presets/speed-set", "NED");
752 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
753 fgSetDouble("/sim/presets/speed-east-fps", atof(arg));
755 fgSetDouble("/sim/presets/speed-east-fps",
756 atof(arg) * SG_METER_TO_FEET);
757 return FG_OPTIONS_OK;
761 fgOptVDown( const char *arg )
763 fgSetString("/sim/presets/speed-set", "NED");
764 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
765 fgSetDouble("/sim/presets/speed-down-fps", atof(arg));
767 fgSetDouble("/sim/presets/speed-down-fps",
768 atof(arg) * SG_METER_TO_FEET);
769 return FG_OPTIONS_OK;
773 fgOptVc( const char *arg )
775 // fgSetString("/sim/presets/speed-set", "knots");
776 // fgSetDouble("/velocities/airspeed-kt", atof(arg.substr(5)));
777 fgSetString("/sim/presets/speed-set", "knots");
778 fgSetDouble("/sim/presets/airspeed-kt", atof(arg));
779 return FG_OPTIONS_OK;
783 fgOptMach( const char *arg )
785 fgSetString("/sim/presets/speed-set", "mach");
786 fgSetDouble("/sim/presets/mach", atof(arg));
787 return FG_OPTIONS_OK;
791 fgOptRoc( const char *arg )
793 fgSetDouble("/velocities/vertical-speed-fps", atof(arg)/60);
794 return FG_OPTIONS_OK;
798 fgOptFgRoot( const char *arg )
800 globals->set_fg_root(arg);
801 return FG_OPTIONS_OK;
805 fgOptFgScenery( const char *arg )
807 globals->set_fg_scenery(arg);
808 return FG_OPTIONS_OK;
812 fgOptFov( const char *arg )
815 return FG_OPTIONS_OK;
819 fgOptGeometry( const char *arg )
821 bool geometry_ok = true;
822 int xsize = 0, ysize = 0;
823 string geometry = arg;
824 string::size_type i = geometry.find('x');
826 if (i != string::npos) {
827 xsize = atoi(geometry.substr(0, i));
828 ysize = atoi(geometry.substr(i+1));
833 if ( xsize <= 0 || ysize <= 0 ) {
839 if ( !geometry_ok ) {
840 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown geometry: " << geometry );
841 SG_LOG( SG_GENERAL, SG_ALERT,
842 "Setting geometry to " << xsize << 'x' << ysize << '\n');
844 SG_LOG( SG_GENERAL, SG_INFO,
845 "Setting geometry to " << xsize << 'x' << ysize << '\n');
846 fgSetInt("/sim/startup/xsize", xsize);
847 fgSetInt("/sim/startup/ysize", ysize);
849 return FG_OPTIONS_OK;
853 fgOptBpp( const char *arg )
855 string bits_per_pix = arg;
856 if ( bits_per_pix == "16" ) {
857 fgSetInt("/sim/rendering/bits-per-pixel", 16);
858 } else if ( bits_per_pix == "24" ) {
859 fgSetInt("/sim/rendering/bits-per-pixel", 24);
860 } else if ( bits_per_pix == "32" ) {
861 fgSetInt("/sim/rendering/bits-per-pixel", 32);
863 SG_LOG(SG_GENERAL, SG_ALERT, "Unsupported bpp " << bits_per_pix);
865 return FG_OPTIONS_OK;
869 fgOptTimeOffset( const char *arg )
871 fgSetInt("/sim/startup/time-offset",
872 parse_time_offset( arg ));
873 fgSetString("/sim/startup/time-offset-type", "system-offset");
874 return FG_OPTIONS_OK;
878 fgOptStartDateSys( const char *arg )
880 fgSetInt("/sim/startup/time-offset", parse_date( arg ) );
881 fgSetString("/sim/startup/time-offset-type", "system");
882 return FG_OPTIONS_OK;
886 fgOptStartDateLat( const char *arg )
888 fgSetInt("/sim/startup/time-offset", parse_date( arg ) );
889 fgSetString("/sim/startup/time-offset-type", "latitude");
890 return FG_OPTIONS_OK;
894 fgOptStartDateGmt( const char *arg )
896 fgSetInt("/sim/startup/time-offset", parse_date( arg ) );
897 fgSetString("/sim/startup/time-offset-type", "gmt");
898 return FG_OPTIONS_OK;
901 #ifdef FG_NETWORK_OLK
903 fgOptNetHud( const char *arg )
905 fgSetBool("/sim/hud/net-display", true);
906 net_hud_display = 1; // FIXME
907 return FG_OPTIONS_OK;
912 fgOptTraceRead( const char *arg )
915 SG_LOG(SG_GENERAL, SG_INFO, "Tracing reads for property " << name);
916 fgGetNode(name.c_str(), true)
917 ->setAttribute(SGPropertyNode::TRACE_READ, true);
918 return FG_OPTIONS_OK;
922 fgOptTraceWrite( const char *arg )
925 SG_LOG(SG_GENERAL, SG_INFO, "Tracing writes for property " << name);
926 fgGetNode(name.c_str(), true)
927 ->setAttribute(SGPropertyNode::TRACE_WRITE, true);
928 return FG_OPTIONS_OK;
932 fgOptViewOffset( const char *arg )
934 // $$$ begin - added VS Renganathan, 14 Oct 2K
935 // for multi-window outside window imagery
936 string woffset = arg;
937 double default_view_offset = 0.0;
938 if ( woffset == "LEFT" ) {
939 default_view_offset = SGD_PI * 0.25;
940 } else if ( woffset == "RIGHT" ) {
941 default_view_offset = SGD_PI * 1.75;
942 } else if ( woffset == "CENTER" ) {
943 default_view_offset = 0.00;
945 default_view_offset = atof( woffset.c_str() ) * SGD_DEGREES_TO_RADIANS;
947 /* apparently not used (CLO, 11 Jun 2002)
948 FGViewer *pilot_view =
949 (FGViewer *)globals->get_viewmgr()->get_view( 0 ); */
950 // this will work without calls to the viewer...
951 fgSetDouble( "/sim/current-view/heading-offset-deg",
952 default_view_offset * SGD_RADIANS_TO_DEGREES );
953 // $$$ end - added VS Renganathan, 14 Oct 2K
954 return FG_OPTIONS_OK;
958 fgOptVisibilityMiles( const char *arg )
960 double visibility = atof( arg ) * 5280.0 * SG_FEET_TO_METER;
961 fgSetDouble("/environment/visibility-m", visibility);
962 return FG_OPTIONS_OK;
966 fgOptRandomWind( const char *arg )
968 double min_hdg = sg_random() * 360.0;
969 double max_hdg = min_hdg + (20 - sqrt(sg_random() * 400));
970 double speed = 40 - sqrt(sg_random() * 1600.0);
971 double gust = speed + (10 - sqrt(sg_random() * 100));
972 setup_wind(min_hdg, max_hdg, speed, gust);
973 return FG_OPTIONS_OK;
977 fgOptWind( const char *arg )
979 double min_hdg, max_hdg, speed, gust;
980 if (!parse_wind( arg, &min_hdg, &max_hdg, &speed, &gust)) {
981 SG_LOG( SG_GENERAL, SG_ALERT, "bad wind value " << arg );
982 return FG_OPTIONS_ERROR;
984 setup_wind(min_hdg, max_hdg, speed, gust);
985 return FG_OPTIONS_OK;
989 fgOptWp( const char *arg )
992 return FG_OPTIONS_OK;
996 fgOptFlightPlan( const char *arg )
998 parse_flightplan ( arg );
999 return FG_OPTIONS_OK;
1003 fgOptConfig( const char *arg )
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);
1014 return FG_OPTIONS_OK;
1017 static map<string,size_t> fgOptionMap;
1019 enum OptionType { OPTION_BOOL, OPTION_STRING, OPTION_DOUBLE, OPTION_INT, OPTION_CHANNEL, OPTION_FUNC };
1023 enum OptionType type;
1027 int (*func)( const char * );
1028 } fgOptionArray[] = {
1030 {"language", true, OPTION_FUNC, "", false, "", fgOptLanguage },
1031 {"disable-game-mode", false, OPTION_BOOL, "/sim/startup/game-mode", false, "", 0 },
1032 {"enable-game-mode", false, OPTION_BOOL, "/sim/startup/game-mode", true, "", 0 },
1033 {"disable-splash-screen", false, OPTION_BOOL, "/sim/startup/splash-screen", false, "", 0 },
1034 {"enable-splash-screen", false, OPTION_BOOL, "/sim/startup/splash-screen", true, "", 0 },
1035 {"disable-intro-music", false, OPTION_BOOL, "/sim/startup/intro-music", false, "", 0 },
1036 {"enable-intro-music", false, OPTION_BOOL, "/sim/startup/intro-music", true, "", 0 },
1037 {"disable-mouse-pointer", false, OPTION_STRING, "/sim/startup/mouse-pointer", false, "disabled", 0 },
1038 {"enable-mouse-pointer", false, OPTION_STRING, "/sim/startup/mouse-pointer", false, "enabled", 0 },
1039 {"disable-random-objects", false, OPTION_BOOL, "/sim/rendering/random-objects", false, "", 0 },
1040 {"enable-random-objects", false, OPTION_BOOL, "/sim/rendering/random-objects", true, "", 0 },
1041 {"disable-freeze", false, OPTION_BOOL, "/sim/freeze/master", false, "", 0 },
1042 {"enable-freeze", false, OPTION_BOOL, "/sim/freeze/master", true, "", 0 },
1043 {"disable-fuel-freeze", false, OPTION_BOOL, "/sim/freeze/fuel", false, "", 0 },
1044 {"enable-fuel-freeze", false, OPTION_BOOL, "/sim/freeze/fuel", true, "", 0 },
1045 {"disable-clock-freeze", false, OPTION_BOOL, "/sim/freeze/clock", false, "", 0 },
1046 {"enable-clock-freeze", false, OPTION_BOOL, "/sim/freeze/clock", true, "", 0 },
1047 {"disable-anti-alias-hud", false, OPTION_BOOL, "/sim/hud/antialiased", false, "", 0 },
1048 {"enable-anti-alias-hud", false, OPTION_BOOL, "/sim/hud/antialiased", true, "", 0 },
1049 {"control", true, OPTION_STRING, "/sim/control-mode", false, "", 0 },
1050 {"disable-auto-coordination", false, OPTION_BOOL, "/sim/auto-coordination", false, "", 0 },
1051 {"enable-auto-coordination", false, OPTION_BOOL, "/sim/auto-coordination", true, "", 0 },
1052 {"browser-app", true, OPTION_STRING, "/sim/startup/browser-app", false, "", 0 },
1053 {"disable-hud", false, OPTION_BOOL, "/sim/hud/visibility", false, "", 0 },
1054 {"enable-hud", false, OPTION_BOOL, "/sim/hud/visibility", true, "", 0 },
1055 {"disable-panel", false, OPTION_BOOL, "/sim/panel/visibility", false, "", 0 },
1056 {"enable-panel", false, OPTION_BOOL, "/sim/panel/visibility", true, "", 0 },
1057 {"disable-sound", false, OPTION_BOOL, "/sim/sound/audible", false, "", 0 },
1058 {"enable-sound", false, OPTION_BOOL, "/sim/sound/audible", true, "", 0 },
1059 {"airport", true, OPTION_STRING, "/sim/presets/airport-id", false, "", 0 },
1060 {"airport-id", true, OPTION_STRING, "/sim/presets/airport-id", false, "", 0 },
1061 {"runway", true, OPTION_STRING, "/sim/presets/runway", false, "", 0 },
1062 {"vor", true, OPTION_FUNC, "", false, "", fgOptVOR },
1063 {"ndb", true, OPTION_FUNC, "", false, "", fgOptNDB },
1064 {"fix", true, OPTION_FUNC, "", false, "", fgOptFIX },
1065 {"offset-distance", true, OPTION_DOUBLE, "/sim/presets/offset-distance", false, "", 0 },
1066 {"offset-azimuth", true, OPTION_DOUBLE, "/sim/presets/offset-azimuth", false, "", 0 },
1067 {"lon", true, OPTION_FUNC, "", false, "", fgOptLon },
1068 {"lat", true, OPTION_FUNC, "", false, "", fgOptLat },
1069 {"altitude", true, OPTION_FUNC, "", false, "", fgOptAltitude },
1070 {"uBody", true, OPTION_FUNC, "", false, "", fgOptUBody },
1071 {"vBody", true, OPTION_FUNC, "", false, "", fgOptVBody },
1072 {"wBody", true, OPTION_FUNC, "", false, "", fgOptWBody },
1073 {"vNorth", true, OPTION_FUNC, "", false, "", fgOptVNorth },
1074 {"vEast", true, OPTION_FUNC, "", false, "", fgOptVEast },
1075 {"vDown", true, OPTION_FUNC, "", false, "", fgOptVDown },
1076 {"vc", true, OPTION_FUNC, "", false, "", fgOptVc },
1077 {"mach", true, OPTION_FUNC, "", false, "", fgOptMach },
1078 {"heading", true, OPTION_DOUBLE, "/sim/presets/heading-deg", false, "", 0 },
1079 {"roll", true, OPTION_DOUBLE, "/sim/presets/roll-deg", false, "", 0 },
1080 {"pitch", true, OPTION_DOUBLE, "/sim/presets/pitch-deg", false, "", 0 },
1081 {"glideslope", true, OPTION_DOUBLE, "/sim/presets/glideslope-deg", false, "", 0 },
1082 {"roc", true, OPTION_FUNC, "", false, "", fgOptRoc },
1083 {"fg-root", true, OPTION_FUNC, "", false, "", fgOptFgRoot },
1084 {"fg-scenery", true, OPTION_FUNC, "", false, "", fgOptFgScenery },
1085 {"fdm", true, OPTION_STRING, "/sim/flight-model", false, "", 0 },
1086 {"aero", true, OPTION_STRING, "/sim/aero", false, "", 0 },
1087 {"aircraft-dir", true, OPTION_STRING, "/sim/aircraft-dir", false, "", 0 },
1088 {"model-hz", true, OPTION_INT, "/sim/model-hz", false, "", 0 },
1089 {"speed", true, OPTION_INT, "/sim/speed-up", false, "", 0 },
1090 {"trim", false, OPTION_BOOL, "/sim/presets/trim", true, "", 0 },
1091 {"notrim", false, OPTION_BOOL, "/sim/presets/trim", false, "", 0 },
1092 {"on-ground", false, OPTION_BOOL, "/sim/presets/onground", true, "", 0 },
1093 {"in-air", false, OPTION_BOOL, "/sim/presets/onground", false, "", 0 },
1094 {"fog-disable", false, OPTION_STRING, "/sim/rendering/fog", false, "disabled", 0 },
1095 {"fog-fastest", false, OPTION_STRING, "/sim/rendering/fog", false, "fastest", 0 },
1096 {"fog-nicest", false, OPTION_STRING, "/sim/fog", false, "nicest", 0 },
1097 {"disable-distance-attenuation", false, OPTION_BOOL, "/environment/distance-attenuation", false, "", 0 },
1098 {"enable-distance-attenuation", false, OPTION_BOOL, "/environment/distance-attenuation", true, "", 0 },
1099 {"disable-clouds", false, OPTION_BOOL, "/environment/clouds/status", false, "", 0 },
1100 {"enable-clouds", false, OPTION_BOOL, "/environment/clouds/status", true, "", 0 },
1101 #ifdef FG_USE_CLOUDS_3D
1102 {"disable-clouds3d", false, OPTION_BOOL, "/sim/rendering/clouds3d", false, "", 0 },
1103 {"enable-clouds3d", false, OPTION_BOOL, "/sim/rendering/clouds3d", true, "", 0 },
1105 {"fov", true, OPTION_FUNC, "", false, "", fgOptFov },
1106 {"disable-fullscreen", false, OPTION_BOOL, "/sim/startup/fullscreen", false, "", 0 },
1107 {"enable-fullscreen", false, OPTION_BOOL, "/sim/startup/fullscreen", true, "", 0 },
1108 {"shading-flat", false, OPTION_BOOL, "/sim/rendering/shading", false, "", 0 },
1109 {"shading-smooth", false, OPTION_BOOL, "/sim/rendering/shading", true, "", 0 },
1110 {"disable-skyblend", false, OPTION_BOOL, "/sim/rendering/skyblend", false, "", 0 },
1111 {"enable-skyblend", false, OPTION_BOOL, "/sim/rendering/skyblend", true, "", 0 },
1112 {"disable-textures", false, OPTION_BOOL, "/sim/rendering/textures", false, "", 0 },
1113 {"enable-textures", false, OPTION_BOOL, "/sim/rendering/textures", true, "", 0 },
1114 {"disable-wireframe", false, OPTION_BOOL, "/sim/rendering/wireframe", false, "", 0 },
1115 {"enable-wireframe", false, OPTION_BOOL, "/sim/rendering/wireframe", true, "", 0 },
1116 {"geometry", true, OPTION_FUNC, "", false, "", fgOptGeometry },
1117 {"bpp", true, OPTION_FUNC, "", false, "", fgOptBpp },
1118 {"units-feet", false, OPTION_STRING, "/sim/startup/units", false, "feet", 0 },
1119 {"units-meters", false, OPTION_STRING, "/sim/startup/units", false, "meters", 0 },
1120 {"time-offset", true, OPTION_FUNC, "", false, "", fgOptTimeOffset },
1121 {"time-match-real", false, OPTION_STRING, "/sim/startup/time-offset-type", false, "system-offset", 0 },
1122 {"time-match-local", false, OPTION_STRING, "/sim/startup/time-offset-type", false, "latitude-offset", 0 },
1123 {"start-date-sys", true, OPTION_FUNC, "", false, "", fgOptStartDateSys },
1124 {"start-date-lat", true, OPTION_FUNC, "", false, "", fgOptStartDateLat },
1125 {"start-date-gmt", true, OPTION_FUNC, "", false, "", fgOptStartDateGmt },
1126 {"hud-tris", false, OPTION_STRING, "/sim/hud/frame-stat-type", false, "tris", 0 },
1127 {"hud-culled", false, OPTION_STRING, "/sim/hud/frame-stat-type", false, "culled", 0 },
1128 {"atc610x", false, OPTION_CHANNEL, "", false, "dummy", 0 },
1129 {"atlas", true, OPTION_CHANNEL, "", false, "", 0 },
1130 {"httpd", true, OPTION_CHANNEL, "", false, "", 0 },
1131 #ifdef FG_JPEG_SERVER
1132 {"jpg-httpd", true, OPTION_CHANNEL, "", false, "", 0 },
1134 {"native", true, OPTION_CHANNEL, "", false, "", 0 },
1135 {"native-ctrls", true, OPTION_CHANNEL, "", false, "", 0 },
1136 {"native-fdm", true, OPTION_CHANNEL, "", false, "", 0 },
1137 {"native-gui", true, OPTION_CHANNEL, "", false, "", 0 },
1138 {"opengc", true, OPTION_CHANNEL, "", false, "", 0 },
1139 {"garmin", true, OPTION_CHANNEL, "", false, "", 0 },
1140 {"nmea", true, OPTION_CHANNEL, "", false, "", 0 },
1141 {"props", true, OPTION_CHANNEL, "", false, "", 0 },
1142 {"telnet", true, OPTION_CHANNEL, "", false, "", 0 },
1143 {"pve", true, OPTION_CHANNEL, "", false, "", 0 },
1144 {"ray", true, OPTION_CHANNEL, "", false, "", 0 },
1145 {"rul", true, OPTION_CHANNEL, "", false, "", 0 },
1146 {"joyclient", true, OPTION_CHANNEL, "", false, "", 0 },
1147 #ifdef FG_NETWORK_OLK
1148 {"disable-network-olk", false, OPTION_BOOL, "/sim/networking/olk", false, "", 0 },
1149 {"enable-network-olk", false, OPTION_BOOL, "/sim/networking/olk", true, "", 0 },
1150 {"net-hud", false, OPTION_FUNC, "", false, "", fgOptNetHud },
1151 {"net-id", true, OPTION_STRING, "sim/networking/call-sign", false, "", 0 },
1153 {"trace-read", true, OPTION_FUNC, "", false, "", fgOptTraceRead },
1154 {"trace-write", true, OPTION_FUNC, "", false, "", fgOptTraceWrite },
1155 {"view-offset", true, OPTION_FUNC, "", false, "", fgOptViewOffset },
1156 {"visibility", true, OPTION_DOUBLE, "/environment/visibility-m", false, "", 0 },
1157 {"visibility-miles", true, OPTION_FUNC, "", false, "", fgOptVisibilityMiles },
1158 {"random-wind", false, OPTION_FUNC, "", false, "", fgOptRandomWind },
1159 {"wind", true, OPTION_FUNC, "", false, "", fgOptWind },
1160 {"turbulence", true, OPTION_DOUBLE, "/environment/turbulence-norm", false, "", 0 },
1161 {"wp", true, OPTION_FUNC, "", false, "", fgOptWp },
1162 {"flight-plan", true, OPTION_FUNC, "", false, "", fgOptFlightPlan },
1163 {"config", true, OPTION_FUNC, "", false, "", fgOptConfig },
1164 {"aircraft", true, OPTION_STRING, "/sim/aircraft", false, "", 0 },
1169 // Parse a single option
1171 parse_option (const string& arg)
1173 #ifdef NEW_OPTION_PARSING
1174 if ( fgOptionMap.size() == 0 ) {
1176 OptionDesc *pt = &fgOptionArray[ 0 ];
1177 while ( pt->option != 0 ) {
1178 fgOptionMap[ pt->option ] = i;
1185 if ( (arg == "--help") || (arg == "-h") ) {
1186 // help/usage request
1187 return(FG_OPTIONS_HELP);
1188 } else if ( (arg == "--verbose") || (arg == "-v") ) {
1189 // verbose help/usage request
1190 return(FG_OPTIONS_VERBOSE_HELP);
1191 } else if ( arg.find( "--show-aircraft") == 0) {
1192 return(FG_OPTIONS_SHOW_AIRCRAFT);
1193 } else if ( arg.find( "--prop:" ) == 0 ) {
1194 string assign = arg.substr(7);
1195 string::size_type pos = assign.find('=');
1196 if ( pos == arg.npos || pos == 0 ) {
1197 SG_LOG( SG_GENERAL, SG_ALERT, "Bad property assignment: " << arg );
1198 return FG_OPTIONS_ERROR;
1200 string name = assign.substr(0, pos);
1201 string value = assign.substr(pos + 1);
1202 fgSetString(name.c_str(), value.c_str());
1203 // SG_LOG(SG_GENERAL, SG_INFO, "Setting default value of property "
1204 // << name << " to \"" << value << '"');
1205 } else if ( arg.find( "--" ) == 0 ) {
1206 size_t pos = arg.find( '=' );
1208 if ( pos == string::npos ) {
1209 arg_name = arg.substr( 2 );
1211 arg_name = arg.substr( 2, pos - 2 );
1213 map<string,size_t>::iterator it = fgOptionMap.find( arg_name );
1214 if ( it != fgOptionMap.end() ) {
1215 OptionDesc *pt = &fgOptionArray[ it->second ];
1216 switch ( pt->type ) {
1218 fgSetBool( pt->property, pt->b_param );
1221 if ( pt->has_param && pos != string::npos ) {
1222 fgSetString( pt->property, arg.substr( pos + 1 ).c_str() );
1223 } else if ( !pt->has_param && pos == string::npos ) {
1224 fgSetString( pt->property, pt->s_param );
1225 } else if ( pt->has_param ) {
1226 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1227 return FG_OPTIONS_ERROR;
1229 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' does not have a parameter" );
1230 return FG_OPTIONS_ERROR;
1234 if ( pos != string::npos ) {
1235 fgSetDouble( pt->property, atof( arg.substr( pos + 1 ) ) );
1237 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1238 return FG_OPTIONS_ERROR;
1242 if ( pos != string::npos ) {
1243 fgSetInt( pt->property, atoi( arg.substr( pos + 1 ) ) );
1245 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1246 return FG_OPTIONS_ERROR;
1249 case OPTION_CHANNEL:
1250 if ( pt->has_param && pos != string::npos ) {
1251 add_channel( pt->option, arg.substr( pos + 1 ) );
1252 } else if ( !pt->has_param && pos == string::npos ) {
1253 add_channel( pt->option, pt->s_param );
1254 } else if ( pt->has_param ) {
1255 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1256 return FG_OPTIONS_ERROR;
1258 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' does not have a parameter" );
1259 return FG_OPTIONS_ERROR;
1263 if ( pt->has_param && pos != string::npos ) {
1264 pt->func( arg.substr( pos + 1 ).c_str() );
1265 } else if ( !pt->has_param && pos == string::npos ) {
1267 } else if ( pt->has_param ) {
1268 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1269 return FG_OPTIONS_ERROR;
1271 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' does not have a parameter" );
1272 return FG_OPTIONS_ERROR;
1277 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" );
1278 return FG_OPTIONS_ERROR;
1281 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" );
1282 return FG_OPTIONS_ERROR;
1288 if ( (arg == "--help") || (arg == "-h") ) {
1289 // help/usage request
1290 return(FG_OPTIONS_HELP);
1291 } else if ( (arg == "--verbose") || (arg == "-v") ) {
1292 // verbose help/usage request
1293 return(FG_OPTIONS_VERBOSE_HELP);
1294 } else if ( arg.find( "--language=") == 0 ) {
1295 globals->set_locale( fgInitLocale( arg.substr( 11 ).c_str() ) );
1296 } else if ( arg == "--disable-game-mode") {
1297 fgSetBool("/sim/startup/game-mode", false);
1298 } else if ( arg == "--enable-game-mode" ) {
1299 fgSetBool("/sim/startup/game-mode", true);
1300 } else if ( arg == "--disable-splash-screen" ) {
1301 fgSetBool("/sim/startup/splash-screen", false);
1302 } else if ( arg == "--enable-splash-screen" ) {
1303 fgSetBool("/sim/startup/splash-screen", true);
1304 } else if ( arg == "--disable-intro-music" ) {
1305 fgSetBool("/sim/startup/intro-music", false);
1306 } else if ( arg == "--enable-intro-music" ) {
1307 fgSetBool("/sim/startup/intro-music", true);
1308 } else if ( arg == "--disable-mouse-pointer" ) {
1309 fgSetString("/sim/startup/mouse-pointer", "disabled");
1310 } else if ( arg == "--enable-mouse-pointer" ) {
1311 fgSetString("/sim/startup/mouse-pointer", "enabled");
1312 } else if ( arg == "--disable-random-objects" ) {
1313 fgSetBool("/sim/rendering/random-objects", false);
1314 } else if ( arg == "--enable-random-objects" ) {
1315 fgSetBool("/sim/rendering/random-objects", true);
1316 } else if ( arg == "--disable-freeze" ) {
1317 fgSetBool("/sim/freeze/master", false);
1318 } else if ( arg == "--enable-freeze" ) {
1319 fgSetBool("/sim/freeze/master", true);
1320 } else if ( arg == "--disable-fuel-freeze" ) {
1321 fgSetBool("/sim/freeze/fuel", false);
1322 } else if ( arg == "--enable-fuel-freeze" ) {
1323 fgSetBool("/sim/freeze/fuel", true);
1324 } else if ( arg == "--disable-clock-freeze" ) {
1325 fgSetBool("/sim/freeze/clock", false);
1326 } else if ( arg == "--enable-clock-freeze" ) {
1327 fgSetBool("/sim/freeze/clock", true);
1328 } else if ( arg == "--disable-anti-alias-hud" ) {
1329 fgSetBool("/sim/hud/antialiased", false);
1330 } else if ( arg == "--enable-anti-alias-hud" ) {
1331 fgSetBool("/sim/hud/antialiased", true);
1332 } else if ( arg.find( "--control=") == 0 ) {
1333 fgSetString("/sim/control-mode", arg.substr(10).c_str());
1334 } else if ( arg == "--disable-auto-coordination" ) {
1335 fgSetBool("/sim/auto-coordination", false);
1336 } else if ( arg == "--enable-auto-coordination" ) {
1337 fgSetBool("/sim/auto-coordination", true);
1338 } else if ( arg.find( "--browser-app=") == 0 ) {
1339 fgSetString("/sim/startup/browser-app", arg.substr(14).c_str());
1340 } else if ( arg == "--disable-hud" ) {
1341 fgSetBool("/sim/hud/visibility", false);
1342 } else if ( arg == "--enable-hud" ) {
1343 fgSetBool("/sim/hud/visibility", true);
1344 } else if ( arg == "--disable-panel" ) {
1345 fgSetBool("/sim/panel/visibility", false);
1346 } else if ( arg == "--enable-panel" ) {
1347 fgSetBool("/sim/panel/visibility", true);
1348 } else if ( arg == "--disable-sound" ) {
1349 fgSetBool("/sim/sound/audible", false);
1350 } else if ( arg == "--enable-sound" ) {
1351 fgSetBool("/sim/sound/audible", true);
1352 } else if ( arg.find( "--airport=") == 0 ) {
1353 fgSetString("/sim/presets/airport-id", arg.substr(10).c_str());
1354 } else if ( arg.find( "--airport-id=") == 0 ) {
1355 fgSetString("/sim/presets/airport-id", arg.substr(13).c_str());
1356 } else if ( arg.find( "--runway=") == 0 ) {
1357 fgSetString("/sim/presets/runway", arg.substr(9).c_str());
1358 } else if ( arg.find( "--offset-distance=") == 0 ) {
1359 fgSetDouble("/sim/presets/offset-distance", atof(arg.substr(18)));
1360 } else if ( arg.find( "--offset-azimuth=") == 0 ) {
1361 fgSetDouble("/sim/presets/offset-azimuth", atof(arg.substr(17)));
1362 } else if ( arg.find( "--lon=" ) == 0 ) {
1363 fgSetDouble("/sim/presets/longitude-deg", parse_degree(arg.substr(6)));
1364 fgSetDouble("/position/longitude-deg", parse_degree(arg.substr(6)));
1365 fgSetString("/sim/presets/airport-id", "");
1366 } else if ( arg.find( "--lat=" ) == 0 ) {
1367 fgSetDouble("/sim/presets/latitude-deg", parse_degree(arg.substr(6)));
1368 fgSetDouble("/position/latitude-deg", parse_degree(arg.substr(6)));
1369 fgSetString("/sim/presets/airport-id", "");
1370 } else if ( arg.find( "--altitude=" ) == 0 ) {
1371 fgSetBool("/sim/presets/onground", false);
1372 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
1373 fgSetDouble("/sim/presets/altitude-ft", atof(arg.substr(11)));
1375 fgSetDouble("/sim/presets/altitude-ft",
1376 atof(arg.substr(11)) * SG_METER_TO_FEET);
1377 } else if ( arg.find( "--uBody=" ) == 0 ) {
1378 fgSetString("/sim/presets/speed-set", "UVW");
1379 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
1380 fgSetDouble("/sim/presets/uBody-fps", atof(arg.substr(8)));
1382 fgSetDouble("/sim/presets/uBody-fps",
1383 atof(arg.substr(8)) * SG_METER_TO_FEET);
1384 } else if ( arg.find( "--vBody=" ) == 0 ) {
1385 fgSetString("/sim/presets/speed-set", "UVW");
1386 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
1387 fgSetDouble("/sim/presets/vBody-fps", atof(arg.substr(8)));
1389 fgSetDouble("/sim/presets/vBody-fps",
1390 atof(arg.substr(8)) * SG_METER_TO_FEET);
1391 } else if ( arg.find( "--wBody=" ) == 0 ) {
1392 fgSetString("/sim/presets/speed-set", "UVW");
1393 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
1394 fgSetDouble("/sim/presets/wBody-fps", atof(arg.substr(8)));
1396 fgSetDouble("/sim/presets/wBody-fps",
1397 atof(arg.substr(8)) * SG_METER_TO_FEET);
1398 } else if ( arg.find( "--vNorth=" ) == 0 ) {
1399 fgSetString("/sim/presets/speed-set", "NED");
1400 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
1401 fgSetDouble("/sim/presets/speed-north-fps", atof(arg.substr(9)));
1403 fgSetDouble("/sim/presets/speed-north-fps",
1404 atof(arg.substr(9)) * SG_METER_TO_FEET);
1405 } else if ( arg.find( "--vEast=" ) == 0 ) {
1406 fgSetString("/sim/presets/speed-set", "NED");
1407 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
1408 fgSetDouble("/sim/presets/speed-east-fps", atof(arg.substr(8)));
1410 fgSetDouble("/sim/presets/speed-east-fps",
1411 atof(arg.substr(8)) * SG_METER_TO_FEET);
1412 } else if ( arg.find( "--vDown=" ) == 0 ) {
1413 fgSetString("/sim/presets/speed-set", "NED");
1414 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
1415 fgSetDouble("/sim/presets/speed-down-fps", atof(arg.substr(8)));
1417 fgSetDouble("/sim/presets/speed-down-fps",
1418 atof(arg.substr(8)) * SG_METER_TO_FEET);
1419 } else if ( arg.find( "--vc=" ) == 0) {
1420 // fgSetString("/sim/presets/speed-set", "knots");
1421 // fgSetDouble("/velocities/airspeed-kt", atof(arg.substr(5)));
1422 fgSetString("/sim/presets/speed-set", "knots");
1423 fgSetDouble("/sim/presets/airspeed-kt", atof(arg.substr(5)));
1424 } else if ( arg.find( "--mach=" ) == 0) {
1425 fgSetString("/sim/presets/speed-set", "mach");
1426 fgSetDouble("/sim/presets/mach", atof(arg.substr(7)));
1427 } else if ( arg.find( "--heading=" ) == 0 ) {
1428 fgSetDouble("/sim/presets/heading-deg", atof(arg.substr(10)));
1429 } else if ( arg.find( "--roll=" ) == 0 ) {
1430 fgSetDouble("/sim/presets/roll-deg", atof(arg.substr(7)));
1431 } else if ( arg.find( "--pitch=" ) == 0 ) {
1432 fgSetDouble("/sim/presets/pitch-deg", atof(arg.substr(8)));
1433 } else if ( arg.find( "--glideslope=" ) == 0 ) {
1434 fgSetDouble("/sim/presets/glideslope-deg",
1435 atof(arg.substr(13)));
1436 } else if ( arg.find( "--roc=" ) == 0 ) {
1437 fgSetDouble("/velocities/vertical-speed-fps", atof(arg.substr(6))/60);
1438 } else if ( arg.find( "--fg-root=" ) == 0 ) {
1439 globals->set_fg_root(arg.substr( 10 ));
1440 } else if ( arg.find( "--fg-scenery=" ) == 0 ) {
1441 globals->set_fg_scenery(arg.substr( 13 ));
1442 } else if ( arg.find( "--fdm=" ) == 0 ) {
1443 fgSetString("/sim/flight-model", arg.substr(6).c_str());
1444 } else if ( arg.find( "--aero=" ) == 0 ) {
1445 fgSetString("/sim/aero", arg.substr(7).c_str());
1446 } else if ( arg.find( "--aircraft-dir=" ) == 0 ) {
1447 fgSetString("/sim/aircraft-dir", arg.substr(15).c_str());
1448 } else if ( arg.find( "--show-aircraft") == 0) {
1449 return(FG_OPTIONS_SHOW_AIRCRAFT);
1450 } else if ( arg.find( "--model-hz=" ) == 0 ) {
1451 fgSetInt("/sim/model-hz", atoi(arg.substr(11)));
1452 } else if ( arg.find( "--speed=" ) == 0 ) {
1453 fgSetInt("/sim/speed-up", atoi(arg.substr(8)));
1454 } else if ( arg.find( "--trim") == 0) {
1455 fgSetBool("/sim/presets/trim", true);
1456 } else if ( arg.find( "--notrim") == 0) {
1457 fgSetBool("/sim/presets/trim", false);
1458 } else if ( arg.find( "--on-ground") == 0) {
1459 fgSetBool("/sim/presets/onground", true);
1460 } else if ( arg.find( "--in-air") == 0) {
1461 fgSetBool("/sim/presets/onground", false);
1462 } else if ( arg == "--fog-disable" ) {
1463 fgSetString("/sim/rendering/fog", "disabled");
1464 } else if ( arg == "--fog-fastest" ) {
1465 fgSetString("/sim/rendering/fog", "fastest");
1466 } else if ( arg == "--fog-nicest" ) {
1467 fgSetString("/sim/fog", "nicest");
1468 } else if ( arg == "--disable-distance-attenuation" ) {
1469 fgSetBool("/environment/distance-attenuation", false);
1470 } else if ( arg == "--enable-distance-attenuation" ) {
1471 fgSetBool("/environment/distance-attenuation", true);
1472 } else if ( arg == "--disable-clouds" ) {
1473 fgSetBool("/environment/clouds/status", false);
1474 } else if ( arg == "--enable-clouds" ) {
1475 fgSetBool("/environment/clouds/status", true);
1476 #ifdef FG_USE_CLOUDS_3D
1477 } else if ( arg == "--disable-clouds3d" ) {
1478 fgSetBool("/sim/rendering/clouds3d", false);
1479 } else if ( arg == "--enable-clouds3d" ) {
1480 fgSetBool("/sim/rendering/clouds3d", true);
1482 } else if ( arg.find( "--fov=" ) == 0 ) {
1483 parse_fov( arg.substr(6) );
1484 } else if ( arg == "--disable-fullscreen" ) {
1485 fgSetBool("/sim/startup/fullscreen", false);
1486 } else if ( arg== "--enable-fullscreen") {
1487 fgSetBool("/sim/startup/fullscreen", true);
1488 } else if ( arg == "--shading-flat") {
1489 fgSetBool("/sim/rendering/shading", false);
1490 } else if ( arg == "--shading-smooth") {
1491 fgSetBool("/sim/rendering/shading", true);
1492 } else if ( arg == "--disable-skyblend") {
1493 fgSetBool("/sim/rendering/skyblend", false);
1494 } else if ( arg== "--enable-skyblend" ) {
1495 fgSetBool("/sim/rendering/skyblend", true);
1496 } else if ( arg == "--disable-textures" ) {
1497 fgSetBool("/sim/rendering/textures", false);
1498 } else if ( arg == "--enable-textures" ) {
1499 fgSetBool("/sim/rendering/textures", true);
1500 } else if ( arg == "--disable-wireframe" ) {
1501 fgSetBool("/sim/rendering/wireframe", false);
1502 } else if ( arg == "--enable-wireframe" ) {
1503 fgSetBool("/sim/rendering/wireframe", true);
1504 } else if ( arg.find( "--geometry=" ) == 0 ) {
1505 bool geometry_ok = true;
1506 int xsize = 0, ysize = 0;
1507 string geometry = arg.substr( 11 );
1508 string::size_type i = geometry.find('x');
1510 if (i != string::npos) {
1511 xsize = atoi(geometry.substr(0, i));
1512 ysize = atoi(geometry.substr(i+1));
1514 geometry_ok = false;
1517 if ( xsize <= 0 || ysize <= 0 ) {
1520 geometry_ok = false;
1523 if ( !geometry_ok ) {
1524 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown geometry: " << geometry );
1525 SG_LOG( SG_GENERAL, SG_ALERT,
1526 "Setting geometry to " << xsize << 'x' << ysize << '\n');
1528 SG_LOG( SG_GENERAL, SG_INFO,
1529 "Setting geometry to " << xsize << 'x' << ysize << '\n');
1530 fgSetInt("/sim/startup/xsize", xsize);
1531 fgSetInt("/sim/startup/ysize", ysize);
1533 } else if ( arg.find( "--bpp=" ) == 0 ) {
1534 string bits_per_pix = arg.substr( 6 );
1535 if ( bits_per_pix == "16" ) {
1536 fgSetInt("/sim/rendering/bits-per-pixel", 16);
1537 } else if ( bits_per_pix == "24" ) {
1538 fgSetInt("/sim/rendering/bits-per-pixel", 24);
1539 } else if ( bits_per_pix == "32" ) {
1540 fgSetInt("/sim/rendering/bits-per-pixel", 32);
1542 SG_LOG(SG_GENERAL, SG_ALERT, "Unsupported bpp " << bits_per_pix);
1544 } else if ( arg == "--units-feet" ) {
1545 fgSetString("/sim/startup/units", "feet");
1546 } else if ( arg == "--units-meters" ) {
1547 fgSetString("/sim/startup/units", "meters");
1548 } else if ( arg.find( "--time-offset" ) == 0 ) {
1549 fgSetInt("/sim/startup/time-offset",
1550 parse_time_offset( (arg.substr(14)) ));
1551 fgSetString("/sim/startup/time-offset-type", "system-offset");
1552 } else if ( arg.find( "--time-match-real") == 0 ) {
1553 fgSetString("/sim/startup/time-offset-type", "system-offset");
1554 } else if ( arg.find( "--time-match-local") == 0 ) {
1555 fgSetString("/sim/startup/time-offset-type", "latitude-offset");
1556 } else if ( arg.find( "--start-date-sys=") == 0 ) {
1557 fgSetInt("/sim/startup/time-offset", parse_date((arg.substr(17))));
1558 fgSetString("/sim/startup/time-offset-type", "system");
1559 } else if ( arg.find( "--start-date-lat=") == 0 ) {
1560 fgSetInt("/sim/startup/time-offset", parse_date((arg.substr(17))));
1561 fgSetString("/sim/startup/time-offset-type", "latitude");
1562 } else if ( arg.find( "--start-date-gmt=") == 0 ) {
1563 fgSetInt("/sim/startup/time-offset", parse_date((arg.substr(17))));
1564 fgSetString("/sim/startup/time-offset-type", "gmt");
1565 } else if ( arg == "--hud-tris" ) {
1566 fgSetString("/sim/hud/frame-stat-type", "tris");
1567 } else if ( arg == "--hud-culled" ) {
1568 fgSetString("/sim/hud/frame-stat-type", "culled");
1569 } else if ( arg.find( "--atc610x" ) == 0 ) {
1570 add_channel( "atc610x", "dummy" );
1571 } else if ( arg.find( "--atlas=" ) == 0 ) {
1572 add_channel( "atlas", arg.substr(8) );
1574 } else if ( arg.find( "--multiplay=" ) == 0 ) {
1575 add_channel( "multiplay", arg.substr(12) );
1577 } else if ( arg.find( "--httpd=" ) == 0 ) {
1578 add_channel( "httpd", arg.substr(8) );
1579 #ifdef FG_JPEG_SERVER
1580 } else if ( arg.find( "--jpg-httpd=" ) == 0 ) {
1581 add_channel( "jpg-httpd", arg.substr(12) );
1583 } else if ( arg.find( "--native=" ) == 0 ) {
1584 add_channel( "native", arg.substr(9) );
1585 } else if ( arg.find( "--native-ctrls=" ) == 0 ) {
1586 add_channel( "native_ctrls", arg.substr(15) );
1587 } else if ( arg.find( "--native-fdm=" ) == 0 ) {
1588 add_channel( "native_fdm", arg.substr(13) );
1589 } else if ( arg.find( "--native-gui=" ) == 0 ) {
1590 add_channel( "native_gui", arg.substr(13) );
1591 } else if ( arg.find( "--opengc=" ) == 0 ) {
1593 // cout << "Adding channel for OpenGC Display" << endl; cin >> stop;
1594 add_channel( "opengc", arg.substr(9) );
1595 } else if ( arg.find( "--garmin=" ) == 0 ) {
1596 add_channel( "garmin", arg.substr(9) );
1597 } else if ( arg.find( "--nmea=" ) == 0 ) {
1598 add_channel( "nmea", arg.substr(7) );
1599 } else if ( arg.find( "--props=" ) == 0 ) {
1600 add_channel( "props", arg.substr(8) );
1601 } else if ( arg.find( "--telnet=" ) == 0 ) {
1602 add_channel( "telnet", arg.substr(9) );
1603 } else if ( arg.find( "--pve=" ) == 0 ) {
1604 add_channel( "pve", arg.substr(6) );
1605 } else if ( arg.find( "--ray=" ) == 0 ) {
1606 add_channel( "ray", arg.substr(6) );
1607 } else if ( arg.find( "--rul=" ) == 0 ) {
1608 add_channel( "rul", arg.substr(6) );
1609 } else if ( arg.find( "--joyclient=" ) == 0 ) {
1610 add_channel( "joyclient", arg.substr(12) );
1611 #ifdef FG_NETWORK_OLK
1612 } else if ( arg == "--disable-network-olk" ) {
1613 fgSetBool("/sim/networking/olk", false);
1614 } else if ( arg== "--enable-network-olk") {
1615 fgSetBool("/sim/networking/olk", true);
1616 } else if ( arg == "--net-hud" ) {
1617 fgSetBool("/sim/hud/net-display", true);
1618 net_hud_display = 1; // FIXME
1619 } else if ( arg.find( "--net-id=") == 0 ) {
1620 fgSetString("sim/networking/call-sign", arg.substr(9).c_str());
1623 #ifdef FG_MPLAYER_AS
1624 } else if ( arg.find( "--callsign=") == 0 ) {
1625 fgSetString("sim/multiplay/callsign", arg.substr(11).c_str());
1628 } else if ( arg.find( "--prop:" ) == 0 ) {
1629 string assign = arg.substr(7);
1630 string::size_type pos = assign.find('=');
1631 if ( pos == arg.npos || pos == 0 ) {
1632 SG_LOG( SG_GENERAL, SG_ALERT, "Bad property assignment: " << arg );
1633 return FG_OPTIONS_ERROR;
1635 string name = assign.substr(0, pos);
1636 string value = assign.substr(pos + 1);
1637 fgSetString(name.c_str(), value.c_str());
1638 // SG_LOG(SG_GENERAL, SG_INFO, "Setting default value of property "
1639 // << name << " to \"" << value << '"');
1640 } else if ( arg.find("--trace-read=") == 0) {
1641 string name = arg.substr(13);
1642 SG_LOG(SG_GENERAL, SG_INFO, "Tracing reads for property " << name);
1643 fgGetNode(name.c_str(), true)
1644 ->setAttribute(SGPropertyNode::TRACE_READ, true);
1645 } else if ( arg.find("--trace-write=") == 0) {
1646 string name = arg.substr(14);
1647 SG_LOG(SG_GENERAL, SG_INFO, "Tracing writes for property " << name);
1648 fgGetNode(name.c_str(), true)
1649 ->setAttribute(SGPropertyNode::TRACE_WRITE, true);
1650 } else if ( arg.find( "--view-offset=" ) == 0 ) {
1651 // $$$ begin - added VS Renganathan, 14 Oct 2K
1652 // for multi-window outside window imagery
1653 string woffset = arg.substr( 14 );
1654 double default_view_offset = 0.0;
1655 if ( woffset == "LEFT" ) {
1656 default_view_offset = SGD_PI * 0.25;
1657 } else if ( woffset == "RIGHT" ) {
1658 default_view_offset = SGD_PI * 1.75;
1659 } else if ( woffset == "CENTER" ) {
1660 default_view_offset = 0.00;
1662 default_view_offset = atof( woffset.c_str() ) * SGD_DEGREES_TO_RADIANS;
1664 /* apparently not used (CLO, 11 Jun 2002)
1665 FGViewer *pilot_view =
1666 (FGViewer *)globals->get_viewmgr()->get_view( 0 ); */
1667 // this will work without calls to the viewer...
1668 fgSetDouble( "/sim/current-view/heading-offset-deg",
1669 default_view_offset * SGD_RADIANS_TO_DEGREES );
1670 // $$$ end - added VS Renganathan, 14 Oct 2K
1671 } else if ( arg.find( "--visibility=" ) == 0 ) {
1672 fgSetDouble("/environment/visibility-m", atof(arg.substr(13)));
1673 } else if ( arg.find( "--visibility-miles=" ) == 0 ) {
1674 double visibility = atof(arg.substr(19)) * 5280.0 * SG_FEET_TO_METER;
1675 fgSetDouble("/environment/visibility-m", visibility);
1676 } else if ( arg.find( "--random-wind" ) == 0 ) {
1677 double min_hdg = sg_random() * 360.0;
1678 double max_hdg = min_hdg + (20 - sqrt(sg_random() * 400));
1679 double speed = 40 - sqrt(sg_random() * 1600.0);
1680 double gust = speed + (10 - sqrt(sg_random() * 100));
1681 setup_wind(min_hdg, max_hdg, speed, gust);
1682 } else if ( arg.find( "--wind=" ) == 0 ) {
1683 double min_hdg, max_hdg, speed, gust;
1684 if (!parse_wind(arg.substr(7), &min_hdg, &max_hdg, &speed, &gust)) {
1685 SG_LOG( SG_GENERAL, SG_ALERT, "bad wind value " << arg.substr(7) );
1686 return FG_OPTIONS_ERROR;
1688 setup_wind(min_hdg, max_hdg, speed, gust);
1689 } else if ( arg.find( "--wp=" ) == 0 ) {
1690 parse_wp( arg.substr( 5 ) );
1691 } else if ( arg.find( "--flight-plan=") == 0) {
1692 parse_flightplan ( arg.substr (14) );
1693 } else if ( arg.find( "--config=" ) == 0 ) {
1694 string file = arg.substr(9);
1696 readProperties(file, globals->get_props());
1697 } catch (const sg_exception &e) {
1698 string message = "Error loading config file: ";
1699 message += e.getFormattedMessage();
1700 SG_LOG(SG_INPUT, SG_ALERT, message);
1703 } else if ( arg.find( "--aircraft=" ) == 0 ) {
1704 fgSetString("/sim/aircraft", arg.substr(11).c_str());
1706 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" );
1707 return FG_OPTIONS_ERROR;
1711 return FG_OPTIONS_OK;
1715 // Parse the command line options
1717 fgParseArgs (int argc, char **argv)
1719 bool in_options = true;
1720 bool verbose = false;
1723 SG_LOG(SG_GENERAL, SG_INFO, "Processing command line arguments");
1725 for (int i = 1; i < argc; i++) {
1726 string arg = argv[i];
1728 if (in_options && (arg.find('-') == 0)) {
1732 int result = parse_option(arg);
1733 if ((result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR))
1736 else if (result == FG_OPTIONS_VERBOSE_HELP)
1739 else if (result == FG_OPTIONS_SHOW_AIRCRAFT) {
1746 SG_LOG(SG_GENERAL, SG_INFO,
1747 "Reading command-line property file " << arg);
1748 readProperties(arg, globals->get_props());
1757 SG_LOG(SG_GENERAL, SG_INFO, "Finished command line arguments");
1761 // Parse config file options
1763 fgParseOptions (const string& path) {
1764 sg_gzifstream in( path );
1765 if ( !in.is_open() ) {
1769 SG_LOG( SG_GENERAL, SG_INFO, "Processing config file: " << path );
1773 while ( ! in.eof() ) {
1776 while ( in.get(c) && c != '\0' ) {
1781 #if defined( macintosh )
1782 getline( in, line, '\r' );
1784 getline( in, line, '\n' );
1787 // catch extraneous (DOS) line ending character
1788 if ( line[line.length() - 1] < 32 ) {
1789 line = line.substr( 0, line.length()-1 );
1792 if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
1793 cerr << endl << "Config file parse error: " << path << " '"
1794 << line << "'" << endl;
1803 // Print usage message
1805 fgUsage (bool verbose)
1807 SGPropertyNode *locale = globals->get_locale();
1809 SGPropertyNode options_root;
1814 fgLoadProps("options.xml", &options_root);
1815 } catch (const sg_exception &ex) {
1816 cout << "Unable to read the help file." << endl;
1817 cout << "Make sure the file options.xml is located in the FlightGear base directory," << endl;
1818 cout << "and the location of the base directory is specified by setting $FG_ROOT or" << endl;
1819 cout << "by adding --fg-root=path as a program argument." << endl;
1824 SGPropertyNode *options = options_root.getNode("options");
1826 SG_LOG( SG_GENERAL, SG_ALERT,
1827 "Error reading options.xml: <options> directive not found." );
1831 SGPropertyNode *usage = locale->getNode(options->getStringValue("usage"));
1833 cout << "Usage: " << usage->getStringValue() << endl;
1836 vector<SGPropertyNode_ptr>section = options->getChildren("section");
1837 for (unsigned int j = 0; j < section.size(); j++) {
1840 vector<SGPropertyNode_ptr>option = section[j]->getChildren("option");
1841 for (unsigned int k = 0; k < option.size(); k++) {
1843 SGPropertyNode *name = option[k]->getNode("name");
1844 SGPropertyNode *short_name = option[k]->getNode("short");
1845 SGPropertyNode *key = option[k]->getNode("key");
1846 SGPropertyNode *arg = option[k]->getNode("arg");
1847 bool brief = option[k]->getNode("brief");
1849 if ((brief || verbose) && name) {
1850 string tmp = name->getStringValue();
1854 tmp.append(key->getStringValue());
1858 tmp.append(arg->getStringValue());
1862 tmp.append(short_name->getStringValue());
1866 if (tmp.size() <= 25) {
1867 snprintf(cstr, 96, " --%-27s", tmp.c_str());
1869 snprintf(cstr, 96, "\n --%s\n%32c", tmp.c_str(), ' ');
1872 // There may be more than one <description> tag assosiated
1876 vector<SGPropertyNode_ptr>desc =
1877 option[k]->getChildren("description");
1879 if (desc.size() > 0) {
1880 for ( unsigned int l = 0; l < desc.size(); l++) {
1882 // There may be more than one translation line.
1884 string t = desc[l]->getStringValue();
1885 SGPropertyNode *n = locale->getNode("strings");
1886 vector<SGPropertyNode_ptr>trans_desc =
1887 n->getChildren(t.substr(8).c_str());
1889 for ( unsigned int m = 0; m < trans_desc.size(); m++ ) {
1890 string t_str = trans_desc[m]->getStringValue();
1892 if ((m > 0) || ((l > 0) && m == 0)) {
1893 snprintf(cstr, 96, "%32c", ' ');
1898 // If the string is too large to fit on the screen,
1899 // then split it up in several pieces.
1901 while ( t_str.size() > 47 ) {
1903 unsigned int m = t_str.rfind(' ', 47);
1904 msg += t_str.substr(0, m);
1905 snprintf(cstr, 96, "\n%32c", ' ');
1908 t_str.erase(t_str.begin(), t_str.begin() + m + 1);
1910 msg += t_str + '\n';
1917 SGPropertyNode *name =
1918 locale->getNode(section[j]->getStringValue("name"));
1920 if (!msg.empty() && name) {
1921 cout << endl << name->getStringValue() << ":" << endl;
1929 cout << "For a complete list of options use --help --verbose" << endl;
1933 // Show available aircraft types
1934 void fgShowAircraft(void) {
1935 vector<string> aircraft;
1937 SGPath path( globals->get_fg_root() );
1938 path.append("Aircraft");
1943 dirp = ulOpenDir(path.c_str());
1945 cerr << "Unable to open aircraft directory." << endl;
1949 while ((dire = ulReadDir(dirp)) != NULL) {
1952 if ((ptr = strstr(dire->d_name, "-set.xml")) && ptr[8] == '\0' ) {
1953 SGPath afile = path;
1954 afile.append(dire->d_name);
1958 SGPropertyNode root;
1960 readProperties(afile.str(), &root);
1965 SGPropertyNode *desc = NULL;
1966 SGPropertyNode *node = root.getNode("sim");
1968 desc = node->getNode("description");
1972 if (strlen(dire->d_name) <= 27)
1973 snprintf(cstr, 96, " %-27s %s", dire->d_name,
1974 (desc) ? desc->getStringValue() : "" );
1977 snprintf(cstr, 96, " %-27s\n%32c%s", dire->d_name, ' ',
1978 (desc) ? desc->getStringValue() : "" );
1980 aircraft.push_back(cstr);
1984 sort(aircraft.begin(), aircraft.end());
1985 cout << "Available aircraft:" << endl;
1986 for ( unsigned int i = 0; i < aircraft.size(); i++ ) {
1987 cout << aircraft[i] << endl;