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>
30 #include <simgear/debug/logstream.hxx>
32 #include <math.h> // rint()
34 #include <stdlib.h> // atof(), atoi()
35 #include <string.h> // strcmp()
42 #include <simgear/math/sg_random.h>
43 #include <simgear/misc/sgstream.hxx>
44 #include <simgear/misc/sg_path.hxx>
45 #include <simgear/route/route.hxx>
46 #include <simgear/route/waypoint.hxx>
48 // #include <Include/general.hxx>
49 // #include <Airports/simple.hxx>
50 // #include <Cockpit/cockpit.hxx>
51 // #include <FDM/flight.hxx>
52 // #include <FDM/UIUCModel/uiuc_aircraftdir.h>
54 # include <NetworkOLK/network.h>
59 #include "globals.hxx"
60 #include "fg_init.hxx"
61 #include "fg_props.hxx"
62 #include "options.hxx"
63 #include "viewmgr.hxx"
68 SG_USING_NAMESPACE(std);
71 #define NEW_DEFAULT_MODEL_HZ 120
78 FG_OPTIONS_VERBOSE_HELP = 3,
79 FG_OPTIONS_SHOW_AIRCRAFT = 4
83 atof( const string& str )
87 // -dw- if ::atof is called, then we get an infinite loop
88 return std::atof( str.c_str() );
90 return ::atof( str.c_str() );
95 atoi( const string& str )
98 // -dw- if ::atoi is called, then we get an infinite loop
99 return std::atoi( str.c_str() );
101 return ::atoi( str.c_str() );
107 * Set a few fail-safe default property values.
109 * These should all be set in $FG_ROOT/preferences.xml, but just
110 * in case, we provide some initial sane values here. This method
111 * should be invoked *before* reading any init files.
116 // set a possibly independent location for scenery data
117 char *envp = ::getenv( "FG_SCENERY" );
119 if ( envp != NULL ) {
120 // fg_root could be anywhere, so default to environmental
121 // variable $FG_ROOT if it is set.
122 globals->set_fg_scenery(envp);
124 // Otherwise, default to Scenery being in $FG_ROOT/Scenery
125 globals->set_fg_scenery("");
127 // Position (deliberately out of range)
128 fgSetDouble("/position/longitude-deg", 9999.0);
129 fgSetDouble("/position/latitude-deg", 9999.0);
130 fgSetDouble("/position/altitude-ft", -9999.0);
133 fgSetDouble("/orientation/heading-deg", 270);
134 fgSetDouble("/orientation/roll-deg", 0);
135 fgSetDouble("/orientation/pitch-deg", 0.424);
138 fgSetDouble("/velocities/uBody-fps", 0.0);
139 fgSetDouble("/velocities/vBody-fps", 0.0);
140 fgSetDouble("/velocities/wBody-fps", 0.0);
141 fgSetDouble("/velocities/speed-north-fps", 0.0);
142 fgSetDouble("/velocities/speed-east-fps", 0.0);
143 fgSetDouble("/velocities/speed-down-fps", 0.0);
144 fgSetDouble("/velocities/airspeed-kt", 0.0);
145 fgSetDouble("/velocities/mach", 0.0);
148 fgSetDouble("/sim/presets/longitude-deg", 9999.0);
149 fgSetDouble("/sim/presets/latitude-deg", 9999.0);
150 fgSetDouble("/sim/presets/altitude-ft", -9999.0);
152 fgSetDouble("/sim/presets/heading-deg", 270);
153 fgSetDouble("/sim/presets/roll-deg", 0);
154 fgSetDouble("/sim/presets/pitch-deg", 0.424);
156 fgSetString("/sim/presets/speed-set", "knots");
157 fgSetDouble("/sim/presets/airspeed-kt", 0.0);
158 fgSetDouble("/sim/presets/mach", 0.0);
159 fgSetDouble("/sim/presets/uBody-fps", 0.0);
160 fgSetDouble("/sim/presets/vBody-fps", 0.0);
161 fgSetDouble("/sim/presets/wBody-fps", 0.0);
162 fgSetDouble("/sim/presets/speed-north-fps", 0.0);
163 fgSetDouble("/sim/presets/speed-east-fps", 0.0);
164 fgSetDouble("/sim/presets/speed-down-fps", 0.0);
166 fgSetBool("/sim/presets/onground", true);
167 fgSetBool("/sim/presets/trim", false);
170 fgSetBool("/sim/startup/game-mode", false);
171 fgSetBool("/sim/startup/splash-screen", true);
172 fgSetBool("/sim/startup/intro-music", true);
173 // we want mouse-pointer to have an undefined value if nothing is
174 // specified so we can do the right thing for voodoo-1/2 cards.
175 // fgSetString("/sim/startup/mouse-pointer", "disabled");
176 fgSetString("/sim/control-mode", "joystick");
177 fgSetBool("/sim/auto-coordination", false);
179 fgSetString("/sim/startup/browser-app", "netscape");
181 fgSetString("/sim/startup/browser-app", "webrun.bat");
183 fgSetInt("/sim/log-level", SG_WARN);
186 fgSetBool("/sim/hud/visibility", false);
187 fgSetBool("/sim/panel/visibility", true);
188 fgSetBool("/sim/sound/audible", true);
189 fgSetBool("/sim/hud/antialiased", false);
191 // Flight Model options
192 fgSetString("/sim/flight-model", "jsb");
193 fgSetString("/sim/aero", "c172");
194 fgSetInt("/sim/model-hz", NEW_DEFAULT_MODEL_HZ);
195 fgSetInt("/sim/speed-up", 1);
198 fgSetString("/sim/rendering/fog", "nicest");
199 fgSetBool("/environment/clouds/status", true);
200 fgSetBool("/sim/startup/fullscreen", false);
201 fgSetBool("/sim/rendering/shading", true);
202 fgSetBool("/sim/rendering/skyblend", true);
203 fgSetBool("/sim/rendering/textures", true);
204 fgSetBool("/sim/rendering/wireframe", false);
205 fgSetBool("/sim/rendering/distance-attenuation", false);
206 fgSetInt("/sim/startup/xsize", 800);
207 fgSetInt("/sim/startup/ysize", 600);
208 fgSetInt("/sim/rendering/bits-per-pixel", 16);
209 fgSetString("/sim/view-mode", "pilot");
210 fgSetDouble("/sim/current-view/heading-offset-deg", 0);
211 fgSetDouble("/environment/visibility-m", 20000);
214 fgSetString("/sim/startup/units", "feet");
215 fgSetString("/sim/hud/frame-stat-type", "tris");
218 fgSetInt("/sim/startup/time-offset", 0);
219 fgSetString("/sim/startup/time-offset-type", "system-offset");
220 fgSetLong("/sim/time/cur-time-override", 0);
222 fgSetBool("/sim/networking/network-olk", false);
223 fgSetString("/sim/networking/call-sign", "Johnny");
226 fgSetBool("/sim/freeze/master", false);
227 fgSetBool("/sim/freeze/position", false);
228 fgSetBool("/sim/freeze/clock", false);
229 fgSetBool("/sim/freeze/fuel", false);
232 fgSetString("/sim/multiplay/callsign", "callsign");
233 fgSetString("/sim/multiplay/rxhost", "0");
234 fgSetString("/sim/multiplay/txhost", "0");
235 fgSetInt("/sim/multiplay/rxport", 0);
236 fgSetInt("/sim/multiplay/txport", 0);
243 parse_wind (const string &wind, double * min_hdg, double * max_hdg,
244 double * speed, double * gust)
246 string::size_type pos = wind.find('@');
247 if (pos == string::npos)
249 string dir = wind.substr(0, pos);
250 string spd = wind.substr(pos+1);
252 if (pos == string::npos) {
253 *min_hdg = *max_hdg = atof(dir.c_str());
255 *min_hdg = atof(dir.substr(0,pos).c_str());
256 *max_hdg = atof(dir.substr(pos+1).c_str());
259 if (pos == string::npos) {
260 *speed = *gust = atof(spd.c_str());
262 *speed = atof(spd.substr(0,pos).c_str());
263 *gust = atof(spd.substr(pos+1).c_str());
268 // parse a time string ([+/-]%f[:%f[:%f]]) into hours
270 parse_time(const string& time_in) {
271 char *time_str, num[256];
272 double hours, minutes, seconds;
277 time_str = (char *)time_in.c_str();
279 // printf("parse_time(): %s\n", time_str);
282 if ( strlen(time_str) ) {
283 if ( time_str[0] == '+' ) {
286 } else if ( time_str[0] == '-' ) {
291 // printf("sign = %d\n", sign);
294 if ( strlen(time_str) ) {
296 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
297 num[i] = time_str[0];
301 if ( time_str[0] == ':' ) {
306 // printf("hours = %.2lf\n", hours);
312 if ( strlen(time_str) ) {
314 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
315 num[i] = time_str[0];
319 if ( time_str[0] == ':' ) {
324 // printf("minutes = %.2lf\n", minutes);
326 result += minutes / 60.0;
330 if ( strlen(time_str) ) {
332 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
333 num[i] = time_str[0];
339 // printf("seconds = %.2lf\n", seconds);
341 result += seconds / 3600.0;
344 SG_LOG( SG_GENERAL, SG_INFO, " parse_time() = " << sign * result );
346 return(sign * result);
350 // parse a date string (yyyy:mm:dd:hh:mm:ss) into a time_t (seconds)
352 parse_date( const string& date)
355 char * date_str, num[256];
357 // initialize to zero
364 gmt.tm_isdst = 0; // ignore daylight savings time for the moment
365 date_str = (char *)date.c_str();
367 if ( strlen(date_str) ) {
369 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
370 num[i] = date_str[0];
374 if ( date_str[0] == ':' ) {
378 gmt.tm_year = atoi(num) - 1900;
381 if ( strlen(date_str) ) {
383 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
384 num[i] = date_str[0];
388 if ( date_str[0] == ':' ) {
392 gmt.tm_mon = atoi(num) -1;
395 if ( strlen(date_str) ) {
397 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
398 num[i] = date_str[0];
402 if ( date_str[0] == ':' ) {
406 gmt.tm_mday = atoi(num);
409 if ( strlen(date_str) ) {
411 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
412 num[i] = date_str[0];
416 if ( date_str[0] == ':' ) {
420 gmt.tm_hour = atoi(num);
423 if ( strlen(date_str) ) {
425 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
426 num[i] = date_str[0];
430 if ( date_str[0] == ':' ) {
434 gmt.tm_min = atoi(num);
437 if ( strlen(date_str) ) {
439 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
440 num[i] = date_str[0];
444 if ( date_str[0] == ':' ) {
448 gmt.tm_sec = atoi(num);
450 time_t theTime = sgTimeGetGMT( gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
451 gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
452 //printf ("Date is %s\n", ctime(&theTime));
453 //printf ("in seconds that is %d\n", theTime);
459 // parse angle in the form of [+/-]ddd:mm:ss into degrees
461 parse_degree( const string& degree_str) {
462 double result = parse_time( degree_str );
464 // printf("Degree = %.4f\n", result);
470 // parse time offset string into seconds
472 parse_time_offset( const string& time_str) {
475 // printf("time offset = %s\n", time_str);
478 result = (int)rint(parse_time(time_str) * 3600.0);
480 result = (int)(parse_time(time_str) * 3600.0);
483 // printf("parse_time_offset(): %d\n", result);
489 // Parse --fov=x.xx type option
491 parse_fov( const string& arg ) {
492 double fov = atof(arg);
494 if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
495 if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
497 fgSetDouble("/sim/current-view/field-of-view", fov);
499 // printf("parse_fov(): result = %.4f\n", fov);
505 // Parse I/O channel option
507 // Format is "--protocol=medium,direction,hz,medium_options,..."
509 // protocol = { native, nmea, garmin, fgfs, rul, pve, etc. }
510 // medium = { serial, socket, file, etc. }
511 // direction = { in, out, bi }
512 // hz = number of times to process channel per second (floating
513 // point values are ok.
515 // Serial example "--nmea=serial,dir,hz,device,baud" where
517 // device = OS device name of serial line to be open()'ed
518 // baud = {300, 1200, 2400, ..., 230400}
520 // Socket exacmple "--native=socket,dir,hz,machine,port,style" where
522 // machine = machine name or ip address if client (leave empty if server)
523 // port = port, leave empty to let system choose
524 // style = tcp or udp
526 // File example "--garmin=file,dir,hz,filename" where
528 // filename = file system file name
531 add_channel( const string& type, const string& channel_str ) {
532 SG_LOG(SG_GENERAL, SG_INFO, "Channel string = " << channel_str );
534 globals->get_channel_options_list()->push_back( type + "," + channel_str );
536 // cout << "here" << endl;
543 setup_wind (double min_hdg, double max_hdg, double speed, double gust)
545 fgSetDouble("/environment/wind-from-heading-deg", min_hdg);
546 fgSetDouble("/environment/params/min-wind-from-heading-deg", min_hdg);
547 fgSetDouble("/environment/params/max-wind-from-heading-deg", max_hdg);
548 fgSetDouble("/environment/wind-speed-kt", speed);
549 fgSetDouble("/environment/params/base-wind-speed-kt", speed);
550 fgSetDouble("/environment/params/gust-wind-speed-kt", gust);
552 SG_LOG(SG_GENERAL, SG_INFO, "WIND: " << min_hdg << '@' <<
553 speed << " knots" << endl);
557 speed *= SG_NM_TO_METER * SG_METER_TO_FEET * (1.0/3600);
558 while (min_hdg > 360)
562 min_hdg *= SGD_DEGREES_TO_RADIANS;
563 fgSetDouble("/environment/wind-from-north-fps", speed * cos(dir));
564 fgSetDouble("/environment/wind-from-east-fps", speed * sin(dir));
565 #endif // FG_WEATHERCM
569 // Parse --wp=ID[@alt]
571 parse_wp( const string& arg ) {
575 string::size_type pos = arg.find( "@" );
576 if ( pos != string::npos ) {
577 id = arg.substr( 0, pos );
578 alt_str = arg.substr( pos + 1 );
579 // cout << "id str = " << id << " alt str = " << alt_str << endl;
580 alt = atof( alt_str.c_str() );
581 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") ) {
582 alt *= SG_FEET_TO_METER;
589 if ( fgFindAirportID( id, &a ) ) {
590 SGWayPoint wp( a.longitude, a.latitude, alt, SGWayPoint::WGS84, id );
591 globals->get_route()->add_waypoint( wp );
600 // Parse --flight-plan=[file]
602 parse_flightplan(const string& arg)
604 sg_gzifstream in(arg.c_str());
605 if ( !in.is_open() ) {
611 #if defined( macintosh )
612 getline( in, line, '\r' );
614 getline( in, line, '\n' );
617 // catch extraneous (DOS) line ending character
618 if ( line[line.length() - 1] < 32 ) {
619 line = line.substr( 0, line.length()-1 );
631 #define NEW_OPTION_PARSING 1
632 #ifdef NEW_OPTION_PARSING
634 fgOptLanguage( const char *arg )
636 globals->set_locale( fgInitLocale( arg ) );
637 return FG_OPTIONS_OK;
643 fgSetString("/sim/presets/airport-id", "");
644 fgSetString("/sim/presets/vor-id", "");
645 fgSetString("/sim/presets/ndb-id", "");
646 fgSetString("/sim/presets/fix", "");
650 fgOptVOR( const char * arg )
653 fgSetString("/sim/presets/vor-id", arg);
654 return FG_OPTIONS_OK;
658 fgOptNDB( const char * arg )
661 fgSetString("/sim/presets/ndb-id", arg);
662 return FG_OPTIONS_OK;
666 fgOptFIX( const char * arg )
669 fgSetString("/sim/presets/fix", arg);
670 return FG_OPTIONS_OK;
674 fgOptLon( const char *arg )
677 fgSetDouble("/sim/presets/longitude-deg", parse_degree( arg ));
678 fgSetDouble("/position/longitude-deg", parse_degree( arg ));
679 return FG_OPTIONS_OK;
683 fgOptLat( const char *arg )
686 fgSetDouble("/sim/presets/latitude-deg", parse_degree( arg ));
687 fgSetDouble("/position/latitude-deg", parse_degree( arg ));
688 return FG_OPTIONS_OK;
692 fgOptAltitude( const char *arg )
694 fgSetBool("/sim/presets/onground", false);
695 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
696 fgSetDouble("/sim/presets/altitude-ft", atof( arg ));
698 fgSetDouble("/sim/presets/altitude-ft",
699 atof( arg ) * SG_METER_TO_FEET);
700 return FG_OPTIONS_OK;
704 fgOptUBody( const char *arg )
706 fgSetString("/sim/presets/speed-set", "UVW");
707 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
708 fgSetDouble("/sim/presets/uBody-fps", atof( arg ));
710 fgSetDouble("/sim/presets/uBody-fps",
711 atof( arg ) * SG_METER_TO_FEET);
712 return FG_OPTIONS_OK;
716 fgOptVBody( const char *arg )
718 fgSetString("/sim/presets/speed-set", "UVW");
719 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
720 fgSetDouble("/sim/presets/vBody-fps", atof( arg ));
722 fgSetDouble("/sim/presets/vBody-fps",
723 atof( arg ) * SG_METER_TO_FEET);
724 return FG_OPTIONS_OK;
728 fgOptWBody( const char *arg )
730 fgSetString("/sim/presets/speed-set", "UVW");
731 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
732 fgSetDouble("/sim/presets/wBody-fps", atof(arg));
734 fgSetDouble("/sim/presets/wBody-fps",
735 atof(arg) * SG_METER_TO_FEET);
736 return FG_OPTIONS_OK;
740 fgOptVNorth( const char *arg )
742 fgSetString("/sim/presets/speed-set", "NED");
743 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
744 fgSetDouble("/sim/presets/speed-north-fps", atof( arg ));
746 fgSetDouble("/sim/presets/speed-north-fps",
747 atof( arg ) * SG_METER_TO_FEET);
748 return FG_OPTIONS_OK;
752 fgOptVEast( const char *arg )
754 fgSetString("/sim/presets/speed-set", "NED");
755 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
756 fgSetDouble("/sim/presets/speed-east-fps", atof(arg));
758 fgSetDouble("/sim/presets/speed-east-fps",
759 atof(arg) * SG_METER_TO_FEET);
760 return FG_OPTIONS_OK;
764 fgOptVDown( const char *arg )
766 fgSetString("/sim/presets/speed-set", "NED");
767 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
768 fgSetDouble("/sim/presets/speed-down-fps", atof(arg));
770 fgSetDouble("/sim/presets/speed-down-fps",
771 atof(arg) * SG_METER_TO_FEET);
772 return FG_OPTIONS_OK;
776 fgOptVc( const char *arg )
778 // fgSetString("/sim/presets/speed-set", "knots");
779 // fgSetDouble("/velocities/airspeed-kt", atof(arg.substr(5)));
780 fgSetString("/sim/presets/speed-set", "knots");
781 fgSetDouble("/sim/presets/airspeed-kt", atof(arg));
782 return FG_OPTIONS_OK;
786 fgOptMach( const char *arg )
788 fgSetString("/sim/presets/speed-set", "mach");
789 fgSetDouble("/sim/presets/mach", atof(arg));
790 return FG_OPTIONS_OK;
794 fgOptRoc( const char *arg )
796 fgSetDouble("/velocities/vertical-speed-fps", atof(arg)/60);
797 return FG_OPTIONS_OK;
801 fgOptFgRoot( const char *arg )
803 globals->set_fg_root(arg);
804 return FG_OPTIONS_OK;
808 fgOptFgScenery( const char *arg )
810 globals->set_fg_scenery(arg);
811 return FG_OPTIONS_OK;
815 fgOptFov( const char *arg )
818 return FG_OPTIONS_OK;
822 fgOptGeometry( const char *arg )
824 bool geometry_ok = true;
825 int xsize = 0, ysize = 0;
826 string geometry = arg;
827 string::size_type i = geometry.find('x');
829 if (i != string::npos) {
830 xsize = atoi(geometry.substr(0, i));
831 ysize = atoi(geometry.substr(i+1));
836 if ( xsize <= 0 || ysize <= 0 ) {
842 if ( !geometry_ok ) {
843 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown geometry: " << geometry );
844 SG_LOG( SG_GENERAL, SG_ALERT,
845 "Setting geometry to " << xsize << 'x' << ysize << '\n');
847 SG_LOG( SG_GENERAL, SG_INFO,
848 "Setting geometry to " << xsize << 'x' << ysize << '\n');
849 fgSetInt("/sim/startup/xsize", xsize);
850 fgSetInt("/sim/startup/ysize", ysize);
852 return FG_OPTIONS_OK;
856 fgOptBpp( const char *arg )
858 string bits_per_pix = arg;
859 if ( bits_per_pix == "16" ) {
860 fgSetInt("/sim/rendering/bits-per-pixel", 16);
861 } else if ( bits_per_pix == "24" ) {
862 fgSetInt("/sim/rendering/bits-per-pixel", 24);
863 } else if ( bits_per_pix == "32" ) {
864 fgSetInt("/sim/rendering/bits-per-pixel", 32);
866 SG_LOG(SG_GENERAL, SG_ALERT, "Unsupported bpp " << bits_per_pix);
868 return FG_OPTIONS_OK;
872 fgOptTimeOffset( const char *arg )
874 fgSetInt("/sim/startup/time-offset",
875 parse_time_offset( arg ));
876 fgSetString("/sim/startup/time-offset-type", "system-offset");
877 return FG_OPTIONS_OK;
881 fgOptStartDateSys( const char *arg )
883 fgSetInt("/sim/startup/time-offset", parse_date( arg ) );
884 fgSetString("/sim/startup/time-offset-type", "system");
885 return FG_OPTIONS_OK;
889 fgOptStartDateLat( const char *arg )
891 fgSetInt("/sim/startup/time-offset", parse_date( arg ) );
892 fgSetString("/sim/startup/time-offset-type", "latitude");
893 return FG_OPTIONS_OK;
897 fgOptStartDateGmt( const char *arg )
899 fgSetInt("/sim/startup/time-offset", parse_date( arg ) );
900 fgSetString("/sim/startup/time-offset-type", "gmt");
901 return FG_OPTIONS_OK;
904 #ifdef FG_NETWORK_OLK
906 fgOptNetHud( const char *arg )
908 fgSetBool("/sim/hud/net-display", true);
909 net_hud_display = 1; // FIXME
910 return FG_OPTIONS_OK;
915 fgOptTraceRead( const char *arg )
918 SG_LOG(SG_GENERAL, SG_INFO, "Tracing reads for property " << name);
919 fgGetNode(name.c_str(), true)
920 ->setAttribute(SGPropertyNode::TRACE_READ, true);
921 return FG_OPTIONS_OK;
925 fgOptTraceWrite( const char *arg )
928 SG_LOG(SG_GENERAL, SG_INFO, "Tracing writes for property " << name);
929 fgGetNode(name.c_str(), true)
930 ->setAttribute(SGPropertyNode::TRACE_WRITE, true);
931 return FG_OPTIONS_OK;
935 fgOptDebugLevel( const char *arg )
937 fgSetInt( "/sim/log-level", atoi( arg ) );
938 return FG_OPTIONS_OK;
942 fgOptViewOffset( const char *arg )
944 // $$$ begin - added VS Renganathan, 14 Oct 2K
945 // for multi-window outside window imagery
946 string woffset = arg;
947 double default_view_offset = 0.0;
948 if ( woffset == "LEFT" ) {
949 default_view_offset = SGD_PI * 0.25;
950 } else if ( woffset == "RIGHT" ) {
951 default_view_offset = SGD_PI * 1.75;
952 } else if ( woffset == "CENTER" ) {
953 default_view_offset = 0.00;
955 default_view_offset = atof( woffset.c_str() ) * SGD_DEGREES_TO_RADIANS;
957 /* apparently not used (CLO, 11 Jun 2002)
958 FGViewer *pilot_view =
959 (FGViewer *)globals->get_viewmgr()->get_view( 0 ); */
960 // this will work without calls to the viewer...
961 fgSetDouble( "/sim/current-view/heading-offset-deg",
962 default_view_offset * SGD_RADIANS_TO_DEGREES );
963 // $$$ end - added VS Renganathan, 14 Oct 2K
964 return FG_OPTIONS_OK;
968 fgOptVisibilityMiles( const char *arg )
970 double visibility = atof( arg ) * 5280.0 * SG_FEET_TO_METER;
971 fgSetDouble("/environment/visibility-m", visibility);
972 return FG_OPTIONS_OK;
976 fgOptRandomWind( const char *arg )
978 double min_hdg = sg_random() * 360.0;
979 double max_hdg = min_hdg + (20 - sqrt(sg_random() * 400));
980 double speed = 40 - sqrt(sg_random() * 1600.0);
981 double gust = speed + (10 - sqrt(sg_random() * 100));
982 setup_wind(min_hdg, max_hdg, speed, gust);
983 return FG_OPTIONS_OK;
987 fgOptWind( const char *arg )
989 double min_hdg, max_hdg, speed, gust;
990 if (!parse_wind( arg, &min_hdg, &max_hdg, &speed, &gust)) {
991 SG_LOG( SG_GENERAL, SG_ALERT, "bad wind value " << arg );
992 return FG_OPTIONS_ERROR;
994 setup_wind(min_hdg, max_hdg, speed, gust);
995 return FG_OPTIONS_OK;
999 fgOptWp( const char *arg )
1002 return FG_OPTIONS_OK;
1006 fgOptFlightPlan( const char *arg )
1008 parse_flightplan ( arg );
1009 return FG_OPTIONS_OK;
1013 fgOptConfig( const char *arg )
1017 readProperties(file, globals->get_props());
1018 } catch (const sg_exception &e) {
1019 string message = "Error loading config file: ";
1020 message += e.getFormattedMessage();
1021 SG_LOG(SG_INPUT, SG_ALERT, message);
1024 return FG_OPTIONS_OK;
1027 static map<string,size_t> fgOptionMap;
1029 enum OptionType { OPTION_BOOL, OPTION_STRING, OPTION_DOUBLE, OPTION_INT, OPTION_CHANNEL, OPTION_FUNC };
1033 enum OptionType type;
1037 int (*func)( const char * );
1038 } fgOptionArray[] = {
1040 {"language", true, OPTION_FUNC, "", false, "", fgOptLanguage },
1041 {"disable-game-mode", false, OPTION_BOOL, "/sim/startup/game-mode", false, "", 0 },
1042 {"enable-game-mode", false, OPTION_BOOL, "/sim/startup/game-mode", true, "", 0 },
1043 {"disable-splash-screen", false, OPTION_BOOL, "/sim/startup/splash-screen", false, "", 0 },
1044 {"enable-splash-screen", false, OPTION_BOOL, "/sim/startup/splash-screen", true, "", 0 },
1045 {"disable-intro-music", false, OPTION_BOOL, "/sim/startup/intro-music", false, "", 0 },
1046 {"enable-intro-music", false, OPTION_BOOL, "/sim/startup/intro-music", true, "", 0 },
1047 {"disable-mouse-pointer", false, OPTION_STRING, "/sim/startup/mouse-pointer", false, "disabled", 0 },
1048 {"enable-mouse-pointer", false, OPTION_STRING, "/sim/startup/mouse-pointer", false, "enabled", 0 },
1049 {"disable-random-objects", false, OPTION_BOOL, "/sim/rendering/random-objects", false, "", 0 },
1050 {"enable-random-objects", false, OPTION_BOOL, "/sim/rendering/random-objects", true, "", 0 },
1051 {"disable-freeze", false, OPTION_BOOL, "/sim/freeze/master", false, "", 0 },
1052 {"enable-freeze", false, OPTION_BOOL, "/sim/freeze/master", true, "", 0 },
1053 {"disable-fuel-freeze", false, OPTION_BOOL, "/sim/freeze/fuel", false, "", 0 },
1054 {"enable-fuel-freeze", false, OPTION_BOOL, "/sim/freeze/fuel", true, "", 0 },
1055 {"disable-clock-freeze", false, OPTION_BOOL, "/sim/freeze/clock", false, "", 0 },
1056 {"enable-clock-freeze", false, OPTION_BOOL, "/sim/freeze/clock", true, "", 0 },
1057 {"disable-anti-alias-hud", false, OPTION_BOOL, "/sim/hud/antialiased", false, "", 0 },
1058 {"enable-anti-alias-hud", false, OPTION_BOOL, "/sim/hud/antialiased", true, "", 0 },
1059 {"control", true, OPTION_STRING, "/sim/control-mode", false, "", 0 },
1060 {"disable-auto-coordination", false, OPTION_BOOL, "/sim/auto-coordination", false, "", 0 },
1061 {"enable-auto-coordination", false, OPTION_BOOL, "/sim/auto-coordination", true, "", 0 },
1062 {"browser-app", true, OPTION_STRING, "/sim/startup/browser-app", false, "", 0 },
1063 {"disable-hud", false, OPTION_BOOL, "/sim/hud/visibility", false, "", 0 },
1064 {"enable-hud", false, OPTION_BOOL, "/sim/hud/visibility", true, "", 0 },
1065 {"disable-panel", false, OPTION_BOOL, "/sim/panel/visibility", false, "", 0 },
1066 {"enable-panel", false, OPTION_BOOL, "/sim/panel/visibility", true, "", 0 },
1067 {"disable-sound", false, OPTION_BOOL, "/sim/sound/audible", false, "", 0 },
1068 {"enable-sound", false, OPTION_BOOL, "/sim/sound/audible", true, "", 0 },
1069 {"airport", true, OPTION_STRING, "/sim/presets/airport-id", false, "", 0 },
1070 {"airport-id", true, OPTION_STRING, "/sim/presets/airport-id", false, "", 0 },
1071 {"runway", true, OPTION_STRING, "/sim/presets/runway", false, "", 0 },
1072 {"vor", true, OPTION_FUNC, "", false, "", fgOptVOR },
1073 {"ndb", true, OPTION_FUNC, "", false, "", fgOptNDB },
1074 {"fix", true, OPTION_FUNC, "", false, "", fgOptFIX },
1075 {"offset-distance", true, OPTION_DOUBLE, "/sim/presets/offset-distance", false, "", 0 },
1076 {"offset-azimuth", true, OPTION_DOUBLE, "/sim/presets/offset-azimuth", false, "", 0 },
1077 {"lon", true, OPTION_FUNC, "", false, "", fgOptLon },
1078 {"lat", true, OPTION_FUNC, "", false, "", fgOptLat },
1079 {"altitude", true, OPTION_FUNC, "", false, "", fgOptAltitude },
1080 {"uBody", true, OPTION_FUNC, "", false, "", fgOptUBody },
1081 {"vBody", true, OPTION_FUNC, "", false, "", fgOptVBody },
1082 {"wBody", true, OPTION_FUNC, "", false, "", fgOptWBody },
1083 {"vNorth", true, OPTION_FUNC, "", false, "", fgOptVNorth },
1084 {"vEast", true, OPTION_FUNC, "", false, "", fgOptVEast },
1085 {"vDown", true, OPTION_FUNC, "", false, "", fgOptVDown },
1086 {"vc", true, OPTION_FUNC, "", false, "", fgOptVc },
1087 {"mach", true, OPTION_FUNC, "", false, "", fgOptMach },
1088 {"heading", true, OPTION_DOUBLE, "/sim/presets/heading-deg", false, "", 0 },
1089 {"roll", true, OPTION_DOUBLE, "/sim/presets/roll-deg", false, "", 0 },
1090 {"pitch", true, OPTION_DOUBLE, "/sim/presets/pitch-deg", false, "", 0 },
1091 {"glideslope", true, OPTION_DOUBLE, "/sim/presets/glideslope-deg", false, "", 0 },
1092 {"roc", true, OPTION_FUNC, "", false, "", fgOptRoc },
1093 {"fg-root", true, OPTION_FUNC, "", false, "", fgOptFgRoot },
1094 {"fg-scenery", true, OPTION_FUNC, "", false, "", fgOptFgScenery },
1095 {"fdm", true, OPTION_STRING, "/sim/flight-model", false, "", 0 },
1096 {"aero", true, OPTION_STRING, "/sim/aero", false, "", 0 },
1097 {"aircraft-dir", true, OPTION_STRING, "/sim/aircraft-dir", false, "", 0 },
1098 {"model-hz", true, OPTION_INT, "/sim/model-hz", false, "", 0 },
1099 {"speed", true, OPTION_INT, "/sim/speed-up", false, "", 0 },
1100 {"trim", false, OPTION_BOOL, "/sim/presets/trim", true, "", 0 },
1101 {"notrim", false, OPTION_BOOL, "/sim/presets/trim", false, "", 0 },
1102 {"on-ground", false, OPTION_BOOL, "/sim/presets/onground", true, "", 0 },
1103 {"in-air", false, OPTION_BOOL, "/sim/presets/onground", false, "", 0 },
1104 {"fog-disable", false, OPTION_STRING, "/sim/rendering/fog", false, "disabled", 0 },
1105 {"fog-fastest", false, OPTION_STRING, "/sim/rendering/fog", false, "fastest", 0 },
1106 {"fog-nicest", false, OPTION_STRING, "/sim/fog", false, "nicest", 0 },
1107 {"disable-distance-attenuation", false, OPTION_BOOL, "/environment/distance-attenuation", false, "", 0 },
1108 {"enable-distance-attenuation", false, OPTION_BOOL, "/environment/distance-attenuation", true, "", 0 },
1109 {"disable-clouds", false, OPTION_BOOL, "/environment/clouds/status", false, "", 0 },
1110 {"enable-clouds", false, OPTION_BOOL, "/environment/clouds/status", true, "", 0 },
1111 #ifdef FG_USE_CLOUDS_3D
1112 {"disable-clouds3d", false, OPTION_BOOL, "/sim/rendering/clouds3d", false, "", 0 },
1113 {"enable-clouds3d", false, OPTION_BOOL, "/sim/rendering/clouds3d", true, "", 0 },
1115 {"fov", true, OPTION_FUNC, "", false, "", fgOptFov },
1116 {"disable-fullscreen", false, OPTION_BOOL, "/sim/startup/fullscreen", false, "", 0 },
1117 {"enable-fullscreen", false, OPTION_BOOL, "/sim/startup/fullscreen", true, "", 0 },
1118 {"shading-flat", false, OPTION_BOOL, "/sim/rendering/shading", false, "", 0 },
1119 {"shading-smooth", false, OPTION_BOOL, "/sim/rendering/shading", true, "", 0 },
1120 {"disable-skyblend", false, OPTION_BOOL, "/sim/rendering/skyblend", false, "", 0 },
1121 {"enable-skyblend", false, OPTION_BOOL, "/sim/rendering/skyblend", true, "", 0 },
1122 {"disable-textures", false, OPTION_BOOL, "/sim/rendering/textures", false, "", 0 },
1123 {"enable-textures", false, OPTION_BOOL, "/sim/rendering/textures", true, "", 0 },
1124 {"disable-wireframe", false, OPTION_BOOL, "/sim/rendering/wireframe", false, "", 0 },
1125 {"enable-wireframe", false, OPTION_BOOL, "/sim/rendering/wireframe", true, "", 0 },
1126 {"geometry", true, OPTION_FUNC, "", false, "", fgOptGeometry },
1127 {"bpp", true, OPTION_FUNC, "", false, "", fgOptBpp },
1128 {"units-feet", false, OPTION_STRING, "/sim/startup/units", false, "feet", 0 },
1129 {"units-meters", false, OPTION_STRING, "/sim/startup/units", false, "meters", 0 },
1130 {"time-offset", true, OPTION_FUNC, "", false, "", fgOptTimeOffset },
1131 {"time-match-real", false, OPTION_STRING, "/sim/startup/time-offset-type", false, "system-offset", 0 },
1132 {"time-match-local", false, OPTION_STRING, "/sim/startup/time-offset-type", false, "latitude-offset", 0 },
1133 {"start-date-sys", true, OPTION_FUNC, "", false, "", fgOptStartDateSys },
1134 {"start-date-lat", true, OPTION_FUNC, "", false, "", fgOptStartDateLat },
1135 {"start-date-gmt", true, OPTION_FUNC, "", false, "", fgOptStartDateGmt },
1136 {"hud-tris", false, OPTION_STRING, "/sim/hud/frame-stat-type", false, "tris", 0 },
1137 {"hud-culled", false, OPTION_STRING, "/sim/hud/frame-stat-type", false, "culled", 0 },
1138 {"atc610x", false, OPTION_CHANNEL, "", false, "dummy", 0 },
1139 {"atlas", true, OPTION_CHANNEL, "", false, "", 0 },
1140 {"httpd", true, OPTION_CHANNEL, "", false, "", 0 },
1141 #ifdef FG_JPEG_SERVER
1142 {"jpg-httpd", true, OPTION_CHANNEL, "", false, "", 0 },
1144 {"native", true, OPTION_CHANNEL, "", false, "", 0 },
1145 {"native-ctrls", true, OPTION_CHANNEL, "", false, "", 0 },
1146 {"native-fdm", true, OPTION_CHANNEL, "", false, "", 0 },
1147 {"native-gui", true, OPTION_CHANNEL, "", false, "", 0 },
1148 {"opengc", true, OPTION_CHANNEL, "", false, "", 0 },
1149 {"garmin", true, OPTION_CHANNEL, "", false, "", 0 },
1150 {"nmea", true, OPTION_CHANNEL, "", false, "", 0 },
1151 {"props", true, OPTION_CHANNEL, "", false, "", 0 },
1152 {"telnet", true, OPTION_CHANNEL, "", false, "", 0 },
1153 {"pve", true, OPTION_CHANNEL, "", false, "", 0 },
1154 {"ray", true, OPTION_CHANNEL, "", false, "", 0 },
1155 {"rul", true, OPTION_CHANNEL, "", false, "", 0 },
1156 {"joyclient", true, OPTION_CHANNEL, "", false, "", 0 },
1157 #ifdef FG_NETWORK_OLK
1158 {"disable-network-olk", false, OPTION_BOOL, "/sim/networking/olk", false, "", 0 },
1159 {"enable-network-olk", false, OPTION_BOOL, "/sim/networking/olk", true, "", 0 },
1160 {"net-hud", false, OPTION_FUNC, "", false, "", fgOptNetHud },
1161 {"net-id", true, OPTION_STRING, "sim/networking/call-sign", false, "", 0 },
1163 {"trace-read", true, OPTION_FUNC, "", false, "", fgOptTraceRead },
1164 {"trace-write", true, OPTION_FUNC, "", false, "", fgOptTraceWrite },
1165 {"log-level", true, OPTION_FUNC, "", false, "", fgOptDebugLevel },
1166 {"view-offset", true, OPTION_FUNC, "", false, "", fgOptViewOffset },
1167 {"visibility", true, OPTION_DOUBLE, "/environment/visibility-m", false, "", 0 },
1168 {"visibility-miles", true, OPTION_FUNC, "", false, "", fgOptVisibilityMiles },
1169 {"random-wind", false, OPTION_FUNC, "", false, "", fgOptRandomWind },
1170 {"wind", true, OPTION_FUNC, "", false, "", fgOptWind },
1171 {"turbulence", true, OPTION_DOUBLE, "/environment/turbulence-norm", false, "", 0 },
1172 {"wp", true, OPTION_FUNC, "", false, "", fgOptWp },
1173 {"flight-plan", true, OPTION_FUNC, "", false, "", fgOptFlightPlan },
1174 {"config", true, OPTION_FUNC, "", false, "", fgOptConfig },
1175 {"aircraft", true, OPTION_STRING, "/sim/aircraft", false, "", 0 },
1180 // Parse a single option
1182 parse_option (const string& arg)
1184 #ifdef NEW_OPTION_PARSING
1185 if ( fgOptionMap.size() == 0 ) {
1187 OptionDesc *pt = &fgOptionArray[ 0 ];
1188 while ( pt->option != 0 ) {
1189 fgOptionMap[ pt->option ] = i;
1196 if ( (arg == "--help") || (arg == "-h") ) {
1197 // help/usage request
1198 return(FG_OPTIONS_HELP);
1199 } else if ( (arg == "--verbose") || (arg == "-v") ) {
1200 // verbose help/usage request
1201 return(FG_OPTIONS_VERBOSE_HELP);
1202 } else if ( arg.find( "--show-aircraft") == 0) {
1203 return(FG_OPTIONS_SHOW_AIRCRAFT);
1204 } else if ( arg.find( "--prop:" ) == 0 ) {
1205 string assign = arg.substr(7);
1206 string::size_type pos = assign.find('=');
1207 if ( pos == arg.npos || pos == 0 ) {
1208 SG_LOG( SG_GENERAL, SG_ALERT, "Bad property assignment: " << arg );
1209 return FG_OPTIONS_ERROR;
1211 string name = assign.substr(0, pos);
1212 string value = assign.substr(pos + 1);
1213 fgSetString(name.c_str(), value.c_str());
1214 // SG_LOG(SG_GENERAL, SG_INFO, "Setting default value of property "
1215 // << name << " to \"" << value << '"');
1216 } else if ( arg.find( "--" ) == 0 ) {
1217 size_t pos = arg.find( '=' );
1219 if ( pos == string::npos ) {
1220 arg_name = arg.substr( 2 );
1222 arg_name = arg.substr( 2, pos - 2 );
1224 map<string,size_t>::iterator it = fgOptionMap.find( arg_name );
1225 if ( it != fgOptionMap.end() ) {
1226 OptionDesc *pt = &fgOptionArray[ it->second ];
1227 switch ( pt->type ) {
1229 fgSetBool( pt->property, pt->b_param );
1232 if ( pt->has_param && pos != string::npos ) {
1233 fgSetString( pt->property, arg.substr( pos + 1 ).c_str() );
1234 } else if ( !pt->has_param && pos == string::npos ) {
1235 fgSetString( pt->property, pt->s_param );
1236 } else if ( pt->has_param ) {
1237 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1238 return FG_OPTIONS_ERROR;
1240 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' does not have a parameter" );
1241 return FG_OPTIONS_ERROR;
1245 if ( pos != string::npos ) {
1246 fgSetDouble( pt->property, atof( arg.substr( pos + 1 ) ) );
1248 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1249 return FG_OPTIONS_ERROR;
1253 if ( pos != string::npos ) {
1254 fgSetInt( pt->property, atoi( arg.substr( pos + 1 ) ) );
1256 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1257 return FG_OPTIONS_ERROR;
1260 case OPTION_CHANNEL:
1261 if ( pt->has_param && pos != string::npos ) {
1262 add_channel( pt->option, arg.substr( pos + 1 ) );
1263 } else if ( !pt->has_param && pos == string::npos ) {
1264 add_channel( pt->option, pt->s_param );
1265 } else if ( pt->has_param ) {
1266 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1267 return FG_OPTIONS_ERROR;
1269 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' does not have a parameter" );
1270 return FG_OPTIONS_ERROR;
1274 if ( pt->has_param && pos != string::npos ) {
1275 pt->func( arg.substr( pos + 1 ).c_str() );
1276 } else if ( !pt->has_param && pos == string::npos ) {
1278 } else if ( pt->has_param ) {
1279 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1280 return FG_OPTIONS_ERROR;
1282 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' does not have a parameter" );
1283 return FG_OPTIONS_ERROR;
1288 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" );
1289 return FG_OPTIONS_ERROR;
1292 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" );
1293 return FG_OPTIONS_ERROR;
1299 if ( (arg == "--help") || (arg == "-h") ) {
1300 // help/usage request
1301 return(FG_OPTIONS_HELP);
1302 } else if ( (arg == "--verbose") || (arg == "-v") ) {
1303 // verbose help/usage request
1304 return(FG_OPTIONS_VERBOSE_HELP);
1305 } else if ( arg.find( "--language=") == 0 ) {
1306 globals->set_locale( fgInitLocale( arg.substr( 11 ).c_str() ) );
1307 } else if ( arg == "--disable-game-mode") {
1308 fgSetBool("/sim/startup/game-mode", false);
1309 } else if ( arg == "--enable-game-mode" ) {
1310 fgSetBool("/sim/startup/game-mode", true);
1311 } else if ( arg == "--disable-splash-screen" ) {
1312 fgSetBool("/sim/startup/splash-screen", false);
1313 } else if ( arg == "--enable-splash-screen" ) {
1314 fgSetBool("/sim/startup/splash-screen", true);
1315 } else if ( arg == "--disable-intro-music" ) {
1316 fgSetBool("/sim/startup/intro-music", false);
1317 } else if ( arg == "--enable-intro-music" ) {
1318 fgSetBool("/sim/startup/intro-music", true);
1319 } else if ( arg == "--disable-mouse-pointer" ) {
1320 fgSetString("/sim/startup/mouse-pointer", "disabled");
1321 } else if ( arg == "--enable-mouse-pointer" ) {
1322 fgSetString("/sim/startup/mouse-pointer", "enabled");
1323 } else if ( arg == "--disable-random-objects" ) {
1324 fgSetBool("/sim/rendering/random-objects", false);
1325 } else if ( arg == "--enable-random-objects" ) {
1326 fgSetBool("/sim/rendering/random-objects", true);
1327 } else if ( arg == "--disable-freeze" ) {
1328 fgSetBool("/sim/freeze/master", false);
1329 } else if ( arg == "--enable-freeze" ) {
1330 fgSetBool("/sim/freeze/master", true);
1331 } else if ( arg == "--disable-fuel-freeze" ) {
1332 fgSetBool("/sim/freeze/fuel", false);
1333 } else if ( arg == "--enable-fuel-freeze" ) {
1334 fgSetBool("/sim/freeze/fuel", true);
1335 } else if ( arg == "--disable-clock-freeze" ) {
1336 fgSetBool("/sim/freeze/clock", false);
1337 } else if ( arg == "--enable-clock-freeze" ) {
1338 fgSetBool("/sim/freeze/clock", true);
1339 } else if ( arg == "--disable-anti-alias-hud" ) {
1340 fgSetBool("/sim/hud/antialiased", false);
1341 } else if ( arg == "--enable-anti-alias-hud" ) {
1342 fgSetBool("/sim/hud/antialiased", true);
1343 } else if ( arg.find( "--control=") == 0 ) {
1344 fgSetString("/sim/control-mode", arg.substr(10).c_str());
1345 } else if ( arg == "--disable-auto-coordination" ) {
1346 fgSetBool("/sim/auto-coordination", false);
1347 } else if ( arg == "--enable-auto-coordination" ) {
1348 fgSetBool("/sim/auto-coordination", true);
1349 } else if ( arg.find( "--browser-app=") == 0 ) {
1350 fgSetString("/sim/startup/browser-app", arg.substr(14).c_str());
1351 } else if ( arg == "--disable-hud" ) {
1352 fgSetBool("/sim/hud/visibility", false);
1353 } else if ( arg == "--enable-hud" ) {
1354 fgSetBool("/sim/hud/visibility", true);
1355 } else if ( arg == "--disable-panel" ) {
1356 fgSetBool("/sim/panel/visibility", false);
1357 } else if ( arg == "--enable-panel" ) {
1358 fgSetBool("/sim/panel/visibility", true);
1359 } else if ( arg == "--disable-sound" ) {
1360 fgSetBool("/sim/sound/audible", false);
1361 } else if ( arg == "--enable-sound" ) {
1362 fgSetBool("/sim/sound/audible", true);
1363 } else if ( arg.find( "--airport=") == 0 ) {
1364 fgSetString("/sim/presets/airport-id", arg.substr(10).c_str());
1365 } else if ( arg.find( "--airport-id=") == 0 ) {
1366 fgSetString("/sim/presets/airport-id", arg.substr(13).c_str());
1367 } else if ( arg.find( "--runway=") == 0 ) {
1368 fgSetString("/sim/presets/runway", arg.substr(9).c_str());
1369 } else if ( arg.find( "--offset-distance=") == 0 ) {
1370 fgSetDouble("/sim/presets/offset-distance", atof(arg.substr(18)));
1371 } else if ( arg.find( "--offset-azimuth=") == 0 ) {
1372 fgSetDouble("/sim/presets/offset-azimuth", atof(arg.substr(17)));
1373 } else if ( arg.find( "--lon=" ) == 0 ) {
1374 fgSetDouble("/sim/presets/longitude-deg", parse_degree(arg.substr(6)));
1375 fgSetDouble("/position/longitude-deg", parse_degree(arg.substr(6)));
1376 fgSetString("/sim/presets/airport-id", "");
1377 } else if ( arg.find( "--lat=" ) == 0 ) {
1378 fgSetDouble("/sim/presets/latitude-deg", parse_degree(arg.substr(6)));
1379 fgSetDouble("/position/latitude-deg", parse_degree(arg.substr(6)));
1380 fgSetString("/sim/presets/airport-id", "");
1381 } else if ( arg.find( "--altitude=" ) == 0 ) {
1382 fgSetBool("/sim/presets/onground", false);
1383 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
1384 fgSetDouble("/sim/presets/altitude-ft", atof(arg.substr(11)));
1386 fgSetDouble("/sim/presets/altitude-ft",
1387 atof(arg.substr(11)) * SG_METER_TO_FEET);
1388 } else if ( arg.find( "--uBody=" ) == 0 ) {
1389 fgSetString("/sim/presets/speed-set", "UVW");
1390 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
1391 fgSetDouble("/sim/presets/uBody-fps", atof(arg.substr(8)));
1393 fgSetDouble("/sim/presets/uBody-fps",
1394 atof(arg.substr(8)) * SG_METER_TO_FEET);
1395 } else if ( arg.find( "--vBody=" ) == 0 ) {
1396 fgSetString("/sim/presets/speed-set", "UVW");
1397 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
1398 fgSetDouble("/sim/presets/vBody-fps", atof(arg.substr(8)));
1400 fgSetDouble("/sim/presets/vBody-fps",
1401 atof(arg.substr(8)) * SG_METER_TO_FEET);
1402 } else if ( arg.find( "--wBody=" ) == 0 ) {
1403 fgSetString("/sim/presets/speed-set", "UVW");
1404 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
1405 fgSetDouble("/sim/presets/wBody-fps", atof(arg.substr(8)));
1407 fgSetDouble("/sim/presets/wBody-fps",
1408 atof(arg.substr(8)) * SG_METER_TO_FEET);
1409 } else if ( arg.find( "--vNorth=" ) == 0 ) {
1410 fgSetString("/sim/presets/speed-set", "NED");
1411 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
1412 fgSetDouble("/sim/presets/speed-north-fps", atof(arg.substr(9)));
1414 fgSetDouble("/sim/presets/speed-north-fps",
1415 atof(arg.substr(9)) * SG_METER_TO_FEET);
1416 } else if ( arg.find( "--vEast=" ) == 0 ) {
1417 fgSetString("/sim/presets/speed-set", "NED");
1418 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
1419 fgSetDouble("/sim/presets/speed-east-fps", atof(arg.substr(8)));
1421 fgSetDouble("/sim/presets/speed-east-fps",
1422 atof(arg.substr(8)) * SG_METER_TO_FEET);
1423 } else if ( arg.find( "--vDown=" ) == 0 ) {
1424 fgSetString("/sim/presets/speed-set", "NED");
1425 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
1426 fgSetDouble("/sim/presets/speed-down-fps", atof(arg.substr(8)));
1428 fgSetDouble("/sim/presets/speed-down-fps",
1429 atof(arg.substr(8)) * SG_METER_TO_FEET);
1430 } else if ( arg.find( "--vc=" ) == 0) {
1431 // fgSetString("/sim/presets/speed-set", "knots");
1432 // fgSetDouble("/velocities/airspeed-kt", atof(arg.substr(5)));
1433 fgSetString("/sim/presets/speed-set", "knots");
1434 fgSetDouble("/sim/presets/airspeed-kt", atof(arg.substr(5)));
1435 } else if ( arg.find( "--mach=" ) == 0) {
1436 fgSetString("/sim/presets/speed-set", "mach");
1437 fgSetDouble("/sim/presets/mach", atof(arg.substr(7)));
1438 } else if ( arg.find( "--heading=" ) == 0 ) {
1439 fgSetDouble("/sim/presets/heading-deg", atof(arg.substr(10)));
1440 } else if ( arg.find( "--roll=" ) == 0 ) {
1441 fgSetDouble("/sim/presets/roll-deg", atof(arg.substr(7)));
1442 } else if ( arg.find( "--pitch=" ) == 0 ) {
1443 fgSetDouble("/sim/presets/pitch-deg", atof(arg.substr(8)));
1444 } else if ( arg.find( "--glideslope=" ) == 0 ) {
1445 fgSetDouble("/sim/presets/glideslope-deg",
1446 atof(arg.substr(13)));
1447 } else if ( arg.find( "--roc=" ) == 0 ) {
1448 fgSetDouble("/velocities/vertical-speed-fps", atof(arg.substr(6))/60);
1449 } else if ( arg.find( "--fg-root=" ) == 0 ) {
1450 globals->set_fg_root(arg.substr( 10 ));
1451 } else if ( arg.find( "--fg-scenery=" ) == 0 ) {
1452 globals->set_fg_scenery(arg.substr( 13 ));
1453 } else if ( arg.find( "--fdm=" ) == 0 ) {
1454 fgSetString("/sim/flight-model", arg.substr(6).c_str());
1455 } else if ( arg.find( "--aero=" ) == 0 ) {
1456 fgSetString("/sim/aero", arg.substr(7).c_str());
1457 } else if ( arg.find( "--aircraft-dir=" ) == 0 ) {
1458 fgSetString("/sim/aircraft-dir", arg.substr(15).c_str());
1459 } else if ( arg.find( "--show-aircraft") == 0) {
1460 return(FG_OPTIONS_SHOW_AIRCRAFT);
1461 } else if ( arg.find( "--model-hz=" ) == 0 ) {
1462 fgSetInt("/sim/model-hz", atoi(arg.substr(11)));
1463 } else if ( arg.find( "--speed=" ) == 0 ) {
1464 fgSetInt("/sim/speed-up", atoi(arg.substr(8)));
1465 } else if ( arg.find( "--trim") == 0) {
1466 fgSetBool("/sim/presets/trim", true);
1467 } else if ( arg.find( "--notrim") == 0) {
1468 fgSetBool("/sim/presets/trim", false);
1469 } else if ( arg.find( "--on-ground") == 0) {
1470 fgSetBool("/sim/presets/onground", true);
1471 } else if ( arg.find( "--in-air") == 0) {
1472 fgSetBool("/sim/presets/onground", false);
1473 } else if ( arg == "--fog-disable" ) {
1474 fgSetString("/sim/rendering/fog", "disabled");
1475 } else if ( arg == "--fog-fastest" ) {
1476 fgSetString("/sim/rendering/fog", "fastest");
1477 } else if ( arg == "--fog-nicest" ) {
1478 fgSetString("/sim/fog", "nicest");
1479 } else if ( arg == "--disable-distance-attenuation" ) {
1480 fgSetBool("/environment/distance-attenuation", false);
1481 } else if ( arg == "--enable-distance-attenuation" ) {
1482 fgSetBool("/environment/distance-attenuation", true);
1483 } else if ( arg == "--disable-clouds" ) {
1484 fgSetBool("/environment/clouds/status", false);
1485 } else if ( arg == "--enable-clouds" ) {
1486 fgSetBool("/environment/clouds/status", true);
1487 #ifdef FG_USE_CLOUDS_3D
1488 } else if ( arg == "--disable-clouds3d" ) {
1489 fgSetBool("/sim/rendering/clouds3d", false);
1490 } else if ( arg == "--enable-clouds3d" ) {
1491 fgSetBool("/sim/rendering/clouds3d", true);
1493 } else if ( arg.find( "--fov=" ) == 0 ) {
1494 parse_fov( arg.substr(6) );
1495 } else if ( arg == "--disable-fullscreen" ) {
1496 fgSetBool("/sim/startup/fullscreen", false);
1497 } else if ( arg== "--enable-fullscreen") {
1498 fgSetBool("/sim/startup/fullscreen", true);
1499 } else if ( arg == "--shading-flat") {
1500 fgSetBool("/sim/rendering/shading", false);
1501 } else if ( arg == "--shading-smooth") {
1502 fgSetBool("/sim/rendering/shading", true);
1503 } else if ( arg == "--disable-skyblend") {
1504 fgSetBool("/sim/rendering/skyblend", false);
1505 } else if ( arg== "--enable-skyblend" ) {
1506 fgSetBool("/sim/rendering/skyblend", true);
1507 } else if ( arg == "--disable-textures" ) {
1508 fgSetBool("/sim/rendering/textures", false);
1509 } else if ( arg == "--enable-textures" ) {
1510 fgSetBool("/sim/rendering/textures", true);
1511 } else if ( arg == "--disable-wireframe" ) {
1512 fgSetBool("/sim/rendering/wireframe", false);
1513 } else if ( arg == "--enable-wireframe" ) {
1514 fgSetBool("/sim/rendering/wireframe", true);
1515 } else if ( arg.find( "--geometry=" ) == 0 ) {
1516 bool geometry_ok = true;
1517 int xsize = 0, ysize = 0;
1518 string geometry = arg.substr( 11 );
1519 string::size_type i = geometry.find('x');
1521 if (i != string::npos) {
1522 xsize = atoi(geometry.substr(0, i));
1523 ysize = atoi(geometry.substr(i+1));
1525 geometry_ok = false;
1528 if ( xsize <= 0 || ysize <= 0 ) {
1531 geometry_ok = false;
1534 if ( !geometry_ok ) {
1535 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown geometry: " << geometry );
1536 SG_LOG( SG_GENERAL, SG_ALERT,
1537 "Setting geometry to " << xsize << 'x' << ysize << '\n');
1539 SG_LOG( SG_GENERAL, SG_INFO,
1540 "Setting geometry to " << xsize << 'x' << ysize << '\n');
1541 fgSetInt("/sim/startup/xsize", xsize);
1542 fgSetInt("/sim/startup/ysize", ysize);
1544 } else if ( arg.find( "--bpp=" ) == 0 ) {
1545 string bits_per_pix = arg.substr( 6 );
1546 if ( bits_per_pix == "16" ) {
1547 fgSetInt("/sim/rendering/bits-per-pixel", 16);
1548 } else if ( bits_per_pix == "24" ) {
1549 fgSetInt("/sim/rendering/bits-per-pixel", 24);
1550 } else if ( bits_per_pix == "32" ) {
1551 fgSetInt("/sim/rendering/bits-per-pixel", 32);
1553 SG_LOG(SG_GENERAL, SG_ALERT, "Unsupported bpp " << bits_per_pix);
1555 } else if ( arg == "--units-feet" ) {
1556 fgSetString("/sim/startup/units", "feet");
1557 } else if ( arg == "--units-meters" ) {
1558 fgSetString("/sim/startup/units", "meters");
1559 } else if ( arg.find( "--time-offset" ) == 0 ) {
1560 fgSetInt("/sim/startup/time-offset",
1561 parse_time_offset( (arg.substr(14)) ));
1562 fgSetString("/sim/startup/time-offset-type", "system-offset");
1563 } else if ( arg.find( "--time-match-real") == 0 ) {
1564 fgSetString("/sim/startup/time-offset-type", "system-offset");
1565 } else if ( arg.find( "--time-match-local") == 0 ) {
1566 fgSetString("/sim/startup/time-offset-type", "latitude-offset");
1567 } else if ( arg.find( "--start-date-sys=") == 0 ) {
1568 fgSetInt("/sim/startup/time-offset", parse_date((arg.substr(17))));
1569 fgSetString("/sim/startup/time-offset-type", "system");
1570 } else if ( arg.find( "--start-date-lat=") == 0 ) {
1571 fgSetInt("/sim/startup/time-offset", parse_date((arg.substr(17))));
1572 fgSetString("/sim/startup/time-offset-type", "latitude");
1573 } else if ( arg.find( "--start-date-gmt=") == 0 ) {
1574 fgSetInt("/sim/startup/time-offset", parse_date((arg.substr(17))));
1575 fgSetString("/sim/startup/time-offset-type", "gmt");
1576 } else if ( arg == "--hud-tris" ) {
1577 fgSetString("/sim/hud/frame-stat-type", "tris");
1578 } else if ( arg == "--hud-culled" ) {
1579 fgSetString("/sim/hud/frame-stat-type", "culled");
1580 } else if ( arg.find( "--atc610x" ) == 0 ) {
1581 add_channel( "atc610x", "dummy" );
1582 } else if ( arg.find( "--atlas=" ) == 0 ) {
1583 add_channel( "atlas", arg.substr(8) );
1585 } else if ( arg.find( "--multiplay=" ) == 0 ) {
1586 add_channel( "multiplay", arg.substr(12) );
1588 } else if ( arg.find( "--httpd=" ) == 0 ) {
1589 add_channel( "httpd", arg.substr(8) );
1590 #ifdef FG_JPEG_SERVER
1591 } else if ( arg.find( "--jpg-httpd=" ) == 0 ) {
1592 add_channel( "jpg-httpd", arg.substr(12) );
1594 } else if ( arg.find( "--native=" ) == 0 ) {
1595 add_channel( "native", arg.substr(9) );
1596 } else if ( arg.find( "--native-ctrls=" ) == 0 ) {
1597 add_channel( "native_ctrls", arg.substr(15) );
1598 } else if ( arg.find( "--native-fdm=" ) == 0 ) {
1599 add_channel( "native_fdm", arg.substr(13) );
1600 } else if ( arg.find( "--native-gui=" ) == 0 ) {
1601 add_channel( "native_gui", arg.substr(13) );
1602 } else if ( arg.find( "--opengc=" ) == 0 ) {
1604 // cout << "Adding channel for OpenGC Display" << endl; cin >> stop;
1605 add_channel( "opengc", arg.substr(9) );
1606 } else if ( arg.find( "--garmin=" ) == 0 ) {
1607 add_channel( "garmin", arg.substr(9) );
1608 } else if ( arg.find( "--nmea=" ) == 0 ) {
1609 add_channel( "nmea", arg.substr(7) );
1610 } else if ( arg.find( "--props=" ) == 0 ) {
1611 add_channel( "props", arg.substr(8) );
1612 } else if ( arg.find( "--telnet=" ) == 0 ) {
1613 add_channel( "telnet", arg.substr(9) );
1614 } else if ( arg.find( "--pve=" ) == 0 ) {
1615 add_channel( "pve", arg.substr(6) );
1616 } else if ( arg.find( "--ray=" ) == 0 ) {
1617 add_channel( "ray", arg.substr(6) );
1618 } else if ( arg.find( "--rul=" ) == 0 ) {
1619 add_channel( "rul", arg.substr(6) );
1620 } else if ( arg.find( "--joyclient=" ) == 0 ) {
1621 add_channel( "joyclient", arg.substr(12) );
1622 #ifdef FG_NETWORK_OLK
1623 } else if ( arg == "--disable-network-olk" ) {
1624 fgSetBool("/sim/networking/olk", false);
1625 } else if ( arg== "--enable-network-olk") {
1626 fgSetBool("/sim/networking/olk", true);
1627 } else if ( arg == "--net-hud" ) {
1628 fgSetBool("/sim/hud/net-display", true);
1629 net_hud_display = 1; // FIXME
1630 } else if ( arg.find( "--net-id=") == 0 ) {
1631 fgSetString("sim/networking/call-sign", arg.substr(9).c_str());
1634 #ifdef FG_MPLAYER_AS
1635 } else if ( arg.find( "--callsign=") == 0 ) {
1636 fgSetString("sim/multiplay/callsign", arg.substr(11).c_str());
1639 } else if ( arg.find( "--prop:" ) == 0 ) {
1640 string assign = arg.substr(7);
1641 string::size_type pos = assign.find('=');
1642 if ( pos == arg.npos || pos == 0 ) {
1643 SG_LOG( SG_GENERAL, SG_ALERT, "Bad property assignment: " << arg );
1644 return FG_OPTIONS_ERROR;
1646 string name = assign.substr(0, pos);
1647 string value = assign.substr(pos + 1);
1648 fgSetString(name.c_str(), value.c_str());
1649 // SG_LOG(SG_GENERAL, SG_INFO, "Setting default value of property "
1650 // << name << " to \"" << value << '"');
1651 } else if ( arg.find("--trace-read=") == 0) {
1652 string name = arg.substr(13);
1653 SG_LOG(SG_GENERAL, SG_INFO, "Tracing reads for property " << name);
1654 fgGetNode(name.c_str(), true)
1655 ->setAttribute(SGPropertyNode::TRACE_READ, true);
1656 } else if ( arg.find("--trace-write=") == 0) {
1657 string name = arg.substr(14);
1658 SG_LOG(SG_GENERAL, SG_INFO, "Tracing writes for property " << name);
1659 fgGetNode(name.c_str(), true)
1660 ->setAttribute(SGPropertyNode::TRACE_WRITE, true);
1661 } else if ( arg.find("--log-level=") == 0) {
1662 int level = atoi(arg.substr(14));
1663 sglog().setLogLevels( SG_ALL, level );
1664 } else if ( arg.find( "--view-offset=" ) == 0 ) {
1665 // $$$ begin - added VS Renganathan, 14 Oct 2K
1666 // for multi-window outside window imagery
1667 string woffset = arg.substr( 14 );
1668 double default_view_offset = 0.0;
1669 if ( woffset == "LEFT" ) {
1670 default_view_offset = SGD_PI * 0.25;
1671 } else if ( woffset == "RIGHT" ) {
1672 default_view_offset = SGD_PI * 1.75;
1673 } else if ( woffset == "CENTER" ) {
1674 default_view_offset = 0.00;
1676 default_view_offset = atof( woffset.c_str() ) * SGD_DEGREES_TO_RADIANS;
1678 /* apparently not used (CLO, 11 Jun 2002)
1679 FGViewer *pilot_view =
1680 (FGViewer *)globals->get_viewmgr()->get_view( 0 ); */
1681 // this will work without calls to the viewer...
1682 fgSetDouble( "/sim/current-view/heading-offset-deg",
1683 default_view_offset * SGD_RADIANS_TO_DEGREES );
1684 // $$$ end - added VS Renganathan, 14 Oct 2K
1685 } else if ( arg.find( "--visibility=" ) == 0 ) {
1686 fgSetDouble("/environment/visibility-m", atof(arg.substr(13)));
1687 } else if ( arg.find( "--visibility-miles=" ) == 0 ) {
1688 double visibility = atof(arg.substr(19)) * 5280.0 * SG_FEET_TO_METER;
1689 fgSetDouble("/environment/visibility-m", visibility);
1690 } else if ( arg.find( "--random-wind" ) == 0 ) {
1691 double min_hdg = sg_random() * 360.0;
1692 double max_hdg = min_hdg + (20 - sqrt(sg_random() * 400));
1693 double speed = 40 - sqrt(sg_random() * 1600.0);
1694 double gust = speed + (10 - sqrt(sg_random() * 100));
1695 setup_wind(min_hdg, max_hdg, speed, gust);
1696 } else if ( arg.find( "--wind=" ) == 0 ) {
1697 double min_hdg, max_hdg, speed, gust;
1698 if (!parse_wind(arg.substr(7), &min_hdg, &max_hdg, &speed, &gust)) {
1699 SG_LOG( SG_GENERAL, SG_ALERT, "bad wind value " << arg.substr(7) );
1700 return FG_OPTIONS_ERROR;
1702 setup_wind(min_hdg, max_hdg, speed, gust);
1703 } else if ( arg.find( "--wp=" ) == 0 ) {
1704 parse_wp( arg.substr( 5 ) );
1705 } else if ( arg.find( "--flight-plan=") == 0) {
1706 parse_flightplan ( arg.substr (14) );
1707 } else if ( arg.find( "--config=" ) == 0 ) {
1708 string file = arg.substr(9);
1710 readProperties(file, globals->get_props());
1711 } catch (const sg_exception &e) {
1712 string message = "Error loading config file: ";
1713 message += e.getFormattedMessage();
1714 SG_LOG(SG_INPUT, SG_ALERT, message);
1717 } else if ( arg.find( "--aircraft=" ) == 0 ) {
1718 fgSetString("/sim/aircraft", arg.substr(11).c_str());
1720 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" );
1721 return FG_OPTIONS_ERROR;
1725 return FG_OPTIONS_OK;
1729 // Parse the command line options
1731 fgParseArgs (int argc, char **argv)
1733 bool in_options = true;
1734 bool verbose = false;
1737 SG_LOG(SG_GENERAL, SG_INFO, "Processing command line arguments");
1739 for (int i = 1; i < argc; i++) {
1740 string arg = argv[i];
1742 if (in_options && (arg.find('-') == 0)) {
1746 int result = parse_option(arg);
1747 if ((result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR))
1750 else if (result == FG_OPTIONS_VERBOSE_HELP)
1753 else if (result == FG_OPTIONS_SHOW_AIRCRAFT) {
1760 SG_LOG(SG_GENERAL, SG_INFO,
1761 "Reading command-line property file " << arg);
1762 readProperties(arg, globals->get_props());
1771 SG_LOG(SG_GENERAL, SG_INFO, "Finished command line arguments");
1775 // Parse config file options
1777 fgParseOptions (const string& path) {
1778 sg_gzifstream in( path );
1779 if ( !in.is_open() ) {
1783 SG_LOG( SG_GENERAL, SG_INFO, "Processing config file: " << path );
1787 while ( ! in.eof() ) {
1790 while ( in.get(c) && c != '\0' ) {
1795 #if defined( macintosh )
1796 getline( in, line, '\r' );
1798 getline( in, line, '\n' );
1801 // catch extraneous (DOS) line ending character
1802 if ( line[line.length() - 1] < 32 ) {
1803 line = line.substr( 0, line.length()-1 );
1806 if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
1807 cerr << endl << "Config file parse error: " << path << " '"
1808 << line << "'" << endl;
1817 // Print usage message
1819 fgUsage (bool verbose)
1821 SGPropertyNode *locale = globals->get_locale();
1823 SGPropertyNode options_root;
1828 fgLoadProps("options.xml", &options_root);
1829 } catch (const sg_exception &ex) {
1830 cout << "Unable to read the help file." << endl;
1831 cout << "Make sure the file options.xml is located in the FlightGear base directory," << endl;
1832 cout << "and the location of the base directory is specified by setting $FG_ROOT or" << endl;
1833 cout << "by adding --fg-root=path as a program argument." << endl;
1838 SGPropertyNode *options = options_root.getNode("options");
1840 SG_LOG( SG_GENERAL, SG_ALERT,
1841 "Error reading options.xml: <options> directive not found." );
1845 SGPropertyNode *usage = locale->getNode(options->getStringValue("usage"));
1847 cout << "Usage: " << usage->getStringValue() << endl;
1850 vector<SGPropertyNode_ptr>section = options->getChildren("section");
1851 for (unsigned int j = 0; j < section.size(); j++) {
1854 vector<SGPropertyNode_ptr>option = section[j]->getChildren("option");
1855 for (unsigned int k = 0; k < option.size(); k++) {
1857 SGPropertyNode *name = option[k]->getNode("name");
1858 SGPropertyNode *short_name = option[k]->getNode("short");
1859 SGPropertyNode *key = option[k]->getNode("key");
1860 SGPropertyNode *arg = option[k]->getNode("arg");
1861 bool brief = option[k]->getNode("brief");
1863 if ((brief || verbose) && name) {
1864 string tmp = name->getStringValue();
1868 tmp.append(key->getStringValue());
1872 tmp.append(arg->getStringValue());
1876 tmp.append(short_name->getStringValue());
1880 if (tmp.size() <= 25) {
1881 snprintf(cstr, 96, " --%-27s", tmp.c_str());
1883 snprintf(cstr, 96, "\n --%s\n%32c", tmp.c_str(), ' ');
1886 // There may be more than one <description> tag assosiated
1890 vector<SGPropertyNode_ptr>desc =
1891 option[k]->getChildren("description");
1893 if (desc.size() > 0) {
1894 for ( unsigned int l = 0; l < desc.size(); l++) {
1896 // There may be more than one translation line.
1898 string t = desc[l]->getStringValue();
1899 SGPropertyNode *n = locale->getNode("strings");
1900 vector<SGPropertyNode_ptr>trans_desc =
1901 n->getChildren(t.substr(8).c_str());
1903 for ( unsigned int m = 0; m < trans_desc.size(); m++ ) {
1904 string t_str = trans_desc[m]->getStringValue();
1906 if ((m > 0) || ((l > 0) && m == 0)) {
1907 snprintf(cstr, 96, "%32c", ' ');
1912 // If the string is too large to fit on the screen,
1913 // then split it up in several pieces.
1915 while ( t_str.size() > 47 ) {
1917 unsigned int m = t_str.rfind(' ', 47);
1918 msg += t_str.substr(0, m);
1919 snprintf(cstr, 96, "\n%32c", ' ');
1922 t_str.erase(t_str.begin(), t_str.begin() + m + 1);
1924 msg += t_str + '\n';
1931 SGPropertyNode *name =
1932 locale->getNode(section[j]->getStringValue("name"));
1934 if (!msg.empty() && name) {
1935 cout << endl << name->getStringValue() << ":" << endl;
1943 cout << "For a complete list of options use --help --verbose" << endl;
1947 // Show available aircraft types
1948 void fgShowAircraft(void) {
1949 vector<string> aircraft;
1951 SGPath path( globals->get_fg_root() );
1952 path.append("Aircraft");
1957 dirp = ulOpenDir(path.c_str());
1959 cerr << "Unable to open aircraft directory." << endl;
1963 while ((dire = ulReadDir(dirp)) != NULL) {
1966 if ((ptr = strstr(dire->d_name, "-set.xml")) && ptr[8] == '\0' ) {
1967 SGPath afile = path;
1968 afile.append(dire->d_name);
1972 SGPropertyNode root;
1974 readProperties(afile.str(), &root);
1979 SGPropertyNode *desc = NULL;
1980 SGPropertyNode *node = root.getNode("sim");
1982 desc = node->getNode("description");
1986 if (strlen(dire->d_name) <= 27)
1987 snprintf(cstr, 96, " %-27s %s", dire->d_name,
1988 (desc) ? desc->getStringValue() : "" );
1991 snprintf(cstr, 96, " %-27s\n%32c%s", dire->d_name, ' ',
1992 (desc) ? desc->getStringValue() : "" );
1994 aircraft.push_back(cstr);
1998 sort(aircraft.begin(), aircraft.end());
1999 cout << "Available aircraft:" << endl;
2000 for ( unsigned int i = 0; i < aircraft.size(); i++ ) {
2001 cout << aircraft[i] << endl;