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>
31 #include <simgear/timing/sg_time.hxx>
32 #include <simgear/misc/sg_dir.hxx>
34 #include <math.h> // rint()
36 #include <stdlib.h> // atof(), atoi()
37 #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>
49 #include <Autopilot/route_mgr.hxx>
52 #include "globals.hxx"
53 #include "fg_init.hxx"
54 #include "fg_props.hxx"
55 #include "options.hxx"
57 #include "viewmgr.hxx"
58 #include <Main/viewer.hxx>
60 #include <simgear/version.h>
61 #include <osg/Version>
69 #if defined( HAVE_VERSION_H ) && HAVE_VERSION_H
70 # include <Include/version.h>
72 # include <Include/no_version.h>
75 #define NEW_DEFAULT_MODEL_HZ 120
83 FG_OPTIONS_VERBOSE_HELP = 4,
84 FG_OPTIONS_SHOW_AIRCRAFT = 5,
85 FG_OPTIONS_SHOW_SOUND_DEVICES = 6
89 atof( const string& str )
91 return ::atof( str.c_str() );
95 atoi( const string& str )
97 return ::atoi( str.c_str() );
101 * Set a few fail-safe default property values.
103 * These should all be set in $FG_ROOT/preferences.xml, but just
104 * in case, we provide some initial sane values here. This method
105 * should be invoked *before* reading any init files.
110 // set a possibly independent location for scenery data
111 const char *envp = ::getenv( "FG_SCENERY" );
113 if ( envp != NULL ) {
114 // fg_root could be anywhere, so default to environmental
115 // variable $FG_ROOT if it is set.
116 globals->set_fg_scenery(envp);
118 // Otherwise, default to Scenery being in $FG_ROOT/Scenery
119 globals->set_fg_scenery("");
122 // Position (deliberately out of range)
123 fgSetDouble("/position/longitude-deg", 9999.0);
124 fgSetDouble("/position/latitude-deg", 9999.0);
125 fgSetDouble("/position/altitude-ft", -9999.0);
128 fgSetDouble("/orientation/heading-deg", 9999.0);
129 fgSetDouble("/orientation/roll-deg", 0.0);
130 fgSetDouble("/orientation/pitch-deg", 0.424);
133 fgSetDouble("/velocities/uBody-fps", 0.0);
134 fgSetDouble("/velocities/vBody-fps", 0.0);
135 fgSetDouble("/velocities/wBody-fps", 0.0);
136 fgSetDouble("/velocities/speed-north-fps", 0.0);
137 fgSetDouble("/velocities/speed-east-fps", 0.0);
138 fgSetDouble("/velocities/speed-down-fps", 0.0);
139 fgSetDouble("/velocities/airspeed-kt", 0.0);
140 fgSetDouble("/velocities/mach", 0.0);
143 fgSetDouble("/sim/presets/longitude-deg", 9999.0);
144 fgSetDouble("/sim/presets/latitude-deg", 9999.0);
145 fgSetDouble("/sim/presets/altitude-ft", -9999.0);
147 fgSetDouble("/sim/presets/heading-deg", 9999.0);
148 fgSetDouble("/sim/presets/roll-deg", 0.0);
149 fgSetDouble("/sim/presets/pitch-deg", 0.424);
151 fgSetString("/sim/presets/speed-set", "knots");
152 fgSetDouble("/sim/presets/airspeed-kt", 0.0);
153 fgSetDouble("/sim/presets/mach", 0.0);
154 fgSetDouble("/sim/presets/uBody-fps", 0.0);
155 fgSetDouble("/sim/presets/vBody-fps", 0.0);
156 fgSetDouble("/sim/presets/wBody-fps", 0.0);
157 fgSetDouble("/sim/presets/speed-north-fps", 0.0);
158 fgSetDouble("/sim/presets/speed-east-fps", 0.0);
159 fgSetDouble("/sim/presets/speed-down-fps", 0.0);
161 fgSetBool("/sim/presets/onground", true);
162 fgSetBool("/sim/presets/trim", false);
165 fgSetBool("/sim/startup/game-mode", false);
166 fgSetBool("/sim/startup/splash-screen", true);
167 fgSetBool("/sim/startup/intro-music", true);
168 // we want mouse-pointer to have an undefined value if nothing is
169 // specified so we can do the right thing for voodoo-1/2 cards.
170 // fgSetString("/sim/startup/mouse-pointer", "disabled");
171 fgSetString("/sim/control-mode", "joystick");
172 fgSetBool("/sim/auto-coordination", false);
174 fgSetString("/sim/startup/browser-app", "webrun.bat");
175 #elif defined(__APPLE__)
176 fgSetString("/sim/startup/browser-app", "open");
178 fgSetString("/sim/startup/browser-app", "launchWebJumper");
180 envp = ::getenv( "WEBBROWSER" );
181 if (!envp) envp = "netscape";
182 fgSetString("/sim/startup/browser-app", envp);
184 fgSetString("/sim/logging/priority", "alert");
187 fgSetBool("/sim/hud/color/antialiased", false);
188 fgSetBool("/sim/hud/enable3d[1]", true);
189 fgSetBool("/sim/hud/visibility[1]", false);
190 fgSetBool("/sim/panel/visibility", true);
191 fgSetBool("/sim/sound/enabled", true);
192 fgSetBool("/sim/sound/working", true);
194 // Flight Model options
195 fgSetString("/sim/flight-model", "jsb");
196 fgSetString("/sim/aero", "c172");
197 fgSetInt("/sim/model-hz", NEW_DEFAULT_MODEL_HZ);
198 fgSetInt("/sim/speed-up", 1);
201 fgSetString("/sim/rendering/fog", "nicest");
202 fgSetBool("/environment/clouds/status", true);
203 fgSetBool("/sim/startup/fullscreen", false);
204 fgSetBool("/sim/rendering/shading", true);
205 fgSetBool("/sim/rendering/skyblend", true);
206 fgSetBool("/sim/rendering/textures", true);
207 fgTie( "/sim/rendering/filtering", SGGetTextureFilter, SGSetTextureFilter, false);
208 fgSetInt("/sim/rendering/filtering", 1);
209 fgSetBool("/sim/rendering/wireframe", false);
210 fgSetBool("/sim/rendering/horizon-effect", false);
211 fgSetBool("/sim/rendering/enhanced-lighting", false);
212 fgSetBool("/sim/rendering/distance-attenuation", false);
213 fgSetBool("/sim/rendering/specular-highlight", true);
214 fgSetInt("/sim/startup/xsize", 800);
215 fgSetInt("/sim/startup/ysize", 600);
216 fgSetInt("/sim/rendering/bits-per-pixel", 16);
217 fgSetString("/sim/view-mode", "pilot");
218 fgSetDouble("/sim/current-view/heading-offset-deg", 0);
221 fgSetString("/sim/startup/units", "feet");
222 fgSetString("/sim/hud/frame-stat-type", "tris");
225 fgSetInt("/sim/startup/time-offset", 0);
226 fgSetString("/sim/startup/time-offset-type", "system-offset");
227 fgSetLong("/sim/time/cur-time-override", 0);
230 fgSetBool("/sim/freeze/master", false);
231 fgSetBool("/sim/freeze/position", false);
232 fgSetBool("/sim/freeze/clock", false);
233 fgSetBool("/sim/freeze/fuel", false);
235 fgSetString("/sim/multiplay/callsign", "callsign");
236 fgSetString("/sim/multiplay/rxhost", "0");
237 fgSetString("/sim/multiplay/txhost", "0");
238 fgSetInt("/sim/multiplay/rxport", 0);
239 fgSetInt("/sim/multiplay/txport", 0);
241 fgSetString("/sim/version/flightgear", FLIGHTGEAR_VERSION);
242 fgSetString("/sim/version/simgear", SG_STRINGIZE(SIMGEAR_VERSION));
243 fgSetString("/sim/version/openscenegraph", osgGetVersion());
244 fgSetString("/sim/version/revision", REVISION);
245 fgSetInt("/sim/version/build-number", HUDSON_BUILD_NUMBER);
246 fgSetString("/sim/version/build-id", HUDSON_BUILD_ID);
250 parse_wind (const string &wind, double * min_hdg, double * max_hdg,
251 double * speed, double * gust)
253 string::size_type pos = wind.find('@');
254 if (pos == string::npos)
256 string dir = wind.substr(0, pos);
257 string spd = wind.substr(pos+1);
259 if (pos == string::npos) {
260 *min_hdg = *max_hdg = atof(dir.c_str());
262 *min_hdg = atof(dir.substr(0,pos).c_str());
263 *max_hdg = atof(dir.substr(pos+1).c_str());
266 if (pos == string::npos) {
267 *speed = *gust = atof(spd.c_str());
269 *speed = atof(spd.substr(0,pos).c_str());
270 *gust = atof(spd.substr(pos+1).c_str());
275 // parse a time string ([+/-]%f[:%f[:%f]]) into hours
277 parse_time(const string& time_in) {
278 char *time_str, num[256];
279 double hours, minutes, seconds;
284 time_str = (char *)time_in.c_str();
286 // printf("parse_time(): %s\n", time_str);
289 if ( strlen(time_str) ) {
290 if ( time_str[0] == '+' ) {
293 } else if ( time_str[0] == '-' ) {
298 // printf("sign = %d\n", sign);
301 if ( strlen(time_str) ) {
303 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
304 num[i] = time_str[0];
308 if ( time_str[0] == ':' ) {
313 // printf("hours = %.2lf\n", hours);
319 if ( strlen(time_str) ) {
321 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
322 num[i] = time_str[0];
326 if ( time_str[0] == ':' ) {
331 // printf("minutes = %.2lf\n", minutes);
333 result += minutes / 60.0;
337 if ( strlen(time_str) ) {
339 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
340 num[i] = time_str[0];
346 // printf("seconds = %.2lf\n", seconds);
348 result += seconds / 3600.0;
351 SG_LOG( SG_GENERAL, SG_INFO, " parse_time() = " << sign * result );
353 return(sign * result);
357 // parse a date string (yyyy:mm:dd:hh:mm:ss) into a time_t (seconds)
359 parse_date( const string& date)
362 char * date_str, num[256];
364 // initialize to zero
371 gmt.tm_isdst = 0; // ignore daylight savings time for the moment
372 date_str = (char *)date.c_str();
374 if ( strlen(date_str) ) {
376 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
377 num[i] = date_str[0];
381 if ( date_str[0] == ':' ) {
385 gmt.tm_year = atoi(num) - 1900;
388 if ( strlen(date_str) ) {
390 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
391 num[i] = date_str[0];
395 if ( date_str[0] == ':' ) {
399 gmt.tm_mon = atoi(num) -1;
402 if ( strlen(date_str) ) {
404 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
405 num[i] = date_str[0];
409 if ( date_str[0] == ':' ) {
413 gmt.tm_mday = atoi(num);
416 if ( strlen(date_str) ) {
418 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
419 num[i] = date_str[0];
423 if ( date_str[0] == ':' ) {
427 gmt.tm_hour = atoi(num);
430 if ( strlen(date_str) ) {
432 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
433 num[i] = date_str[0];
437 if ( date_str[0] == ':' ) {
441 gmt.tm_min = atoi(num);
444 if ( strlen(date_str) ) {
446 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
447 num[i] = date_str[0];
451 if ( date_str[0] == ':' ) {
455 gmt.tm_sec = atoi(num);
457 time_t theTime = sgTimeGetGMT( gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
458 gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
459 //printf ("Date is %s\n", ctime(&theTime));
460 //printf ("in seconds that is %d\n", theTime);
466 // parse angle in the form of [+/-]ddd:mm:ss into degrees
468 parse_degree( const string& degree_str) {
469 double result = parse_time( degree_str );
471 // printf("Degree = %.4f\n", result);
477 // parse time offset string into seconds
479 parse_time_offset( const string& time_str) {
482 // printf("time offset = %s\n", time_str);
485 result = (int)rint(parse_time(time_str) * 3600.0);
487 result = (int)(parse_time(time_str) * 3600.0);
490 // printf("parse_time_offset(): %d\n", result);
496 // Parse --fov=x.xx type option
498 parse_fov( const string& arg ) {
499 double fov = atof(arg);
501 if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
502 if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
504 fgSetDouble("/sim/view[0]/config/default-field-of-view-deg", fov);
506 // printf("parse_fov(): result = %.4f\n", fov);
512 // Parse I/O channel option
514 // Format is "--protocol=medium,direction,hz,medium_options,..."
516 // protocol = { native, nmea, garmin, AV400, AV400Sim, fgfs, rul, pve, etc. }
517 // medium = { serial, socket, file, etc. }
518 // direction = { in, out, bi }
519 // hz = number of times to process channel per second (floating
520 // point values are ok.
522 // Serial example "--nmea=serial,dir,hz,device,baud" where
524 // device = OS device name of serial line to be open()'ed
525 // baud = {300, 1200, 2400, ..., 230400}
527 // Socket exacmple "--native=socket,dir,hz,machine,port,style" where
529 // machine = machine name or ip address if client (leave empty if server)
530 // port = port, leave empty to let system choose
531 // style = tcp or udp
533 // File example "--garmin=file,dir,hz,filename" where
535 // filename = file system file name
538 add_channel( const string& type, const string& channel_str ) {
539 // This check is neccessary to prevent fgviewer from segfaulting when given
540 // weird options. (It doesn't run the full initailization)
541 if(!globals->get_channel_options_list())
543 SG_LOG(SG_GENERAL, SG_ALERT, "Option " << type << "=" << channel_str
547 SG_LOG(SG_GENERAL, SG_INFO, "Channel string = " << channel_str );
548 globals->get_channel_options_list()->push_back( type + "," + channel_str );
553 // The parse wp and parse flight-plan options don't work anymore, because
554 // the route manager and the airport subsystems have not yet been initialized
557 // Parse --wp=ID[@alt]
559 parse_wp( const string& arg ) {
560 string_list *waypoints = globals->get_initial_waypoints();
562 waypoints = new string_list;
563 globals->set_initial_waypoints(waypoints);
565 waypoints->push_back(arg);
569 // Parse --flight-plan=[file]
571 parse_flightplan(const string& arg)
573 string_list *waypoints = globals->get_initial_waypoints();
575 waypoints = new string_list;
576 globals->set_initial_waypoints(waypoints);
579 sg_gzifstream in(arg.c_str());
585 getline( in, line, '\n' );
587 // catch extraneous (DOS) line ending character
588 if ( line[line.length() - 1] < 32 )
589 line = line.substr( 0, line.length()-1 );
594 waypoints->push_back(line);
601 fgOptLanguage( const char *arg )
603 globals->set_locale( fgInitLocale( arg ) );
604 return FG_OPTIONS_OK;
610 fgSetString("/sim/presets/airport-id", "");
611 fgSetString("/sim/presets/vor-id", "");
612 fgSetString("/sim/presets/ndb-id", "");
613 fgSetString("/sim/presets/carrier", "");
614 fgSetString("/sim/presets/parkpos", "");
615 fgSetString("/sim/presets/fix", "");
619 fgOptVOR( const char * arg )
622 fgSetString("/sim/presets/vor-id", arg);
623 return FG_OPTIONS_OK;
627 fgOptNDB( const char * arg )
630 fgSetString("/sim/presets/ndb-id", arg);
631 return FG_OPTIONS_OK;
635 fgOptCarrier( const char * arg )
638 fgSetString("/sim/presets/carrier", arg);
639 return FG_OPTIONS_OK;
643 fgOptParkpos( const char * arg )
645 fgSetString("/sim/presets/parkpos", arg);
646 return FG_OPTIONS_OK;
650 fgOptFIX( const char * arg )
653 fgSetString("/sim/presets/fix", arg);
654 return FG_OPTIONS_OK;
658 fgOptLon( const char *arg )
661 fgSetDouble("/sim/presets/longitude-deg", parse_degree( arg ));
662 fgSetDouble("/position/longitude-deg", parse_degree( arg ));
663 return FG_OPTIONS_OK;
667 fgOptLat( const char *arg )
670 fgSetDouble("/sim/presets/latitude-deg", parse_degree( arg ));
671 fgSetDouble("/position/latitude-deg", parse_degree( arg ));
672 return FG_OPTIONS_OK;
676 fgOptAltitude( const char *arg )
678 fgSetBool("/sim/presets/onground", false);
679 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
680 fgSetDouble("/sim/presets/altitude-ft", atof( arg ));
682 fgSetDouble("/sim/presets/altitude-ft",
683 atof( arg ) * SG_METER_TO_FEET);
684 return FG_OPTIONS_OK;
688 fgOptUBody( const char *arg )
690 fgSetString("/sim/presets/speed-set", "UVW");
691 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
692 fgSetDouble("/sim/presets/uBody-fps", atof( arg ));
694 fgSetDouble("/sim/presets/uBody-fps",
695 atof( arg ) * SG_METER_TO_FEET);
696 return FG_OPTIONS_OK;
700 fgOptVBody( const char *arg )
702 fgSetString("/sim/presets/speed-set", "UVW");
703 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
704 fgSetDouble("/sim/presets/vBody-fps", atof( arg ));
706 fgSetDouble("/sim/presets/vBody-fps",
707 atof( arg ) * SG_METER_TO_FEET);
708 return FG_OPTIONS_OK;
712 fgOptWBody( const char *arg )
714 fgSetString("/sim/presets/speed-set", "UVW");
715 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
716 fgSetDouble("/sim/presets/wBody-fps", atof(arg));
718 fgSetDouble("/sim/presets/wBody-fps",
719 atof(arg) * SG_METER_TO_FEET);
720 return FG_OPTIONS_OK;
724 fgOptVNorth( const char *arg )
726 fgSetString("/sim/presets/speed-set", "NED");
727 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
728 fgSetDouble("/sim/presets/speed-north-fps", atof( arg ));
730 fgSetDouble("/sim/presets/speed-north-fps",
731 atof( arg ) * SG_METER_TO_FEET);
732 return FG_OPTIONS_OK;
736 fgOptVEast( const char *arg )
738 fgSetString("/sim/presets/speed-set", "NED");
739 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
740 fgSetDouble("/sim/presets/speed-east-fps", atof(arg));
742 fgSetDouble("/sim/presets/speed-east-fps",
743 atof(arg) * SG_METER_TO_FEET);
744 return FG_OPTIONS_OK;
748 fgOptVDown( const char *arg )
750 fgSetString("/sim/presets/speed-set", "NED");
751 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
752 fgSetDouble("/sim/presets/speed-down-fps", atof(arg));
754 fgSetDouble("/sim/presets/speed-down-fps",
755 atof(arg) * SG_METER_TO_FEET);
756 return FG_OPTIONS_OK;
760 fgOptVc( const char *arg )
762 // fgSetString("/sim/presets/speed-set", "knots");
763 // fgSetDouble("/velocities/airspeed-kt", atof(arg.substr(5)));
764 fgSetString("/sim/presets/speed-set", "knots");
765 fgSetDouble("/sim/presets/airspeed-kt", atof(arg));
766 return FG_OPTIONS_OK;
770 fgOptMach( const char *arg )
772 fgSetString("/sim/presets/speed-set", "mach");
773 fgSetDouble("/sim/presets/mach", atof(arg));
774 return FG_OPTIONS_OK;
778 fgOptRoc( const char *arg )
780 fgSetDouble("/velocities/vertical-speed-fps", atof(arg)/60);
781 return FG_OPTIONS_OK;
785 fgOptFgRoot( const char *arg )
787 // this option is dealt with by fgInitFGRoot
788 return FG_OPTIONS_OK;
792 fgOptFgScenery( const char *arg )
794 globals->set_fg_scenery(arg);
795 return FG_OPTIONS_OK;
799 fgOptFgAircraft(const char* arg)
801 // this option is dealt with by fgInitFGAircraft
802 return FG_OPTIONS_OK;
806 fgOptFov( const char *arg )
809 return FG_OPTIONS_OK;
813 fgOptGeometry( const char *arg )
815 bool geometry_ok = true;
816 int xsize = 0, ysize = 0;
817 string geometry = arg;
818 string::size_type i = geometry.find('x');
820 if (i != string::npos) {
821 xsize = atoi(geometry.substr(0, i));
822 ysize = atoi(geometry.substr(i+1));
827 if ( xsize <= 0 || ysize <= 0 ) {
833 if ( !geometry_ok ) {
834 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown geometry: " << geometry );
835 SG_LOG( SG_GENERAL, SG_ALERT,
836 "Setting geometry to " << xsize << 'x' << ysize << '\n');
838 SG_LOG( SG_GENERAL, SG_INFO,
839 "Setting geometry to " << xsize << 'x' << ysize << '\n');
840 fgSetInt("/sim/startup/xsize", xsize);
841 fgSetInt("/sim/startup/ysize", ysize);
843 return FG_OPTIONS_OK;
847 fgOptBpp( const char *arg )
849 string bits_per_pix = arg;
850 if ( bits_per_pix == "16" ) {
851 fgSetInt("/sim/rendering/bits-per-pixel", 16);
852 } else if ( bits_per_pix == "24" ) {
853 fgSetInt("/sim/rendering/bits-per-pixel", 24);
854 } else if ( bits_per_pix == "32" ) {
855 fgSetInt("/sim/rendering/bits-per-pixel", 32);
857 SG_LOG(SG_GENERAL, SG_ALERT, "Unsupported bpp " << bits_per_pix);
859 return FG_OPTIONS_OK;
863 fgOptTimeOffset( const char *arg )
865 fgSetInt("/sim/startup/time-offset",
866 parse_time_offset( arg ));
867 fgSetString("/sim/startup/time-offset-type", "system-offset");
868 return FG_OPTIONS_OK;
872 fgOptStartDateSys( const char *arg )
874 fgSetInt("/sim/startup/time-offset", parse_date( arg ) );
875 fgSetString("/sim/startup/time-offset-type", "system");
876 return FG_OPTIONS_OK;
880 fgOptStartDateLat( const char *arg )
882 fgSetInt("/sim/startup/time-offset", parse_date( arg ) );
883 fgSetString("/sim/startup/time-offset-type", "latitude");
884 return FG_OPTIONS_OK;
888 fgOptStartDateGmt( const char *arg )
890 fgSetInt("/sim/startup/time-offset", parse_date( arg ) );
891 fgSetString("/sim/startup/time-offset-type", "gmt");
892 return FG_OPTIONS_OK;
896 fgSetupProxy( const char *arg )
898 string options = arg;
899 string host, port, auth;
900 string::size_type pos;
902 host = port = auth = "";
903 if ((pos = options.find("@")) != string::npos)
904 auth = options.substr(0, pos++);
908 host = options.substr(pos, options.size());
909 if ((pos = host.find(":")) != string::npos) {
910 port = host.substr(++pos, host.size());
911 host.erase(--pos, host.size());
914 fgSetString("/sim/presets/proxy/host", host.c_str());
915 fgSetString("/sim/presets/proxy/port", port.c_str());
916 fgSetString("/sim/presets/proxy/authentication", auth.c_str());
918 return FG_OPTIONS_OK;
922 fgOptTraceRead( const char *arg )
925 SG_LOG(SG_GENERAL, SG_INFO, "Tracing reads for property " << name);
926 fgGetNode(name.c_str(), true)
927 ->setAttribute(SGPropertyNode::TRACE_READ, true);
928 return FG_OPTIONS_OK;
932 fgOptLogLevel( const char *arg )
934 fgSetString("/sim/logging/classes", "all");
935 fgSetString("/sim/logging/priority", arg);
937 string priority = arg;
938 logbuf::set_log_classes(SG_ALL);
939 if (priority == "bulk") {
940 logbuf::set_log_priority(SG_BULK);
941 } else if (priority == "debug") {
942 logbuf::set_log_priority(SG_DEBUG);
943 } else if (priority == "info") {
944 logbuf::set_log_priority(SG_INFO);
945 } else if (priority == "warn") {
946 logbuf::set_log_priority(SG_WARN);
947 } else if (priority == "alert") {
948 logbuf::set_log_priority(SG_ALERT);
950 SG_LOG(SG_GENERAL, SG_WARN, "Unknown logging priority " << priority);
952 SG_LOG(SG_GENERAL, SG_DEBUG, "Logging priority is " << priority);
954 return FG_OPTIONS_OK;
959 fgOptTraceWrite( const char *arg )
962 SG_LOG(SG_GENERAL, SG_INFO, "Tracing writes for property " << name);
963 fgGetNode(name.c_str(), true)
964 ->setAttribute(SGPropertyNode::TRACE_WRITE, true);
965 return FG_OPTIONS_OK;
969 fgOptViewOffset( const char *arg )
971 // $$$ begin - added VS Renganathan, 14 Oct 2K
972 // for multi-window outside window imagery
973 string woffset = arg;
974 double default_view_offset = 0.0;
975 if ( woffset == "LEFT" ) {
976 default_view_offset = SGD_PI * 0.25;
977 } else if ( woffset == "RIGHT" ) {
978 default_view_offset = SGD_PI * 1.75;
979 } else if ( woffset == "CENTER" ) {
980 default_view_offset = 0.00;
982 default_view_offset = atof( woffset.c_str() ) * SGD_DEGREES_TO_RADIANS;
984 /* apparently not used (CLO, 11 Jun 2002)
985 FGViewer *pilot_view =
986 (FGViewer *)globals->get_viewmgr()->get_view( 0 ); */
987 // this will work without calls to the viewer...
988 fgSetDouble( "/sim/current-view/heading-offset-deg",
989 default_view_offset * SGD_RADIANS_TO_DEGREES );
990 // $$$ end - added VS Renganathan, 14 Oct 2K
991 return FG_OPTIONS_OK;
995 fgOptVisibilityMeters( const char *arg )
997 double visibility = atof( arg );
998 fgDefaultWeatherValue("visibility-m", visibility);
999 fgSetDouble("/environment/visibility-m", visibility);
1000 return FG_OPTIONS_OK;
1004 fgOptVisibilityMiles( const char *arg )
1006 double visibility = atof( arg ) * 5280.0 * SG_FEET_TO_METER;
1007 fgDefaultWeatherValue("visibility-m", visibility);
1008 fgSetDouble("/environment/visibility-m", visibility);
1009 return FG_OPTIONS_OK;
1013 fgOptRandomWind( const char *arg )
1015 double min_hdg = sg_random() * 360.0;
1016 double max_hdg = min_hdg + (20 - sqrt(sg_random() * 400));
1017 double speed = sg_random() * sg_random() * 40;
1018 double gust = speed + (10 - sqrt(sg_random() * 100));
1019 fgSetupWind(min_hdg, max_hdg, speed, gust);
1020 return FG_OPTIONS_OK;
1024 fgOptWind( const char *arg )
1026 double min_hdg = 0.0, max_hdg = 0.0, speed = 0.0, gust = 0.0;
1027 if (!parse_wind( arg, &min_hdg, &max_hdg, &speed, &gust)) {
1028 SG_LOG( SG_GENERAL, SG_ALERT, "bad wind value " << arg );
1029 return FG_OPTIONS_ERROR;
1031 fgSetupWind(min_hdg, max_hdg, speed, gust);
1032 return FG_OPTIONS_OK;
1036 fgOptTurbulence( const char *arg )
1038 fgDefaultWeatherValue("turbulence/magnitude-norm", atof(arg));
1039 return FG_OPTIONS_OK;
1043 fgOptCeiling( const char *arg )
1045 double elevation, thickness;
1047 string::size_type pos = spec.find(':');
1048 if (pos == string::npos) {
1049 elevation = atof(spec.c_str());
1052 elevation = atof(spec.substr(0, pos).c_str());
1053 thickness = atof(spec.substr(pos + 1).c_str());
1055 fgSetDouble("/environment/clouds/layer[0]/elevation-ft", elevation);
1056 fgSetDouble("/environment/clouds/layer[0]/thickness-ft", thickness);
1057 fgSetString("/environment/clouds/layer[0]/coverage", "overcast");
1058 return FG_OPTIONS_OK;
1062 fgOptWp( const char *arg )
1065 return FG_OPTIONS_OK;
1069 fgOptFlightPlan( const char *arg )
1071 parse_flightplan ( arg );
1072 return FG_OPTIONS_OK;
1076 fgOptConfig( const char *arg )
1080 readProperties(file, globals->get_props());
1081 } catch (const sg_exception &e) {
1082 string message = "Error loading config file: ";
1083 message += e.getFormattedMessage() + e.getOrigin();
1084 SG_LOG(SG_INPUT, SG_ALERT, message);
1087 return FG_OPTIONS_OK;
1091 parse_colon (const string &s, double * val1, double * val2)
1093 string::size_type pos = s.find(':');
1094 if (pos == string::npos) {
1098 *val1 = atof(s.substr(0, pos).c_str());
1099 *val2 = atof(s.substr(pos+1).c_str());
1106 fgOptFailure( const char * arg )
1110 fgSetBool("/systems/pitot/serviceable", false);
1111 } else if (a == "static") {
1112 fgSetBool("/systems/static/serviceable", false);
1113 } else if (a == "vacuum") {
1114 fgSetBool("/systems/vacuum/serviceable", false);
1115 } else if (a == "electrical") {
1116 fgSetBool("/systems/electrical/serviceable", false);
1118 SG_LOG(SG_INPUT, SG_ALERT, "Unknown failure mode: " << a);
1119 return FG_OPTIONS_ERROR;
1122 return FG_OPTIONS_OK;
1127 fgOptNAV1( const char * arg )
1129 double radial, freq;
1130 if (parse_colon(arg, &radial, &freq))
1131 fgSetDouble("/instrumentation/nav[0]/radials/selected-deg", radial);
1132 fgSetDouble("/instrumentation/nav[0]/frequencies/selected-mhz", freq);
1133 return FG_OPTIONS_OK;
1137 fgOptNAV2( const char * arg )
1139 double radial, freq;
1140 if (parse_colon(arg, &radial, &freq))
1141 fgSetDouble("/instrumentation/nav[1]/radials/selected-deg", radial);
1142 fgSetDouble("/instrumentation/nav[1]/frequencies/selected-mhz", freq);
1143 return FG_OPTIONS_OK;
1147 fgOptADF( const char * arg )
1150 if (parse_colon(arg, &rot, &freq))
1151 fgSetDouble("/instrumentation/adf/rotation-deg", rot);
1152 fgSetDouble("/instrumentation/adf/frequencies/selected-khz", freq);
1153 return FG_OPTIONS_OK;
1157 fgOptDME( const char *arg )
1160 if (opt == "nav1") {
1161 fgSetInt("/instrumentation/dme/switch-position", 1);
1162 fgSetString("/instrumentation/dme/frequencies/source",
1163 "/instrumentation/nav[0]/frequencies/selected-mhz");
1164 } else if (opt == "nav2") {
1165 fgSetInt("/instrumentation/dme/switch-position", 3);
1166 fgSetString("/instrumentation/dme/frequencies/source",
1167 "/instrumentation/nav[1]/frequencies/selected-mhz");
1169 fgSetInt("/instrumentation/dme/switch-position", 2);
1170 fgSetString("/instrumentation/dme/frequencies/source",
1171 "/instrumentation/dme/frequencies/selected-mhz");
1172 fgSetString("/instrumentation/dme/frequencies/selected-mhz", arg);
1174 return FG_OPTIONS_OK;
1178 fgOptLivery( const char *arg )
1181 string livery_path = "livery/" + opt;
1182 fgSetString("/sim/model/texture-path", livery_path.c_str() );
1183 return FG_OPTIONS_OK;
1187 fgOptScenario( const char *arg )
1189 SGPropertyNode_ptr ai_node = fgGetNode( "/sim/ai", true );
1190 vector<SGPropertyNode_ptr> scenarii = ai_node->getChildren( "scenario" );
1192 for ( size_t i = 0; i < scenarii.size(); ++i ) {
1193 int ind = scenarii[i]->getIndex();
1194 if ( index < ind ) {
1198 SGPropertyNode_ptr scenario = ai_node->getNode( "scenario", index + 1, true );
1199 scenario->setStringValue( arg );
1200 ai_node->setBoolValue( "enabled", true );
1201 return FG_OPTIONS_OK;
1205 fgOptRunway( const char *arg )
1207 fgSetString("/sim/presets/runway", arg );
1208 fgSetBool("/sim/presets/runway-requested", true );
1209 return FG_OPTIONS_OK;
1213 fgOptParking( const char *arg )
1215 cerr << "Processing argument " << arg << endl;
1216 fgSetString("/sim/presets/parking", arg );
1217 fgSetBool ("/sim/presets/parking-requested", true );
1218 return FG_OPTIONS_OK;
1222 fgOptVersion( const char *arg )
1224 cerr << "FlightGear version: " << FLIGHTGEAR_VERSION << endl;
1225 cerr << "Revision: " << REVISION << endl;
1226 cerr << "Build-Id: " << HUDSON_BUILD_ID << endl;
1227 cerr << "FG_ROOT=" << globals->get_fg_root() << endl;
1228 cerr << "FG_HOME=" << fgGetString("/sim/fg-home") << endl;
1229 cerr << "FG_SCENERY=";
1232 string_list scn = globals->get_fg_scenery();
1233 for (string_list::const_iterator it = scn.begin(); it != scn.end(); it++)
1235 if (didsome) cerr << ":";
1240 cerr << "SimGear version: " << SG_STRINGIZE(SIMGEAR_VERSION) << endl;
1241 cerr << "PLIB version: " << PLIB_VERSION << endl;
1242 return FG_OPTIONS_EXIT;
1246 fgOptFpe(const char* arg)
1248 // Actually handled in bootstrap.cxx
1249 return FG_OPTIONS_OK;
1253 fgOptFgviewer(const char* arg)
1255 // Actually handled in bootstrap.cxx
1256 return FG_OPTIONS_OK;
1260 fgOptCallSign(const char * arg)
1264 strncpy(callsign,arg,10);
1266 for (i=0;callsign[i];i++)
1268 char c = callsign[i];
1269 if (c >= 'A' && c <= 'Z') continue;
1270 if (c >= 'a' && c <= 'z') continue;
1271 if (c >= '0' && c <= '9') continue;
1272 if (c == '-' || c == '_') continue;
1273 // convert any other illegal characters
1276 fgSetString("sim/multiplay/callsign", callsign );
1277 return FG_OPTIONS_OK;
1281 static map<string,size_t> fgOptionMap;
1284 option has_param type property b_param s_param func
1287 option : name of the option
1288 has_param : option is --name=value if true or --name if false
1289 type : OPTION_BOOL - property is a boolean
1290 OPTION_STRING - property is a string
1291 OPTION_DOUBLE - property is a double
1292 OPTION_INT - property is an integer
1293 OPTION_CHANNEL - name of option is the name of a channel
1294 OPTION_FUNC - the option trigger a function
1295 b_param : if type==OPTION_BOOL,
1296 value set to the property (has_param is false for boolean)
1297 s_param : if type==OPTION_STRING,
1298 value set to the property if has_param is false
1299 func : function called if type==OPTION_FUNC. if has_param is true,
1300 the value is passed to the function as a string, otherwise,
1303 For OPTION_DOUBLE and OPTION_INT, the parameter value is converted into a
1304 double or an integer and set to the property.
1306 For OPTION_CHANNEL, add_channel is called with the parameter value as the
1310 enum OptionType { OPTION_BOOL, OPTION_STRING, OPTION_DOUBLE, OPTION_INT, OPTION_CHANNEL, OPTION_FUNC };
1314 enum OptionType type;
1315 const char *property;
1317 const char *s_param;
1318 int (*func)( const char * );
1319 } fgOptionArray[] = {
1321 {"language", true, OPTION_FUNC, "", false, "", fgOptLanguage },
1322 {"disable-game-mode", false, OPTION_BOOL, "/sim/startup/game-mode", false, "", 0 },
1323 {"enable-game-mode", false, OPTION_BOOL, "/sim/startup/game-mode", true, "", 0 },
1324 {"disable-splash-screen", false, OPTION_BOOL, "/sim/startup/splash-screen", false, "", 0 },
1325 {"enable-splash-screen", false, OPTION_BOOL, "/sim/startup/splash-screen", true, "", 0 },
1326 {"disable-intro-music", false, OPTION_BOOL, "/sim/startup/intro-music", false, "", 0 },
1327 {"enable-intro-music", false, OPTION_BOOL, "/sim/startup/intro-music", true, "", 0 },
1328 {"disable-mouse-pointer", false, OPTION_STRING, "/sim/startup/mouse-pointer", false, "disabled", 0 },
1329 {"enable-mouse-pointer", false, OPTION_STRING, "/sim/startup/mouse-pointer", false, "enabled", 0 },
1330 {"disable-random-objects", false, OPTION_BOOL, "/sim/rendering/random-objects", false, "", 0 },
1331 {"enable-random-objects", false, OPTION_BOOL, "/sim/rendering/random-objects", true, "", 0 },
1332 {"disable-real-weather-fetch", false, OPTION_BOOL, "/environment/realwx/enabled", false, "", 0 },
1333 {"enable-real-weather-fetch", false, OPTION_BOOL, "/environment/realwx/enabled", true, "", 0 },
1334 {"metar", true, OPTION_STRING, "/environment/metar/data", false, "", 0 },
1335 {"disable-ai-models", false, OPTION_BOOL, "/sim/ai/enabled", false, "", 0 },
1336 {"enable-ai-models", false, OPTION_BOOL, "/sim/ai/enabled", true, "", 0 },
1337 {"disable-ai-traffic", false, OPTION_BOOL, "/sim/traffic-manager/enabled", false, "", 0 },
1338 {"enable-ai-traffic", false, OPTION_BOOL, "/sim/traffic-manager/enabled", true, "", 0 },
1339 {"disable-freeze", false, OPTION_BOOL, "/sim/freeze/master", false, "", 0 },
1340 {"enable-freeze", false, OPTION_BOOL, "/sim/freeze/master", true, "", 0 },
1341 {"disable-fuel-freeze", false, OPTION_BOOL, "/sim/freeze/fuel", false, "", 0 },
1342 {"enable-fuel-freeze", false, OPTION_BOOL, "/sim/freeze/fuel", true, "", 0 },
1343 {"disable-clock-freeze", false, OPTION_BOOL, "/sim/freeze/clock", false, "", 0 },
1344 {"enable-clock-freeze", false, OPTION_BOOL, "/sim/freeze/clock", true, "", 0 },
1345 {"disable-hud-3d", false, OPTION_BOOL, "/sim/hud/enable3d[1]", false, "", 0 },
1346 {"enable-hud-3d", false, OPTION_BOOL, "/sim/hud/enable3d[1]", true, "", 0 },
1347 {"disable-anti-alias-hud", false, OPTION_BOOL, "/sim/hud/color/antialiased", false, "", 0 },
1348 {"enable-anti-alias-hud", false, OPTION_BOOL, "/sim/hud/color/antialiased", true, "", 0 },
1349 {"control", true, OPTION_STRING, "/sim/control-mode", false, "", 0 },
1350 {"disable-auto-coordination", false, OPTION_BOOL, "/sim/auto-coordination", false, "", 0 },
1351 {"enable-auto-coordination", false, OPTION_BOOL, "/sim/auto-coordination", true, "", 0 },
1352 {"browser-app", true, OPTION_STRING, "/sim/startup/browser-app", false, "", 0 },
1353 {"disable-hud", false, OPTION_BOOL, "/sim/hud/visibility[1]", false, "", 0 },
1354 {"enable-hud", false, OPTION_BOOL, "/sim/hud/visibility[1]", true, "", 0 },
1355 {"disable-panel", false, OPTION_BOOL, "/sim/panel/visibility", false, "", 0 },
1356 {"enable-panel", false, OPTION_BOOL, "/sim/panel/visibility", true, "", 0 },
1357 {"disable-sound", false, OPTION_BOOL, "/sim/sound/working", false, "", 0 },
1358 {"enable-sound", false, OPTION_BOOL, "/sim/sound/working", true, "", 0 },
1359 {"sound-device", true, OPTION_STRING, "/sim/sound/device-name", false, "", 0 },
1360 {"airport", true, OPTION_STRING, "/sim/presets/airport-id", false, "", 0 },
1361 {"runway", true, OPTION_FUNC, "", false, "", fgOptRunway },
1362 {"vor", true, OPTION_FUNC, "", false, "", fgOptVOR },
1363 {"ndb", true, OPTION_FUNC, "", false, "", fgOptNDB },
1364 {"carrier", true, OPTION_FUNC, "", false, "", fgOptCarrier },
1365 {"parkpos", true, OPTION_FUNC, "", false, "", fgOptParkpos },
1366 {"fix", true, OPTION_FUNC, "", false, "", fgOptFIX },
1367 {"offset-distance", true, OPTION_DOUBLE, "/sim/presets/offset-distance-nm", false, "", 0 },
1368 {"offset-azimuth", true, OPTION_DOUBLE, "/sim/presets/offset-azimuth-deg", false, "", 0 },
1369 {"lon", true, OPTION_FUNC, "", false, "", fgOptLon },
1370 {"lat", true, OPTION_FUNC, "", false, "", fgOptLat },
1371 {"altitude", true, OPTION_FUNC, "", false, "", fgOptAltitude },
1372 {"uBody", true, OPTION_FUNC, "", false, "", fgOptUBody },
1373 {"vBody", true, OPTION_FUNC, "", false, "", fgOptVBody },
1374 {"wBody", true, OPTION_FUNC, "", false, "", fgOptWBody },
1375 {"vNorth", true, OPTION_FUNC, "", false, "", fgOptVNorth },
1376 {"vEast", true, OPTION_FUNC, "", false, "", fgOptVEast },
1377 {"vDown", true, OPTION_FUNC, "", false, "", fgOptVDown },
1378 {"vc", true, OPTION_FUNC, "", false, "", fgOptVc },
1379 {"mach", true, OPTION_FUNC, "", false, "", fgOptMach },
1380 {"heading", true, OPTION_DOUBLE, "/sim/presets/heading-deg", false, "", 0 },
1381 {"roll", true, OPTION_DOUBLE, "/sim/presets/roll-deg", false, "", 0 },
1382 {"pitch", true, OPTION_DOUBLE, "/sim/presets/pitch-deg", false, "", 0 },
1383 {"glideslope", true, OPTION_DOUBLE, "/sim/presets/glideslope-deg", false, "", 0 },
1384 {"roc", true, OPTION_FUNC, "", false, "", fgOptRoc },
1385 {"fg-root", true, OPTION_FUNC, "", false, "", fgOptFgRoot },
1386 {"fg-scenery", true, OPTION_FUNC, "", false, "", fgOptFgScenery },
1387 {"fg-aircraft", true, OPTION_FUNC, "", false, "", fgOptFgAircraft },
1388 {"fdm", true, OPTION_STRING, "/sim/flight-model", false, "", 0 },
1389 {"aero", true, OPTION_STRING, "/sim/aero", false, "", 0 },
1390 {"aircraft-dir", true, OPTION_STRING, "/sim/aircraft-dir", false, "", 0 },
1391 {"model-hz", true, OPTION_INT, "/sim/model-hz", false, "", 0 },
1392 {"speed", true, OPTION_INT, "/sim/speed-up", false, "", 0 },
1393 {"trim", false, OPTION_BOOL, "/sim/presets/trim", true, "", 0 },
1394 {"notrim", false, OPTION_BOOL, "/sim/presets/trim", false, "", 0 },
1395 {"on-ground", false, OPTION_BOOL, "/sim/presets/onground", true, "", 0 },
1396 {"in-air", false, OPTION_BOOL, "/sim/presets/onground", false, "", 0 },
1397 {"fog-disable", false, OPTION_STRING, "/sim/rendering/fog", false, "disabled", 0 },
1398 {"fog-fastest", false, OPTION_STRING, "/sim/rendering/fog", false, "fastest", 0 },
1399 {"fog-nicest", false, OPTION_STRING, "/sim/rendering/fog", false, "nicest", 0 },
1400 {"disable-horizon-effect", false, OPTION_BOOL, "/sim/rendering/horizon-effect", false, "", 0 },
1401 {"enable-horizon-effect", false, OPTION_BOOL, "/sim/rendering/horizon-effect", true, "", 0 },
1402 {"disable-enhanced-lighting", false, OPTION_BOOL, "/sim/rendering/enhanced-lighting", false, "", 0 },
1403 {"enable-enhanced-lighting", false, OPTION_BOOL, "/sim/rendering/enhanced-lighting", true, "", 0 },
1404 {"disable-distance-attenuation", false, OPTION_BOOL, "/sim/rendering/distance-attenuation", false, "", 0 },
1405 {"enable-distance-attenuation", false, OPTION_BOOL, "/sim/rendering/distance-attenuation", true, "", 0 },
1406 {"disable-specular-highlight", false, OPTION_BOOL, "/sim/rendering/specular-highlight", false, "", 0 },
1407 {"enable-specular-highlight", false, OPTION_BOOL, "/sim/rendering/specular-highlight", true, "", 0 },
1408 {"disable-clouds", false, OPTION_BOOL, "/environment/clouds/status", false, "", 0 },
1409 {"enable-clouds", false, OPTION_BOOL, "/environment/clouds/status", true, "", 0 },
1410 {"disable-clouds3d", false, OPTION_BOOL, "/sim/rendering/clouds3d-enable", false, "", 0 },
1411 {"enable-clouds3d", false, OPTION_BOOL, "/sim/rendering/clouds3d-enable", true, "", 0 },
1412 {"fov", true, OPTION_FUNC, "", false, "", fgOptFov },
1413 {"aspect-ratio-multiplier", true, OPTION_DOUBLE, "/sim/current-view/aspect-ratio-multiplier", false, "", 0 },
1414 {"disable-fullscreen", false, OPTION_BOOL, "/sim/startup/fullscreen", false, "", 0 },
1415 {"enable-fullscreen", false, OPTION_BOOL, "/sim/startup/fullscreen", true, "", 0 },
1416 {"disable-save-on-exit", false, OPTION_BOOL, "/sim/startup/save-on-exit", false, "", 0 },
1417 {"enable-save-on-exit", false, OPTION_BOOL, "/sim/startup/save-on-exit", true, "", 0 },
1418 {"shading-flat", false, OPTION_BOOL, "/sim/rendering/shading", false, "", 0 },
1419 {"shading-smooth", false, OPTION_BOOL, "/sim/rendering/shading", true, "", 0 },
1420 {"disable-skyblend", false, OPTION_BOOL, "/sim/rendering/skyblend", false, "", 0 },
1421 {"enable-skyblend", false, OPTION_BOOL, "/sim/rendering/skyblend", true, "", 0 },
1422 {"disable-textures", false, OPTION_BOOL, "/sim/rendering/textures", false, "", 0 },
1423 {"enable-textures", false, OPTION_BOOL, "/sim/rendering/textures", true, "", 0 },
1424 {"texture-filtering", false, OPTION_INT, "/sim/rendering/filtering", 1, "", 0 },
1425 {"disable-wireframe", false, OPTION_BOOL, "/sim/rendering/wireframe", false, "", 0 },
1426 {"enable-wireframe", false, OPTION_BOOL, "/sim/rendering/wireframe", true, "", 0 },
1427 {"geometry", true, OPTION_FUNC, "", false, "", fgOptGeometry },
1428 {"bpp", true, OPTION_FUNC, "", false, "", fgOptBpp },
1429 {"units-feet", false, OPTION_STRING, "/sim/startup/units", false, "feet", 0 },
1430 {"units-meters", false, OPTION_STRING, "/sim/startup/units", false, "meters", 0 },
1431 {"timeofday", true, OPTION_STRING, "/sim/startup/time-offset-type", false, "noon", 0 },
1432 {"season", true, OPTION_STRING, "/sim/startup/season", false, "summer", 0 },
1433 {"time-offset", true, OPTION_FUNC, "", false, "", fgOptTimeOffset },
1434 {"time-match-real", false, OPTION_STRING, "/sim/startup/time-offset-type", false, "system-offset", 0 },
1435 {"time-match-local", false, OPTION_STRING, "/sim/startup/time-offset-type", false, "latitude-offset", 0 },
1436 {"start-date-sys", true, OPTION_FUNC, "", false, "", fgOptStartDateSys },
1437 {"start-date-lat", true, OPTION_FUNC, "", false, "", fgOptStartDateLat },
1438 {"start-date-gmt", true, OPTION_FUNC, "", false, "", fgOptStartDateGmt },
1439 {"hud-tris", false, OPTION_STRING, "/sim/hud/frame-stat-type", false, "tris", 0 },
1440 {"hud-culled", false, OPTION_STRING, "/sim/hud/frame-stat-type", false, "culled", 0 },
1441 {"atcsim", true, OPTION_CHANNEL, "", false, "dummy", 0 },
1442 {"atlas", true, OPTION_CHANNEL, "", false, "", 0 },
1443 {"httpd", true, OPTION_CHANNEL, "", false, "", 0 },
1444 #ifdef FG_JPEG_SERVER
1445 {"jpg-httpd", true, OPTION_CHANNEL, "", false, "", 0 },
1447 {"native", true, OPTION_CHANNEL, "", false, "", 0 },
1448 {"native-ctrls", true, OPTION_CHANNEL, "", false, "", 0 },
1449 {"native-fdm", true, OPTION_CHANNEL, "", false, "", 0 },
1450 {"native-gui", true, OPTION_CHANNEL, "", false, "", 0 },
1451 {"opengc", true, OPTION_CHANNEL, "", false, "", 0 },
1452 {"AV400", true, OPTION_CHANNEL, "", false, "", 0 },
1453 {"AV400Sim", true, OPTION_CHANNEL, "", false, "", 0 },
1454 {"garmin", true, OPTION_CHANNEL, "", false, "", 0 },
1455 {"nmea", true, OPTION_CHANNEL, "", false, "", 0 },
1456 {"generic", true, OPTION_CHANNEL, "", false, "", 0 },
1457 {"props", true, OPTION_CHANNEL, "", false, "", 0 },
1458 {"telnet", true, OPTION_CHANNEL, "", false, "", 0 },
1459 {"pve", true, OPTION_CHANNEL, "", false, "", 0 },
1460 {"ray", true, OPTION_CHANNEL, "", false, "", 0 },
1461 {"rul", true, OPTION_CHANNEL, "", false, "", 0 },
1462 {"joyclient", true, OPTION_CHANNEL, "", false, "", 0 },
1463 {"jsclient", true, OPTION_CHANNEL, "", false, "", 0 },
1464 {"proxy", true, OPTION_FUNC, "", false, "", fgSetupProxy },
1465 {"callsign", true, OPTION_FUNC, "", false, "", fgOptCallSign},
1466 {"multiplay", true, OPTION_CHANNEL, "", false, "", 0 },
1467 {"trace-read", true, OPTION_FUNC, "", false, "", fgOptTraceRead },
1468 {"trace-write", true, OPTION_FUNC, "", false, "", fgOptTraceWrite },
1469 {"log-level", true, OPTION_FUNC, "", false, "", fgOptLogLevel },
1470 {"view-offset", true, OPTION_FUNC, "", false, "", fgOptViewOffset },
1471 {"visibility", true, OPTION_FUNC, "", false, "", fgOptVisibilityMeters },
1472 {"visibility-miles", true, OPTION_FUNC, "", false, "", fgOptVisibilityMiles },
1473 {"random-wind", false, OPTION_FUNC, "", false, "", fgOptRandomWind },
1474 {"wind", true, OPTION_FUNC, "", false, "", fgOptWind },
1475 {"turbulence", true, OPTION_FUNC, "", false, "", fgOptTurbulence },
1476 {"ceiling", true, OPTION_FUNC, "", false, "", fgOptCeiling },
1477 {"wp", true, OPTION_FUNC, "", false, "", fgOptWp },
1478 {"flight-plan", true, OPTION_FUNC, "", false, "", fgOptFlightPlan },
1479 {"config", true, OPTION_FUNC, "", false, "", fgOptConfig },
1480 {"aircraft", true, OPTION_STRING, "/sim/aircraft", false, "", 0 },
1481 {"vehicle", true, OPTION_STRING, "/sim/aircraft", false, "", 0 },
1482 {"failure", true, OPTION_FUNC, "", false, "", fgOptFailure },
1483 {"com1", true, OPTION_DOUBLE, "/instrumentation/comm[0]/frequencies/selected-mhz", false, "", 0 },
1484 {"com2", true, OPTION_DOUBLE, "/instrumentation/comm[1]/frequencies/selected-mhz", false, "", 0 },
1485 {"nav1", true, OPTION_FUNC, "", false, "", fgOptNAV1 },
1486 {"nav2", true, OPTION_FUNC, "", false, "", fgOptNAV2 },
1487 {"adf", true, OPTION_FUNC, "", false, "", fgOptADF },
1488 {"dme", true, OPTION_FUNC, "", false, "", fgOptDME },
1489 {"min-status", true, OPTION_STRING, "/sim/aircraft-min-status", false, "all", 0 },
1490 {"livery", true, OPTION_FUNC, "", false, "", fgOptLivery },
1491 {"ai-scenario", true, OPTION_FUNC, "", false, "", fgOptScenario },
1492 {"parking-id", true, OPTION_FUNC, "", false, "", fgOptParking },
1493 {"version", false, OPTION_FUNC, "", false, "", fgOptVersion },
1494 {"enable-fpe", false, OPTION_FUNC, "", false, "", fgOptFpe},
1495 {"fgviewer", false, OPTION_FUNC, "", false, "", fgOptFgviewer},
1500 // Set a property for the --prop: option. Syntax: --prop:[<type>:]<name>=<value>
1501 // <type> can be "double" etc. but also only the first letter "d".
1502 // Examples: --prop:alpha=1 --prop:bool:beta=true --prop:d:gamma=0.123
1504 set_property(const string& arg)
1506 string::size_type pos = arg.find('=');
1507 if (pos == arg.npos || pos == 0 || pos + 1 == arg.size())
1510 string name = arg.substr(0, pos);
1511 string value = arg.substr(pos + 1);
1513 pos = name.find(':');
1515 if (pos != name.npos && pos != 0 && pos + 1 != name.size()) {
1516 type = name.substr(0, pos);
1517 name = name.substr(pos + 1);
1519 SGPropertyNode *n = fgGetNode(name.c_str(), true);
1521 bool writable = n->getAttribute(SGPropertyNode::WRITE);
1523 n->setAttribute(SGPropertyNode::WRITE, true);
1527 ret = n->setUnspecifiedValue(value.c_str());
1528 else if (type == "s" || type == "string")
1529 ret = n->setStringValue(value.c_str());
1530 else if (type == "d" || type == "double")
1531 ret = n->setDoubleValue(strtod(value.c_str(), 0));
1532 else if (type == "f" || type == "float")
1533 ret = n->setFloatValue(atof(value.c_str()));
1534 else if (type == "l" || type == "long")
1535 ret = n->setLongValue(strtol(value.c_str(), 0, 0));
1536 else if (type == "i" || type == "int")
1537 ret = n->setIntValue(atoi(value.c_str()));
1538 else if (type == "b" || type == "bool")
1539 ret = n->setBoolValue(value == "true" || atoi(value.c_str()) != 0);
1542 n->setAttribute(SGPropertyNode::WRITE, false);
1547 // Parse a single option
1549 parse_option (const string& arg)
1551 if ( fgOptionMap.size() == 0 ) {
1553 OptionDesc *pt = &fgOptionArray[ 0 ];
1554 while ( pt->option != 0 ) {
1555 fgOptionMap[ pt->option ] = i;
1562 if ( (arg == "--help") || (arg == "-h") ) {
1563 // help/usage request
1564 return(FG_OPTIONS_HELP);
1565 } else if ( (arg == "--verbose") || (arg == "-v") ) {
1566 // verbose help/usage request
1567 return(FG_OPTIONS_VERBOSE_HELP);
1568 } else if ( arg.find( "--show-aircraft") == 0) {
1569 return(FG_OPTIONS_SHOW_AIRCRAFT);
1570 } else if ( arg.find( "--show-sound-devices") == 0) {
1571 return(FG_OPTIONS_SHOW_SOUND_DEVICES);
1572 } else if ( arg.find( "--prop:" ) == 0 ) {
1573 if (!set_property(arg.substr(7))) {
1574 SG_LOG( SG_GENERAL, SG_ALERT, "Bad property assignment: " << arg );
1575 return FG_OPTIONS_ERROR;
1577 } else if ( arg.find("-psn_") == 0) {
1578 // on Mac, when launched from the GUI, we are passed the ProcessSerialNumber
1579 // as an argument (and no others). Silently ignore the argument here.
1580 return FG_OPTIONS_OK;
1581 } else if ( arg.find( "--" ) == 0 ) {
1582 size_t pos = arg.find( '=' );
1583 string arg_name, arg_value;
1584 if ( pos == string::npos ) {
1585 arg_name = arg.substr( 2 );
1587 arg_name = arg.substr( 2, pos - 2 );
1588 arg_value = arg.substr( pos + 1);
1590 map<string,size_t>::iterator it = fgOptionMap.find( arg_name );
1591 if ( it != fgOptionMap.end() ) {
1592 OptionDesc *pt = &fgOptionArray[ it->second ];
1593 switch ( pt->type ) {
1595 fgSetBool( pt->property, pt->b_param );
1598 if ( pt->has_param && !arg_value.empty() ) {
1599 fgSetString( pt->property, arg_value.c_str() );
1600 } else if ( !pt->has_param && arg_value.empty() ) {
1601 fgSetString( pt->property, pt->s_param );
1602 } else if ( pt->has_param ) {
1603 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1604 return FG_OPTIONS_ERROR;
1606 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' does not have a parameter" );
1607 return FG_OPTIONS_ERROR;
1611 if ( !arg_value.empty() ) {
1612 fgSetDouble( pt->property, atof( arg_value ) );
1614 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1615 return FG_OPTIONS_ERROR;
1619 if ( !arg_value.empty() ) {
1620 fgSetInt( pt->property, atoi( arg_value ) );
1622 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1623 return FG_OPTIONS_ERROR;
1626 case OPTION_CHANNEL:
1627 // XXX return value of add_channel should be checked?
1628 if ( pt->has_param && !arg_value.empty() ) {
1629 add_channel( pt->option, arg_value );
1630 } else if ( !pt->has_param && arg_value.empty() ) {
1631 add_channel( pt->option, pt->s_param );
1632 } else if ( pt->has_param ) {
1633 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1634 return FG_OPTIONS_ERROR;
1636 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' does not have a parameter" );
1637 return FG_OPTIONS_ERROR;
1641 if ( pt->has_param && !arg_value.empty() ) {
1642 return pt->func( arg_value.c_str() );
1643 } else if ( !pt->has_param && arg_value.empty() ) {
1644 return pt->func( pt->s_param );
1645 } else if ( pt->has_param ) {
1646 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1647 return FG_OPTIONS_ERROR;
1649 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' does not have a parameter" );
1650 return FG_OPTIONS_ERROR;
1655 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" );
1656 return FG_OPTIONS_ERROR;
1659 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" );
1660 return FG_OPTIONS_ERROR;
1663 return FG_OPTIONS_OK;
1667 // Parse the command line options
1669 fgParseArgs (int argc, char **argv)
1671 bool in_options = true;
1672 bool verbose = false;
1675 SG_LOG(SG_GENERAL, SG_ALERT, "Processing command line arguments");
1677 for (int i = 1; i < argc; i++) {
1678 string arg = argv[i];
1680 if (in_options && (arg.find('-') == 0)) {
1684 int result = parse_option(arg);
1685 if ((result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR))
1688 else if (result == FG_OPTIONS_VERBOSE_HELP)
1691 else if (result == FG_OPTIONS_SHOW_AIRCRAFT) {
1692 fgOptLogLevel( "alert" );
1693 SGPath path( globals->get_fg_root() );
1694 path.append("Aircraft");
1695 fgShowAircraft(path);
1698 } else if (result == FG_OPTIONS_SHOW_SOUND_DEVICES) {
1702 string vendor = smgr.get_vendor();
1703 string renderer = smgr.get_renderer();
1704 cout << renderer << " provided by " << vendor << endl;
1705 cout << endl << "No. Device" << endl;
1707 vector <const char*>devices = smgr.get_available_devices();
1708 for (vector <const char*>::size_type i=0; i<devices.size(); i++) {
1709 cout << i << ". \"" << devices[i] << "\"" << endl;
1715 else if (result == FG_OPTIONS_EXIT)
1720 SG_LOG(SG_GENERAL, SG_INFO,
1721 "Reading command-line property file " << arg);
1722 readProperties(arg, globals->get_props());
1727 fgOptLogLevel( "alert" );
1732 SG_LOG(SG_GENERAL, SG_INFO, "Finished command line arguments");
1736 // Parse config file options
1738 fgParseOptions (const string& path) {
1739 sg_gzifstream in( path );
1740 if ( !in.is_open() ) {
1744 SG_LOG( SG_GENERAL, SG_INFO, "Processing config file: " << path );
1747 while ( ! in.eof() ) {
1749 getline( in, line, '\n' );
1751 // catch extraneous (DOS) line ending character
1753 for (i = line.length(); i > 0; i--)
1754 if (line[i - 1] > 32)
1756 line = line.substr( 0, i );
1758 if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
1759 cerr << endl << "Config file parse error: " << path << " '"
1760 << line << "'" << endl;
1769 // Print usage message
1771 fgUsage (bool verbose)
1773 SGPropertyNode *locale = globals->get_locale();
1775 SGPropertyNode options_root;
1777 SG_LOG( SG_GENERAL, SG_ALERT, "" ); // To popup the console on Windows
1781 fgLoadProps("options.xml", &options_root);
1782 } catch (const sg_exception &) {
1783 cout << "Unable to read the help file." << endl;
1784 cout << "Make sure the file options.xml is located in the FlightGear base directory," << endl;
1785 cout << "and the location of the base directory is specified by setting $FG_ROOT or" << endl;
1786 cout << "by adding --fg-root=path as a program argument." << endl;
1791 SGPropertyNode *options = options_root.getNode("options");
1793 SG_LOG( SG_GENERAL, SG_ALERT,
1794 "Error reading options.xml: <options> directive not found." );
1798 SGPropertyNode *usage = locale->getNode(options->getStringValue("usage"));
1800 cout << "Usage: " << usage->getStringValue() << endl;
1803 vector<SGPropertyNode_ptr>section = options->getChildren("section");
1804 for (unsigned int j = 0; j < section.size(); j++) {
1807 vector<SGPropertyNode_ptr>option = section[j]->getChildren("option");
1808 for (unsigned int k = 0; k < option.size(); k++) {
1810 SGPropertyNode *name = option[k]->getNode("name");
1811 SGPropertyNode *short_name = option[k]->getNode("short");
1812 SGPropertyNode *key = option[k]->getNode("key");
1813 SGPropertyNode *arg = option[k]->getNode("arg");
1814 bool brief = option[k]->getNode("brief") != 0;
1816 if ((brief || verbose) && name) {
1817 string tmp = name->getStringValue();
1821 tmp.append(key->getStringValue());
1825 tmp.append(arg->getStringValue());
1829 tmp.append(short_name->getStringValue());
1832 if (tmp.size() <= 25) {
1835 msg.append( 27-tmp.size(), ' ');
1839 msg.append(32, ' ');
1841 // There may be more than one <description> tag assosiated
1844 vector<SGPropertyNode_ptr> desc;
1845 desc = option[k]->getChildren("description");
1846 if (desc.size() > 0) {
1847 for ( unsigned int l = 0; l < desc.size(); l++) {
1849 // There may be more than one translation line.
1851 string t = desc[l]->getStringValue();
1852 SGPropertyNode *n = locale->getNode("strings");
1853 vector<SGPropertyNode_ptr>trans_desc =
1854 n->getChildren(t.substr(8).c_str());
1856 for ( unsigned int m = 0; m < trans_desc.size(); m++ ) {
1857 string t_str = trans_desc[m]->getStringValue();
1859 if ((m > 0) || ((l > 0) && m == 0)) {
1860 msg.append( 32, ' ');
1863 // If the string is too large to fit on the screen,
1864 // then split it up in several pieces.
1866 while ( t_str.size() > 47 ) {
1868 unsigned int m = t_str.rfind(' ', 47);
1869 msg += t_str.substr(0, m) + '\n';
1870 msg.append( 32, ' ');
1872 t_str.erase(t_str.begin(), t_str.begin() + m + 1);
1874 msg += t_str + '\n';
1881 SGPropertyNode *name;
1882 name = locale->getNode(section[j]->getStringValue("name"));
1884 if (!msg.empty() && name) {
1885 cout << endl << name->getStringValue() << ":" << endl;
1893 cout << "For a complete list of options use --help --verbose" << endl;
1896 cout << "Hit a key to continue..." << endl;