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()
43 #include <simgear/math/sg_random.h>
44 #include <simgear/props/props_io.hxx>
45 #include <simgear/misc/sgstream.hxx>
46 #include <simgear/misc/sg_path.hxx>
47 #include <simgear/scene/material/mat.hxx>
48 #include <simgear/sound/soundmgr_openal.hxx>
50 // #include <Include/general.hxx>
51 // #include <Airports/simple.hxx>
52 // #include <Cockpit/cockpit.hxx>
53 // #include <FDM/flight.hxx>
55 #include <Autopilot/route_mgr.hxx>
58 #include "globals.hxx"
59 #include "fg_init.hxx"
60 #include "fg_props.hxx"
61 #include "options.hxx"
63 #include "viewmgr.hxx"
64 #include <Main/viewer.hxx>
65 #include <simgear/version.h>
74 #define VERSION "CVS "__DATE__
77 #define NEW_DEFAULT_MODEL_HZ 120
85 FG_OPTIONS_VERBOSE_HELP = 4,
86 FG_OPTIONS_SHOW_AIRCRAFT = 5,
87 FG_OPTIONS_SHOW_SOUND_DEVICES = 6
91 atof( const string& str )
93 return ::atof( str.c_str() );
97 atoi( const string& str )
99 return ::atoi( str.c_str() );
103 * Set a few fail-safe default property values.
105 * These should all be set in $FG_ROOT/preferences.xml, but just
106 * in case, we provide some initial sane values here. This method
107 * should be invoked *before* reading any init files.
112 // set a possibly independent location for scenery data
113 const char *envp = ::getenv( "FG_SCENERY" );
115 if ( envp != NULL ) {
116 // fg_root could be anywhere, so default to environmental
117 // variable $FG_ROOT if it is set.
118 globals->set_fg_scenery(envp);
120 // Otherwise, default to Scenery being in $FG_ROOT/Scenery
121 globals->set_fg_scenery("");
123 // Position (deliberately out of range)
124 fgSetDouble("/position/longitude-deg", 9999.0);
125 fgSetDouble("/position/latitude-deg", 9999.0);
126 fgSetDouble("/position/altitude-ft", -9999.0);
129 fgSetDouble("/orientation/heading-deg", 9999.0);
130 fgSetDouble("/orientation/roll-deg", 0.0);
131 fgSetDouble("/orientation/pitch-deg", 0.424);
134 fgSetDouble("/velocities/uBody-fps", 0.0);
135 fgSetDouble("/velocities/vBody-fps", 0.0);
136 fgSetDouble("/velocities/wBody-fps", 0.0);
137 fgSetDouble("/velocities/speed-north-fps", 0.0);
138 fgSetDouble("/velocities/speed-east-fps", 0.0);
139 fgSetDouble("/velocities/speed-down-fps", 0.0);
140 fgSetDouble("/velocities/airspeed-kt", 0.0);
141 fgSetDouble("/velocities/mach", 0.0);
144 fgSetDouble("/sim/presets/longitude-deg", 9999.0);
145 fgSetDouble("/sim/presets/latitude-deg", 9999.0);
146 fgSetDouble("/sim/presets/altitude-ft", -9999.0);
148 fgSetDouble("/sim/presets/heading-deg", 9999.0);
149 fgSetDouble("/sim/presets/roll-deg", 0.0);
150 fgSetDouble("/sim/presets/pitch-deg", 0.424);
152 fgSetString("/sim/presets/speed-set", "knots");
153 fgSetDouble("/sim/presets/airspeed-kt", 0.0);
154 fgSetDouble("/sim/presets/mach", 0.0);
155 fgSetDouble("/sim/presets/uBody-fps", 0.0);
156 fgSetDouble("/sim/presets/vBody-fps", 0.0);
157 fgSetDouble("/sim/presets/wBody-fps", 0.0);
158 fgSetDouble("/sim/presets/speed-north-fps", 0.0);
159 fgSetDouble("/sim/presets/speed-east-fps", 0.0);
160 fgSetDouble("/sim/presets/speed-down-fps", 0.0);
162 fgSetBool("/sim/presets/onground", true);
163 fgSetBool("/sim/presets/trim", false);
166 fgSetBool("/sim/startup/game-mode", false);
167 fgSetBool("/sim/startup/splash-screen", true);
168 fgSetBool("/sim/startup/intro-music", true);
169 // we want mouse-pointer to have an undefined value if nothing is
170 // specified so we can do the right thing for voodoo-1/2 cards.
171 // fgSetString("/sim/startup/mouse-pointer", "disabled");
172 fgSetString("/sim/control-mode", "joystick");
173 fgSetBool("/sim/auto-coordination", false);
175 fgSetString("/sim/startup/browser-app", "webrun.bat");
176 #elif defined(__APPLE__)
177 fgSetString("/sim/startup/browser-app", "open");
179 fgSetString("/sim/startup/browser-app", "launchWebJumper");
181 envp = ::getenv( "WEBBROWSER" );
182 if (!envp) envp = "netscape";
183 fgSetString("/sim/startup/browser-app", envp);
185 fgSetString("/sim/logging/priority", "alert");
188 fgSetBool("/sim/hud/color/antialiased", false);
189 fgSetBool("/sim/hud/enable3d", true);
190 fgSetBool("/sim/hud/visibility", false);
191 fgSetBool("/sim/panel/visibility", true);
192 fgSetBool("/sim/sound/enabled", true);
193 fgSetBool("/sim/sound/working", true);
195 // Flight Model options
196 fgSetString("/sim/flight-model", "jsb");
197 fgSetString("/sim/aero", "c172");
198 fgSetInt("/sim/model-hz", NEW_DEFAULT_MODEL_HZ);
199 fgSetInt("/sim/speed-up", 1);
202 fgSetString("/sim/rendering/fog", "nicest");
203 fgSetBool("/environment/clouds/status", true);
204 fgSetBool("/sim/startup/fullscreen", false);
205 fgSetBool("/sim/rendering/shading", true);
206 fgSetBool("/sim/rendering/skyblend", true);
207 fgSetBool("/sim/rendering/textures", true);
208 fgTie( "/sim/rendering/filtering", SGGetTextureFilter, SGSetTextureFilter, false);
209 fgSetInt("/sim/rendering/filtering", 1);
210 fgSetBool("/sim/rendering/wireframe", false);
211 fgSetBool("/sim/rendering/horizon-effect", false);
212 fgSetBool("/sim/rendering/enhanced-lighting", false);
213 fgSetBool("/sim/rendering/distance-attenuation", false);
214 fgSetBool("/sim/rendering/specular-highlight", true);
215 fgSetInt("/sim/startup/xsize", 800);
216 fgSetInt("/sim/startup/ysize", 600);
217 fgSetInt("/sim/rendering/bits-per-pixel", 16);
218 fgSetString("/sim/view-mode", "pilot");
219 fgSetDouble("/sim/current-view/heading-offset-deg", 0);
222 fgSetString("/sim/startup/units", "feet");
223 fgSetString("/sim/hud/frame-stat-type", "tris");
226 fgSetInt("/sim/startup/time-offset", 0);
227 fgSetString("/sim/startup/time-offset-type", "system-offset");
228 fgSetLong("/sim/time/cur-time-override", 0);
231 fgSetBool("/sim/freeze/master", false);
232 fgSetBool("/sim/freeze/position", false);
233 fgSetBool("/sim/freeze/clock", false);
234 fgSetBool("/sim/freeze/fuel", false);
236 fgSetString("/sim/multiplay/callsign", "callsign");
237 fgSetString("/sim/multiplay/rxhost", "0");
238 fgSetString("/sim/multiplay/txhost", "0");
239 fgSetInt("/sim/multiplay/rxport", 0);
240 fgSetInt("/sim/multiplay/txport", 0);
244 parse_wind (const string &wind, double * min_hdg, double * max_hdg,
245 double * speed, double * gust)
247 string::size_type pos = wind.find('@');
248 if (pos == string::npos)
250 string dir = wind.substr(0, pos);
251 string spd = wind.substr(pos+1);
253 if (pos == string::npos) {
254 *min_hdg = *max_hdg = atof(dir.c_str());
256 *min_hdg = atof(dir.substr(0,pos).c_str());
257 *max_hdg = atof(dir.substr(pos+1).c_str());
260 if (pos == string::npos) {
261 *speed = *gust = atof(spd.c_str());
263 *speed = atof(spd.substr(0,pos).c_str());
264 *gust = atof(spd.substr(pos+1).c_str());
269 // parse a time string ([+/-]%f[:%f[:%f]]) into hours
271 parse_time(const string& time_in) {
272 char *time_str, num[256];
273 double hours, minutes, seconds;
278 time_str = (char *)time_in.c_str();
280 // printf("parse_time(): %s\n", time_str);
283 if ( strlen(time_str) ) {
284 if ( time_str[0] == '+' ) {
287 } else if ( time_str[0] == '-' ) {
292 // printf("sign = %d\n", sign);
295 if ( strlen(time_str) ) {
297 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
298 num[i] = time_str[0];
302 if ( time_str[0] == ':' ) {
307 // printf("hours = %.2lf\n", hours);
313 if ( strlen(time_str) ) {
315 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
316 num[i] = time_str[0];
320 if ( time_str[0] == ':' ) {
325 // printf("minutes = %.2lf\n", minutes);
327 result += minutes / 60.0;
331 if ( strlen(time_str) ) {
333 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
334 num[i] = time_str[0];
340 // printf("seconds = %.2lf\n", seconds);
342 result += seconds / 3600.0;
345 SG_LOG( SG_GENERAL, SG_INFO, " parse_time() = " << sign * result );
347 return(sign * result);
351 // parse a date string (yyyy:mm:dd:hh:mm:ss) into a time_t (seconds)
353 parse_date( const string& date)
356 char * date_str, num[256];
358 // initialize to zero
365 gmt.tm_isdst = 0; // ignore daylight savings time for the moment
366 date_str = (char *)date.c_str();
368 if ( strlen(date_str) ) {
370 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
371 num[i] = date_str[0];
375 if ( date_str[0] == ':' ) {
379 gmt.tm_year = atoi(num) - 1900;
382 if ( strlen(date_str) ) {
384 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
385 num[i] = date_str[0];
389 if ( date_str[0] == ':' ) {
393 gmt.tm_mon = atoi(num) -1;
396 if ( strlen(date_str) ) {
398 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
399 num[i] = date_str[0];
403 if ( date_str[0] == ':' ) {
407 gmt.tm_mday = atoi(num);
410 if ( strlen(date_str) ) {
412 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
413 num[i] = date_str[0];
417 if ( date_str[0] == ':' ) {
421 gmt.tm_hour = atoi(num);
424 if ( strlen(date_str) ) {
426 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
427 num[i] = date_str[0];
431 if ( date_str[0] == ':' ) {
435 gmt.tm_min = atoi(num);
438 if ( strlen(date_str) ) {
440 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
441 num[i] = date_str[0];
445 if ( date_str[0] == ':' ) {
449 gmt.tm_sec = atoi(num);
451 time_t theTime = sgTimeGetGMT( gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
452 gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
453 //printf ("Date is %s\n", ctime(&theTime));
454 //printf ("in seconds that is %d\n", theTime);
460 // parse angle in the form of [+/-]ddd:mm:ss into degrees
462 parse_degree( const string& degree_str) {
463 double result = parse_time( degree_str );
465 // printf("Degree = %.4f\n", result);
471 // parse time offset string into seconds
473 parse_time_offset( const string& time_str) {
476 // printf("time offset = %s\n", time_str);
479 result = (int)rint(parse_time(time_str) * 3600.0);
481 result = (int)(parse_time(time_str) * 3600.0);
484 // printf("parse_time_offset(): %d\n", result);
490 // Parse --fov=x.xx type option
492 parse_fov( const string& arg ) {
493 double fov = atof(arg);
495 if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
496 if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
498 fgSetDouble("/sim/view[0]/config/default-field-of-view-deg", fov);
500 // printf("parse_fov(): result = %.4f\n", fov);
506 // Parse I/O channel option
508 // Format is "--protocol=medium,direction,hz,medium_options,..."
510 // protocol = { native, nmea, garmin, AV400, AV400Sim, fgfs, rul, pve, etc. }
511 // medium = { serial, socket, file, etc. }
512 // direction = { in, out, bi }
513 // hz = number of times to process channel per second (floating
514 // point values are ok.
516 // Serial example "--nmea=serial,dir,hz,device,baud" where
518 // device = OS device name of serial line to be open()'ed
519 // baud = {300, 1200, 2400, ..., 230400}
521 // Socket exacmple "--native=socket,dir,hz,machine,port,style" where
523 // machine = machine name or ip address if client (leave empty if server)
524 // port = port, leave empty to let system choose
525 // style = tcp or udp
527 // File example "--garmin=file,dir,hz,filename" where
529 // filename = file system file name
532 add_channel( const string& type, const string& channel_str ) {
533 SG_LOG(SG_GENERAL, SG_INFO, "Channel string = " << channel_str );
534 globals->get_channel_options_list()->push_back( type + "," + channel_str );
539 // The parse wp and parse flight-plan options don't work anymore, because
540 // the route manager and the airport subsystems have not yet been initialized
543 // Parse --wp=ID[@alt]
545 parse_wp( const string& arg ) {
546 string_list *waypoints = globals->get_initial_waypoints();
548 waypoints = new string_list;
549 globals->set_initial_waypoints(waypoints);
551 waypoints->push_back(arg);
555 // Parse --flight-plan=[file]
557 parse_flightplan(const string& arg)
559 string_list *waypoints = globals->get_initial_waypoints();
561 waypoints = new string_list;
562 globals->set_initial_waypoints(waypoints);
565 sg_gzifstream in(arg.c_str());
571 getline( in, line, '\n' );
573 // catch extraneous (DOS) line ending character
574 if ( line[line.length() - 1] < 32 )
575 line = line.substr( 0, line.length()-1 );
580 waypoints->push_back(line);
587 fgOptLanguage( const char *arg )
589 globals->set_locale( fgInitLocale( arg ) );
590 return FG_OPTIONS_OK;
596 fgSetString("/sim/presets/airport-id", "");
597 fgSetString("/sim/presets/vor-id", "");
598 fgSetString("/sim/presets/ndb-id", "");
599 fgSetString("/sim/presets/carrier", "");
600 fgSetString("/sim/presets/parkpos", "");
601 fgSetString("/sim/presets/fix", "");
605 fgOptVOR( const char * arg )
608 fgSetString("/sim/presets/vor-id", arg);
609 return FG_OPTIONS_OK;
613 fgOptNDB( const char * arg )
616 fgSetString("/sim/presets/ndb-id", arg);
617 return FG_OPTIONS_OK;
621 fgOptCarrier( const char * arg )
624 fgSetString("/sim/presets/carrier", arg);
625 return FG_OPTIONS_OK;
629 fgOptParkpos( const char * arg )
631 fgSetString("/sim/presets/parkpos", arg);
632 return FG_OPTIONS_OK;
636 fgOptFIX( const char * arg )
639 fgSetString("/sim/presets/fix", arg);
640 return FG_OPTIONS_OK;
644 fgOptLon( const char *arg )
647 fgSetDouble("/sim/presets/longitude-deg", parse_degree( arg ));
648 fgSetDouble("/position/longitude-deg", parse_degree( arg ));
649 return FG_OPTIONS_OK;
653 fgOptLat( const char *arg )
656 fgSetDouble("/sim/presets/latitude-deg", parse_degree( arg ));
657 fgSetDouble("/position/latitude-deg", parse_degree( arg ));
658 return FG_OPTIONS_OK;
662 fgOptAltitude( const char *arg )
664 fgSetBool("/sim/presets/onground", false);
665 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
666 fgSetDouble("/sim/presets/altitude-ft", atof( arg ));
668 fgSetDouble("/sim/presets/altitude-ft",
669 atof( arg ) * SG_METER_TO_FEET);
670 return FG_OPTIONS_OK;
674 fgOptUBody( const char *arg )
676 fgSetString("/sim/presets/speed-set", "UVW");
677 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
678 fgSetDouble("/sim/presets/uBody-fps", atof( arg ));
680 fgSetDouble("/sim/presets/uBody-fps",
681 atof( arg ) * SG_METER_TO_FEET);
682 return FG_OPTIONS_OK;
686 fgOptVBody( const char *arg )
688 fgSetString("/sim/presets/speed-set", "UVW");
689 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
690 fgSetDouble("/sim/presets/vBody-fps", atof( arg ));
692 fgSetDouble("/sim/presets/vBody-fps",
693 atof( arg ) * SG_METER_TO_FEET);
694 return FG_OPTIONS_OK;
698 fgOptWBody( const char *arg )
700 fgSetString("/sim/presets/speed-set", "UVW");
701 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
702 fgSetDouble("/sim/presets/wBody-fps", atof(arg));
704 fgSetDouble("/sim/presets/wBody-fps",
705 atof(arg) * SG_METER_TO_FEET);
706 return FG_OPTIONS_OK;
710 fgOptVNorth( const char *arg )
712 fgSetString("/sim/presets/speed-set", "NED");
713 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
714 fgSetDouble("/sim/presets/speed-north-fps", atof( arg ));
716 fgSetDouble("/sim/presets/speed-north-fps",
717 atof( arg ) * SG_METER_TO_FEET);
718 return FG_OPTIONS_OK;
722 fgOptVEast( const char *arg )
724 fgSetString("/sim/presets/speed-set", "NED");
725 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
726 fgSetDouble("/sim/presets/speed-east-fps", atof(arg));
728 fgSetDouble("/sim/presets/speed-east-fps",
729 atof(arg) * SG_METER_TO_FEET);
730 return FG_OPTIONS_OK;
734 fgOptVDown( const char *arg )
736 fgSetString("/sim/presets/speed-set", "NED");
737 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
738 fgSetDouble("/sim/presets/speed-down-fps", atof(arg));
740 fgSetDouble("/sim/presets/speed-down-fps",
741 atof(arg) * SG_METER_TO_FEET);
742 return FG_OPTIONS_OK;
746 fgOptVc( const char *arg )
748 // fgSetString("/sim/presets/speed-set", "knots");
749 // fgSetDouble("/velocities/airspeed-kt", atof(arg.substr(5)));
750 fgSetString("/sim/presets/speed-set", "knots");
751 fgSetDouble("/sim/presets/airspeed-kt", atof(arg));
752 return FG_OPTIONS_OK;
756 fgOptMach( const char *arg )
758 fgSetString("/sim/presets/speed-set", "mach");
759 fgSetDouble("/sim/presets/mach", atof(arg));
760 return FG_OPTIONS_OK;
764 fgOptRoc( const char *arg )
766 fgSetDouble("/velocities/vertical-speed-fps", atof(arg)/60);
767 return FG_OPTIONS_OK;
771 fgOptFgRoot( const char *arg )
773 globals->set_fg_root(arg);
774 return FG_OPTIONS_OK;
778 fgOptFgScenery( const char *arg )
780 globals->set_fg_scenery(arg);
781 return FG_OPTIONS_OK;
785 fgOptFov( const char *arg )
788 return FG_OPTIONS_OK;
792 fgOptGeometry( const char *arg )
794 bool geometry_ok = true;
795 int xsize = 0, ysize = 0;
796 string geometry = arg;
797 string::size_type i = geometry.find('x');
799 if (i != string::npos) {
800 xsize = atoi(geometry.substr(0, i));
801 ysize = atoi(geometry.substr(i+1));
806 if ( xsize <= 0 || ysize <= 0 ) {
812 if ( !geometry_ok ) {
813 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown geometry: " << geometry );
814 SG_LOG( SG_GENERAL, SG_ALERT,
815 "Setting geometry to " << xsize << 'x' << ysize << '\n');
817 SG_LOG( SG_GENERAL, SG_INFO,
818 "Setting geometry to " << xsize << 'x' << ysize << '\n');
819 fgSetInt("/sim/startup/xsize", xsize);
820 fgSetInt("/sim/startup/ysize", ysize);
822 return FG_OPTIONS_OK;
826 fgOptBpp( const char *arg )
828 string bits_per_pix = arg;
829 if ( bits_per_pix == "16" ) {
830 fgSetInt("/sim/rendering/bits-per-pixel", 16);
831 } else if ( bits_per_pix == "24" ) {
832 fgSetInt("/sim/rendering/bits-per-pixel", 24);
833 } else if ( bits_per_pix == "32" ) {
834 fgSetInt("/sim/rendering/bits-per-pixel", 32);
836 SG_LOG(SG_GENERAL, SG_ALERT, "Unsupported bpp " << bits_per_pix);
838 return FG_OPTIONS_OK;
842 fgOptTimeOffset( const char *arg )
844 fgSetInt("/sim/startup/time-offset",
845 parse_time_offset( arg ));
846 fgSetString("/sim/startup/time-offset-type", "system-offset");
847 return FG_OPTIONS_OK;
851 fgOptStartDateSys( const char *arg )
853 fgSetInt("/sim/startup/time-offset", parse_date( arg ) );
854 fgSetString("/sim/startup/time-offset-type", "system");
855 return FG_OPTIONS_OK;
859 fgOptStartDateLat( const char *arg )
861 fgSetInt("/sim/startup/time-offset", parse_date( arg ) );
862 fgSetString("/sim/startup/time-offset-type", "latitude");
863 return FG_OPTIONS_OK;
867 fgOptStartDateGmt( const char *arg )
869 fgSetInt("/sim/startup/time-offset", parse_date( arg ) );
870 fgSetString("/sim/startup/time-offset-type", "gmt");
871 return FG_OPTIONS_OK;
875 fgSetupProxy( const char *arg )
877 string options = arg;
878 string host, port, auth;
879 string::size_type pos;
881 host = port = auth = "";
882 if ((pos = options.find("@")) != string::npos)
883 auth = options.substr(0, pos++);
887 host = options.substr(pos, options.size());
888 if ((pos = host.find(":")) != string::npos) {
889 port = host.substr(++pos, host.size());
890 host.erase(--pos, host.size());
893 fgSetString("/sim/presets/proxy/host", host.c_str());
894 fgSetString("/sim/presets/proxy/port", port.c_str());
895 fgSetString("/sim/presets/proxy/authentication", auth.c_str());
897 return FG_OPTIONS_OK;
901 fgOptTraceRead( const char *arg )
904 SG_LOG(SG_GENERAL, SG_INFO, "Tracing reads for property " << name);
905 fgGetNode(name.c_str(), true)
906 ->setAttribute(SGPropertyNode::TRACE_READ, true);
907 return FG_OPTIONS_OK;
911 fgOptLogLevel( const char *arg )
913 fgSetString("/sim/logging/classes", "all");
914 fgSetString("/sim/logging/priority", arg);
916 string priority = arg;
917 logbuf::set_log_classes(SG_ALL);
918 if (priority == "bulk") {
919 logbuf::set_log_priority(SG_BULK);
920 } else if (priority == "debug") {
921 logbuf::set_log_priority(SG_DEBUG);
922 } else if (priority == "info") {
923 logbuf::set_log_priority(SG_INFO);
924 } else if (priority == "warn") {
925 logbuf::set_log_priority(SG_WARN);
926 } else if (priority == "alert") {
927 logbuf::set_log_priority(SG_ALERT);
929 SG_LOG(SG_GENERAL, SG_WARN, "Unknown logging priority " << priority);
931 SG_LOG(SG_GENERAL, SG_DEBUG, "Logging priority is " << priority);
933 return FG_OPTIONS_OK;
938 fgOptTraceWrite( const char *arg )
941 SG_LOG(SG_GENERAL, SG_INFO, "Tracing writes for property " << name);
942 fgGetNode(name.c_str(), true)
943 ->setAttribute(SGPropertyNode::TRACE_WRITE, true);
944 return FG_OPTIONS_OK;
948 fgOptViewOffset( const char *arg )
950 // $$$ begin - added VS Renganathan, 14 Oct 2K
951 // for multi-window outside window imagery
952 string woffset = arg;
953 double default_view_offset = 0.0;
954 if ( woffset == "LEFT" ) {
955 default_view_offset = SGD_PI * 0.25;
956 } else if ( woffset == "RIGHT" ) {
957 default_view_offset = SGD_PI * 1.75;
958 } else if ( woffset == "CENTER" ) {
959 default_view_offset = 0.00;
961 default_view_offset = atof( woffset.c_str() ) * SGD_DEGREES_TO_RADIANS;
963 /* apparently not used (CLO, 11 Jun 2002)
964 FGViewer *pilot_view =
965 (FGViewer *)globals->get_viewmgr()->get_view( 0 ); */
966 // this will work without calls to the viewer...
967 fgSetDouble( "/sim/current-view/heading-offset-deg",
968 default_view_offset * SGD_RADIANS_TO_DEGREES );
969 // $$$ end - added VS Renganathan, 14 Oct 2K
970 return FG_OPTIONS_OK;
974 fgOptVisibilityMeters( const char *arg )
976 double visibility = atof( arg );
977 fgDefaultWeatherValue("visibility-m", visibility);
978 return FG_OPTIONS_OK;
982 fgOptVisibilityMiles( const char *arg )
984 double visibility = atof( arg ) * 5280.0 * SG_FEET_TO_METER;
985 fgDefaultWeatherValue("visibility-m", visibility);
986 return FG_OPTIONS_OK;
990 fgOptRandomWind( const char *arg )
992 double min_hdg = sg_random() * 360.0;
993 double max_hdg = min_hdg + (20 - sqrt(sg_random() * 400));
994 double speed = sg_random() * sg_random() * 40;
995 double gust = speed + (10 - sqrt(sg_random() * 100));
996 fgSetupWind(min_hdg, max_hdg, speed, gust);
997 return FG_OPTIONS_OK;
1001 fgOptWind( const char *arg )
1003 double min_hdg = 0.0, max_hdg = 0.0, speed = 0.0, gust = 0.0;
1004 if (!parse_wind( arg, &min_hdg, &max_hdg, &speed, &gust)) {
1005 SG_LOG( SG_GENERAL, SG_ALERT, "bad wind value " << arg );
1006 return FG_OPTIONS_ERROR;
1008 fgSetupWind(min_hdg, max_hdg, speed, gust);
1009 return FG_OPTIONS_OK;
1013 fgOptTurbulence( const char *arg )
1015 fgDefaultWeatherValue("turbulence/magnitude-norm", atof(arg));
1016 return FG_OPTIONS_OK;
1020 fgOptCeiling( const char *arg )
1022 double elevation, thickness;
1024 string::size_type pos = spec.find(':');
1025 if (pos == string::npos) {
1026 elevation = atof(spec.c_str());
1029 elevation = atof(spec.substr(0, pos).c_str());
1030 thickness = atof(spec.substr(pos + 1).c_str());
1032 fgSetDouble("/environment/clouds/layer[0]/elevation-ft", elevation);
1033 fgSetDouble("/environment/clouds/layer[0]/thickness-ft", thickness);
1034 fgSetString("/environment/clouds/layer[0]/coverage", "overcast");
1035 return FG_OPTIONS_OK;
1039 fgOptWp( const char *arg )
1042 return FG_OPTIONS_OK;
1046 fgOptFlightPlan( const char *arg )
1048 parse_flightplan ( arg );
1049 return FG_OPTIONS_OK;
1053 fgOptConfig( const char *arg )
1057 readProperties(file, globals->get_props());
1058 } catch (const sg_exception &e) {
1059 string message = "Error loading config file: ";
1060 message += e.getFormattedMessage() + e.getOrigin();
1061 SG_LOG(SG_INPUT, SG_ALERT, message);
1064 return FG_OPTIONS_OK;
1068 parse_colon (const string &s, double * val1, double * val2)
1070 string::size_type pos = s.find(':');
1071 if (pos == string::npos) {
1075 *val1 = atof(s.substr(0, pos).c_str());
1076 *val2 = atof(s.substr(pos+1).c_str());
1083 fgOptFailure( const char * arg )
1087 fgSetBool("/systems/pitot/serviceable", false);
1088 } else if (a == "static") {
1089 fgSetBool("/systems/static/serviceable", false);
1090 } else if (a == "vacuum") {
1091 fgSetBool("/systems/vacuum/serviceable", false);
1092 } else if (a == "electrical") {
1093 fgSetBool("/systems/electrical/serviceable", false);
1095 SG_LOG(SG_INPUT, SG_ALERT, "Unknown failure mode: " << a);
1096 return FG_OPTIONS_ERROR;
1099 return FG_OPTIONS_OK;
1104 fgOptNAV1( const char * arg )
1106 double radial, freq;
1107 if (parse_colon(arg, &radial, &freq))
1108 fgSetDouble("/instrumentation/nav[0]/radials/selected-deg", radial);
1109 fgSetDouble("/instrumentation/nav[0]/frequencies/selected-mhz", freq);
1110 return FG_OPTIONS_OK;
1114 fgOptNAV2( const char * arg )
1116 double radial, freq;
1117 if (parse_colon(arg, &radial, &freq))
1118 fgSetDouble("/instrumentation/nav[1]/radials/selected-deg", radial);
1119 fgSetDouble("/instrumentation/nav[1]/frequencies/selected-mhz", freq);
1120 return FG_OPTIONS_OK;
1124 fgOptADF( const char * arg )
1127 if (parse_colon(arg, &rot, &freq))
1128 fgSetDouble("/instrumentation/adf/rotation-deg", rot);
1129 fgSetDouble("/instrumentation/adf/frequencies/selected-khz", freq);
1130 return FG_OPTIONS_OK;
1134 fgOptDME( const char *arg )
1137 if (opt == "nav1") {
1138 fgSetInt("/instrumentation/dme/switch-position", 1);
1139 fgSetString("/instrumentation/dme/frequencies/source",
1140 "/instrumentation/nav[0]/frequencies/selected-mhz");
1141 } else if (opt == "nav2") {
1142 fgSetInt("/instrumentation/dme/switch-position", 3);
1143 fgSetString("/instrumentation/dme/frequencies/source",
1144 "/instrumentation/nav[1]/frequencies/selected-mhz");
1146 fgSetInt("/instrumentation/dme/switch-position", 2);
1147 fgSetString("/instrumentation/dme/frequencies/source",
1148 "/instrumentation/dme/frequencies/selected-mhz");
1149 fgSetString("/instrumentation/dme/frequencies/selected-mhz", arg);
1151 return FG_OPTIONS_OK;
1155 fgOptLivery( const char *arg )
1158 string livery_path = "livery/" + opt;
1159 fgSetString("/sim/model/texture-path", livery_path.c_str() );
1160 return FG_OPTIONS_OK;
1164 fgOptScenario( const char *arg )
1166 SGPropertyNode_ptr ai_node = fgGetNode( "/sim/ai", true );
1167 vector<SGPropertyNode_ptr> scenarii = ai_node->getChildren( "scenario" );
1169 for ( size_t i = 0; i < scenarii.size(); ++i ) {
1170 int ind = scenarii[i]->getIndex();
1171 if ( index < ind ) {
1175 SGPropertyNode_ptr scenario = ai_node->getNode( "scenario", index + 1, true );
1176 scenario->setStringValue( arg );
1177 ai_node->setBoolValue( "enabled", true );
1178 return FG_OPTIONS_OK;
1182 fgOptRunway( const char *arg )
1184 fgSetString("/sim/presets/runway", arg );
1185 fgSetBool("/sim/presets/runway-requested", true );
1186 return FG_OPTIONS_OK;
1190 fgOptParking( const char *arg )
1192 cerr << "Processing argument " << arg << endl;
1193 fgSetString("/sim/presets/parking", arg );
1194 fgSetBool ("/sim/presets/parking-requested", true );
1195 return FG_OPTIONS_OK;
1199 fgOptVersion( const char *arg )
1201 cerr << "FlightGear version: " << VERSION << endl;
1202 cerr << "FG_ROOT=" << globals->get_fg_root() << endl;
1203 cerr << "FG_HOME=" << fgGetString("/sim/fg-home") << endl;
1204 cerr << "FG_SCENERY=";
1207 string_list scn = globals->get_fg_scenery();
1208 for (string_list::const_iterator it = scn.begin(); it != scn.end(); it++)
1210 if (didsome) cerr << ":";
1215 cerr << "SimGear version: " << SG_STRINGIZE(SIMGEAR_VERSION) << endl;
1216 cerr << "PLIB version: " << PLIB_VERSION << endl;
1217 return FG_OPTIONS_EXIT;
1221 fgOptFpe(const char* arg)
1223 // Actually handled in bootstrap.cxx
1224 return FG_OPTIONS_OK;
1228 fgOptFgviewer(const char* arg)
1230 // Actually handled in bootstrap.cxx
1231 return FG_OPTIONS_OK;
1236 static map<string,size_t> fgOptionMap;
1239 option has_param type property b_param s_param func
1242 option : name of the option
1243 has_param : option is --name=value if true or --name if false
1244 type : OPTION_BOOL - property is a boolean
1245 OPTION_STRING - property is a string
1246 OPTION_DOUBLE - property is a double
1247 OPTION_INT - property is an integer
1248 OPTION_CHANNEL - name of option is the name of a channel
1249 OPTION_FUNC - the option trigger a function
1250 b_param : if type==OPTION_BOOL,
1251 value set to the property (has_param is false for boolean)
1252 s_param : if type==OPTION_STRING,
1253 value set to the property if has_param is false
1254 func : function called if type==OPTION_FUNC. if has_param is true,
1255 the value is passed to the function as a string, otherwise,
1258 For OPTION_DOUBLE and OPTION_INT, the parameter value is converted into a
1259 double or an integer and set to the property.
1261 For OPTION_CHANNEL, add_channel is called with the parameter value as the
1265 enum OptionType { OPTION_BOOL, OPTION_STRING, OPTION_DOUBLE, OPTION_INT, OPTION_CHANNEL, OPTION_FUNC };
1269 enum OptionType type;
1270 const char *property;
1272 const char *s_param;
1273 int (*func)( const char * );
1274 } fgOptionArray[] = {
1276 {"language", true, OPTION_FUNC, "", false, "", fgOptLanguage },
1277 {"disable-game-mode", false, OPTION_BOOL, "/sim/startup/game-mode", false, "", 0 },
1278 {"enable-game-mode", false, OPTION_BOOL, "/sim/startup/game-mode", true, "", 0 },
1279 {"disable-splash-screen", false, OPTION_BOOL, "/sim/startup/splash-screen", false, "", 0 },
1280 {"enable-splash-screen", false, OPTION_BOOL, "/sim/startup/splash-screen", true, "", 0 },
1281 {"disable-intro-music", false, OPTION_BOOL, "/sim/startup/intro-music", false, "", 0 },
1282 {"enable-intro-music", false, OPTION_BOOL, "/sim/startup/intro-music", true, "", 0 },
1283 {"disable-mouse-pointer", false, OPTION_STRING, "/sim/startup/mouse-pointer", false, "disabled", 0 },
1284 {"enable-mouse-pointer", false, OPTION_STRING, "/sim/startup/mouse-pointer", false, "enabled", 0 },
1285 {"disable-random-objects", false, OPTION_BOOL, "/sim/rendering/random-objects", false, "", 0 },
1286 {"enable-random-objects", false, OPTION_BOOL, "/sim/rendering/random-objects", true, "", 0 },
1287 {"disable-real-weather-fetch", false, OPTION_BOOL, "/environment/params/real-world-weather-fetch", false, "", 0 },
1288 {"enable-real-weather-fetch", false, OPTION_BOOL, "/environment/params/real-world-weather-fetch", true, "", 0 },
1289 {"metar", true, OPTION_STRING, "/environment/metar/data", false, "", 0 },
1290 {"disable-ai-models", false, OPTION_BOOL, "/sim/ai/enabled", false, "", 0 },
1291 {"enable-ai-models", false, OPTION_BOOL, "/sim/ai/enabled", true, "", 0 },
1292 {"disable-freeze", false, OPTION_BOOL, "/sim/freeze/master", false, "", 0 },
1293 {"enable-freeze", false, OPTION_BOOL, "/sim/freeze/master", true, "", 0 },
1294 {"disable-fuel-freeze", false, OPTION_BOOL, "/sim/freeze/fuel", false, "", 0 },
1295 {"enable-fuel-freeze", false, OPTION_BOOL, "/sim/freeze/fuel", true, "", 0 },
1296 {"disable-clock-freeze", false, OPTION_BOOL, "/sim/freeze/clock", false, "", 0 },
1297 {"enable-clock-freeze", false, OPTION_BOOL, "/sim/freeze/clock", true, "", 0 },
1298 {"disable-hud-3d", false, OPTION_BOOL, "/sim/hud/enable3d", false, "", 0 },
1299 {"enable-hud-3d", false, OPTION_BOOL, "/sim/hud/enable3d", true, "", 0 },
1300 {"disable-anti-alias-hud", false, OPTION_BOOL, "/sim/hud/color/antialiased", false, "", 0 },
1301 {"enable-anti-alias-hud", false, OPTION_BOOL, "/sim/hud/color/antialiased", true, "", 0 },
1302 {"control", true, OPTION_STRING, "/sim/control-mode", false, "", 0 },
1303 {"disable-auto-coordination", false, OPTION_BOOL, "/sim/auto-coordination", false, "", 0 },
1304 {"enable-auto-coordination", false, OPTION_BOOL, "/sim/auto-coordination", true, "", 0 },
1305 {"browser-app", true, OPTION_STRING, "/sim/startup/browser-app", false, "", 0 },
1306 {"disable-hud", false, OPTION_BOOL, "/sim/hud/visibility", false, "", 0 },
1307 {"enable-hud", false, OPTION_BOOL, "/sim/hud/visibility", true, "", 0 },
1308 {"disable-panel", false, OPTION_BOOL, "/sim/panel/visibility", false, "", 0 },
1309 {"enable-panel", false, OPTION_BOOL, "/sim/panel/visibility", true, "", 0 },
1310 {"disable-sound", false, OPTION_BOOL, "/sim/sound/working", false, "", 0 },
1311 {"enable-sound", false, OPTION_BOOL, "/sim/sound/working", true, "", 0 },
1312 {"sound-device", true, OPTION_STRING, "/sim/sound/device-name", false, "", 0 },
1313 {"airport", true, OPTION_STRING, "/sim/presets/airport-id", false, "", 0 },
1314 {"runway", true, OPTION_FUNC, "", false, "", fgOptRunway },
1315 {"vor", true, OPTION_FUNC, "", false, "", fgOptVOR },
1316 {"ndb", true, OPTION_FUNC, "", false, "", fgOptNDB },
1317 {"carrier", true, OPTION_FUNC, "", false, "", fgOptCarrier },
1318 {"parkpos", true, OPTION_FUNC, "", false, "", fgOptParkpos },
1319 {"fix", true, OPTION_FUNC, "", false, "", fgOptFIX },
1320 {"offset-distance", true, OPTION_DOUBLE, "/sim/presets/offset-distance-nm", false, "", 0 },
1321 {"offset-azimuth", true, OPTION_DOUBLE, "/sim/presets/offset-azimuth-deg", false, "", 0 },
1322 {"lon", true, OPTION_FUNC, "", false, "", fgOptLon },
1323 {"lat", true, OPTION_FUNC, "", false, "", fgOptLat },
1324 {"altitude", true, OPTION_FUNC, "", false, "", fgOptAltitude },
1325 {"uBody", true, OPTION_FUNC, "", false, "", fgOptUBody },
1326 {"vBody", true, OPTION_FUNC, "", false, "", fgOptVBody },
1327 {"wBody", true, OPTION_FUNC, "", false, "", fgOptWBody },
1328 {"vNorth", true, OPTION_FUNC, "", false, "", fgOptVNorth },
1329 {"vEast", true, OPTION_FUNC, "", false, "", fgOptVEast },
1330 {"vDown", true, OPTION_FUNC, "", false, "", fgOptVDown },
1331 {"vc", true, OPTION_FUNC, "", false, "", fgOptVc },
1332 {"mach", true, OPTION_FUNC, "", false, "", fgOptMach },
1333 {"heading", true, OPTION_DOUBLE, "/sim/presets/heading-deg", false, "", 0 },
1334 {"roll", true, OPTION_DOUBLE, "/sim/presets/roll-deg", false, "", 0 },
1335 {"pitch", true, OPTION_DOUBLE, "/sim/presets/pitch-deg", false, "", 0 },
1336 {"glideslope", true, OPTION_DOUBLE, "/sim/presets/glideslope-deg", false, "", 0 },
1337 {"roc", true, OPTION_FUNC, "", false, "", fgOptRoc },
1338 {"fg-root", true, OPTION_FUNC, "", false, "", fgOptFgRoot },
1339 {"fg-scenery", true, OPTION_FUNC, "", false, "", fgOptFgScenery },
1340 {"fdm", true, OPTION_STRING, "/sim/flight-model", false, "", 0 },
1341 {"aero", true, OPTION_STRING, "/sim/aero", false, "", 0 },
1342 {"aircraft-dir", true, OPTION_STRING, "/sim/aircraft-dir", false, "", 0 },
1343 {"model-hz", true, OPTION_INT, "/sim/model-hz", false, "", 0 },
1344 {"speed", true, OPTION_INT, "/sim/speed-up", false, "", 0 },
1345 {"trim", false, OPTION_BOOL, "/sim/presets/trim", true, "", 0 },
1346 {"notrim", false, OPTION_BOOL, "/sim/presets/trim", false, "", 0 },
1347 {"on-ground", false, OPTION_BOOL, "/sim/presets/onground", true, "", 0 },
1348 {"in-air", false, OPTION_BOOL, "/sim/presets/onground", false, "", 0 },
1349 {"fog-disable", false, OPTION_STRING, "/sim/rendering/fog", false, "disabled", 0 },
1350 {"fog-fastest", false, OPTION_STRING, "/sim/rendering/fog", false, "fastest", 0 },
1351 {"fog-nicest", false, OPTION_STRING, "/sim/rendering/fog", false, "nicest", 0 },
1352 {"disable-horizon-effect", false, OPTION_BOOL, "/sim/rendering/horizon-effect", false, "", 0 },
1353 {"enable-horizon-effect", false, OPTION_BOOL, "/sim/rendering/horizon-effect", true, "", 0 },
1354 {"disable-enhanced-lighting", false, OPTION_BOOL, "/sim/rendering/enhanced-lighting", false, "", 0 },
1355 {"enable-enhanced-lighting", false, OPTION_BOOL, "/sim/rendering/enhanced-lighting", true, "", 0 },
1356 {"disable-distance-attenuation", false, OPTION_BOOL, "/sim/rendering/distance-attenuation", false, "", 0 },
1357 {"enable-distance-attenuation", false, OPTION_BOOL, "/sim/rendering/distance-attenuation", true, "", 0 },
1358 {"disable-specular-highlight", false, OPTION_BOOL, "/sim/rendering/specular-highlight", false, "", 0 },
1359 {"enable-specular-highlight", false, OPTION_BOOL, "/sim/rendering/specular-highlight", true, "", 0 },
1360 {"disable-clouds", false, OPTION_BOOL, "/environment/clouds/status", false, "", 0 },
1361 {"enable-clouds", false, OPTION_BOOL, "/environment/clouds/status", true, "", 0 },
1362 {"disable-clouds3d", false, OPTION_BOOL, "/sim/rendering/clouds3d-enable", false, "", 0 },
1363 {"enable-clouds3d", false, OPTION_BOOL, "/sim/rendering/clouds3d-enable", true, "", 0 },
1364 {"fov", true, OPTION_FUNC, "", false, "", fgOptFov },
1365 {"aspect-ratio-multiplier", true, OPTION_DOUBLE, "/sim/current-view/aspect-ratio-multiplier", false, "", 0 },
1366 {"disable-fullscreen", false, OPTION_BOOL, "/sim/startup/fullscreen", false, "", 0 },
1367 {"enable-fullscreen", false, OPTION_BOOL, "/sim/startup/fullscreen", true, "", 0 },
1368 {"disable-save-on-exit", false, OPTION_BOOL, "/sim/startup/save-on-exit", false, "", 0 },
1369 {"enable-save-on-exit", false, OPTION_BOOL, "/sim/startup/save-on-exit", true, "", 0 },
1370 {"shading-flat", false, OPTION_BOOL, "/sim/rendering/shading", false, "", 0 },
1371 {"shading-smooth", false, OPTION_BOOL, "/sim/rendering/shading", true, "", 0 },
1372 {"disable-skyblend", false, OPTION_BOOL, "/sim/rendering/skyblend", false, "", 0 },
1373 {"enable-skyblend", false, OPTION_BOOL, "/sim/rendering/skyblend", true, "", 0 },
1374 {"disable-textures", false, OPTION_BOOL, "/sim/rendering/textures", false, "", 0 },
1375 {"enable-textures", false, OPTION_BOOL, "/sim/rendering/textures", true, "", 0 },
1376 {"texture-filtering", false, OPTION_INT, "/sim/rendering/filtering", 1, "", 0 },
1377 {"disable-wireframe", false, OPTION_BOOL, "/sim/rendering/wireframe", false, "", 0 },
1378 {"enable-wireframe", false, OPTION_BOOL, "/sim/rendering/wireframe", true, "", 0 },
1379 {"geometry", true, OPTION_FUNC, "", false, "", fgOptGeometry },
1380 {"bpp", true, OPTION_FUNC, "", false, "", fgOptBpp },
1381 {"units-feet", false, OPTION_STRING, "/sim/startup/units", false, "feet", 0 },
1382 {"units-meters", false, OPTION_STRING, "/sim/startup/units", false, "meters", 0 },
1383 {"timeofday", true, OPTION_STRING, "/sim/startup/time-offset-type", false, "noon", 0 },
1384 {"season", true, OPTION_STRING, "/sim/startup/season", false, "summer", 0 },
1385 {"time-offset", true, OPTION_FUNC, "", false, "", fgOptTimeOffset },
1386 {"time-match-real", false, OPTION_STRING, "/sim/startup/time-offset-type", false, "system-offset", 0 },
1387 {"time-match-local", false, OPTION_STRING, "/sim/startup/time-offset-type", false, "latitude-offset", 0 },
1388 {"start-date-sys", true, OPTION_FUNC, "", false, "", fgOptStartDateSys },
1389 {"start-date-lat", true, OPTION_FUNC, "", false, "", fgOptStartDateLat },
1390 {"start-date-gmt", true, OPTION_FUNC, "", false, "", fgOptStartDateGmt },
1391 {"hud-tris", false, OPTION_STRING, "/sim/hud/frame-stat-type", false, "tris", 0 },
1392 {"hud-culled", false, OPTION_STRING, "/sim/hud/frame-stat-type", false, "culled", 0 },
1393 {"atcsim", true, OPTION_CHANNEL, "", false, "dummy", 0 },
1394 {"atlas", true, OPTION_CHANNEL, "", false, "", 0 },
1395 {"httpd", true, OPTION_CHANNEL, "", false, "", 0 },
1396 #ifdef FG_JPEG_SERVER
1397 {"jpg-httpd", true, OPTION_CHANNEL, "", false, "", 0 },
1399 {"native", true, OPTION_CHANNEL, "", false, "", 0 },
1400 {"native-ctrls", true, OPTION_CHANNEL, "", false, "", 0 },
1401 {"native-fdm", true, OPTION_CHANNEL, "", false, "", 0 },
1402 {"native-gui", true, OPTION_CHANNEL, "", false, "", 0 },
1403 {"opengc", true, OPTION_CHANNEL, "", false, "", 0 },
1404 {"AV400", true, OPTION_CHANNEL, "", false, "", 0 },
1405 {"AV400Sim", true, OPTION_CHANNEL, "", false, "", 0 },
1406 {"garmin", true, OPTION_CHANNEL, "", false, "", 0 },
1407 {"nmea", true, OPTION_CHANNEL, "", false, "", 0 },
1408 {"generic", true, OPTION_CHANNEL, "", false, "", 0 },
1409 {"props", true, OPTION_CHANNEL, "", false, "", 0 },
1410 {"telnet", true, OPTION_CHANNEL, "", false, "", 0 },
1411 {"pve", true, OPTION_CHANNEL, "", false, "", 0 },
1412 {"ray", true, OPTION_CHANNEL, "", false, "", 0 },
1413 {"rul", true, OPTION_CHANNEL, "", false, "", 0 },
1414 {"joyclient", true, OPTION_CHANNEL, "", false, "", 0 },
1415 {"jsclient", true, OPTION_CHANNEL, "", false, "", 0 },
1416 {"proxy", true, OPTION_FUNC, "", false, "", fgSetupProxy },
1417 {"callsign", true, OPTION_STRING, "sim/multiplay/callsign", false, "", 0 },
1418 {"multiplay", true, OPTION_CHANNEL, "", false, "", 0 },
1419 {"trace-read", true, OPTION_FUNC, "", false, "", fgOptTraceRead },
1420 {"trace-write", true, OPTION_FUNC, "", false, "", fgOptTraceWrite },
1421 {"log-level", true, OPTION_FUNC, "", false, "", fgOptLogLevel },
1422 {"view-offset", true, OPTION_FUNC, "", false, "", fgOptViewOffset },
1423 {"visibility", true, OPTION_FUNC, "", false, "", fgOptVisibilityMeters },
1424 {"visibility-miles", true, OPTION_FUNC, "", false, "", fgOptVisibilityMiles },
1425 {"random-wind", false, OPTION_FUNC, "", false, "", fgOptRandomWind },
1426 {"wind", true, OPTION_FUNC, "", false, "", fgOptWind },
1427 {"turbulence", true, OPTION_FUNC, "", false, "", fgOptTurbulence },
1428 {"ceiling", true, OPTION_FUNC, "", false, "", fgOptCeiling },
1429 {"wp", true, OPTION_FUNC, "", false, "", fgOptWp },
1430 {"flight-plan", true, OPTION_FUNC, "", false, "", fgOptFlightPlan },
1431 {"config", true, OPTION_FUNC, "", false, "", fgOptConfig },
1432 {"aircraft", true, OPTION_STRING, "/sim/aircraft", false, "", 0 },
1433 {"vehicle", true, OPTION_STRING, "/sim/aircraft", false, "", 0 },
1434 {"failure", true, OPTION_FUNC, "", false, "", fgOptFailure },
1435 {"com1", true, OPTION_DOUBLE, "/instrumentation/comm[0]/frequencies/selected-mhz", false, "", 0 },
1436 {"com2", true, OPTION_DOUBLE, "/instrumentation/comm[1]/frequencies/selected-mhz", false, "", 0 },
1437 {"nav1", true, OPTION_FUNC, "", false, "", fgOptNAV1 },
1438 {"nav2", true, OPTION_FUNC, "", false, "", fgOptNAV2 },
1439 {"adf", true, OPTION_FUNC, "", false, "", fgOptADF },
1440 {"dme", true, OPTION_FUNC, "", false, "", fgOptDME },
1441 {"min-status", true, OPTION_STRING, "/sim/aircraft-min-status", false, "all", 0 },
1442 {"livery", true, OPTION_FUNC, "", false, "", fgOptLivery },
1443 {"ai-scenario", true, OPTION_FUNC, "", false, "", fgOptScenario },
1444 {"parking-id", true, OPTION_FUNC, "", false, "", fgOptParking },
1445 {"version", false, OPTION_FUNC, "", false, "", fgOptVersion },
1446 {"enable-fpe", false, OPTION_FUNC, "", false, "", fgOptFpe},
1447 {"fgviewer", false, OPTION_FUNC, "", false, "", fgOptFgviewer},
1452 // Set a property for the --prop: option. Syntax: --prop:[<type>:]<name>=<value>
1453 // <type> can be "double" etc. but also only the first letter "d".
1454 // Examples: --prop:alpha=1 --prop:bool:beta=true --prop:d:gamma=0.123
1456 set_property(const string& arg)
1458 string::size_type pos = arg.find('=');
1459 if (pos == arg.npos || pos == 0 || pos + 1 == arg.size())
1462 string name = arg.substr(0, pos);
1463 string value = arg.substr(pos + 1);
1465 pos = name.find(':');
1467 if (pos != name.npos && pos != 0 && pos + 1 != name.size()) {
1468 type = name.substr(0, pos);
1469 name = name.substr(pos + 1);
1471 SGPropertyNode *n = fgGetNode(name.c_str(), true);
1473 bool writable = n->getAttribute(SGPropertyNode::WRITE);
1475 n->setAttribute(SGPropertyNode::WRITE, true);
1479 ret = n->setUnspecifiedValue(value.c_str());
1480 else if (type == "s" || type == "string")
1481 ret = n->setStringValue(value.c_str());
1482 else if (type == "d" || type == "double")
1483 ret = n->setDoubleValue(strtod(value.c_str(), 0));
1484 else if (type == "f" || type == "float")
1485 ret = n->setFloatValue(atof(value.c_str()));
1486 else if (type == "l" || type == "long")
1487 ret = n->setLongValue(strtol(value.c_str(), 0, 0));
1488 else if (type == "i" || type == "int")
1489 ret = n->setIntValue(atoi(value.c_str()));
1490 else if (type == "b" || type == "bool")
1491 ret = n->setBoolValue(value == "true" || atoi(value.c_str()) != 0);
1494 n->setAttribute(SGPropertyNode::WRITE, false);
1499 // Parse a single option
1501 parse_option (const string& arg)
1503 if ( fgOptionMap.size() == 0 ) {
1505 OptionDesc *pt = &fgOptionArray[ 0 ];
1506 while ( pt->option != 0 ) {
1507 fgOptionMap[ pt->option ] = i;
1514 if ( (arg == "--help") || (arg == "-h") ) {
1515 // help/usage request
1516 return(FG_OPTIONS_HELP);
1517 } else if ( (arg == "--verbose") || (arg == "-v") ) {
1518 // verbose help/usage request
1519 return(FG_OPTIONS_VERBOSE_HELP);
1520 } else if ( arg.find( "--show-aircraft") == 0) {
1521 return(FG_OPTIONS_SHOW_AIRCRAFT);
1522 } else if ( arg.find( "--show-sound-devices") == 0) {
1523 return(FG_OPTIONS_SHOW_SOUND_DEVICES);
1524 } else if ( arg.find( "--prop:" ) == 0 ) {
1525 if (!set_property(arg.substr(7))) {
1526 SG_LOG( SG_GENERAL, SG_ALERT, "Bad property assignment: " << arg );
1527 return FG_OPTIONS_ERROR;
1529 } else if ( arg.find( "--" ) == 0 ) {
1530 size_t pos = arg.find( '=' );
1531 string arg_name, arg_value;
1532 if ( pos == string::npos ) {
1533 arg_name = arg.substr( 2 );
1535 arg_name = arg.substr( 2, pos - 2 );
1536 arg_value = arg.substr( pos + 1);
1538 map<string,size_t>::iterator it = fgOptionMap.find( arg_name );
1539 if ( it != fgOptionMap.end() ) {
1540 OptionDesc *pt = &fgOptionArray[ it->second ];
1541 switch ( pt->type ) {
1543 fgSetBool( pt->property, pt->b_param );
1546 if ( pt->has_param && !arg_value.empty() ) {
1547 fgSetString( pt->property, arg_value.c_str() );
1548 } else if ( !pt->has_param && arg_value.empty() ) {
1549 fgSetString( pt->property, 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 ( !arg_value.empty() ) {
1560 fgSetDouble( pt->property, atof( arg_value ) );
1562 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1563 return FG_OPTIONS_ERROR;
1567 if ( !arg_value.empty() ) {
1568 fgSetInt( pt->property, atoi( arg_value ) );
1570 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1571 return FG_OPTIONS_ERROR;
1574 case OPTION_CHANNEL:
1575 if ( pt->has_param && !arg_value.empty() ) {
1576 add_channel( pt->option, arg_value );
1577 } else if ( !pt->has_param && arg_value.empty() ) {
1578 add_channel( pt->option, pt->s_param );
1579 } else if ( pt->has_param ) {
1580 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1581 return FG_OPTIONS_ERROR;
1583 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' does not have a parameter" );
1584 return FG_OPTIONS_ERROR;
1588 if ( pt->has_param && !arg_value.empty() ) {
1589 return pt->func( arg_value.c_str() );
1590 } else if ( !pt->has_param && arg_value.empty() ) {
1591 return pt->func( pt->s_param );
1592 } else if ( pt->has_param ) {
1593 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1594 return FG_OPTIONS_ERROR;
1596 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' does not have a parameter" );
1597 return FG_OPTIONS_ERROR;
1602 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" );
1603 return FG_OPTIONS_ERROR;
1606 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" );
1607 return FG_OPTIONS_ERROR;
1610 return FG_OPTIONS_OK;
1614 // Parse the command line options
1616 fgParseArgs (int argc, char **argv)
1618 bool in_options = true;
1619 bool verbose = false;
1622 SG_LOG(SG_GENERAL, SG_INFO, "Processing command line arguments");
1624 for (int i = 1; i < argc; i++) {
1625 string arg = argv[i];
1627 if (in_options && (arg.find('-') == 0)) {
1631 int result = parse_option(arg);
1632 if ((result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR))
1635 else if (result == FG_OPTIONS_VERBOSE_HELP)
1638 else if (result == FG_OPTIONS_SHOW_AIRCRAFT) {
1639 fgOptLogLevel( "alert" );
1640 SGPath path( globals->get_fg_root() );
1641 path.append("Aircraft");
1642 fgShowAircraft(path, true);
1645 } else if (result == FG_OPTIONS_SHOW_SOUND_DEVICES) {
1647 vector <const char*>devices = smgr.get_available_devices();
1648 for (int i=0; i<devices.size(); i++) {
1649 printf("%i. \"%s\"\n", i, devices[i]);
1655 else if (result == FG_OPTIONS_EXIT)
1660 SG_LOG(SG_GENERAL, SG_INFO,
1661 "Reading command-line property file " << arg);
1662 readProperties(arg, globals->get_props());
1667 fgOptLogLevel( "alert" );
1672 SG_LOG(SG_GENERAL, SG_INFO, "Finished command line arguments");
1676 // Parse config file options
1678 fgParseOptions (const string& path) {
1679 sg_gzifstream in( path );
1680 if ( !in.is_open() ) {
1684 SG_LOG( SG_GENERAL, SG_INFO, "Processing config file: " << path );
1687 while ( ! in.eof() ) {
1689 getline( in, line, '\n' );
1691 // catch extraneous (DOS) line ending character
1693 for (i = line.length(); i > 0; i--)
1694 if (line[i - 1] > 32)
1696 line = line.substr( 0, i );
1698 if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
1699 cerr << endl << "Config file parse error: " << path << " '"
1700 << line << "'" << endl;
1709 // Print usage message
1711 fgUsage (bool verbose)
1713 SGPropertyNode *locale = globals->get_locale();
1715 SGPropertyNode options_root;
1717 SG_LOG( SG_GENERAL, SG_ALERT, "" ); // To popup the console on Windows
1721 fgLoadProps("options.xml", &options_root);
1722 } catch (const sg_exception &) {
1723 cout << "Unable to read the help file." << endl;
1724 cout << "Make sure the file options.xml is located in the FlightGear base directory," << endl;
1725 cout << "and the location of the base directory is specified by setting $FG_ROOT or" << endl;
1726 cout << "by adding --fg-root=path as a program argument." << endl;
1731 SGPropertyNode *options = options_root.getNode("options");
1733 SG_LOG( SG_GENERAL, SG_ALERT,
1734 "Error reading options.xml: <options> directive not found." );
1738 SGPropertyNode *usage = locale->getNode(options->getStringValue("usage"));
1740 cout << "Usage: " << usage->getStringValue() << endl;
1743 vector<SGPropertyNode_ptr>section = options->getChildren("section");
1744 for (unsigned int j = 0; j < section.size(); j++) {
1747 vector<SGPropertyNode_ptr>option = section[j]->getChildren("option");
1748 for (unsigned int k = 0; k < option.size(); k++) {
1750 SGPropertyNode *name = option[k]->getNode("name");
1751 SGPropertyNode *short_name = option[k]->getNode("short");
1752 SGPropertyNode *key = option[k]->getNode("key");
1753 SGPropertyNode *arg = option[k]->getNode("arg");
1754 bool brief = option[k]->getNode("brief") != 0;
1756 if ((brief || verbose) && name) {
1757 string tmp = name->getStringValue();
1761 tmp.append(key->getStringValue());
1765 tmp.append(arg->getStringValue());
1769 tmp.append(short_name->getStringValue());
1772 if (tmp.size() <= 25) {
1775 msg.append( 27-tmp.size(), ' ');
1779 msg.append(32, ' ');
1781 // There may be more than one <description> tag assosiated
1784 vector<SGPropertyNode_ptr> desc;
1785 desc = option[k]->getChildren("description");
1786 if (desc.size() > 0) {
1787 for ( unsigned int l = 0; l < desc.size(); l++) {
1789 // There may be more than one translation line.
1791 string t = desc[l]->getStringValue();
1792 SGPropertyNode *n = locale->getNode("strings");
1793 vector<SGPropertyNode_ptr>trans_desc =
1794 n->getChildren(t.substr(8).c_str());
1796 for ( unsigned int m = 0; m < trans_desc.size(); m++ ) {
1797 string t_str = trans_desc[m]->getStringValue();
1799 if ((m > 0) || ((l > 0) && m == 0)) {
1800 msg.append( 32, ' ');
1803 // If the string is too large to fit on the screen,
1804 // then split it up in several pieces.
1806 while ( t_str.size() > 47 ) {
1808 unsigned int m = t_str.rfind(' ', 47);
1809 msg += t_str.substr(0, m) + '\n';
1810 msg.append( 32, ' ');
1812 t_str.erase(t_str.begin(), t_str.begin() + m + 1);
1814 msg += t_str + '\n';
1821 SGPropertyNode *name;
1822 name = locale->getNode(section[j]->getStringValue("name"));
1824 if (!msg.empty() && name) {
1825 cout << endl << name->getStringValue() << ":" << endl;
1833 cout << "For a complete list of options use --help --verbose" << endl;
1836 cout << "Hit a key to continue..." << endl;
1841 // A simple function to return an integer depending on the position
1842 // of the status string within the array in order to determine the hierarchy.
1843 unsigned int getNumMaturity(const char * str)
1845 // changes should also be reflected in $FG_ROOT/data/options.xml &
1846 // $FG_ROOT/data/Translations/string-default.xml
1847 const char* levels[] = {"alpha","beta","early-production","production"};
1849 for (size_t i=0; i<(sizeof(levels)/sizeof(levels[0]));i++)
1850 if (strcmp(str,levels[i])==0)
1857 static void fgSearchAircraft(const SGPath &path, string_list &aircraft,
1862 ulDir *dirp = ulOpenDir(path.str().c_str());
1864 cerr << "Unable to open aircraft directory '" << path.str() << '\'' << endl;
1868 while ((dire = ulReadDir(dirp)) != NULL) {
1871 if (dire->d_isdir) {
1872 if (recursive && strcmp("CVS", dire->d_name)
1873 && strcmp(".", dire->d_name) && strcmp("..", dire->d_name))
1876 next.append(dire->d_name);
1878 fgSearchAircraft(next, aircraft, true);
1880 } else if ((ptr = strstr(dire->d_name, "-set.xml")) && (ptr[8] == '\0')) {
1882 SGPath afile = path;
1883 afile.append(dire->d_name);
1887 SGPropertyNode root;
1889 readProperties(afile.str(), &root);
1894 SGPropertyNode *desc = NULL;
1895 SGPropertyNode *status = NULL;
1897 SGPropertyNode *node = root.getNode("sim");
1899 desc = node->getNode("description");
1900 // if a status tag is found, read it in
1901 if (node->hasValue("status"))
1902 status = node->getNode("status");
1905 //additionally display status information where it is available
1907 string descStr(" ");
1908 descStr += dire->d_name;
1910 if (descStr.size() <= 27+3) {
1911 descStr.append(29+3-descStr.size(), ' ');
1914 descStr.append( 32, ' ');
1916 descStr += desc->getStringValue();
1919 SGPropertyNode * required_status
1920 = fgGetNode ("/sim/aircraft-min-status", true);
1922 // If the node holds the value "all", then there wasn't any status
1923 // level specified, so we simply go ahead and output ALL aircraft
1924 if (strcmp(required_status->getStringValue(),"all")==0) {
1925 aircraft.push_back(descStr);
1929 // If the node doesn't hold "all" as its value, then we are supposed
1930 // to show only aircraft meeting specific status (development status)
1933 if (node->hasValue("status")) {
1934 //Compare (minimally) required status level with actual aircraft status:
1935 if ( getNumMaturity(status->getStringValue() ) >=
1936 getNumMaturity(required_status->getStringValue() ) )
1937 aircraft.push_back(descStr); }
1949 * Search in the current directory, and in on directory deeper
1950 * for <aircraft>-set.xml configuration files and show the aircaft name
1951 * and the contents of the<description> tag in a sorted manner.
1953 * @parampath the directory to search for configuration files
1954 * @param recursive defines whether the directory should be searched recursively
1956 void fgShowAircraft(const SGPath &path, bool recursive) {
1957 string_list aircraft;
1959 fgSearchAircraft( path, aircraft, recursive );
1961 sort(aircraft.begin(), aircraft.end());
1962 SG_LOG( SG_GENERAL, SG_ALERT, "" ); // To popup the console on Windows
1963 cout << "Available aircraft:" << endl;
1964 for ( unsigned int i = 0; i < aircraft.size(); i++ ) {
1965 cout << aircraft[i] << endl;
1968 cout << "Hit a key to continue..." << endl;