1 // options.cxx -- class to handle command line options
3 // Written by Curtis Olson, started April 1998.
5 // Copyright (C) 1998 Curtis L. Olson - http://www.flightgear.org/~curt
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28 #include <simgear/compiler.h>
29 #include <simgear/structure/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/scene/material/mat.hxx>
47 // #include <Include/general.hxx>
48 // #include <Airports/simple.hxx>
49 // #include <Cockpit/cockpit.hxx>
50 // #include <FDM/flight.hxx>
52 #include <Autopilot/route_mgr.hxx>
55 #include "globals.hxx"
56 #include "fg_init.hxx"
57 #include "fg_props.hxx"
58 #include "options.hxx"
60 #include "viewmgr.hxx"
65 SG_USING_NAMESPACE(std);
68 #define VERSION "CVS "__DATE__
71 #define NEW_DEFAULT_MODEL_HZ 120
79 FG_OPTIONS_VERBOSE_HELP = 4,
80 FG_OPTIONS_SHOW_AIRCRAFT = 5
84 atof( const string& str )
88 // -dw- if ::atof is called, then we get an infinite loop
89 return std::atof( str.c_str() );
91 return ::atof( str.c_str() );
96 atoi( const string& str )
99 // -dw- if ::atoi is called, then we get an infinite loop
100 return std::atoi( str.c_str() );
102 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", 9999.0);
134 fgSetDouble("/orientation/roll-deg", 0.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", 9999.0);
153 fgSetDouble("/sim/presets/roll-deg", 0.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", "webrun.bat");
180 #elif defined(__APPLE__)
181 fgSetString("/sim/startup/browser-app", "open");
183 fgSetString("/sim/startup/browser-app", "launchWebJumper");
185 envp = ::getenv( "WEBBROWSER" );
186 if (!envp) envp = "netscape";
187 fgSetString("/sim/startup/browser-app", envp);
189 fgSetString("/sim/logging/priority", "alert");
192 fgSetBool("/sim/hud/color/antialiased", false);
193 fgSetBool("/sim/hud/enable3d", true);
194 fgSetBool("/sim/hud/visibility", false);
195 fgSetBool("/sim/panel/visibility", true);
196 fgSetBool("/sim/sound/pause", false);
198 // Flight Model options
199 fgSetString("/sim/flight-model", "jsb");
200 fgSetString("/sim/aero", "c172");
201 fgSetInt("/sim/model-hz", NEW_DEFAULT_MODEL_HZ);
202 fgSetInt("/sim/speed-up", 1);
205 fgSetString("/sim/rendering/fog", "nicest");
206 fgSetBool("/environment/clouds/status", true);
207 fgSetBool("/sim/startup/fullscreen", false);
208 fgSetBool("/sim/rendering/shading", true);
209 fgSetBool("/sim/rendering/skyblend", true);
210 fgSetBool("/sim/rendering/textures", true);
211 fgTie( "/sim/rendering/filtering", SGGetTextureFilter, SGSetTextureFilter, false);
212 fgSetInt("/sim/rendering/filtering", 1);
213 fgSetBool("/sim/rendering/wireframe", false);
214 fgSetBool("/sim/rendering/horizon-effect", false);
215 fgSetBool("/sim/rendering/enhanced-lighting", false);
216 fgSetBool("/sim/rendering/distance-attenuation", false);
217 fgSetBool("/sim/rendering/specular-highlight", true);
218 fgSetInt("/sim/startup/xsize", 800);
219 fgSetInt("/sim/startup/ysize", 600);
220 fgSetInt("/sim/rendering/bits-per-pixel", 16);
221 fgSetString("/sim/view-mode", "pilot");
222 fgSetDouble("/sim/current-view/heading-offset-deg", 0);
225 fgSetString("/sim/startup/units", "feet");
226 fgSetString("/sim/hud/frame-stat-type", "tris");
229 fgSetInt("/sim/startup/time-offset", 0);
230 fgSetString("/sim/startup/time-offset-type", "system-offset");
231 fgSetLong("/sim/time/cur-time-override", 0);
234 fgSetBool("/sim/freeze/master", false);
235 fgSetBool("/sim/freeze/position", false);
236 fgSetBool("/sim/freeze/clock", false);
237 fgSetBool("/sim/freeze/fuel", false);
239 fgSetString("/sim/multiplay/callsign", "callsign");
240 fgSetString("/sim/multiplay/rxhost", "0");
241 fgSetString("/sim/multiplay/txhost", "0");
242 fgSetInt("/sim/multiplay/rxport", 0);
243 fgSetInt("/sim/multiplay/txport", 0);
247 parse_wind (const string &wind, double * min_hdg, double * max_hdg,
248 double * speed, double * gust)
250 string::size_type pos = wind.find('@');
251 if (pos == string::npos)
253 string dir = wind.substr(0, pos);
254 string spd = wind.substr(pos+1);
256 if (pos == string::npos) {
257 *min_hdg = *max_hdg = atof(dir.c_str());
259 *min_hdg = atof(dir.substr(0,pos).c_str());
260 *max_hdg = atof(dir.substr(pos+1).c_str());
263 if (pos == string::npos) {
264 *speed = *gust = atof(spd.c_str());
266 *speed = atof(spd.substr(0,pos).c_str());
267 *gust = atof(spd.substr(pos+1).c_str());
272 // parse a time string ([+/-]%f[:%f[:%f]]) into hours
274 parse_time(const string& time_in) {
275 char *time_str, num[256];
276 double hours, minutes, seconds;
281 time_str = (char *)time_in.c_str();
283 // printf("parse_time(): %s\n", time_str);
286 if ( strlen(time_str) ) {
287 if ( time_str[0] == '+' ) {
290 } else if ( time_str[0] == '-' ) {
295 // printf("sign = %d\n", sign);
298 if ( strlen(time_str) ) {
300 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
301 num[i] = time_str[0];
305 if ( time_str[0] == ':' ) {
310 // printf("hours = %.2lf\n", hours);
316 if ( strlen(time_str) ) {
318 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
319 num[i] = time_str[0];
323 if ( time_str[0] == ':' ) {
328 // printf("minutes = %.2lf\n", minutes);
330 result += minutes / 60.0;
334 if ( strlen(time_str) ) {
336 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
337 num[i] = time_str[0];
343 // printf("seconds = %.2lf\n", seconds);
345 result += seconds / 3600.0;
348 SG_LOG( SG_GENERAL, SG_INFO, " parse_time() = " << sign * result );
350 return(sign * result);
354 // parse a date string (yyyy:mm:dd:hh:mm:ss) into a time_t (seconds)
356 parse_date( const string& date)
359 char * date_str, num[256];
361 // initialize to zero
368 gmt.tm_isdst = 0; // ignore daylight savings time for the moment
369 date_str = (char *)date.c_str();
371 if ( strlen(date_str) ) {
373 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
374 num[i] = date_str[0];
378 if ( date_str[0] == ':' ) {
382 gmt.tm_year = atoi(num) - 1900;
385 if ( strlen(date_str) ) {
387 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
388 num[i] = date_str[0];
392 if ( date_str[0] == ':' ) {
396 gmt.tm_mon = atoi(num) -1;
399 if ( strlen(date_str) ) {
401 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
402 num[i] = date_str[0];
406 if ( date_str[0] == ':' ) {
410 gmt.tm_mday = atoi(num);
413 if ( strlen(date_str) ) {
415 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
416 num[i] = date_str[0];
420 if ( date_str[0] == ':' ) {
424 gmt.tm_hour = atoi(num);
427 if ( strlen(date_str) ) {
429 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
430 num[i] = date_str[0];
434 if ( date_str[0] == ':' ) {
438 gmt.tm_min = atoi(num);
441 if ( strlen(date_str) ) {
443 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
444 num[i] = date_str[0];
448 if ( date_str[0] == ':' ) {
452 gmt.tm_sec = atoi(num);
454 time_t theTime = sgTimeGetGMT( gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
455 gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
456 //printf ("Date is %s\n", ctime(&theTime));
457 //printf ("in seconds that is %d\n", theTime);
463 // parse angle in the form of [+/-]ddd:mm:ss into degrees
465 parse_degree( const string& degree_str) {
466 double result = parse_time( degree_str );
468 // printf("Degree = %.4f\n", result);
474 // parse time offset string into seconds
476 parse_time_offset( const string& time_str) {
479 // printf("time offset = %s\n", time_str);
482 result = (int)rint(parse_time(time_str) * 3600.0);
484 result = (int)(parse_time(time_str) * 3600.0);
487 // printf("parse_time_offset(): %d\n", result);
493 // Parse --fov=x.xx type option
495 parse_fov( const string& arg ) {
496 double fov = atof(arg);
498 if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
499 if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
501 fgSetDouble("/sim/view[0]/config/default-field-of-view-deg", fov);
503 // printf("parse_fov(): result = %.4f\n", fov);
509 // Parse I/O channel option
511 // Format is "--protocol=medium,direction,hz,medium_options,..."
513 // protocol = { native, nmea, garmin, AV400, fgfs, rul, pve, etc. }
514 // medium = { serial, socket, file, etc. }
515 // direction = { in, out, bi }
516 // hz = number of times to process channel per second (floating
517 // point values are ok.
519 // Serial example "--nmea=serial,dir,hz,device,baud" where
521 // device = OS device name of serial line to be open()'ed
522 // baud = {300, 1200, 2400, ..., 230400}
524 // Socket exacmple "--native=socket,dir,hz,machine,port,style" where
526 // machine = machine name or ip address if client (leave empty if server)
527 // port = port, leave empty to let system choose
528 // style = tcp or udp
530 // File example "--garmin=file,dir,hz,filename" where
532 // filename = file system file name
535 add_channel( const string& type, const string& channel_str ) {
536 SG_LOG(SG_GENERAL, SG_INFO, "Channel string = " << channel_str );
537 globals->get_channel_options_list()->push_back( type + "," + channel_str );
542 // The parse wp and parse flight-plan options don't work anymore, because
543 // the route manager and the airport subsystems have not yet been initialized
546 // Parse --wp=ID[@alt]
548 parse_wp( const string& arg ) {
549 string_list *waypoints = globals->get_initial_waypoints();
551 waypoints = new string_list;
552 globals->set_initial_waypoints(waypoints);
554 waypoints->push_back(arg);
558 // Parse --flight-plan=[file]
560 parse_flightplan(const string& arg)
562 string_list *waypoints = globals->get_initial_waypoints();
564 waypoints = new string_list;
565 globals->set_initial_waypoints(waypoints);
568 sg_gzifstream in(arg.c_str());
575 #if defined( macintosh )
576 getline( in, line, '\r' );
578 getline( in, line, '\n' );
580 // catch extraneous (DOS) line ending character
581 if ( line[line.length() - 1] < 32 )
582 line = line.substr( 0, line.length()-1 );
587 waypoints->push_back(line);
594 fgOptLanguage( const char *arg )
596 globals->set_locale( fgInitLocale( arg ) );
597 return FG_OPTIONS_OK;
603 fgSetString("/sim/presets/airport-id", "");
604 fgSetString("/sim/presets/vor-id", "");
605 fgSetString("/sim/presets/ndb-id", "");
606 fgSetString("/sim/presets/carrier", "");
607 fgSetString("/sim/presets/parkpos", "");
608 fgSetString("/sim/presets/fix", "");
612 fgOptVOR( const char * arg )
615 fgSetString("/sim/presets/vor-id", arg);
616 return FG_OPTIONS_OK;
620 fgOptNDB( const char * arg )
623 fgSetString("/sim/presets/ndb-id", arg);
624 return FG_OPTIONS_OK;
628 fgOptCarrier( const char * arg )
631 fgSetString("/sim/presets/carrier", arg);
632 return FG_OPTIONS_OK;
636 fgOptParkpos( const char * arg )
638 fgSetString("/sim/presets/parkpos", arg);
639 return FG_OPTIONS_OK;
643 fgOptFIX( const char * arg )
646 fgSetString("/sim/presets/fix", arg);
647 return FG_OPTIONS_OK;
651 fgOptLon( const char *arg )
654 fgSetDouble("/sim/presets/longitude-deg", parse_degree( arg ));
655 fgSetDouble("/position/longitude-deg", parse_degree( arg ));
656 return FG_OPTIONS_OK;
660 fgOptLat( const char *arg )
663 fgSetDouble("/sim/presets/latitude-deg", parse_degree( arg ));
664 fgSetDouble("/position/latitude-deg", parse_degree( arg ));
665 return FG_OPTIONS_OK;
669 fgOptAltitude( const char *arg )
671 fgSetBool("/sim/presets/onground", false);
672 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
673 fgSetDouble("/sim/presets/altitude-ft", atof( arg ));
675 fgSetDouble("/sim/presets/altitude-ft",
676 atof( arg ) * SG_METER_TO_FEET);
677 return FG_OPTIONS_OK;
681 fgOptUBody( const char *arg )
683 fgSetString("/sim/presets/speed-set", "UVW");
684 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
685 fgSetDouble("/sim/presets/uBody-fps", atof( arg ));
687 fgSetDouble("/sim/presets/uBody-fps",
688 atof( arg ) * SG_METER_TO_FEET);
689 return FG_OPTIONS_OK;
693 fgOptVBody( const char *arg )
695 fgSetString("/sim/presets/speed-set", "UVW");
696 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
697 fgSetDouble("/sim/presets/vBody-fps", atof( arg ));
699 fgSetDouble("/sim/presets/vBody-fps",
700 atof( arg ) * SG_METER_TO_FEET);
701 return FG_OPTIONS_OK;
705 fgOptWBody( const char *arg )
707 fgSetString("/sim/presets/speed-set", "UVW");
708 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
709 fgSetDouble("/sim/presets/wBody-fps", atof(arg));
711 fgSetDouble("/sim/presets/wBody-fps",
712 atof(arg) * SG_METER_TO_FEET);
713 return FG_OPTIONS_OK;
717 fgOptVNorth( const char *arg )
719 fgSetString("/sim/presets/speed-set", "NED");
720 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
721 fgSetDouble("/sim/presets/speed-north-fps", atof( arg ));
723 fgSetDouble("/sim/presets/speed-north-fps",
724 atof( arg ) * SG_METER_TO_FEET);
725 return FG_OPTIONS_OK;
729 fgOptVEast( const char *arg )
731 fgSetString("/sim/presets/speed-set", "NED");
732 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
733 fgSetDouble("/sim/presets/speed-east-fps", atof(arg));
735 fgSetDouble("/sim/presets/speed-east-fps",
736 atof(arg) * SG_METER_TO_FEET);
737 return FG_OPTIONS_OK;
741 fgOptVDown( const char *arg )
743 fgSetString("/sim/presets/speed-set", "NED");
744 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
745 fgSetDouble("/sim/presets/speed-down-fps", atof(arg));
747 fgSetDouble("/sim/presets/speed-down-fps",
748 atof(arg) * SG_METER_TO_FEET);
749 return FG_OPTIONS_OK;
753 fgOptVc( const char *arg )
755 // fgSetString("/sim/presets/speed-set", "knots");
756 // fgSetDouble("/velocities/airspeed-kt", atof(arg.substr(5)));
757 fgSetString("/sim/presets/speed-set", "knots");
758 fgSetDouble("/sim/presets/airspeed-kt", atof(arg));
759 return FG_OPTIONS_OK;
763 fgOptMach( const char *arg )
765 fgSetString("/sim/presets/speed-set", "mach");
766 fgSetDouble("/sim/presets/mach", atof(arg));
767 return FG_OPTIONS_OK;
771 fgOptRoc( const char *arg )
773 fgSetDouble("/velocities/vertical-speed-fps", atof(arg)/60);
774 return FG_OPTIONS_OK;
778 fgOptFgRoot( const char *arg )
780 globals->set_fg_root(arg);
781 return FG_OPTIONS_OK;
785 fgOptFgScenery( const char *arg )
787 globals->set_fg_scenery(arg);
788 return FG_OPTIONS_OK;
792 fgOptFov( const char *arg )
795 return FG_OPTIONS_OK;
799 fgOptGeometry( const char *arg )
801 bool geometry_ok = true;
802 int xsize = 0, ysize = 0;
803 string geometry = arg;
804 string::size_type i = geometry.find('x');
806 if (i != string::npos) {
807 xsize = atoi(geometry.substr(0, i));
808 ysize = atoi(geometry.substr(i+1));
813 if ( xsize <= 0 || ysize <= 0 ) {
819 if ( !geometry_ok ) {
820 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown geometry: " << geometry );
821 SG_LOG( SG_GENERAL, SG_ALERT,
822 "Setting geometry to " << xsize << 'x' << ysize << '\n');
824 SG_LOG( SG_GENERAL, SG_INFO,
825 "Setting geometry to " << xsize << 'x' << ysize << '\n');
826 fgSetInt("/sim/startup/xsize", xsize);
827 fgSetInt("/sim/startup/ysize", ysize);
829 return FG_OPTIONS_OK;
833 fgOptBpp( const char *arg )
835 string bits_per_pix = arg;
836 if ( bits_per_pix == "16" ) {
837 fgSetInt("/sim/rendering/bits-per-pixel", 16);
838 } else if ( bits_per_pix == "24" ) {
839 fgSetInt("/sim/rendering/bits-per-pixel", 24);
840 } else if ( bits_per_pix == "32" ) {
841 fgSetInt("/sim/rendering/bits-per-pixel", 32);
843 SG_LOG(SG_GENERAL, SG_ALERT, "Unsupported bpp " << bits_per_pix);
845 return FG_OPTIONS_OK;
849 fgOptTimeOffset( const char *arg )
851 fgSetInt("/sim/startup/time-offset",
852 parse_time_offset( arg ));
853 fgSetString("/sim/startup/time-offset-type", "system-offset");
854 return FG_OPTIONS_OK;
858 fgOptStartDateSys( const char *arg )
860 fgSetInt("/sim/startup/time-offset", parse_date( arg ) );
861 fgSetString("/sim/startup/time-offset-type", "system");
862 return FG_OPTIONS_OK;
866 fgOptStartDateLat( const char *arg )
868 fgSetInt("/sim/startup/time-offset", parse_date( arg ) );
869 fgSetString("/sim/startup/time-offset-type", "latitude");
870 return FG_OPTIONS_OK;
874 fgOptStartDateGmt( const char *arg )
876 fgSetInt("/sim/startup/time-offset", parse_date( arg ) );
877 fgSetString("/sim/startup/time-offset-type", "gmt");
878 return FG_OPTIONS_OK;
882 fgSetupProxy( const char *arg )
884 string options = arg;
885 string host, port, auth;
886 string::size_type pos;
888 host = port = auth = "";
889 if ((pos = options.find("@")) != string::npos)
890 auth = options.substr(0, pos++);
894 host = options.substr(pos, options.size());
895 if ((pos = host.find(":")) != string::npos) {
896 port = host.substr(++pos, host.size());
897 host.erase(--pos, host.size());
900 fgSetString("/sim/presets/proxy/host", host.c_str());
901 fgSetString("/sim/presets/proxy/port", port.c_str());
902 fgSetString("/sim/presets/proxy/authentication", auth.c_str());
904 return FG_OPTIONS_OK;
908 fgOptTraceRead( const char *arg )
911 SG_LOG(SG_GENERAL, SG_INFO, "Tracing reads for property " << name);
912 fgGetNode(name.c_str(), true)
913 ->setAttribute(SGPropertyNode::TRACE_READ, true);
914 return FG_OPTIONS_OK;
918 fgOptLogLevel( const char *arg )
920 fgSetString("/sim/logging/classes", "all");
921 fgSetString("/sim/logging/priority", arg);
923 string priority = arg;
924 logbuf::set_log_classes(SG_ALL);
925 if (priority == "bulk") {
926 logbuf::set_log_priority(SG_BULK);
927 } else if (priority == "debug") {
928 logbuf::set_log_priority(SG_DEBUG);
929 } else if (priority == "info") {
930 logbuf::set_log_priority(SG_INFO);
931 } else if (priority == "warn") {
932 logbuf::set_log_priority(SG_WARN);
933 } else if (priority == "alert") {
934 logbuf::set_log_priority(SG_ALERT);
936 SG_LOG(SG_GENERAL, SG_WARN, "Unknown logging priority " << priority);
938 SG_LOG(SG_GENERAL, SG_DEBUG, "Logging priority is " << priority);
940 return FG_OPTIONS_OK;
945 fgOptTraceWrite( const char *arg )
948 SG_LOG(SG_GENERAL, SG_INFO, "Tracing writes for property " << name);
949 fgGetNode(name.c_str(), true)
950 ->setAttribute(SGPropertyNode::TRACE_WRITE, true);
951 return FG_OPTIONS_OK;
955 fgOptViewOffset( const char *arg )
957 // $$$ begin - added VS Renganathan, 14 Oct 2K
958 // for multi-window outside window imagery
959 string woffset = arg;
960 double default_view_offset = 0.0;
961 if ( woffset == "LEFT" ) {
962 default_view_offset = SGD_PI * 0.25;
963 } else if ( woffset == "RIGHT" ) {
964 default_view_offset = SGD_PI * 1.75;
965 } else if ( woffset == "CENTER" ) {
966 default_view_offset = 0.00;
968 default_view_offset = atof( woffset.c_str() ) * SGD_DEGREES_TO_RADIANS;
970 /* apparently not used (CLO, 11 Jun 2002)
971 FGViewer *pilot_view =
972 (FGViewer *)globals->get_viewmgr()->get_view( 0 ); */
973 // this will work without calls to the viewer...
974 fgSetDouble( "/sim/current-view/heading-offset-deg",
975 default_view_offset * SGD_RADIANS_TO_DEGREES );
976 // $$$ end - added VS Renganathan, 14 Oct 2K
977 return FG_OPTIONS_OK;
981 fgOptVisibilityMeters( const char *arg )
983 double visibility = atof( arg );
984 fgDefaultWeatherValue("visibility-m", visibility);
985 return FG_OPTIONS_OK;
989 fgOptVisibilityMiles( const char *arg )
991 double visibility = atof( arg ) * 5280.0 * SG_FEET_TO_METER;
992 fgDefaultWeatherValue("visibility-m", visibility);
993 return FG_OPTIONS_OK;
997 fgOptRandomWind( const char *arg )
999 double min_hdg = sg_random() * 360.0;
1000 double max_hdg = min_hdg + (20 - sqrt(sg_random() * 400));
1001 double speed = sg_random() * sg_random() * 40;
1002 double gust = speed + (10 - sqrt(sg_random() * 100));
1003 fgSetupWind(min_hdg, max_hdg, speed, gust);
1004 return FG_OPTIONS_OK;
1008 fgOptWind( const char *arg )
1010 double min_hdg, max_hdg, speed, gust;
1011 if (!parse_wind( arg, &min_hdg, &max_hdg, &speed, &gust)) {
1012 SG_LOG( SG_GENERAL, SG_ALERT, "bad wind value " << arg );
1013 return FG_OPTIONS_ERROR;
1015 fgSetupWind(min_hdg, max_hdg, speed, gust);
1016 return FG_OPTIONS_OK;
1020 fgOptTurbulence( const char *arg )
1022 fgDefaultWeatherValue("turbulence/magnitude-norm", atof(arg));
1023 return FG_OPTIONS_OK;
1027 fgOptCeiling( const char *arg )
1029 double elevation, thickness;
1031 string::size_type pos = spec.find(':');
1032 if (pos == string::npos) {
1033 elevation = atof(spec.c_str());
1036 elevation = atof(spec.substr(0, pos).c_str());
1037 thickness = atof(spec.substr(pos + 1).c_str());
1039 fgSetDouble("/environment/clouds/layer[0]/elevation-ft", elevation);
1040 fgSetDouble("/environment/clouds/layer[0]/thickness-ft", thickness);
1041 fgSetString("/environment/clouds/layer[0]/coverage", "overcast");
1042 return FG_OPTIONS_OK;
1046 fgOptWp( const char *arg )
1049 return FG_OPTIONS_OK;
1053 fgOptFlightPlan( const char *arg )
1055 parse_flightplan ( arg );
1056 return FG_OPTIONS_OK;
1060 fgOptConfig( const char *arg )
1064 readProperties(file, globals->get_props());
1065 } catch (const sg_exception &e) {
1066 string message = "Error loading config file: ";
1067 message += e.getFormattedMessage() + e.getOrigin();
1068 SG_LOG(SG_INPUT, SG_ALERT, message);
1071 return FG_OPTIONS_OK;
1075 parse_colon (const string &s, double * val1, double * val2)
1077 string::size_type pos = s.find(':');
1078 if (pos == string::npos) {
1082 *val1 = atof(s.substr(0, pos).c_str());
1083 *val2 = atof(s.substr(pos+1).c_str());
1090 fgOptFailure( const char * arg )
1094 fgSetBool("/systems/pitot/serviceable", false);
1095 } else if (a == "static") {
1096 fgSetBool("/systems/static/serviceable", false);
1097 } else if (a == "vacuum") {
1098 fgSetBool("/systems/vacuum/serviceable", false);
1099 } else if (a == "electrical") {
1100 fgSetBool("/systems/electrical/serviceable", false);
1102 SG_LOG(SG_INPUT, SG_ALERT, "Unknown failure mode: " << a);
1103 return FG_OPTIONS_ERROR;
1106 return FG_OPTIONS_OK;
1111 fgOptNAV1( const char * arg )
1113 double radial, freq;
1114 if (parse_colon(arg, &radial, &freq))
1115 fgSetDouble("/instrumentation/nav[0]/radials/selected-deg", radial);
1116 fgSetDouble("/instrumentation/nav[0]/frequencies/selected-mhz", freq);
1117 return FG_OPTIONS_OK;
1121 fgOptNAV2( const char * arg )
1123 double radial, freq;
1124 if (parse_colon(arg, &radial, &freq))
1125 fgSetDouble("/instrumentation/nav[1]/radials/selected-deg", radial);
1126 fgSetDouble("/instrumentation/nav[1]/frequencies/selected-mhz", freq);
1127 return FG_OPTIONS_OK;
1131 fgOptADF( const char * arg )
1134 if (parse_colon(arg, &rot, &freq))
1135 fgSetDouble("/instrumentation/adf/rotation-deg", rot);
1136 fgSetDouble("/instrumentation/adf/frequencies/selected-khz", freq);
1137 return FG_OPTIONS_OK;
1141 fgOptDME( const char *arg )
1144 if (opt == "nav1") {
1145 fgSetInt("/instrumentation/dme/switch-position", 1);
1146 fgSetString("/instrumentation/dme/frequencies/source",
1147 "/instrumentation/nav[0]/frequencies/selected-mhz");
1148 } else if (opt == "nav2") {
1149 fgSetInt("/instrumentation/dme/switch-position", 3);
1150 fgSetString("/instrumentation/dme/frequencies/source",
1151 "/instrumentation/nav[1]/frequencies/selected-mhz");
1153 fgSetInt("/instrumentation/dme/switch-position", 2);
1154 fgSetString("/instrumentation/dme/frequencies/source",
1155 "/instrumentation/dme/frequencies/selected-mhz");
1156 fgSetString("/instrumentation/dme/frequencies/selected-mhz", arg);
1158 return FG_OPTIONS_OK;
1162 fgOptLivery( const char *arg )
1165 string livery_path = "livery/" + opt;
1166 fgSetString("/sim/model/texture-path", livery_path.c_str() );
1167 return FG_OPTIONS_OK;
1171 fgOptScenario( const char *arg )
1173 SGPropertyNode_ptr ai_node = fgGetNode( "/sim/ai", true );
1174 vector<SGPropertyNode_ptr> scenarii = ai_node->getChildren( "scenario" );
1176 for ( size_t i = 0; i < scenarii.size(); ++i ) {
1177 int ind = scenarii[i]->getIndex();
1178 if ( index < ind ) {
1182 SGPropertyNode_ptr scenario = ai_node->getNode( "scenario", index + 1, true );
1183 scenario->setStringValue( arg );
1184 ai_node->setBoolValue( "enabled", true );
1185 return FG_OPTIONS_OK;
1189 fgOptRunway( const char *arg )
1191 fgSetString("/sim/presets/runway", arg );
1192 fgSetBool("/sim/presets/runway-requested", true );
1193 return FG_OPTIONS_OK;
1197 fgOptParking( const char *arg )
1199 cerr << "Processing argument " << arg << endl;
1200 fgSetString("/sim/presets/parking", arg );
1201 fgSetBool ("/sim/presets/parking-requested", true );
1202 return FG_OPTIONS_OK;
1206 fgOptVersion( const char *arg )
1208 cerr << VERSION << endl;
1209 cerr << "FG_ROOT=" << globals->get_fg_root() << endl;
1210 cerr << "FG_HOME=" << fgGetString("/sim/fg-home") << endl;
1211 return FG_OPTIONS_EXIT;
1214 static map<string,size_t> fgOptionMap;
1217 option has_param type property b_param s_param func
1220 option : name of the option
1221 has_param : option is --name=value if true or --name if false
1222 type : OPTION_BOOL - property is a boolean
1223 OPTION_STRING - property is a string
1224 OPTION_DOUBLE - property is a double
1225 OPTION_INT - property is an integer
1226 OPTION_CHANNEL - name of option is the name of a channel
1227 OPTION_FUNC - the option trigger a function
1228 b_param : if type==OPTION_BOOL,
1229 value set to the property (has_param is false for boolean)
1230 s_param : if type==OPTION_STRING,
1231 value set to the property if has_param is false
1232 func : function called if type==OPTION_FUNC. if has_param is true,
1233 the value is passed to the function as a string, otherwise,
1236 For OPTION_DOUBLE and OPTION_INT, the parameter value is converted into a
1237 double or an integer and set to the property.
1239 For OPTION_CHANNEL, add_channel is called with the parameter value as the
1243 enum OptionType { OPTION_BOOL, OPTION_STRING, OPTION_DOUBLE, OPTION_INT, OPTION_CHANNEL, OPTION_FUNC };
1247 enum OptionType type;
1251 int (*func)( const char * );
1252 } fgOptionArray[] = {
1254 {"language", true, OPTION_FUNC, "", false, "", fgOptLanguage },
1255 {"disable-game-mode", false, OPTION_BOOL, "/sim/startup/game-mode", false, "", 0 },
1256 {"enable-game-mode", false, OPTION_BOOL, "/sim/startup/game-mode", true, "", 0 },
1257 {"disable-splash-screen", false, OPTION_BOOL, "/sim/startup/splash-screen", false, "", 0 },
1258 {"enable-splash-screen", false, OPTION_BOOL, "/sim/startup/splash-screen", true, "", 0 },
1259 {"disable-intro-music", false, OPTION_BOOL, "/sim/startup/intro-music", false, "", 0 },
1260 {"enable-intro-music", false, OPTION_BOOL, "/sim/startup/intro-music", true, "", 0 },
1261 {"disable-mouse-pointer", false, OPTION_STRING, "/sim/startup/mouse-pointer", false, "disabled", 0 },
1262 {"enable-mouse-pointer", false, OPTION_STRING, "/sim/startup/mouse-pointer", false, "enabled", 0 },
1263 {"disable-random-objects", false, OPTION_BOOL, "/sim/rendering/random-objects", false, "", 0 },
1264 {"enable-random-objects", false, OPTION_BOOL, "/sim/rendering/random-objects", true, "", 0 },
1265 {"disable-real-weather-fetch", false, OPTION_BOOL, "/environment/params/real-world-weather-fetch", false, "", 0 },
1266 {"enable-real-weather-fetch", false, OPTION_BOOL, "/environment/params/real-world-weather-fetch", true, "", 0 },
1267 {"disable-ai-models", false, OPTION_BOOL, "/sim/ai/enabled", false, "", 0 },
1268 {"enable-ai-models", false, OPTION_BOOL, "/sim/ai/enabled", true, "", 0 },
1269 {"disable-freeze", false, OPTION_BOOL, "/sim/freeze/master", false, "", 0 },
1270 {"enable-freeze", false, OPTION_BOOL, "/sim/freeze/master", true, "", 0 },
1271 {"disable-fuel-freeze", false, OPTION_BOOL, "/sim/freeze/fuel", false, "", 0 },
1272 {"enable-fuel-freeze", false, OPTION_BOOL, "/sim/freeze/fuel", true, "", 0 },
1273 {"disable-clock-freeze", false, OPTION_BOOL, "/sim/freeze/clock", false, "", 0 },
1274 {"enable-clock-freeze", false, OPTION_BOOL, "/sim/freeze/clock", true, "", 0 },
1275 {"disable-hud-3d", false, OPTION_BOOL, "/sim/hud/enable3d", false, "", 0 },
1276 {"enable-hud-3d", false, OPTION_BOOL, "/sim/hud/enable3d", true, "", 0 },
1277 {"disable-anti-alias-hud", false, OPTION_BOOL, "/sim/hud/color/antialiased", false, "", 0 },
1278 {"enable-anti-alias-hud", false, OPTION_BOOL, "/sim/hud/color/antialiased", true, "", 0 },
1279 {"control", true, OPTION_STRING, "/sim/control-mode", false, "", 0 },
1280 {"disable-auto-coordination", false, OPTION_BOOL, "/sim/auto-coordination", false, "", 0 },
1281 {"enable-auto-coordination", false, OPTION_BOOL, "/sim/auto-coordination", true, "", 0 },
1282 {"browser-app", true, OPTION_STRING, "/sim/startup/browser-app", false, "", 0 },
1283 {"disable-hud", false, OPTION_BOOL, "/sim/hud/visibility", false, "", 0 },
1284 {"enable-hud", false, OPTION_BOOL, "/sim/hud/visibility", true, "", 0 },
1285 {"disable-panel", false, OPTION_BOOL, "/sim/panel/visibility", false, "", 0 },
1286 {"enable-panel", false, OPTION_BOOL, "/sim/panel/visibility", true, "", 0 },
1287 {"disable-sound", false, OPTION_BOOL, "/sim/sound/pause", true, "", 0 },
1288 {"enable-sound", false, OPTION_BOOL, "/sim/sound/pause", false, "", 0 },
1289 {"airport", true, OPTION_STRING, "/sim/presets/airport-id", false, "", 0 },
1290 {"runway", true, OPTION_FUNC, "", false, "", fgOptRunway },
1291 {"vor", true, OPTION_FUNC, "", false, "", fgOptVOR },
1292 {"ndb", true, OPTION_FUNC, "", false, "", fgOptNDB },
1293 {"carrier", true, OPTION_FUNC, "", false, "", fgOptCarrier },
1294 {"parkpos", true, OPTION_FUNC, "", false, "", fgOptParkpos },
1295 {"fix", true, OPTION_FUNC, "", false, "", fgOptFIX },
1296 {"offset-distance", true, OPTION_DOUBLE, "/sim/presets/offset-distance-nm", false, "", 0 },
1297 {"offset-azimuth", true, OPTION_DOUBLE, "/sim/presets/offset-azimuth-deg", false, "", 0 },
1298 {"lon", true, OPTION_FUNC, "", false, "", fgOptLon },
1299 {"lat", true, OPTION_FUNC, "", false, "", fgOptLat },
1300 {"altitude", true, OPTION_FUNC, "", false, "", fgOptAltitude },
1301 {"uBody", true, OPTION_FUNC, "", false, "", fgOptUBody },
1302 {"vBody", true, OPTION_FUNC, "", false, "", fgOptVBody },
1303 {"wBody", true, OPTION_FUNC, "", false, "", fgOptWBody },
1304 {"vNorth", true, OPTION_FUNC, "", false, "", fgOptVNorth },
1305 {"vEast", true, OPTION_FUNC, "", false, "", fgOptVEast },
1306 {"vDown", true, OPTION_FUNC, "", false, "", fgOptVDown },
1307 {"vc", true, OPTION_FUNC, "", false, "", fgOptVc },
1308 {"mach", true, OPTION_FUNC, "", false, "", fgOptMach },
1309 {"heading", true, OPTION_DOUBLE, "/sim/presets/heading-deg", false, "", 0 },
1310 {"roll", true, OPTION_DOUBLE, "/sim/presets/roll-deg", false, "", 0 },
1311 {"pitch", true, OPTION_DOUBLE, "/sim/presets/pitch-deg", false, "", 0 },
1312 {"glideslope", true, OPTION_DOUBLE, "/sim/presets/glideslope-deg", false, "", 0 },
1313 {"roc", true, OPTION_FUNC, "", false, "", fgOptRoc },
1314 {"fg-root", true, OPTION_FUNC, "", false, "", fgOptFgRoot },
1315 {"fg-scenery", true, OPTION_FUNC, "", false, "", fgOptFgScenery },
1316 {"fdm", true, OPTION_STRING, "/sim/flight-model", false, "", 0 },
1317 {"aero", true, OPTION_STRING, "/sim/aero", false, "", 0 },
1318 {"aircraft-dir", true, OPTION_STRING, "/sim/aircraft-dir", false, "", 0 },
1319 {"model-hz", true, OPTION_INT, "/sim/model-hz", false, "", 0 },
1320 {"speed", true, OPTION_INT, "/sim/speed-up", false, "", 0 },
1321 {"trim", false, OPTION_BOOL, "/sim/presets/trim", true, "", 0 },
1322 {"notrim", false, OPTION_BOOL, "/sim/presets/trim", false, "", 0 },
1323 {"on-ground", false, OPTION_BOOL, "/sim/presets/onground", true, "", 0 },
1324 {"in-air", false, OPTION_BOOL, "/sim/presets/onground", false, "", 0 },
1325 {"fog-disable", false, OPTION_STRING, "/sim/rendering/fog", false, "disabled", 0 },
1326 {"fog-fastest", false, OPTION_STRING, "/sim/rendering/fog", false, "fastest", 0 },
1327 {"fog-nicest", false, OPTION_STRING, "/sim/rendering/fog", false, "nicest", 0 },
1328 {"disable-horizon-effect", false, OPTION_BOOL, "/sim/rendering/horizon-effect", false, "", 0 },
1329 {"enable-horizon-effect", false, OPTION_BOOL, "/sim/rendering/horizon-effect", true, "", 0 },
1330 {"disable-enhanced-lighting", false, OPTION_BOOL, "/sim/rendering/enhanced-lighting", false, "", 0 },
1331 {"enable-enhanced-lighting", false, OPTION_BOOL, "/sim/rendering/enhanced-lighting", true, "", 0 },
1332 {"disable-distance-attenuation", false, OPTION_BOOL, "/sim/rendering/distance-attenuation", false, "", 0 },
1333 {"enable-distance-attenuation", false, OPTION_BOOL, "/sim/rendering/distance-attenuation", true, "", 0 },
1334 {"disable-specular-highlight", false, OPTION_BOOL, "/sim/rendering/specular-highlight", false, "", 0 },
1335 {"enable-specular-highlight", false, OPTION_BOOL, "/sim/rendering/specular-highlight", true, "", 0 },
1336 {"disable-clouds", false, OPTION_BOOL, "/environment/clouds/status", false, "", 0 },
1337 {"enable-clouds", false, OPTION_BOOL, "/environment/clouds/status", true, "", 0 },
1338 {"disable-clouds3d", false, OPTION_BOOL, "/sim/rendering/clouds3d-enable", false, "", 0 },
1339 {"enable-clouds3d", false, OPTION_BOOL, "/sim/rendering/clouds3d-enable", true, "", 0 },
1340 {"fov", true, OPTION_FUNC, "", false, "", fgOptFov },
1341 {"aspect-ratio-multiplier", true, OPTION_DOUBLE, "/sim/current-view/aspect-ratio-multiplier", false, "", 0 },
1342 {"disable-fullscreen", false, OPTION_BOOL, "/sim/startup/fullscreen", false, "", 0 },
1343 {"enable-fullscreen", false, OPTION_BOOL, "/sim/startup/fullscreen", true, "", 0 },
1344 {"disable-save-on-exit", false, OPTION_BOOL, "/sim/startup/save-on-exit", false, "", 0 },
1345 {"enable-save-on-exit", false, OPTION_BOOL, "/sim/startup/save-on-exit", true, "", 0 },
1346 {"shading-flat", false, OPTION_BOOL, "/sim/rendering/shading", false, "", 0 },
1347 {"shading-smooth", false, OPTION_BOOL, "/sim/rendering/shading", true, "", 0 },
1348 {"disable-skyblend", false, OPTION_BOOL, "/sim/rendering/skyblend", false, "", 0 },
1349 {"enable-skyblend", false, OPTION_BOOL, "/sim/rendering/skyblend", true, "", 0 },
1350 {"disable-textures", false, OPTION_BOOL, "/sim/rendering/textures", false, "", 0 },
1351 {"enable-textures", false, OPTION_BOOL, "/sim/rendering/textures", true, "", 0 },
1352 {"texture-filtering", false, OPTION_INT, "/sim/rendering/filtering", 1, "", 0 },
1353 {"disable-wireframe", false, OPTION_BOOL, "/sim/rendering/wireframe", false, "", 0 },
1354 {"enable-wireframe", false, OPTION_BOOL, "/sim/rendering/wireframe", true, "", 0 },
1355 {"geometry", true, OPTION_FUNC, "", false, "", fgOptGeometry },
1356 {"bpp", true, OPTION_FUNC, "", false, "", fgOptBpp },
1357 {"units-feet", false, OPTION_STRING, "/sim/startup/units", false, "feet", 0 },
1358 {"units-meters", false, OPTION_STRING, "/sim/startup/units", false, "meters", 0 },
1359 {"timeofday", true, OPTION_STRING, "/sim/startup/time-offset-type", false, "noon", 0 },
1360 {"season", true, OPTION_STRING, "/sim/startup/season", false, "summer", 0 },
1361 {"time-offset", true, OPTION_FUNC, "", false, "", fgOptTimeOffset },
1362 {"time-match-real", false, OPTION_STRING, "/sim/startup/time-offset-type", false, "system-offset", 0 },
1363 {"time-match-local", false, OPTION_STRING, "/sim/startup/time-offset-type", false, "latitude-offset", 0 },
1364 {"start-date-sys", true, OPTION_FUNC, "", false, "", fgOptStartDateSys },
1365 {"start-date-lat", true, OPTION_FUNC, "", false, "", fgOptStartDateLat },
1366 {"start-date-gmt", true, OPTION_FUNC, "", false, "", fgOptStartDateGmt },
1367 {"hud-tris", false, OPTION_STRING, "/sim/hud/frame-stat-type", false, "tris", 0 },
1368 {"hud-culled", false, OPTION_STRING, "/sim/hud/frame-stat-type", false, "culled", 0 },
1369 {"atcsim", true, OPTION_CHANNEL, "", false, "dummy", 0 },
1370 {"atlas", true, OPTION_CHANNEL, "", false, "", 0 },
1371 {"httpd", true, OPTION_CHANNEL, "", false, "", 0 },
1372 #ifdef FG_JPEG_SERVER
1373 {"jpg-httpd", true, OPTION_CHANNEL, "", false, "", 0 },
1375 {"native", true, OPTION_CHANNEL, "", false, "", 0 },
1376 {"native-ctrls", true, OPTION_CHANNEL, "", false, "", 0 },
1377 {"native-fdm", true, OPTION_CHANNEL, "", false, "", 0 },
1378 {"native-gui", true, OPTION_CHANNEL, "", false, "", 0 },
1379 {"opengc", true, OPTION_CHANNEL, "", false, "", 0 },
1380 {"AV400", true, OPTION_CHANNEL, "", false, "", 0 },
1381 {"garmin", true, OPTION_CHANNEL, "", false, "", 0 },
1382 {"nmea", true, OPTION_CHANNEL, "", false, "", 0 },
1383 {"generic", true, OPTION_CHANNEL, "", false, "", 0 },
1384 {"props", true, OPTION_CHANNEL, "", false, "", 0 },
1385 {"telnet", true, OPTION_CHANNEL, "", false, "", 0 },
1386 {"pve", true, OPTION_CHANNEL, "", false, "", 0 },
1387 {"ray", true, OPTION_CHANNEL, "", false, "", 0 },
1388 {"rul", true, OPTION_CHANNEL, "", false, "", 0 },
1389 {"joyclient", true, OPTION_CHANNEL, "", false, "", 0 },
1390 {"jsclient", true, OPTION_CHANNEL, "", false, "", 0 },
1391 {"proxy", true, OPTION_FUNC, "", false, "", fgSetupProxy },
1392 {"callsign", true, OPTION_STRING, "sim/multiplay/callsign", false, "", 0 },
1393 {"multiplay", true, OPTION_CHANNEL, "", false, "", 0 },
1394 {"trace-read", true, OPTION_FUNC, "", false, "", fgOptTraceRead },
1395 {"trace-write", true, OPTION_FUNC, "", false, "", fgOptTraceWrite },
1396 {"log-level", true, OPTION_FUNC, "", false, "", fgOptLogLevel },
1397 {"view-offset", true, OPTION_FUNC, "", false, "", fgOptViewOffset },
1398 {"visibility", true, OPTION_FUNC, "", false, "", fgOptVisibilityMeters },
1399 {"visibility-miles", true, OPTION_FUNC, "", false, "", fgOptVisibilityMiles },
1400 {"random-wind", false, OPTION_FUNC, "", false, "", fgOptRandomWind },
1401 {"wind", true, OPTION_FUNC, "", false, "", fgOptWind },
1402 {"turbulence", true, OPTION_FUNC, "", false, "", fgOptTurbulence },
1403 {"ceiling", true, OPTION_FUNC, "", false, "", fgOptCeiling },
1404 {"wp", true, OPTION_FUNC, "", false, "", fgOptWp },
1405 {"flight-plan", true, OPTION_FUNC, "", false, "", fgOptFlightPlan },
1406 {"config", true, OPTION_FUNC, "", false, "", fgOptConfig },
1407 {"aircraft", true, OPTION_STRING, "/sim/aircraft", false, "", 0 },
1408 {"vehicle", true, OPTION_STRING, "/sim/aircraft", false, "", 0 },
1409 {"failure", true, OPTION_FUNC, "", false, "", fgOptFailure },
1410 {"com1", true, OPTION_DOUBLE, "/instrumentation/comm[0]/frequencies/selected-mhz", false, "", 0 },
1411 {"com2", true, OPTION_DOUBLE, "/instrumentation/comm[1]/frequencies/selected-mhz", false, "", 0 },
1412 {"nav1", true, OPTION_FUNC, "", false, "", fgOptNAV1 },
1413 {"nav2", true, OPTION_FUNC, "", false, "", fgOptNAV2 },
1414 {"adf", true, OPTION_FUNC, "", false, "", fgOptADF },
1415 {"dme", true, OPTION_FUNC, "", false, "", fgOptDME },
1416 {"min-status", true, OPTION_STRING, "/sim/aircraft-min-status", false, "all", 0 },
1417 {"livery", true, OPTION_FUNC, "", false, "", fgOptLivery },
1418 {"ai-scenario", true, OPTION_FUNC, "", false, "", fgOptScenario },
1419 {"parking-id", true, OPTION_FUNC, "", false, "", fgOptParking },
1420 {"version", false, OPTION_FUNC, "", false, "", fgOptVersion },
1425 // Set a property for the --prop: option. Syntax: --prop:[<type>:]<name>=<value>
1426 // <type> can be "double" etc. but also only the first letter "d".
1427 // Examples: --prop:alpha=1 --prop:bool:beta=true --prop:d:gamma=0.123
1429 set_property(const string& arg)
1431 string::size_type pos = arg.find('=');
1432 if (pos == arg.npos || pos == 0 || pos + 1 == arg.size())
1435 string name = arg.substr(0, pos);
1436 string value = arg.substr(pos + 1);
1438 pos = name.find(':');
1440 if (pos != name.npos && pos != 0 && pos + 1 != name.size()) {
1441 type = name.substr(0, pos);
1442 name = name.substr(pos + 1);
1444 SGPropertyNode *n = fgGetNode(name.c_str(), true);
1446 bool writable = n->getAttribute(SGPropertyNode::WRITE);
1448 n->setAttribute(SGPropertyNode::WRITE, true);
1452 ret = n->setUnspecifiedValue(value.c_str());
1453 else if (type == "s" || type == "string")
1454 ret = n->setStringValue(value.c_str());
1455 else if (type == "d" || type == "double")
1456 ret = n->setDoubleValue(strtod(value.c_str(), 0));
1457 else if (type == "f" || type == "float")
1458 ret = n->setFloatValue(atof(value.c_str()));
1459 else if (type == "l" || type == "long")
1460 ret = n->setLongValue(strtol(value.c_str(), 0, 0));
1461 else if (type == "i" || type == "int")
1462 ret = n->setIntValue(atoi(value.c_str()));
1463 else if (type == "b" || type == "bool")
1464 ret = n->setBoolValue(value == "true" || atoi(value.c_str()) != 0);
1467 n->setAttribute(SGPropertyNode::WRITE, false);
1472 // Parse a single option
1474 parse_option (const string& arg)
1476 if ( fgOptionMap.size() == 0 ) {
1478 OptionDesc *pt = &fgOptionArray[ 0 ];
1479 while ( pt->option != 0 ) {
1480 fgOptionMap[ pt->option ] = i;
1487 if ( (arg == "--help") || (arg == "-h") ) {
1488 // help/usage request
1489 return(FG_OPTIONS_HELP);
1490 } else if ( (arg == "--verbose") || (arg == "-v") ) {
1491 // verbose help/usage request
1492 return(FG_OPTIONS_VERBOSE_HELP);
1493 } else if ( arg.find( "--show-aircraft") == 0) {
1494 return(FG_OPTIONS_SHOW_AIRCRAFT);
1495 } else if ( arg.find( "--prop:" ) == 0 ) {
1496 if (!set_property(arg.substr(7))) {
1497 SG_LOG( SG_GENERAL, SG_ALERT, "Bad property assignment: " << arg );
1498 return FG_OPTIONS_ERROR;
1500 } else if ( arg.find( "--" ) == 0 ) {
1501 size_t pos = arg.find( '=' );
1502 string arg_name, arg_value;
1503 if ( pos == string::npos ) {
1504 arg_name = arg.substr( 2 );
1506 arg_name = arg.substr( 2, pos - 2 );
1507 arg_value = arg.substr( pos + 1);
1509 map<string,size_t>::iterator it = fgOptionMap.find( arg_name );
1510 if ( it != fgOptionMap.end() ) {
1511 OptionDesc *pt = &fgOptionArray[ it->second ];
1512 switch ( pt->type ) {
1514 fgSetBool( pt->property, pt->b_param );
1517 if ( pt->has_param && !arg_value.empty() ) {
1518 fgSetString( pt->property, arg_value.c_str() );
1519 } else if ( !pt->has_param && arg_value.empty() ) {
1520 fgSetString( pt->property, pt->s_param );
1521 } else if ( pt->has_param ) {
1522 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1523 return FG_OPTIONS_ERROR;
1525 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' does not have a parameter" );
1526 return FG_OPTIONS_ERROR;
1530 if ( !arg_value.empty() ) {
1531 fgSetDouble( pt->property, atof( arg_value ) );
1533 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1534 return FG_OPTIONS_ERROR;
1538 if ( !arg_value.empty() ) {
1539 fgSetInt( pt->property, atoi( arg_value ) );
1541 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1542 return FG_OPTIONS_ERROR;
1545 case OPTION_CHANNEL:
1546 if ( pt->has_param && !arg_value.empty() ) {
1547 add_channel( pt->option, arg_value );
1548 } else if ( !pt->has_param && arg_value.empty() ) {
1549 add_channel( pt->option, pt->s_param );
1550 } else if ( pt->has_param ) {
1551 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1552 return FG_OPTIONS_ERROR;
1554 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' does not have a parameter" );
1555 return FG_OPTIONS_ERROR;
1559 if ( pt->has_param && !arg_value.empty() ) {
1560 return pt->func( arg_value.c_str() );
1561 } else if ( !pt->has_param && arg_value.empty() ) {
1562 return pt->func( 0 );
1563 } else if ( pt->has_param ) {
1564 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1565 return FG_OPTIONS_ERROR;
1567 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' does not have a parameter" );
1568 return FG_OPTIONS_ERROR;
1573 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" );
1574 return FG_OPTIONS_ERROR;
1577 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" );
1578 return FG_OPTIONS_ERROR;
1581 return FG_OPTIONS_OK;
1585 // Parse the command line options
1587 fgParseArgs (int argc, char **argv)
1589 bool in_options = true;
1590 bool verbose = false;
1593 SG_LOG(SG_GENERAL, SG_INFO, "Processing command line arguments");
1595 for (int i = 1; i < argc; i++) {
1596 string arg = argv[i];
1598 if (in_options && (arg.find('-') == 0)) {
1602 int result = parse_option(arg);
1603 if ((result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR))
1606 else if (result == FG_OPTIONS_VERBOSE_HELP)
1609 else if (result == FG_OPTIONS_SHOW_AIRCRAFT) {
1610 fgOptLogLevel( "alert" );
1611 SGPath path( globals->get_fg_root() );
1612 path.append("Aircraft");
1613 fgShowAircraft(path, true);
1617 else if (result == FG_OPTIONS_EXIT)
1622 SG_LOG(SG_GENERAL, SG_INFO,
1623 "Reading command-line property file " << arg);
1624 readProperties(arg, globals->get_props());
1629 fgOptLogLevel( "alert" );
1634 SG_LOG(SG_GENERAL, SG_INFO, "Finished command line arguments");
1638 // Parse config file options
1640 fgParseOptions (const string& path) {
1641 sg_gzifstream in( path );
1642 if ( !in.is_open() ) {
1646 SG_LOG( SG_GENERAL, SG_INFO, "Processing config file: " << path );
1650 while ( ! in.eof() ) {
1653 while ( in.get(c) && c != '\0' ) {
1658 #if defined( macintosh )
1659 getline( in, line, '\r' );
1661 getline( in, line, '\n' );
1664 // catch extraneous (DOS) line ending character
1666 for (i = line.length(); i > 0; i--)
1667 if (line[i - 1] > 32)
1669 line = line.substr( 0, i );
1671 if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
1672 cerr << endl << "Config file parse error: " << path << " '"
1673 << line << "'" << endl;
1682 // Print usage message
1684 fgUsage (bool verbose)
1686 SGPropertyNode *locale = globals->get_locale();
1688 SGPropertyNode options_root;
1690 SG_LOG( SG_GENERAL, SG_ALERT, "" ); // To popup the console on Windows
1694 fgLoadProps("options.xml", &options_root);
1695 } catch (const sg_exception &) {
1696 cout << "Unable to read the help file." << endl;
1697 cout << "Make sure the file options.xml is located in the FlightGear base directory," << endl;
1698 cout << "and the location of the base directory is specified by setting $FG_ROOT or" << endl;
1699 cout << "by adding --fg-root=path as a program argument." << endl;
1704 SGPropertyNode *options = options_root.getNode("options");
1706 SG_LOG( SG_GENERAL, SG_ALERT,
1707 "Error reading options.xml: <options> directive not found." );
1711 SGPropertyNode *usage = locale->getNode(options->getStringValue("usage"));
1713 cout << "Usage: " << usage->getStringValue() << endl;
1716 vector<SGPropertyNode_ptr>section = options->getChildren("section");
1717 for (unsigned int j = 0; j < section.size(); j++) {
1720 vector<SGPropertyNode_ptr>option = section[j]->getChildren("option");
1721 for (unsigned int k = 0; k < option.size(); k++) {
1723 SGPropertyNode *name = option[k]->getNode("name");
1724 SGPropertyNode *short_name = option[k]->getNode("short");
1725 SGPropertyNode *key = option[k]->getNode("key");
1726 SGPropertyNode *arg = option[k]->getNode("arg");
1727 bool brief = option[k]->getNode("brief") != 0;
1729 if ((brief || verbose) && name) {
1730 string tmp = name->getStringValue();
1734 tmp.append(key->getStringValue());
1738 tmp.append(arg->getStringValue());
1742 tmp.append(short_name->getStringValue());
1745 if (tmp.size() <= 25) {
1748 msg.append( 27-tmp.size(), ' ');
1752 msg.append(32, ' ');
1754 // There may be more than one <description> tag assosiated
1757 vector<SGPropertyNode_ptr> desc;
1758 desc = option[k]->getChildren("description");
1759 if (desc.size() > 0) {
1760 for ( unsigned int l = 0; l < desc.size(); l++) {
1762 // There may be more than one translation line.
1764 string t = desc[l]->getStringValue();
1765 SGPropertyNode *n = locale->getNode("strings");
1766 vector<SGPropertyNode_ptr>trans_desc =
1767 n->getChildren(t.substr(8).c_str());
1769 for ( unsigned int m = 0; m < trans_desc.size(); m++ ) {
1770 string t_str = trans_desc[m]->getStringValue();
1772 if ((m > 0) || ((l > 0) && m == 0)) {
1773 msg.append( 32, ' ');
1776 // If the string is too large to fit on the screen,
1777 // then split it up in several pieces.
1779 while ( t_str.size() > 47 ) {
1781 unsigned int m = t_str.rfind(' ', 47);
1782 msg += t_str.substr(0, m) + '\n';
1783 msg.append( 32, ' ');
1785 t_str.erase(t_str.begin(), t_str.begin() + m + 1);
1787 msg += t_str + '\n';
1794 SGPropertyNode *name;
1795 name = locale->getNode(section[j]->getStringValue("name"));
1797 if (!msg.empty() && name) {
1798 cout << endl << name->getStringValue() << ":" << endl;
1806 cout << "For a complete list of options use --help --verbose" << endl;
1809 cout << "Hit a key to continue..." << endl;
1814 // A simple function to return an integer depending on the position
1815 // of the status string within the array in order to determine the hierarchy.
1816 unsigned int getNumMaturity(const char * str)
1818 // changes should also be reflected in $FG_ROOT/data/options.xml &
1819 // $FG_ROOT/data/Translations/string-default.xml
1820 const char levels[][20]= {"alpha","beta","early-production","production",0};
1822 for (unsigned int i=0; i<(sizeof(levels)/sizeof(levels[0])-1);i++)
1823 if (strcmp(str,levels[i])==0)
1830 static void fgSearchAircraft(const SGPath &path, string_list &aircraft,
1835 ulDir *dirp = ulOpenDir(path.str().c_str());
1837 cerr << "Unable to open aircraft directory '" << path.str() << '\'' << endl;
1841 while ((dire = ulReadDir(dirp)) != NULL) {
1844 if (dire->d_isdir) {
1845 if (recursive && strcmp("CVS", dire->d_name)
1846 && strcmp(".", dire->d_name) && strcmp("..", dire->d_name))
1849 next.append(dire->d_name);
1851 fgSearchAircraft(next, aircraft, true);
1853 } else if ((ptr = strstr(dire->d_name, "-set.xml")) && (ptr[8] == '\0')) {
1855 SGPath afile = path;
1856 afile.append(dire->d_name);
1860 SGPropertyNode root;
1862 readProperties(afile.str(), &root);
1867 SGPropertyNode *desc = NULL;
1868 SGPropertyNode *status = NULL;
1870 SGPropertyNode *node = root.getNode("sim");
1872 desc = node->getNode("description");
1873 // if a status tag is found, read it in
1874 if (node->hasValue("status"))
1875 status = node->getNode("status");
1878 //additionally display status information where it is available
1880 string descStr(" ");
1881 descStr += dire->d_name;
1883 if (descStr.size() <= 27+3) {
1884 descStr.append(29+3-descStr.size(), ' ');
1887 descStr.append( 32, ' ');
1889 descStr += desc->getStringValue();
1892 SGPropertyNode * required_status
1893 = fgGetNode ("/sim/aircraft-min-status", true);
1895 // If the node holds the value "all", then there wasn't any status
1896 // level specified, so we simply go ahead and output ALL aircraft
1897 if (strcmp(required_status->getStringValue(),"all")==0) {
1898 aircraft.push_back(descStr);
1902 // If the node doesn't hold "all" as its value, then we are supposed
1903 // to show only aircraft meeting specific status (development status)
1906 if (node->hasValue("status")) {
1907 //Compare (minimally) required status level with actual aircraft status:
1908 if ( getNumMaturity(status->getStringValue() ) >=
1909 getNumMaturity(required_status->getStringValue() ) )
1910 aircraft.push_back(descStr); }
1922 * Search in the current directory, and in on directory deeper
1923 * for <aircraft>-set.xml configuration files and show the aircaft name
1924 * and the contents of the<description> tag in a sorted manner.
1926 * @parampath the directory to search for configuration files
1927 * @param recursive defines whether the directory should be searched recursively
1929 void fgShowAircraft(const SGPath &path, bool recursive) {
1930 string_list aircraft;
1932 fgSearchAircraft( path, aircraft, recursive );
1934 sort(aircraft.begin(), aircraft.end());
1935 SG_LOG( SG_GENERAL, SG_ALERT, "" ); // To popup the console on Windows
1936 cout << "Available aircraft:" << endl;
1937 for ( unsigned int i = 0; i < aircraft.size(); i++ ) {
1938 cout << aircraft[i] << endl;
1941 cout << "Hit a key to continue..." << endl;