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 <boost/foreach.hpp>
36 #include <math.h> // rint()
38 #include <stdlib.h> // atof(), atoi()
39 #include <string.h> // strcmp()
45 #include <simgear/math/sg_random.h>
46 #include <simgear/props/props_io.hxx>
47 #include <simgear/misc/sgstream.hxx>
48 #include <simgear/misc/sg_path.hxx>
49 #include <simgear/scene/material/mat.hxx>
50 #include <simgear/sound/soundmgr_openal.hxx>
51 #include <simgear/misc/strutils.hxx>
52 #include <Autopilot/route_mgr.hxx>
55 #include "globals.hxx"
56 #include "fg_init.hxx"
57 #include "fg_props.hxx"
58 #include "options.hxx"
62 #include <Viewer/viewer.hxx>
63 #include <Viewer/viewmgr.hxx>
64 #include <Environment/presets.hxx>
66 #include <osg/Version>
68 #if defined( HAVE_VERSION_H ) && HAVE_VERSION_H
69 # include <Include/version.h>
70 # include <simgear/version.h>
72 # include <Include/no_version.h>
76 # include <CoreFoundation/CoreFoundation.h>
87 #define NEW_DEFAULT_MODEL_HZ 120
95 FG_OPTIONS_VERBOSE_HELP = 4,
96 FG_OPTIONS_SHOW_AIRCRAFT = 5,
97 FG_OPTIONS_SHOW_SOUND_DEVICES = 6
100 static flightgear::Options* shared_instance = NULL;
103 atof( const string& str )
105 return ::atof( str.c_str() );
109 atoi( const string& str )
111 return ::atoi( str.c_str() );
114 static int fgSetupProxy( const char *arg );
117 * Set a few fail-safe default property values.
119 * These should all be set in $FG_ROOT/preferences.xml, but just
120 * in case, we provide some initial sane values here. This method
121 * should be invoked *before* reading any init files.
127 // Position (deliberately out of range)
128 fgSetDouble("/position/longitude-deg", 9999.0);
129 fgSetDouble("/position/latitude-deg", 9999.0);
130 fgSetDouble("/position/altitude-ft", -9999.0);
133 fgSetDouble("/orientation/heading-deg", 9999.0);
134 fgSetDouble("/orientation/roll-deg", 0.0);
135 fgSetDouble("/orientation/pitch-deg", 0.424);
138 fgSetDouble("/velocities/uBody-fps", 0.0);
139 fgSetDouble("/velocities/vBody-fps", 0.0);
140 fgSetDouble("/velocities/wBody-fps", 0.0);
141 fgSetDouble("/velocities/speed-north-fps", 0.0);
142 fgSetDouble("/velocities/speed-east-fps", 0.0);
143 fgSetDouble("/velocities/speed-down-fps", 0.0);
144 fgSetDouble("/velocities/airspeed-kt", 0.0);
145 fgSetDouble("/velocities/mach", 0.0);
148 fgSetDouble("/sim/presets/longitude-deg", 9999.0);
149 fgSetDouble("/sim/presets/latitude-deg", 9999.0);
150 fgSetDouble("/sim/presets/altitude-ft", -9999.0);
152 fgSetDouble("/sim/presets/heading-deg", 9999.0);
153 fgSetDouble("/sim/presets/roll-deg", 0.0);
154 fgSetDouble("/sim/presets/pitch-deg", 0.424);
156 fgSetString("/sim/presets/speed-set", "knots");
157 fgSetDouble("/sim/presets/airspeed-kt", 0.0);
158 fgSetDouble("/sim/presets/mach", 0.0);
159 fgSetDouble("/sim/presets/uBody-fps", 0.0);
160 fgSetDouble("/sim/presets/vBody-fps", 0.0);
161 fgSetDouble("/sim/presets/wBody-fps", 0.0);
162 fgSetDouble("/sim/presets/speed-north-fps", 0.0);
163 fgSetDouble("/sim/presets/speed-east-fps", 0.0);
164 fgSetDouble("/sim/presets/speed-down-fps", 0.0);
166 fgSetBool("/sim/presets/onground", true);
167 fgSetBool("/sim/presets/trim", false);
170 fgSetBool("/sim/startup/game-mode", false);
171 fgSetBool("/sim/startup/splash-screen", true);
172 fgSetBool("/sim/startup/intro-music", true);
173 // we want mouse-pointer to have an undefined value if nothing is
174 // specified so we can do the right thing for voodoo-1/2 cards.
175 // fgSetString("/sim/startup/mouse-pointer", "disabled");
176 fgSetString("/sim/control-mode", "joystick");
177 fgSetBool("/controls/flight/auto-coordination", false);
178 fgSetString("/sim/logging/priority", "alert");
181 fgSetBool("/sim/hud/color/antialiased", false);
182 fgSetBool("/sim/hud/enable3d[1]", true);
183 fgSetBool("/sim/hud/visibility[1]", false);
184 fgSetBool("/sim/panel/visibility", true);
185 fgSetBool("/sim/sound/enabled", true);
186 fgSetBool("/sim/sound/working", true);
188 // Flight Model options
189 fgSetString("/sim/flight-model", "jsb");
190 fgSetString("/sim/aero", "c172");
191 fgSetInt("/sim/model-hz", NEW_DEFAULT_MODEL_HZ);
192 fgSetInt("/sim/speed-up", 1);
195 fgSetString("/sim/rendering/fog", "nicest");
196 fgSetBool("/environment/clouds/status", true);
197 fgSetBool("/sim/startup/fullscreen", false);
198 fgSetBool("/sim/rendering/shading", true);
199 fgSetBool("/sim/rendering/skyblend", true);
200 fgSetBool("/sim/rendering/textures", true);
201 fgTie( "/sim/rendering/filtering", SGGetTextureFilter, SGSetTextureFilter, false);
202 fgSetInt("/sim/rendering/filtering", 1);
203 fgSetBool("/sim/rendering/wireframe", false);
204 fgSetBool("/sim/rendering/horizon-effect", false);
205 fgSetBool("/sim/rendering/enhanced-lighting", false);
206 fgSetBool("/sim/rendering/distance-attenuation", false);
207 fgSetBool("/sim/rendering/specular-highlight", true);
208 fgSetString("/sim/rendering/materials-file", "materials.xml");
209 fgSetInt("/sim/startup/xsize", 800);
210 fgSetInt("/sim/startup/ysize", 600);
211 fgSetInt("/sim/rendering/bits-per-pixel", 16);
212 fgSetString("/sim/view-mode", "pilot");
213 fgSetDouble("/sim/current-view/heading-offset-deg", 0);
216 fgSetString("/sim/startup/units", "feet");
217 fgSetString("/sim/hud/frame-stat-type", "tris");
220 fgSetInt("/sim/startup/time-offset", 0);
221 fgSetString("/sim/startup/time-offset-type", "system-offset");
222 fgSetLong("/sim/time/cur-time-override", 0);
225 fgSetBool("/sim/freeze/master", false);
226 fgSetBool("/sim/freeze/position", false);
227 fgSetBool("/sim/freeze/clock", false);
228 fgSetBool("/sim/freeze/fuel", false);
230 fgSetString("/sim/multiplay/callsign", "callsign");
231 fgSetString("/sim/multiplay/rxhost", "");
232 fgSetString("/sim/multiplay/txhost", "");
233 fgSetInt("/sim/multiplay/rxport", 0);
234 fgSetInt("/sim/multiplay/txport", 0);
236 fgSetString("/sim/version/flightgear", FLIGHTGEAR_VERSION);
237 fgSetString("/sim/version/simgear", SG_STRINGIZE(SIMGEAR_VERSION));
238 fgSetString("/sim/version/openscenegraph", osgGetVersion());
239 fgSetString("/sim/version/revision", REVISION);
240 fgSetInt("/sim/version/build-number", HUDSON_BUILD_NUMBER);
241 fgSetString("/sim/version/build-id", HUDSON_BUILD_ID);
243 char* envp = ::getenv( "http_proxy" );
245 fgSetupProxy( envp );
249 parse_wind (const string &wind, double * min_hdg, double * max_hdg,
250 double * speed, double * gust)
252 string::size_type pos = wind.find('@');
253 if (pos == string::npos)
255 string dir = wind.substr(0, pos);
256 string spd = wind.substr(pos+1);
258 if (pos == string::npos) {
259 *min_hdg = *max_hdg = atof(dir.c_str());
261 *min_hdg = atof(dir.substr(0,pos).c_str());
262 *max_hdg = atof(dir.substr(pos+1).c_str());
265 if (pos == string::npos) {
266 *speed = *gust = atof(spd.c_str());
268 *speed = atof(spd.substr(0,pos).c_str());
269 *gust = atof(spd.substr(pos+1).c_str());
275 parseIntValue(char** ppParserPos, int* pValue,int min, int max, const char* field, const char* argument)
277 if ( !strlen(*ppParserPos) )
283 while ( isdigit((*ppParserPos)[0]) && (i<255) )
285 num[i] = (*ppParserPos)[0];
291 switch ((*ppParserPos)[0])
299 SG_LOG(SG_GENERAL, SG_ALERT, "Illegal character in time string for " << field << ": '" <<
300 (*ppParserPos)[0] << "'.");
301 // invalid field - skip rest of string to avoid further errors
302 while ((*ppParserPos)[0])
310 int value = atoi(num);
311 if ((value < min)||(value > max))
313 SG_LOG(SG_GENERAL, SG_ALERT, "Invalid " << field << " in '" << argument <<
314 "'. Valid range is " << min << "-" << max << ".");
324 // parse a time string ([+/-]%f[:%f[:%f]]) into hours
326 parse_time(const string& time_in) {
327 char *time_str, num[256];
328 double hours, minutes, seconds;
333 time_str = (char *)time_in.c_str();
335 // printf("parse_time(): %s\n", time_str);
338 if ( strlen(time_str) ) {
339 if ( time_str[0] == '+' ) {
342 } else if ( time_str[0] == '-' ) {
347 // printf("sign = %d\n", sign);
350 if ( strlen(time_str) ) {
352 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
353 num[i] = time_str[0];
357 if ( time_str[0] == ':' ) {
362 // printf("hours = %.2lf\n", hours);
368 if ( strlen(time_str) ) {
370 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
371 num[i] = time_str[0];
375 if ( time_str[0] == ':' ) {
380 // printf("minutes = %.2lf\n", minutes);
382 result += minutes / 60.0;
386 if ( strlen(time_str) ) {
388 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
389 num[i] = time_str[0];
395 // printf("seconds = %.2lf\n", seconds);
397 result += seconds / 3600.0;
400 SG_LOG( SG_GENERAL, SG_INFO, " parse_time() = " << sign * result );
402 return(sign * result);
405 // parse a date string (yyyy:mm:dd:hh:mm:ss) into a time_t (seconds)
407 parse_date( const string& date, const char* timeType)
409 struct tm gmt,*pCurrentTime;
410 int year,month,day,hour,minute,second;
411 char *argument, *date_str;
413 SGTime CurrentTime = SGTime();
414 CurrentTime.update(0,0,0,0);
416 // FIXME This should obtain system/aircraft/GMT time depending on timeType
417 pCurrentTime = CurrentTime.getGmt();
419 // initialize all fields with current time
420 year = pCurrentTime->tm_year + 1900;
421 month = pCurrentTime->tm_mon + 1;
422 day = pCurrentTime->tm_mday;
423 hour = pCurrentTime->tm_hour;
424 minute = pCurrentTime->tm_min;
425 second = pCurrentTime->tm_sec;
427 argument = (char *)date.c_str();
430 // start with parsing year
431 if (!strlen(date_str) ||
432 !parseIntValue(&date_str,&year,0,9999,"year",argument))
439 SG_LOG(SG_GENERAL, SG_ALERT, "Invalid year '" << year << "'. Use 1970 or later.");
443 parseIntValue(&date_str, &month, 1, 12, "month", argument);
444 parseIntValue(&date_str, &day, 1, 31, "day", argument);
445 parseIntValue(&date_str, &hour, 0, 23, "hour", argument);
446 parseIntValue(&date_str, &minute, 0, 59, "minute", argument);
447 parseIntValue(&date_str, &second, 0, 59, "second", argument);
453 gmt.tm_mon = month - 1;
454 gmt.tm_year = year -1900;
455 gmt.tm_isdst = 0; // ignore daylight savings time for the moment
457 time_t theTime = sgTimeGetGMT( gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
458 gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
460 SG_LOG(SG_GENERAL, SG_INFO, "Configuring startup time to " << ctime(&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 );
555 fgSetString("/sim/presets/airport-id", "");
556 fgSetString("/sim/presets/vor-id", "");
557 fgSetString("/sim/presets/ndb-id", "");
558 fgSetString("/sim/presets/carrier", "");
559 fgSetString("/sim/presets/parkpos", "");
560 fgSetString("/sim/presets/fix", "");
564 fgOptVOR( const char * arg )
567 fgSetString("/sim/presets/vor-id", arg);
568 return FG_OPTIONS_OK;
572 fgOptNDB( const char * arg )
575 fgSetString("/sim/presets/ndb-id", arg);
576 return FG_OPTIONS_OK;
580 fgOptCarrier( const char * arg )
583 fgSetString("/sim/presets/carrier", arg);
584 return FG_OPTIONS_OK;
588 fgOptParkpos( const char * arg )
590 fgSetString("/sim/presets/parkpos", arg);
591 return FG_OPTIONS_OK;
595 fgOptFIX( const char * arg )
598 fgSetString("/sim/presets/fix", arg);
599 return FG_OPTIONS_OK;
603 fgOptLon( const char *arg )
606 fgSetDouble("/sim/presets/longitude-deg", parse_degree( arg ));
607 fgSetDouble("/position/longitude-deg", parse_degree( arg ));
608 return FG_OPTIONS_OK;
612 fgOptLat( const char *arg )
615 fgSetDouble("/sim/presets/latitude-deg", parse_degree( arg ));
616 fgSetDouble("/position/latitude-deg", parse_degree( arg ));
617 return FG_OPTIONS_OK;
621 fgOptAltitude( const char *arg )
623 fgSetBool("/sim/presets/onground", false);
624 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
625 fgSetDouble("/sim/presets/altitude-ft", atof( arg ));
627 fgSetDouble("/sim/presets/altitude-ft",
628 atof( arg ) * SG_METER_TO_FEET);
629 return FG_OPTIONS_OK;
633 fgOptUBody( const char *arg )
635 fgSetString("/sim/presets/speed-set", "UVW");
636 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
637 fgSetDouble("/sim/presets/uBody-fps", atof( arg ));
639 fgSetDouble("/sim/presets/uBody-fps",
640 atof( arg ) * SG_METER_TO_FEET);
641 return FG_OPTIONS_OK;
645 fgOptVBody( const char *arg )
647 fgSetString("/sim/presets/speed-set", "UVW");
648 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
649 fgSetDouble("/sim/presets/vBody-fps", atof( arg ));
651 fgSetDouble("/sim/presets/vBody-fps",
652 atof( arg ) * SG_METER_TO_FEET);
653 return FG_OPTIONS_OK;
657 fgOptWBody( const char *arg )
659 fgSetString("/sim/presets/speed-set", "UVW");
660 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
661 fgSetDouble("/sim/presets/wBody-fps", atof(arg));
663 fgSetDouble("/sim/presets/wBody-fps",
664 atof(arg) * SG_METER_TO_FEET);
665 return FG_OPTIONS_OK;
669 fgOptVNorth( const char *arg )
671 fgSetString("/sim/presets/speed-set", "NED");
672 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
673 fgSetDouble("/sim/presets/speed-north-fps", atof( arg ));
675 fgSetDouble("/sim/presets/speed-north-fps",
676 atof( arg ) * SG_METER_TO_FEET);
677 return FG_OPTIONS_OK;
681 fgOptVEast( const char *arg )
683 fgSetString("/sim/presets/speed-set", "NED");
684 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
685 fgSetDouble("/sim/presets/speed-east-fps", atof(arg));
687 fgSetDouble("/sim/presets/speed-east-fps",
688 atof(arg) * SG_METER_TO_FEET);
689 return FG_OPTIONS_OK;
693 fgOptVDown( const char *arg )
695 fgSetString("/sim/presets/speed-set", "NED");
696 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
697 fgSetDouble("/sim/presets/speed-down-fps", atof(arg));
699 fgSetDouble("/sim/presets/speed-down-fps",
700 atof(arg) * SG_METER_TO_FEET);
701 return FG_OPTIONS_OK;
705 fgOptVc( const char *arg )
707 // fgSetString("/sim/presets/speed-set", "knots");
708 // fgSetDouble("/velocities/airspeed-kt", atof(arg.substr(5)));
709 fgSetString("/sim/presets/speed-set", "knots");
710 fgSetDouble("/sim/presets/airspeed-kt", atof(arg));
711 return FG_OPTIONS_OK;
715 fgOptMach( const char *arg )
717 fgSetString("/sim/presets/speed-set", "mach");
718 fgSetDouble("/sim/presets/mach", atof(arg));
719 return FG_OPTIONS_OK;
723 fgOptRoc( const char *arg )
725 fgSetDouble("/sim/presets/vertical-speed-fps", atof(arg)/60);
726 return FG_OPTIONS_OK;
730 fgOptFgScenery( const char *arg )
732 globals->append_fg_scenery(arg);
733 return FG_OPTIONS_OK;
737 fgOptFov( const char *arg )
740 return FG_OPTIONS_OK;
744 fgOptGeometry( const char *arg )
746 bool geometry_ok = true;
747 int xsize = 0, ysize = 0;
748 string geometry = arg;
749 string::size_type i = geometry.find('x');
751 if (i != string::npos) {
752 xsize = atoi(geometry.substr(0, i));
753 ysize = atoi(geometry.substr(i+1));
758 if ( xsize <= 0 || ysize <= 0 ) {
764 if ( !geometry_ok ) {
765 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown geometry: " << geometry );
766 SG_LOG( SG_GENERAL, SG_ALERT,
767 "Setting geometry to " << xsize << 'x' << ysize << '\n');
769 SG_LOG( SG_GENERAL, SG_INFO,
770 "Setting geometry to " << xsize << 'x' << ysize << '\n');
771 fgSetInt("/sim/startup/xsize", xsize);
772 fgSetInt("/sim/startup/ysize", ysize);
774 return FG_OPTIONS_OK;
778 fgOptBpp( const char *arg )
780 string bits_per_pix = arg;
781 if ( bits_per_pix == "16" ) {
782 fgSetInt("/sim/rendering/bits-per-pixel", 16);
783 } else if ( bits_per_pix == "24" ) {
784 fgSetInt("/sim/rendering/bits-per-pixel", 24);
785 } else if ( bits_per_pix == "32" ) {
786 fgSetInt("/sim/rendering/bits-per-pixel", 32);
788 SG_LOG(SG_GENERAL, SG_ALERT, "Unsupported bpp " << bits_per_pix);
790 return FG_OPTIONS_OK;
794 fgOptTimeOffset( const char *arg )
796 fgSetLong("/sim/startup/time-offset",
797 parse_time_offset( arg ));
798 fgSetString("/sim/startup/time-offset-type", "system-offset");
799 return FG_OPTIONS_OK;
803 fgOptStartDateSys( const char *arg )
805 long int theTime = parse_date( arg, "system" );
808 fgSetLong("/sim/startup/time-offset", theTime);
809 fgSetString("/sim/startup/time-offset-type", "system");
811 return FG_OPTIONS_OK;
815 fgOptStartDateLat( const char *arg )
817 long int theTime = parse_date( arg, "latitude" );
820 fgSetLong("/sim/startup/time-offset", theTime);
821 fgSetString("/sim/startup/time-offset-type", "latitude");
823 return FG_OPTIONS_OK;
827 fgOptStartDateGmt( const char *arg )
829 long int theTime = parse_date( arg, "gmt" );
832 fgSetLong("/sim/startup/time-offset", theTime);
833 fgSetString("/sim/startup/time-offset-type", "gmt");
835 return FG_OPTIONS_OK;
839 fgSetupProxy( const char *arg )
841 string options = simgear::strutils::strip( arg );
842 string host, port, auth;
843 string::size_type pos;
845 // this is NURLP - NURLP is not an url parser
846 if( simgear::strutils::starts_with( options, "http://" ) )
847 options = options.substr( 7 );
848 if( simgear::strutils::ends_with( options, "/" ) )
849 options = options.substr( 0, options.length() - 1 );
851 host = port = auth = "";
852 if ((pos = options.find("@")) != string::npos)
853 auth = options.substr(0, pos++);
857 host = options.substr(pos, options.size());
858 if ((pos = host.find(":")) != string::npos) {
859 port = host.substr(++pos, host.size());
860 host.erase(--pos, host.size());
863 fgSetString("/sim/presets/proxy/host", host.c_str());
864 fgSetString("/sim/presets/proxy/port", port.c_str());
865 fgSetString("/sim/presets/proxy/authentication", auth.c_str());
867 return FG_OPTIONS_OK;
871 fgOptTraceRead( const char *arg )
874 SG_LOG(SG_GENERAL, SG_INFO, "Tracing reads for property " << name);
875 fgGetNode(name.c_str(), true)
876 ->setAttribute(SGPropertyNode::TRACE_READ, true);
877 return FG_OPTIONS_OK;
881 fgOptLogLevel( const char *arg )
883 fgSetString("/sim/logging/priority", arg);
884 setLoggingPriority(arg);
886 return FG_OPTIONS_OK;
890 fgOptLogClasses( const char *arg )
892 fgSetString("/sim/logging/classes", arg);
893 setLoggingClasses (arg);
895 return FG_OPTIONS_OK;
899 fgOptTraceWrite( const char *arg )
902 SG_LOG(SG_GENERAL, SG_INFO, "Tracing writes for property " << name);
903 fgGetNode(name.c_str(), true)
904 ->setAttribute(SGPropertyNode::TRACE_WRITE, true);
905 return FG_OPTIONS_OK;
909 fgOptViewOffset( const char *arg )
911 // $$$ begin - added VS Renganathan, 14 Oct 2K
912 // for multi-window outside window imagery
913 string woffset = arg;
914 double default_view_offset = 0.0;
915 if ( woffset == "LEFT" ) {
916 default_view_offset = SGD_PI * 0.25;
917 } else if ( woffset == "RIGHT" ) {
918 default_view_offset = SGD_PI * 1.75;
919 } else if ( woffset == "CENTER" ) {
920 default_view_offset = 0.00;
922 default_view_offset = atof( woffset.c_str() ) * SGD_DEGREES_TO_RADIANS;
924 /* apparently not used (CLO, 11 Jun 2002)
925 FGViewer *pilot_view =
926 (FGViewer *)globals->get_viewmgr()->get_view( 0 ); */
927 // this will work without calls to the viewer...
928 fgSetDouble( "/sim/current-view/heading-offset-deg",
929 default_view_offset * SGD_RADIANS_TO_DEGREES );
930 // $$$ end - added VS Renganathan, 14 Oct 2K
931 return FG_OPTIONS_OK;
935 fgOptVisibilityMeters( const char *arg )
937 Environment::Presets::VisibilitySingleton::instance()->preset( atof( arg ) );
938 return FG_OPTIONS_OK;
942 fgOptVisibilityMiles( const char *arg )
944 Environment::Presets::VisibilitySingleton::instance()->preset( atof( arg ) * 5280.0 * SG_FEET_TO_METER );
945 return FG_OPTIONS_OK;
949 fgOptRandomWind( const char *arg )
951 double min_hdg = sg_random() * 360.0;
952 double max_hdg = min_hdg + (20 - sqrt(sg_random() * 400));
953 double speed = sg_random() * sg_random() * 40;
954 double gust = speed + (10 - sqrt(sg_random() * 100));
955 Environment::Presets::WindSingleton::instance()->preset(min_hdg, max_hdg, speed, gust);
956 return FG_OPTIONS_OK;
960 fgOptWind( const char *arg )
962 double min_hdg = 0.0, max_hdg = 0.0, speed = 0.0, gust = 0.0;
963 if (!parse_wind( arg, &min_hdg, &max_hdg, &speed, &gust)) {
964 SG_LOG( SG_GENERAL, SG_ALERT, "bad wind value " << arg );
965 return FG_OPTIONS_ERROR;
967 Environment::Presets::WindSingleton::instance()->preset(min_hdg, max_hdg, speed, gust);
968 return FG_OPTIONS_OK;
972 fgOptTurbulence( const char *arg )
974 Environment::Presets::TurbulenceSingleton::instance()->preset( atof(arg) );
975 return FG_OPTIONS_OK;
979 fgOptCeiling( const char *arg )
981 double elevation, thickness;
983 string::size_type pos = spec.find(':');
984 if (pos == string::npos) {
985 elevation = atof(spec.c_str());
988 elevation = atof(spec.substr(0, pos).c_str());
989 thickness = atof(spec.substr(pos + 1).c_str());
991 Environment::Presets::CeilingSingleton::instance()->preset( elevation, thickness );
992 return FG_OPTIONS_OK;
996 fgOptWp( const char *arg )
998 string_list *waypoints = globals->get_initial_waypoints();
1000 waypoints = new string_list;
1001 globals->set_initial_waypoints(waypoints);
1003 waypoints->push_back(arg);
1004 return FG_OPTIONS_OK;
1008 fgOptConfig( const char *arg )
1012 readProperties(file, globals->get_props());
1013 } catch (const sg_exception &e) {
1014 string message = "Error loading config file: ";
1015 message += e.getFormattedMessage() + e.getOrigin();
1016 SG_LOG(SG_INPUT, SG_ALERT, message);
1019 return FG_OPTIONS_OK;
1023 parse_colon (const string &s, double * val1, double * val2)
1025 string::size_type pos = s.find(':');
1026 if (pos == string::npos) {
1030 *val1 = atof(s.substr(0, pos).c_str());
1031 *val2 = atof(s.substr(pos+1).c_str());
1038 fgOptFailure( const char * arg )
1042 fgSetBool("/systems/pitot/serviceable", false);
1043 } else if (a == "static") {
1044 fgSetBool("/systems/static/serviceable", false);
1045 } else if (a == "vacuum") {
1046 fgSetBool("/systems/vacuum/serviceable", false);
1047 } else if (a == "electrical") {
1048 fgSetBool("/systems/electrical/serviceable", false);
1050 SG_LOG(SG_INPUT, SG_ALERT, "Unknown failure mode: " << a);
1051 return FG_OPTIONS_ERROR;
1054 return FG_OPTIONS_OK;
1059 fgOptNAV1( const char * arg )
1061 double radial, freq;
1062 if (parse_colon(arg, &radial, &freq))
1063 fgSetDouble("/instrumentation/nav[0]/radials/selected-deg", radial);
1064 fgSetDouble("/instrumentation/nav[0]/frequencies/selected-mhz", freq);
1065 return FG_OPTIONS_OK;
1069 fgOptNAV2( const char * arg )
1071 double radial, freq;
1072 if (parse_colon(arg, &radial, &freq))
1073 fgSetDouble("/instrumentation/nav[1]/radials/selected-deg", radial);
1074 fgSetDouble("/instrumentation/nav[1]/frequencies/selected-mhz", freq);
1075 return FG_OPTIONS_OK;
1079 fgOptADF1( const char * arg )
1082 if (parse_colon(arg, &rot, &freq))
1083 fgSetDouble("/instrumentation/adf[0]/rotation-deg", rot);
1084 fgSetDouble("/instrumentation/adf[0]/frequencies/selected-khz", freq);
1085 return FG_OPTIONS_OK;
1089 fgOptADF2( const char * arg )
1092 if (parse_colon(arg, &rot, &freq))
1093 fgSetDouble("/instrumentation/adf[1]/rotation-deg", rot);
1094 fgSetDouble("/instrumentation/adf[1]/frequencies/selected-khz", freq);
1095 return FG_OPTIONS_OK;
1099 fgOptDME( const char *arg )
1102 if (opt == "nav1") {
1103 fgSetInt("/instrumentation/dme/switch-position", 1);
1104 fgSetString("/instrumentation/dme/frequencies/source",
1105 "/instrumentation/nav[0]/frequencies/selected-mhz");
1106 } else if (opt == "nav2") {
1107 fgSetInt("/instrumentation/dme/switch-position", 3);
1108 fgSetString("/instrumentation/dme/frequencies/source",
1109 "/instrumentation/nav[1]/frequencies/selected-mhz");
1111 double frequency = atof(arg);
1114 SG_LOG(SG_INPUT, SG_ALERT, "Invalid DME frequency: '" << arg << "'.");
1115 return FG_OPTIONS_ERROR;
1117 fgSetInt("/instrumentation/dme/switch-position", 2);
1118 fgSetString("/instrumentation/dme/frequencies/source",
1119 "/instrumentation/dme/frequencies/selected-mhz");
1120 fgSetDouble("/instrumentation/dme/frequencies/selected-mhz", frequency);
1122 return FG_OPTIONS_OK;
1126 fgOptLivery( const char *arg )
1129 string livery_path = "livery/" + opt;
1130 fgSetString("/sim/model/texture-path", livery_path.c_str() );
1131 return FG_OPTIONS_OK;
1135 fgOptScenario( const char *arg )
1137 SGPropertyNode_ptr ai_node = fgGetNode( "/sim/ai", true );
1138 vector<SGPropertyNode_ptr> scenarii = ai_node->getChildren( "scenario" );
1140 for ( size_t i = 0; i < scenarii.size(); ++i ) {
1141 int ind = scenarii[i]->getIndex();
1142 if ( index < ind ) {
1146 SGPropertyNode_ptr scenario = ai_node->getNode( "scenario", index + 1, true );
1147 scenario->setStringValue( arg );
1148 ai_node->setBoolValue( "scenarios-enabled", true );
1149 return FG_OPTIONS_OK;
1153 fgOptNoScenarios( const char *arg )
1155 SGPropertyNode_ptr ai_node = fgGetNode( "/sim/ai", true );
1156 ai_node->removeChildren("scenario",false);
1157 ai_node->setBoolValue( "scenarios-enabled", false );
1158 return FG_OPTIONS_OK;
1162 fgOptRunway( const char *arg )
1164 fgSetString("/sim/presets/runway", arg );
1165 fgSetBool("/sim/presets/runway-requested", true );
1166 return FG_OPTIONS_OK;
1170 fgOptParking( const char *arg )
1172 cerr << "Processing argument " << arg << endl;
1173 fgSetString("/sim/presets/parking", arg );
1174 fgSetBool ("/sim/presets/parking-requested", true );
1175 return FG_OPTIONS_OK;
1179 fgOptVersion( const char *arg )
1181 cerr << "FlightGear version: " << FLIGHTGEAR_VERSION << endl;
1182 cerr << "Revision: " << REVISION << endl;
1183 cerr << "Build-Id: " << HUDSON_BUILD_ID << endl;
1184 cerr << "FG_ROOT=" << globals->get_fg_root() << endl;
1185 cerr << "FG_HOME=" << globals->get_fg_home() << endl;
1186 cerr << "FG_SCENERY=";
1189 string_list scn = globals->get_fg_scenery();
1190 for (string_list::const_iterator it = scn.begin(); it != scn.end(); it++)
1192 if (didsome) cerr << ":";
1197 cerr << "SimGear version: " << SG_STRINGIZE(SIMGEAR_VERSION) << endl;
1198 cerr << "PLIB version: " << PLIB_VERSION << endl;
1199 return FG_OPTIONS_EXIT;
1203 fgOptCallSign(const char * arg)
1207 strncpy(callsign,arg,10);
1209 for (i=0;callsign[i];i++)
1211 char c = callsign[i];
1212 if (c >= 'A' && c <= 'Z') continue;
1213 if (c >= 'a' && c <= 'z') continue;
1214 if (c >= '0' && c <= '9') continue;
1215 if (c == '-' || c == '_') continue;
1216 // convert any other illegal characters
1219 fgSetString("sim/multiplay/callsign", callsign );
1220 return FG_OPTIONS_OK;
1224 // Set a property for the --prop: option. Syntax: --prop:[<type>:]<name>=<value>
1225 // <type> can be "double" etc. but also only the first letter "d".
1226 // Examples: --prop:alpha=1 --prop:bool:beta=true --prop:d:gamma=0.123
1228 fgOptSetProperty(const char* raw)
1231 string::size_type pos = arg.find('=');
1232 if (pos == arg.npos || pos == 0 || pos + 1 == arg.size())
1233 return FG_OPTIONS_ERROR;
1235 string name = arg.substr(0, pos);
1236 string value = arg.substr(pos + 1);
1238 pos = name.find(':');
1240 if (pos != name.npos && pos != 0 && pos + 1 != name.size()) {
1241 type = name.substr(0, pos);
1242 name = name.substr(pos + 1);
1244 SGPropertyNode *n = fgGetNode(name.c_str(), true);
1246 bool writable = n->getAttribute(SGPropertyNode::WRITE);
1248 n->setAttribute(SGPropertyNode::WRITE, true);
1252 ret = n->setUnspecifiedValue(value.c_str());
1253 else if (type == "s" || type == "string")
1254 ret = n->setStringValue(value.c_str());
1255 else if (type == "d" || type == "double")
1256 ret = n->setDoubleValue(strtod(value.c_str(), 0));
1257 else if (type == "f" || type == "float")
1258 ret = n->setFloatValue(atof(value.c_str()));
1259 else if (type == "l" || type == "long")
1260 ret = n->setLongValue(strtol(value.c_str(), 0, 0));
1261 else if (type == "i" || type == "int")
1262 ret = n->setIntValue(atoi(value.c_str()));
1263 else if (type == "b" || type == "bool")
1264 ret = n->setBoolValue(value == "true" || atoi(value.c_str()) != 0);
1267 n->setAttribute(SGPropertyNode::WRITE, false);
1268 return ret ? FG_OPTIONS_OK : FG_OPTIONS_ERROR;
1274 option has_param type property b_param s_param func
1277 option : name of the option
1278 has_param : option is --name=value if true or --name if false
1279 type : OPTION_BOOL - property is a boolean
1280 OPTION_STRING - property is a string
1281 OPTION_DOUBLE - property is a double
1282 OPTION_INT - property is an integer
1283 OPTION_CHANNEL - name of option is the name of a channel
1284 OPTION_FUNC - the option trigger a function
1285 b_param : if type==OPTION_BOOL,
1286 value set to the property (has_param is false for boolean)
1287 s_param : if type==OPTION_STRING,
1288 value set to the property if has_param is false
1289 func : function called if type==OPTION_FUNC. if has_param is true,
1290 the value is passed to the function as a string, otherwise,
1293 For OPTION_DOUBLE and OPTION_INT, the parameter value is converted into a
1294 double or an integer and set to the property.
1296 For OPTION_CHANNEL, add_channel is called with the parameter value as the
1300 enum OptionType { OPTION_BOOL = 0, OPTION_STRING, OPTION_DOUBLE, OPTION_INT, OPTION_CHANNEL, OPTION_FUNC, OPTION_IGNORE };
1301 const int OPTION_MULTI = 1 << 17;
1307 const char *property;
1309 const char *s_param;
1310 int (*func)( const char * );
1311 } fgOptionArray[] = {
1313 {"language", true, OPTION_IGNORE, "", false, "", 0 },
1314 {"disable-rembrandt", false, OPTION_BOOL, "/sim/rendering/rembrandt/enabled", false, "", 0 },
1315 {"enable-rembrandt", false, OPTION_BOOL, "/sim/rendering/rembrandt/enabled", true, "", 0 },
1316 {"renderer", true, OPTION_STRING, "/sim/rendering/rembrandt/renderer", false, "", 0 },
1317 {"disable-game-mode", false, OPTION_BOOL, "/sim/startup/game-mode", false, "", 0 },
1318 {"enable-game-mode", false, OPTION_BOOL, "/sim/startup/game-mode", true, "", 0 },
1319 {"disable-splash-screen", false, OPTION_BOOL, "/sim/startup/splash-screen", false, "", 0 },
1320 {"enable-splash-screen", false, OPTION_BOOL, "/sim/startup/splash-screen", true, "", 0 },
1321 {"disable-intro-music", false, OPTION_BOOL, "/sim/startup/intro-music", false, "", 0 },
1322 {"enable-intro-music", false, OPTION_BOOL, "/sim/startup/intro-music", true, "", 0 },
1323 {"disable-mouse-pointer", false, OPTION_STRING, "/sim/startup/mouse-pointer", false, "disabled", 0 },
1324 {"enable-mouse-pointer", false, OPTION_STRING, "/sim/startup/mouse-pointer", false, "enabled", 0 },
1325 {"disable-random-objects", false, OPTION_BOOL, "/sim/rendering/random-objects", false, "", 0 },
1326 {"enable-random-objects", false, OPTION_BOOL, "/sim/rendering/random-objects", true, "", 0 },
1327 {"disable-random-vegetation", false, OPTION_BOOL, "/sim/rendering/random-vegetation", false, "", 0 },
1328 {"enable-random-vegetation", false, OPTION_BOOL, "/sim/rendering/random-vegetation", true, "", 0 },
1329 {"disable-random-buildings", false, OPTION_BOOL, "/sim/rendering/random-buildings", false, "", 0 },
1330 {"enable-random-buildings", false, OPTION_BOOL, "/sim/rendering/random-buildings", true, "", 0 },
1331 {"disable-real-weather-fetch", false, OPTION_BOOL, "/environment/realwx/enabled", false, "", 0 },
1332 {"enable-real-weather-fetch", false, OPTION_BOOL, "/environment/realwx/enabled", true, "", 0 },
1333 {"metar", true, OPTION_STRING, "/environment/metar/data", false, "", 0 },
1334 {"disable-ai-models", false, OPTION_BOOL, "/sim/ai/enabled", false, "", 0 },
1335 {"enable-ai-models", false, OPTION_BOOL, "/sim/ai/enabled", true, "", 0 },
1336 {"disable-ai-traffic", false, OPTION_BOOL, "/sim/traffic-manager/enabled", false, "", 0 },
1337 {"enable-ai-traffic", false, OPTION_BOOL, "/sim/traffic-manager/enabled", true, "", 0 },
1338 {"disable-freeze", false, OPTION_BOOL, "/sim/freeze/master", false, "", 0 },
1339 {"enable-freeze", false, OPTION_BOOL, "/sim/freeze/master", true, "", 0 },
1340 {"disable-fuel-freeze", false, OPTION_BOOL, "/sim/freeze/fuel", false, "", 0 },
1341 {"enable-fuel-freeze", false, OPTION_BOOL, "/sim/freeze/fuel", true, "", 0 },
1342 {"disable-clock-freeze", false, OPTION_BOOL, "/sim/freeze/clock", false, "", 0 },
1343 {"enable-clock-freeze", false, OPTION_BOOL, "/sim/freeze/clock", true, "", 0 },
1344 {"disable-hud-3d", false, OPTION_BOOL, "/sim/hud/enable3d[1]", false, "", 0 },
1345 {"enable-hud-3d", false, OPTION_BOOL, "/sim/hud/enable3d[1]", true, "", 0 },
1346 {"disable-anti-alias-hud", false, OPTION_BOOL, "/sim/hud/color/antialiased", false, "", 0 },
1347 {"enable-anti-alias-hud", false, OPTION_BOOL, "/sim/hud/color/antialiased", true, "", 0 },
1348 {"control", true, OPTION_STRING, "/sim/control-mode", false, "", 0 },
1349 {"disable-auto-coordination", false, OPTION_BOOL, "/controls/flight/auto-coordination", false, "", 0 },
1350 {"enable-auto-coordination", false, OPTION_BOOL, "/controls/flight/auto-coordination", true, "", 0 },
1351 {"browser-app", true, OPTION_STRING, "/sim/startup/browser-app", false, "", 0 },
1352 {"disable-hud", false, OPTION_BOOL, "/sim/hud/visibility[1]", false, "", 0 },
1353 {"enable-hud", false, OPTION_BOOL, "/sim/hud/visibility[1]", true, "", 0 },
1354 {"disable-panel", false, OPTION_BOOL, "/sim/panel/visibility", false, "", 0 },
1355 {"enable-panel", false, OPTION_BOOL, "/sim/panel/visibility", true, "", 0 },
1356 {"disable-sound", false, OPTION_BOOL, "/sim/sound/working", false, "", 0 },
1357 {"enable-sound", false, OPTION_BOOL, "/sim/sound/working", true, "", 0 },
1358 {"sound-device", true, OPTION_STRING, "/sim/sound/device-name", false, "", 0 },
1359 {"airport", true, OPTION_STRING, "/sim/presets/airport-id", false, "", 0 },
1360 {"runway", true, OPTION_FUNC, "", false, "", fgOptRunway },
1361 {"vor", true, OPTION_FUNC, "", false, "", fgOptVOR },
1362 {"vor-frequency", true, OPTION_DOUBLE, "/sim/presets/vor-freq", false, "", fgOptVOR },
1363 {"ndb", true, OPTION_FUNC, "", false, "", fgOptNDB },
1364 {"ndb-frequency", true, OPTION_DOUBLE, "/sim/presets/ndb-freq", false, "", fgOptVOR },
1365 {"carrier", true, OPTION_FUNC, "", false, "", fgOptCarrier },
1366 {"parkpos", true, OPTION_FUNC, "", false, "", fgOptParkpos },
1367 {"fix", true, OPTION_FUNC, "", false, "", fgOptFIX },
1368 {"offset-distance", true, OPTION_DOUBLE, "/sim/presets/offset-distance-nm", false, "", 0 },
1369 {"offset-azimuth", true, OPTION_DOUBLE, "/sim/presets/offset-azimuth-deg", false, "", 0 },
1370 {"lon", true, OPTION_FUNC, "", false, "", fgOptLon },
1371 {"lat", true, OPTION_FUNC, "", false, "", fgOptLat },
1372 {"altitude", true, OPTION_FUNC, "", false, "", fgOptAltitude },
1373 {"uBody", true, OPTION_FUNC, "", false, "", fgOptUBody },
1374 {"vBody", true, OPTION_FUNC, "", false, "", fgOptVBody },
1375 {"wBody", true, OPTION_FUNC, "", false, "", fgOptWBody },
1376 {"vNorth", true, OPTION_FUNC, "", false, "", fgOptVNorth },
1377 {"vEast", true, OPTION_FUNC, "", false, "", fgOptVEast },
1378 {"vDown", true, OPTION_FUNC, "", false, "", fgOptVDown },
1379 {"vc", true, OPTION_FUNC, "", false, "", fgOptVc },
1380 {"mach", true, OPTION_FUNC, "", false, "", fgOptMach },
1381 {"heading", true, OPTION_DOUBLE, "/sim/presets/heading-deg", false, "", 0 },
1382 {"roll", true, OPTION_DOUBLE, "/sim/presets/roll-deg", false, "", 0 },
1383 {"pitch", true, OPTION_DOUBLE, "/sim/presets/pitch-deg", false, "", 0 },
1384 {"glideslope", true, OPTION_DOUBLE, "/sim/presets/glideslope-deg", false, "", 0 },
1385 {"roc", true, OPTION_FUNC, "", false, "", fgOptRoc },
1386 {"fg-root", true, OPTION_IGNORE, "", false, "", 0 },
1387 {"fg-scenery", true, OPTION_FUNC | OPTION_MULTI, "", false, "", fgOptFgScenery },
1388 {"fg-aircraft", true, OPTION_IGNORE | OPTION_MULTI, "", false, "", 0 },
1389 {"fdm", true, OPTION_STRING, "/sim/flight-model", false, "", 0 },
1390 {"aero", true, OPTION_STRING, "/sim/aero", false, "", 0 },
1391 {"aircraft-dir", true, OPTION_IGNORE, "", false, "", 0 },
1392 {"model-hz", true, OPTION_INT, "/sim/model-hz", false, "", 0 },
1393 {"max-fps", true, OPTION_DOUBLE, "/sim/frame-rate-throttle-hz", false, "", 0 },
1394 {"speed", true, OPTION_INT, "/sim/speed-up", false, "", 0 },
1395 {"trim", false, OPTION_BOOL, "/sim/presets/trim", true, "", 0 },
1396 {"notrim", false, OPTION_BOOL, "/sim/presets/trim", false, "", 0 },
1397 {"on-ground", false, OPTION_BOOL, "/sim/presets/onground", true, "", 0 },
1398 {"in-air", false, OPTION_BOOL, "/sim/presets/onground", false, "", 0 },
1399 {"fog-disable", false, OPTION_STRING, "/sim/rendering/fog", false, "disabled", 0 },
1400 {"fog-fastest", false, OPTION_STRING, "/sim/rendering/fog", false, "fastest", 0 },
1401 {"fog-nicest", false, OPTION_STRING, "/sim/rendering/fog", false, "nicest", 0 },
1402 {"disable-horizon-effect", false, OPTION_BOOL, "/sim/rendering/horizon-effect", false, "", 0 },
1403 {"enable-horizon-effect", false, OPTION_BOOL, "/sim/rendering/horizon-effect", true, "", 0 },
1404 {"disable-enhanced-lighting", false, OPTION_BOOL, "/sim/rendering/enhanced-lighting", false, "", 0 },
1405 {"enable-enhanced-lighting", false, OPTION_BOOL, "/sim/rendering/enhanced-lighting", true, "", 0 },
1406 {"disable-distance-attenuation", false, OPTION_BOOL, "/sim/rendering/distance-attenuation", false, "", 0 },
1407 {"enable-distance-attenuation", false, OPTION_BOOL, "/sim/rendering/distance-attenuation", true, "", 0 },
1408 {"disable-specular-highlight", false, OPTION_BOOL, "/sim/rendering/specular-highlight", false, "", 0 },
1409 {"enable-specular-highlight", false, OPTION_BOOL, "/sim/rendering/specular-highlight", true, "", 0 },
1410 {"disable-clouds", false, OPTION_BOOL, "/environment/clouds/status", false, "", 0 },
1411 {"enable-clouds", false, OPTION_BOOL, "/environment/clouds/status", true, "", 0 },
1412 {"disable-clouds3d", false, OPTION_BOOL, "/sim/rendering/clouds3d-enable", false, "", 0 },
1413 {"enable-clouds3d", false, OPTION_BOOL, "/sim/rendering/clouds3d-enable", true, "", 0 },
1414 {"fov", true, OPTION_FUNC, "", false, "", fgOptFov },
1415 {"aspect-ratio-multiplier", true, OPTION_DOUBLE, "/sim/current-view/aspect-ratio-multiplier", false, "", 0 },
1416 {"disable-fullscreen", false, OPTION_BOOL, "/sim/startup/fullscreen", false, "", 0 },
1417 {"enable-fullscreen", false, OPTION_BOOL, "/sim/startup/fullscreen", true, "", 0 },
1418 {"disable-save-on-exit", false, OPTION_BOOL, "/sim/startup/save-on-exit", false, "", 0 },
1419 {"enable-save-on-exit", false, OPTION_BOOL, "/sim/startup/save-on-exit", true, "", 0 },
1420 {"restore-defaults", false, OPTION_BOOL, "/sim/startup/restore-defaults", true, "", 0 },
1421 {"shading-flat", false, OPTION_BOOL, "/sim/rendering/shading", false, "", 0 },
1422 {"shading-smooth", false, OPTION_BOOL, "/sim/rendering/shading", true, "", 0 },
1423 {"disable-skyblend", false, OPTION_BOOL, "/sim/rendering/skyblend", false, "", 0 },
1424 {"enable-skyblend", false, OPTION_BOOL, "/sim/rendering/skyblend", true, "", 0 },
1425 {"disable-textures", false, OPTION_BOOL, "/sim/rendering/textures", false, "", 0 },
1426 {"enable-textures", false, OPTION_BOOL, "/sim/rendering/textures", true, "", 0 },
1427 {"texture-filtering", false, OPTION_INT, "/sim/rendering/filtering", 1, "", 0 },
1428 {"disable-wireframe", false, OPTION_BOOL, "/sim/rendering/wireframe", false, "", 0 },
1429 {"enable-wireframe", false, OPTION_BOOL, "/sim/rendering/wireframe", true, "", 0 },
1430 {"materials-file", true, OPTION_STRING, "/sim/rendering/materials-file", false, "", 0 },
1431 {"disable-terrasync", false, OPTION_BOOL, "/sim/terrasync/enabled", false, "", 0 },
1432 {"enable-terrasync", false, OPTION_BOOL, "/sim/terrasync/enabled", true, "", 0 },
1433 {"terrasync-dir", true, OPTION_STRING, "/sim/terrasync/scenery-dir", false, "", 0 },
1434 {"geometry", true, OPTION_FUNC, "", false, "", fgOptGeometry },
1435 {"bpp", true, OPTION_FUNC, "", false, "", fgOptBpp },
1436 {"units-feet", false, OPTION_STRING, "/sim/startup/units", false, "feet", 0 },
1437 {"units-meters", false, OPTION_STRING, "/sim/startup/units", false, "meters", 0 },
1438 {"timeofday", true, OPTION_STRING, "/sim/startup/time-offset-type", false, "noon", 0 },
1439 {"season", true, OPTION_STRING, "/sim/startup/season", false, "summer", 0 },
1440 {"time-offset", true, OPTION_FUNC, "", false, "", fgOptTimeOffset },
1441 {"time-match-real", false, OPTION_STRING, "/sim/startup/time-offset-type", false, "system-offset", 0 },
1442 {"time-match-local", false, OPTION_STRING, "/sim/startup/time-offset-type", false, "latitude-offset", 0 },
1443 {"start-date-sys", true, OPTION_FUNC, "", false, "", fgOptStartDateSys },
1444 {"start-date-lat", true, OPTION_FUNC, "", false, "", fgOptStartDateLat },
1445 {"start-date-gmt", true, OPTION_FUNC, "", false, "", fgOptStartDateGmt },
1446 {"hud-tris", false, OPTION_STRING, "/sim/hud/frame-stat-type", false, "tris", 0 },
1447 {"hud-culled", false, OPTION_STRING, "/sim/hud/frame-stat-type", false, "culled", 0 },
1448 {"atcsim", true, OPTION_CHANNEL, "", false, "dummy", 0 },
1449 {"atlas", true, OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1450 {"httpd", true, OPTION_CHANNEL, "", false, "", 0 },
1451 #ifdef FG_JPEG_SERVER
1452 {"jpg-httpd", true, OPTION_CHANNEL, "", false, "", 0 },
1454 {"native", true, OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1455 {"native-ctrls", true, OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1456 {"native-fdm", true, OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1457 {"native-gui", true, OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1458 {"opengc", true, OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1459 {"AV400", true, OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1460 {"AV400Sim", true, OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1461 {"AV400WSimA", true, OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1462 {"AV400WSimB", true, OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1463 {"garmin", true, OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1464 {"nmea", true, OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1465 {"generic", true, OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1466 {"props", true, OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1467 {"telnet", true, OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1468 {"pve", true, OPTION_CHANNEL, "", false, "", 0 },
1469 {"ray", true, OPTION_CHANNEL, "", false, "", 0 },
1470 {"rul", true, OPTION_CHANNEL, "", false, "", 0 },
1471 {"joyclient", true, OPTION_CHANNEL, "", false, "", 0 },
1472 {"jsclient", true, OPTION_CHANNEL, "", false, "", 0 },
1473 {"proxy", true, OPTION_FUNC, "", false, "", fgSetupProxy },
1474 {"callsign", true, OPTION_FUNC, "", false, "", fgOptCallSign},
1475 {"multiplay", true, OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1477 {"hla", true, OPTION_CHANNEL, "", false, "", 0 },
1479 {"trace-read", true, OPTION_FUNC | OPTION_MULTI, "", false, "", fgOptTraceRead },
1480 {"trace-write", true, OPTION_FUNC | OPTION_MULTI, "", false, "", fgOptTraceWrite },
1481 {"log-level", true, OPTION_FUNC, "", false, "", fgOptLogLevel },
1482 {"log-class", true, OPTION_FUNC, "", false, "", fgOptLogClasses },
1483 {"view-offset", true, OPTION_FUNC | OPTION_MULTI, "", false, "", fgOptViewOffset },
1484 {"visibility", true, OPTION_FUNC, "", false, "", fgOptVisibilityMeters },
1485 {"visibility-miles", true, OPTION_FUNC, "", false, "", fgOptVisibilityMiles },
1486 {"random-wind", false, OPTION_FUNC, "", false, "", fgOptRandomWind },
1487 {"wind", true, OPTION_FUNC | OPTION_MULTI, "", false, "", fgOptWind },
1488 {"turbulence", true, OPTION_FUNC, "", false, "", fgOptTurbulence },
1489 {"ceiling", true, OPTION_FUNC, "", false, "", fgOptCeiling },
1490 {"wp", true, OPTION_FUNC | OPTION_MULTI, "", false, "", fgOptWp },
1491 {"flight-plan", true, OPTION_STRING, "/autopilot/route-manager/file-path", false, "", NULL },
1492 {"config", true, OPTION_FUNC | OPTION_MULTI, "", false, "", fgOptConfig },
1493 {"aircraft", true, OPTION_STRING, "/sim/aircraft", false, "", 0 },
1494 {"vehicle", true, OPTION_STRING, "/sim/aircraft", false, "", 0 },
1495 {"failure", true, OPTION_FUNC | OPTION_MULTI, "", false, "", fgOptFailure },
1496 {"com1", true, OPTION_DOUBLE, "/instrumentation/comm[0]/frequencies/selected-mhz", false, "", 0 },
1497 {"com2", true, OPTION_DOUBLE, "/instrumentation/comm[1]/frequencies/selected-mhz", false, "", 0 },
1498 {"nav1", true, OPTION_FUNC, "", false, "", fgOptNAV1 },
1499 {"nav2", true, OPTION_FUNC, "", false, "", fgOptNAV2 },
1500 {"adf", /*legacy*/ true, OPTION_FUNC, "", false, "", fgOptADF1 },
1501 {"adf1", true, OPTION_FUNC, "", false, "", fgOptADF1 },
1502 {"adf2", true, OPTION_FUNC, "", false, "", fgOptADF2 },
1503 {"dme", true, OPTION_FUNC, "", false, "", fgOptDME },
1504 {"min-status", true, OPTION_STRING, "/sim/aircraft-min-status", false, "all", 0 },
1505 {"livery", true, OPTION_FUNC, "", false, "", fgOptLivery },
1506 {"ai-scenario", true, OPTION_FUNC | OPTION_MULTI, "", false, "", fgOptScenario },
1507 {"disable-ai-scenarios", false, OPTION_FUNC, "", false, "", fgOptNoScenarios},
1508 {"parking-id", true, OPTION_FUNC, "", false, "", fgOptParking },
1509 {"version", false, OPTION_FUNC, "", false, "", fgOptVersion },
1510 {"enable-fpe", false, OPTION_IGNORE, "", false, "", 0},
1511 {"fgviewer", false, OPTION_IGNORE, "", false, "", 0},
1512 {"prop", true, OPTION_FUNC | OPTION_MULTI, "", false, "", fgOptSetProperty},
1517 namespace flightgear
1521 * internal storage of a value->option binding
1526 OptionValue(OptionDesc* d, const string& v) :
1534 typedef std::vector<OptionValue> OptionValueVec;
1535 typedef std::map<string, OptionDesc*> OptionDescDict;
1537 class Options::OptionsPrivate
1541 OptionValueVec::const_iterator findValue(const string& key) const
1543 OptionValueVec::const_iterator it = values.begin();
1544 for (; it != values.end(); ++it) {
1546 continue; // ignore markers
1549 if (it->desc->option == key) {
1552 } // of set values iteration
1554 return it; // not found
1557 OptionDesc* findOption(const string& key) const
1559 OptionDescDict::const_iterator it = options.find(key);
1560 if (it == options.end()) {
1567 int processOption(OptionDesc* desc, const string& arg_value)
1570 return FG_OPTIONS_OK; // tolerate marker options
1573 switch ( desc->type & 0xffff ) {
1575 fgSetBool( desc->property, desc->b_param );
1578 if ( desc->has_param && !arg_value.empty() ) {
1579 fgSetString( desc->property, arg_value.c_str() );
1580 } else if ( !desc->has_param && arg_value.empty() ) {
1581 fgSetString( desc->property, desc->s_param );
1582 } else if ( desc->has_param ) {
1583 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << desc->option << "' needs a parameter" );
1584 return FG_OPTIONS_ERROR;
1586 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << desc->option << "' does not have a parameter" );
1587 return FG_OPTIONS_ERROR;
1591 if ( !arg_value.empty() ) {
1592 fgSetDouble( desc->property, atof( arg_value ) );
1594 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << desc->option << "' needs a parameter" );
1595 return FG_OPTIONS_ERROR;
1599 if ( !arg_value.empty() ) {
1600 fgSetInt( desc->property, atoi( arg_value ) );
1602 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << desc->option << "' needs a parameter" );
1603 return FG_OPTIONS_ERROR;
1606 case OPTION_CHANNEL:
1607 // XXX return value of add_channel should be checked?
1608 if ( desc->has_param && !arg_value.empty() ) {
1609 add_channel( desc->option, arg_value );
1610 } else if ( !desc->has_param && arg_value.empty() ) {
1611 add_channel( desc->option, desc->s_param );
1612 } else if ( desc->has_param ) {
1613 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << desc->option << "' needs a parameter" );
1614 return FG_OPTIONS_ERROR;
1616 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << desc->option << "' does not have a parameter" );
1617 return FG_OPTIONS_ERROR;
1621 if ( desc->has_param && !arg_value.empty() ) {
1622 return desc->func( arg_value.c_str() );
1623 } else if ( !desc->has_param && arg_value.empty() ) {
1624 return desc->func( desc->s_param );
1625 } else if ( desc->has_param ) {
1626 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << desc->option << "' needs a parameter" );
1627 return FG_OPTIONS_ERROR;
1629 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << desc->option << "' does not have a parameter" );
1630 return FG_OPTIONS_ERROR;
1638 return FG_OPTIONS_OK;
1642 * insert a marker value into the values vector. This is necessary
1643 * when processing options, to ensure the correct ordering, where we scan
1644 * for marker values in reverse, and then forwards within each group.
1646 void insertGroupMarker()
1648 values.push_back(OptionValue(NULL, "-"));
1652 * given a current iterator into the values, find the preceeding group marker,
1653 * or return the beginning of the value vector.
1655 OptionValueVec::const_iterator rfindGroup(OptionValueVec::const_iterator pos) const
1657 while (--pos != values.begin()) {
1658 if (pos->desc == NULL) {
1659 return pos; // found a marker, we're done
1670 OptionDescDict options;
1671 OptionValueVec values;
1672 simgear::PathList propertyFiles;
1675 Options* Options::sharedInstance()
1677 if (shared_instance == NULL) {
1678 shared_instance = new Options;
1681 return shared_instance;
1684 Options::Options() :
1685 p(new OptionsPrivate())
1687 p->showHelp = false;
1689 p->showAircraft = false;
1692 OptionDesc *desc = &fgOptionArray[ 0 ];
1693 while ( desc->option != 0 ) {
1694 p->options[ desc->option ] = desc;
1703 void Options::init(int argc, char **argv, const SGPath& appDataPath)
1707 // first, process the command line
1708 bool inOptions = true;
1709 for (int i=1; i<argc; ++i) {
1710 if (inOptions && (argv[i][0] == '-')) {
1711 if (strcmp(argv[i], "--") == 0) { // end of options delimiter
1716 int result = parseOption(argv[i]);
1717 processArgResult(result);
1719 // XML properties file
1722 SG_LOG(SG_GENERAL, SG_ALERT, "config file not found:" << f.str());
1726 p->propertyFiles.push_back(f);
1728 } // of arguments iteration
1729 p->insertGroupMarker(); // command line is one group
1731 // establish log-level before anything else - otherwise it is not possible
1732 // to show extra (debug/info/warning) messages for the start-up phase.
1733 fgOptLogLevel(valueForOption("log-level", "alert").c_str());
1735 // then config files
1738 if( homedir.size() && hostname.size() ) {
1739 // Check for ~/.fgfsrc.hostname
1740 config.set(homedir);
1741 config.append(".fgfsrc");
1742 config.concat( "." );
1743 config.concat( hostname );
1747 // Check for ~/.fgfsrc
1748 if( homedir.size() ) {
1749 config.set(homedir);
1750 config.append(".fgfsrc");
1754 // check for a config file in app data
1755 SGPath appDataConfig(appDataPath);
1756 appDataConfig.append("fgfsrc");
1757 if (appDataConfig.exists()) {
1758 readConfig(appDataConfig);
1764 // system.fgfsrc handling
1765 if( hostname.size() > 0 ) {
1766 config.set(globals->get_fg_root());
1767 config.append( "system.fgfsrc" );
1768 config.concat( "." );
1769 config.concat( hostname );
1773 config.set(globals->get_fg_root());
1774 config.append( "system.fgfsrc" );
1778 void Options::initAircraft()
1780 BOOST_FOREACH(const string& paths, valuesForOption("fg-aircraft")) {
1781 globals->append_aircraft_paths(paths);
1784 const char* envp = ::getenv("FG_AIRCRAFT");
1786 globals->append_aircraft_paths(envp);
1790 if (isOptionSet("aircraft")) {
1791 aircraft = valueForOption("aircraft");
1792 } else if (isOptionSet("vehicle")) {
1793 aircraft = valueForOption("vehicle");
1796 if (!aircraft.empty()) {
1797 SG_LOG(SG_INPUT, SG_INFO, "aircraft = " << aircraft );
1798 fgSetString("/sim/aircraft", aircraft.c_str() );
1800 SG_LOG(SG_INPUT, SG_INFO, "No user specified aircraft, using default" );
1803 if (p->showAircraft) {
1804 fgOptLogLevel( "alert" );
1805 SGPath path( globals->get_fg_root() );
1806 path.append("Aircraft");
1807 fgShowAircraft(path);
1811 if (isOptionSet("aircraft-dir")) {
1812 // set this now, so it's available in FindAndCacheAircraft
1813 fgSetString("/sim/aircraft-dir", valueForOption("aircraft-dir"));
1817 void Options::processArgResult(int result)
1819 if ((result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR))
1821 else if (result == FG_OPTIONS_VERBOSE_HELP)
1823 else if (result == FG_OPTIONS_SHOW_AIRCRAFT) {
1824 p->showAircraft = true;
1825 } else if (result == FG_OPTIONS_SHOW_SOUND_DEVICES) {
1829 string vendor = smgr.get_vendor();
1830 string renderer = smgr.get_renderer();
1831 cout << renderer << " provided by " << vendor << endl;
1832 cout << endl << "No. Device" << endl;
1834 vector <const char*>devices = smgr.get_available_devices();
1835 for (vector <const char*>::size_type i=0; i<devices.size(); i++) {
1836 cout << i << ". \"" << devices[i] << "\"" << endl;
1840 } else if (result == FG_OPTIONS_EXIT) {
1845 void Options::readConfig(const SGPath& path)
1847 sg_gzifstream in( path.str() );
1848 if ( !in.is_open() ) {
1852 SG_LOG( SG_GENERAL, SG_INFO, "Processing config file: " << path.str() );
1855 while ( ! in.eof() ) {
1857 getline( in, line, '\n' );
1859 // catch extraneous (DOS) line ending character
1861 for (i = line.length(); i > 0; i--)
1862 if (line[i - 1] > 32)
1864 line = line.substr( 0, i );
1866 if ( parseOption( line ) == FG_OPTIONS_ERROR ) {
1867 cerr << endl << "Config file parse error: " << path.str() << " '"
1868 << line << "'" << endl;
1874 p->insertGroupMarker(); // each config file is a group
1877 int Options::parseOption(const string& s)
1879 if ((s == "--help") || (s=="-h")) {
1880 return FG_OPTIONS_HELP;
1881 } else if ( (s == "--verbose") || (s == "-v") ) {
1882 // verbose help/usage request
1883 return FG_OPTIONS_VERBOSE_HELP;
1884 } else if (s.find("-psn") == 0) {
1885 // on Mac, when launched from the GUI, we are passed the ProcessSerialNumber
1886 // as an argument (and no others). Silently ignore the argument here.
1887 return FG_OPTIONS_OK;
1888 } else if ( s.find( "--show-aircraft") == 0) {
1889 return(FG_OPTIONS_SHOW_AIRCRAFT);
1890 } else if ( s.find( "--show-sound-devices") == 0) {
1891 return(FG_OPTIONS_SHOW_SOUND_DEVICES);
1892 } else if ( s.find( "--prop:") == 0) {
1893 // property setting has a slightly different syntax, so fudge things
1894 OptionDesc* desc = p->findOption("prop");
1895 if (s.find("=", 7) == string::npos) { // no equals token
1896 SG_LOG(SG_GENERAL, SG_ALERT, "malformed property option:" << s);
1897 return FG_OPTIONS_ERROR;
1900 p->values.push_back(OptionValue(desc, s.substr(7)));
1901 return FG_OPTIONS_OK;
1902 } else if ( s.find( "--" ) == 0 ) {
1903 size_t eqPos = s.find( '=' );
1905 if (eqPos == string::npos) {
1908 key = s.substr( 2, eqPos - 2 );
1909 value = s.substr( eqPos + 1);
1912 return addOption(key, value);
1914 SG_LOG(SG_GENERAL, SG_ALERT, "unknown option:" << s);
1915 return FG_OPTIONS_ERROR;
1919 int Options::addOption(const string &key, const string &value)
1921 OptionDesc* desc = p->findOption(key);
1923 SG_LOG(SG_GENERAL, SG_ALERT, "unknown option:" << key);
1924 return FG_OPTIONS_ERROR;
1927 if (!(desc->type & OPTION_MULTI)) {
1928 OptionValueVec::const_iterator it = p->findValue(key);
1929 if (it != p->values.end()) {
1930 SG_LOG(SG_GENERAL, SG_INFO, "multiple values forbidden for option:" << key << ", ignoring:" << value);
1931 return FG_OPTIONS_OK;
1935 p->values.push_back(OptionValue(desc, value));
1936 return FG_OPTIONS_OK;
1939 bool Options::isOptionSet(const string &key) const
1941 OptionValueVec::const_iterator it = p->findValue(key);
1942 return (it != p->values.end());
1945 string Options::valueForOption(const string& key, const string& defValue) const
1947 OptionValueVec::const_iterator it = p->findValue(key);
1948 if (it == p->values.end()) {
1955 string_list Options::valuesForOption(const std::string& key) const
1958 OptionValueVec::const_iterator it = p->values.begin();
1959 for (; it != p->values.end(); ++it) {
1961 continue; // ignore marker values
1964 if (it->desc->option == key) {
1965 result.push_back(it->value);
1972 void Options::processOptions()
1974 // establish locale before showing help (this selects the default locale,
1975 // when no explicit option was set)
1976 globals->get_locale()->selectLanguage(valueForOption("language").c_str());
1978 // now FG_ROOT is setup, process various command line options that bail us
1979 // out quickly, but rely on aircraft / root settings
1985 // processing order is complicated. We must process groups LIFO, but the
1986 // values *within* each group in FIFO order, to retain consistency with
1987 // older versions of FG, and existing user configs.
1988 // in practice this means system.fgfsrc must be *processed* before
1989 // .fgfsrc, which must be processed before the command line args, and so on.
1990 OptionValueVec::const_iterator groupEnd = p->values.end();
1992 while (groupEnd != p->values.begin()) {
1993 OptionValueVec::const_iterator groupBegin = p->rfindGroup(groupEnd);
1994 // run over the group in FIFO order
1995 OptionValueVec::const_iterator it;
1996 for (it = groupBegin; it != groupEnd; ++it) {
1997 int result = p->processOption(it->desc, it->value);
2000 case FG_OPTIONS_ERROR:
2002 exit(-1); // exit and return an error
2003 case FG_OPTIONS_EXIT:
2004 exit(0); // clean exit
2010 groupEnd = groupBegin;
2013 BOOST_FOREACH(const SGPath& file, p->propertyFiles) {
2014 if (!file.exists()) {
2015 SG_LOG(SG_GENERAL, SG_ALERT, "config file not found:" << file.str());
2019 SG_LOG(SG_GENERAL, SG_INFO,
2020 "Reading command-line property file " << file.str());
2021 readProperties(file.str(), globals->get_props());
2024 // now options are process, do supplemental fixup
2025 const char *envp = ::getenv( "FG_SCENERY" );
2027 globals->append_fg_scenery(envp);
2030 // terrasync directory fixup
2031 if (fgGetBool("/sim/terrasync/enabled")) {
2032 string terrasyncDir = fgGetString("/sim/terrasync/scenery-dir");
2033 if (terrasyncDir.empty()) {
2034 SGPath p(globals->get_fg_home());
2035 p.append("TerraSync");
2041 terrasyncDir = p.str();
2042 SG_LOG(SG_GENERAL, SG_INFO,
2043 "Using default TerraSync dir: " << terrasyncDir);
2044 fgSetString("/sim/terrasync/scenery-dir", terrasyncDir);
2047 const string_list& scenery_paths(globals->get_fg_scenery());
2048 if (std::find(scenery_paths.begin(), scenery_paths.end(), terrasyncDir) == scenery_paths.end()) {
2049 // terrasync dir is not in the scenery paths, add it
2050 globals->append_fg_scenery(terrasyncDir);
2054 if (globals->get_fg_scenery().empty()) {
2055 // no scenery paths set *at all*, use the data in FG_ROOT
2056 SGPath root(globals->get_fg_root());
2057 root.append("Scenery");
2058 globals->append_fg_scenery(root.str());
2062 void Options::showUsage() const
2064 fgOptLogLevel( "alert" );
2066 FGLocale *locale = globals->get_locale();
2067 SGPropertyNode options_root;
2069 SG_LOG( SG_GENERAL, SG_ALERT, "" ); // To popup the console on Windows
2073 fgLoadProps("options.xml", &options_root);
2074 } catch (const sg_exception &) {
2075 cout << "Unable to read the help file." << endl;
2076 cout << "Make sure the file options.xml is located in the FlightGear base directory," << endl;
2077 cout << "and the location of the base directory is specified by setting $FG_ROOT or" << endl;
2078 cout << "by adding --fg-root=path as a program argument." << endl;
2083 SGPropertyNode *options = options_root.getNode("options");
2085 SG_LOG( SG_GENERAL, SG_ALERT,
2086 "Error reading options.xml: <options> directive not found." );
2090 if (!locale->loadResource("options"))
2092 cout << "Unable to read the language resource." << endl;
2096 const char* usage = locale->getLocalizedString(options->getStringValue("usage"), "options");
2098 cout << usage << endl;
2101 vector<SGPropertyNode_ptr>section = options->getChildren("section");
2102 for (unsigned int j = 0; j < section.size(); j++) {
2105 vector<SGPropertyNode_ptr>option = section[j]->getChildren("option");
2106 for (unsigned int k = 0; k < option.size(); k++) {
2108 SGPropertyNode *name = option[k]->getNode("name");
2109 SGPropertyNode *short_name = option[k]->getNode("short");
2110 SGPropertyNode *key = option[k]->getNode("key");
2111 SGPropertyNode *arg = option[k]->getNode("arg");
2112 bool brief = option[k]->getNode("brief") != 0;
2114 if ((brief || p->verbose) && name) {
2115 string tmp = name->getStringValue();
2119 tmp.append(key->getStringValue());
2123 tmp.append(arg->getStringValue());
2127 tmp.append(short_name->getStringValue());
2130 if (tmp.size() <= 25) {
2133 msg.append( 27-tmp.size(), ' ');
2137 msg.append(32, ' ');
2139 // There may be more than one <description> tag associated
2142 vector<SGPropertyNode_ptr> desc;
2143 desc = option[k]->getChildren("description");
2144 if (desc.size() > 0) {
2145 for ( unsigned int l = 0; l < desc.size(); l++) {
2146 string t = desc[l]->getStringValue();
2148 // There may be more than one translation line.
2149 vector<SGPropertyNode_ptr>trans_desc = locale->getLocalizedStrings(t.c_str(),"options");
2150 for ( unsigned int m = 0; m < trans_desc.size(); m++ ) {
2151 string t_str = trans_desc[m]->getStringValue();
2153 if ((m > 0) || ((l > 0) && m == 0)) {
2154 msg.append( 32, ' ');
2157 // If the string is too large to fit on the screen,
2158 // then split it up in several pieces.
2160 while ( t_str.size() > 47 ) {
2162 string::size_type m = t_str.rfind(' ', 47);
2163 msg += t_str.substr(0, m) + '\n';
2164 msg.append( 32, ' ');
2166 t_str.erase(t_str.begin(), t_str.begin() + m + 1);
2168 msg += t_str + '\n';
2175 const char* name = locale->getLocalizedString(section[j]->getStringValue("name"),"options");
2176 if (!msg.empty() && name) {
2177 cout << endl << name << ":" << endl;
2183 if ( !p->verbose ) {
2184 const char* verbose_help = locale->getLocalizedString(options->getStringValue("verbose-help"),"options");
2186 cout << endl << verbose_help << endl;
2189 std::cout << "Hit a key to continue..." << std::endl;
2194 #if defined(__CYGWIN__)
2195 string Options::platformDefaultRoot() const
2200 #elif defined(_WIN32)
2201 string Options::platformDefaultRoot() const
2205 #elif defined(__APPLE__)
2206 string Options::platformDefaultRoot() const
2209 The following code looks for the base package inside the application
2210 bundle, in the standard Contents/Resources location.
2212 CFURLRef resourcesUrl = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
2214 // look for a 'data' subdir
2215 CFURLRef dataDir = CFURLCreateCopyAppendingPathComponent(NULL, resourcesUrl, CFSTR("data"), true);
2217 // now convert down to a path, and the a c-string
2218 CFStringRef path = CFURLCopyFileSystemPath(dataDir, kCFURLPOSIXPathStyle);
2219 string root = CFStringGetCStringPtr(path, CFStringGetSystemEncoding());
2221 CFRelease(resourcesUrl);
2228 string Options::platformDefaultRoot() const
2234 void Options::setupRoot()
2237 if (isOptionSet("fg-root")) {
2238 root = valueForOption("fg-root"); // easy!
2240 // Next check if fg-root is set as an env variable
2241 char *envp = ::getenv( "FG_ROOT" );
2242 if ( envp != NULL ) {
2245 root = platformDefaultRoot();
2249 SG_LOG(SG_INPUT, SG_INFO, "fg_root = " << root );
2250 globals->set_fg_root(root);
2253 static char required_version[] = FLIGHTGEAR_VERSION;
2254 string base_version = fgBasePackageVersion();
2255 if ( !(base_version == required_version) ) {
2256 // tell the operator how to use this application
2258 SG_LOG( SG_GENERAL, SG_ALERT, "" ); // To popup the console on windows
2259 cerr << endl << "Base package check failed:" << endl \
2260 << " Version " << base_version << " found at: " \
2261 << globals->get_fg_root() << endl \
2262 << " Version " << required_version << " is required." << endl \
2263 << "Please upgrade/downgrade base package and set the path to your fgdata" << endl \
2264 << "with --fg-root=path_to_your_fgdata" << endl;
2266 cerr << "Hit a key to continue..." << endl;
2273 } // of namespace flightgear