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"
60 #include "viewmgr.hxx"
61 #include <Main/viewer.hxx>
62 #include <Environment/presets.hxx>
64 #include <osg/Version>
66 #if defined( HAVE_VERSION_H ) && HAVE_VERSION_H
67 # include <Include/version.h>
68 # include <simgear/version.h>
70 # include <Include/no_version.h>
74 # include <CoreFoundation/CoreFoundation.h>
85 #define NEW_DEFAULT_MODEL_HZ 120
87 // defined in bootstrap.cxx
89 extern char *hostname;
97 FG_OPTIONS_VERBOSE_HELP = 4,
98 FG_OPTIONS_SHOW_AIRCRAFT = 5,
99 FG_OPTIONS_SHOW_SOUND_DEVICES = 6
102 static flightgear::Options* shared_instance = NULL;
105 atof( const string& str )
107 return ::atof( str.c_str() );
111 atoi( const string& str )
113 return ::atoi( str.c_str() );
116 static int fgSetupProxy( const char *arg );
119 * Set a few fail-safe default property values.
121 * These should all be set in $FG_ROOT/preferences.xml, but just
122 * in case, we provide some initial sane values here. This method
123 * should be invoked *before* reading any init files.
129 // Position (deliberately out of range)
130 fgSetDouble("/position/longitude-deg", 9999.0);
131 fgSetDouble("/position/latitude-deg", 9999.0);
132 fgSetDouble("/position/altitude-ft", -9999.0);
135 fgSetDouble("/orientation/heading-deg", 9999.0);
136 fgSetDouble("/orientation/roll-deg", 0.0);
137 fgSetDouble("/orientation/pitch-deg", 0.424);
140 fgSetDouble("/velocities/uBody-fps", 0.0);
141 fgSetDouble("/velocities/vBody-fps", 0.0);
142 fgSetDouble("/velocities/wBody-fps", 0.0);
143 fgSetDouble("/velocities/speed-north-fps", 0.0);
144 fgSetDouble("/velocities/speed-east-fps", 0.0);
145 fgSetDouble("/velocities/speed-down-fps", 0.0);
146 fgSetDouble("/velocities/airspeed-kt", 0.0);
147 fgSetDouble("/velocities/mach", 0.0);
150 fgSetDouble("/sim/presets/longitude-deg", 9999.0);
151 fgSetDouble("/sim/presets/latitude-deg", 9999.0);
152 fgSetDouble("/sim/presets/altitude-ft", -9999.0);
154 fgSetDouble("/sim/presets/heading-deg", 9999.0);
155 fgSetDouble("/sim/presets/roll-deg", 0.0);
156 fgSetDouble("/sim/presets/pitch-deg", 0.424);
158 fgSetString("/sim/presets/speed-set", "knots");
159 fgSetDouble("/sim/presets/airspeed-kt", 0.0);
160 fgSetDouble("/sim/presets/mach", 0.0);
161 fgSetDouble("/sim/presets/uBody-fps", 0.0);
162 fgSetDouble("/sim/presets/vBody-fps", 0.0);
163 fgSetDouble("/sim/presets/wBody-fps", 0.0);
164 fgSetDouble("/sim/presets/speed-north-fps", 0.0);
165 fgSetDouble("/sim/presets/speed-east-fps", 0.0);
166 fgSetDouble("/sim/presets/speed-down-fps", 0.0);
168 fgSetBool("/sim/presets/onground", true);
169 fgSetBool("/sim/presets/trim", false);
172 fgSetBool("/sim/startup/game-mode", false);
173 fgSetBool("/sim/startup/splash-screen", true);
174 fgSetBool("/sim/startup/intro-music", true);
175 // we want mouse-pointer to have an undefined value if nothing is
176 // specified so we can do the right thing for voodoo-1/2 cards.
177 // fgSetString("/sim/startup/mouse-pointer", "disabled");
178 fgSetString("/sim/control-mode", "joystick");
179 fgSetBool("/sim/auto-coordination", false);
181 fgSetString("/sim/startup/browser-app", "webrun.bat");
182 #elif defined(__APPLE__)
183 fgSetString("/sim/startup/browser-app", "open");
185 fgSetString("/sim/startup/browser-app", "launchWebJumper");
187 const char* browserEnv = ::getenv( "WEBBROWSER" );
188 if (!browserEnv) browserEnv = "netscape";
189 fgSetString("/sim/startup/browser-app", browserEnv);
191 fgSetString("/sim/logging/priority", "alert");
194 fgSetBool("/sim/hud/color/antialiased", false);
195 fgSetBool("/sim/hud/enable3d[1]", true);
196 fgSetBool("/sim/hud/visibility[1]", false);
197 fgSetBool("/sim/panel/visibility", true);
198 fgSetBool("/sim/sound/enabled", true);
199 fgSetBool("/sim/sound/working", true);
201 // Flight Model options
202 fgSetString("/sim/flight-model", "jsb");
203 fgSetString("/sim/aero", "c172");
204 fgSetInt("/sim/model-hz", NEW_DEFAULT_MODEL_HZ);
205 fgSetInt("/sim/speed-up", 1);
208 fgSetString("/sim/rendering/fog", "nicest");
209 fgSetBool("/environment/clouds/status", true);
210 fgSetBool("/sim/startup/fullscreen", false);
211 fgSetBool("/sim/rendering/shading", true);
212 fgSetBool("/sim/rendering/skyblend", true);
213 fgSetBool("/sim/rendering/textures", true);
214 fgTie( "/sim/rendering/filtering", SGGetTextureFilter, SGSetTextureFilter, false);
215 fgSetInt("/sim/rendering/filtering", 1);
216 fgSetBool("/sim/rendering/wireframe", false);
217 fgSetBool("/sim/rendering/horizon-effect", false);
218 fgSetBool("/sim/rendering/enhanced-lighting", false);
219 fgSetBool("/sim/rendering/distance-attenuation", false);
220 fgSetBool("/sim/rendering/specular-highlight", true);
221 fgSetString("/sim/rendering/materials-file", "materials.xml");
222 fgSetInt("/sim/startup/xsize", 800);
223 fgSetInt("/sim/startup/ysize", 600);
224 fgSetInt("/sim/rendering/bits-per-pixel", 16);
225 fgSetString("/sim/view-mode", "pilot");
226 fgSetDouble("/sim/current-view/heading-offset-deg", 0);
229 fgSetString("/sim/startup/units", "feet");
230 fgSetString("/sim/hud/frame-stat-type", "tris");
233 fgSetInt("/sim/startup/time-offset", 0);
234 fgSetString("/sim/startup/time-offset-type", "system-offset");
235 fgSetLong("/sim/time/cur-time-override", 0);
238 fgSetBool("/sim/freeze/master", false);
239 fgSetBool("/sim/freeze/position", false);
240 fgSetBool("/sim/freeze/clock", false);
241 fgSetBool("/sim/freeze/fuel", false);
243 fgSetString("/sim/multiplay/callsign", "callsign");
244 fgSetString("/sim/multiplay/rxhost", "");
245 fgSetString("/sim/multiplay/txhost", "");
246 fgSetInt("/sim/multiplay/rxport", 0);
247 fgSetInt("/sim/multiplay/txport", 0);
249 fgSetString("/sim/version/flightgear", FLIGHTGEAR_VERSION);
250 fgSetString("/sim/version/simgear", SG_STRINGIZE(SIMGEAR_VERSION));
251 fgSetString("/sim/version/openscenegraph", osgGetVersion());
252 fgSetString("/sim/version/revision", REVISION);
253 fgSetInt("/sim/version/build-number", HUDSON_BUILD_NUMBER);
254 fgSetString("/sim/version/build-id", HUDSON_BUILD_ID);
256 char* envp = ::getenv( "http_proxy" );
258 fgSetupProxy( envp );
262 parse_wind (const string &wind, double * min_hdg, double * max_hdg,
263 double * speed, double * gust)
265 string::size_type pos = wind.find('@');
266 if (pos == string::npos)
268 string dir = wind.substr(0, pos);
269 string spd = wind.substr(pos+1);
271 if (pos == string::npos) {
272 *min_hdg = *max_hdg = atof(dir.c_str());
274 *min_hdg = atof(dir.substr(0,pos).c_str());
275 *max_hdg = atof(dir.substr(pos+1).c_str());
278 if (pos == string::npos) {
279 *speed = *gust = atof(spd.c_str());
281 *speed = atof(spd.substr(0,pos).c_str());
282 *gust = atof(spd.substr(pos+1).c_str());
288 parseIntValue(char** ppParserPos, int* pValue,int min, int max, const char* field, const char* argument)
290 if ( !strlen(*ppParserPos) )
296 while ( isdigit((*ppParserPos)[0]) && (i<255) )
298 num[i] = (*ppParserPos)[0];
304 switch ((*ppParserPos)[0])
312 SG_LOG(SG_GENERAL, SG_ALERT, "Illegal character in time string for " << field << ": '" <<
313 (*ppParserPos)[0] << "'.");
314 // invalid field - skip rest of string to avoid further errors
315 while ((*ppParserPos)[0])
323 int value = atoi(num);
324 if ((value < min)||(value > max))
326 SG_LOG(SG_GENERAL, SG_ALERT, "Invalid " << field << " in '" << argument <<
327 "'. Valid range is " << min << "-" << max << ".");
337 // parse a time string ([+/-]%f[:%f[:%f]]) into hours
339 parse_time(const string& time_in) {
340 char *time_str, num[256];
341 double hours, minutes, seconds;
346 time_str = (char *)time_in.c_str();
348 // printf("parse_time(): %s\n", time_str);
351 if ( strlen(time_str) ) {
352 if ( time_str[0] == '+' ) {
355 } else if ( time_str[0] == '-' ) {
360 // printf("sign = %d\n", sign);
363 if ( strlen(time_str) ) {
365 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
366 num[i] = time_str[0];
370 if ( time_str[0] == ':' ) {
375 // printf("hours = %.2lf\n", hours);
381 if ( strlen(time_str) ) {
383 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
384 num[i] = time_str[0];
388 if ( time_str[0] == ':' ) {
393 // printf("minutes = %.2lf\n", minutes);
395 result += minutes / 60.0;
399 if ( strlen(time_str) ) {
401 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
402 num[i] = time_str[0];
408 // printf("seconds = %.2lf\n", seconds);
410 result += seconds / 3600.0;
413 SG_LOG( SG_GENERAL, SG_INFO, " parse_time() = " << sign * result );
415 return(sign * result);
418 // parse a date string (yyyy:mm:dd:hh:mm:ss) into a time_t (seconds)
420 parse_date( const string& date, const char* timeType)
422 struct tm gmt,*pCurrentTime;
423 int year,month,day,hour,minute,second;
424 char *argument, *date_str;
426 SGTime CurrentTime = SGTime();
427 CurrentTime.update(0,0,0,0);
429 // FIXME This should obtain system/aircraft/GMT time depending on timeType
430 pCurrentTime = CurrentTime.getGmt();
432 // initialize all fields with current time
433 year = pCurrentTime->tm_year + 1900;
434 month = pCurrentTime->tm_mon + 1;
435 day = pCurrentTime->tm_mday;
436 hour = pCurrentTime->tm_hour;
437 minute = pCurrentTime->tm_min;
438 second = pCurrentTime->tm_sec;
440 argument = (char *)date.c_str();
443 // start with parsing year
444 if (!strlen(date_str) ||
445 !parseIntValue(&date_str,&year,0,9999,"year",argument))
452 SG_LOG(SG_GENERAL, SG_ALERT, "Invalid year '" << year << "'. Use 1970 or later.");
456 parseIntValue(&date_str, &month, 1, 12, "month", argument);
457 parseIntValue(&date_str, &day, 1, 31, "day", argument);
458 parseIntValue(&date_str, &hour, 0, 23, "hour", argument);
459 parseIntValue(&date_str, &minute, 0, 59, "minute", argument);
460 parseIntValue(&date_str, &second, 0, 59, "second", argument);
466 gmt.tm_mon = month - 1;
467 gmt.tm_year = year -1900;
468 gmt.tm_isdst = 0; // ignore daylight savings time for the moment
470 time_t theTime = sgTimeGetGMT( gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
471 gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
473 SG_LOG(SG_GENERAL, SG_INFO, "Configuring startup time to " << ctime(&theTime));
479 // parse angle in the form of [+/-]ddd:mm:ss into degrees
481 parse_degree( const string& degree_str) {
482 double result = parse_time( degree_str );
484 // printf("Degree = %.4f\n", result);
490 // parse time offset string into seconds
492 parse_time_offset( const string& time_str) {
495 // printf("time offset = %s\n", time_str);
498 result = (int)rint(parse_time(time_str) * 3600.0);
500 result = (int)(parse_time(time_str) * 3600.0);
503 // printf("parse_time_offset(): %d\n", result);
509 // Parse --fov=x.xx type option
511 parse_fov( const string& arg ) {
512 double fov = atof(arg);
514 if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
515 if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
517 fgSetDouble("/sim/view[0]/config/default-field-of-view-deg", fov);
519 // printf("parse_fov(): result = %.4f\n", fov);
525 // Parse I/O channel option
527 // Format is "--protocol=medium,direction,hz,medium_options,..."
529 // protocol = { native, nmea, garmin, AV400, AV400Sim, fgfs, rul, pve, etc. }
530 // medium = { serial, socket, file, etc. }
531 // direction = { in, out, bi }
532 // hz = number of times to process channel per second (floating
533 // point values are ok.
535 // Serial example "--nmea=serial,dir,hz,device,baud" where
537 // device = OS device name of serial line to be open()'ed
538 // baud = {300, 1200, 2400, ..., 230400}
540 // Socket exacmple "--native=socket,dir,hz,machine,port,style" where
542 // machine = machine name or ip address if client (leave empty if server)
543 // port = port, leave empty to let system choose
544 // style = tcp or udp
546 // File example "--garmin=file,dir,hz,filename" where
548 // filename = file system file name
551 add_channel( const string& type, const string& channel_str ) {
552 // This check is neccessary to prevent fgviewer from segfaulting when given
553 // weird options. (It doesn't run the full initailization)
554 if(!globals->get_channel_options_list())
556 SG_LOG(SG_GENERAL, SG_ALERT, "Option " << type << "=" << channel_str
560 SG_LOG(SG_GENERAL, SG_INFO, "Channel string = " << channel_str );
561 globals->get_channel_options_list()->push_back( type + "," + channel_str );
566 fgOptLanguage( const char *arg )
568 globals->set_locale( fgInitLocale( arg ) );
569 return FG_OPTIONS_OK;
575 fgSetString("/sim/presets/airport-id", "");
576 fgSetString("/sim/presets/vor-id", "");
577 fgSetString("/sim/presets/ndb-id", "");
578 fgSetString("/sim/presets/carrier", "");
579 fgSetString("/sim/presets/parkpos", "");
580 fgSetString("/sim/presets/fix", "");
584 fgOptVOR( const char * arg )
587 fgSetString("/sim/presets/vor-id", arg);
588 return FG_OPTIONS_OK;
592 fgOptNDB( const char * arg )
595 fgSetString("/sim/presets/ndb-id", arg);
596 return FG_OPTIONS_OK;
600 fgOptCarrier( const char * arg )
603 fgSetString("/sim/presets/carrier", arg);
604 return FG_OPTIONS_OK;
608 fgOptParkpos( const char * arg )
610 fgSetString("/sim/presets/parkpos", arg);
611 return FG_OPTIONS_OK;
615 fgOptFIX( const char * arg )
618 fgSetString("/sim/presets/fix", arg);
619 return FG_OPTIONS_OK;
623 fgOptLon( const char *arg )
626 fgSetDouble("/sim/presets/longitude-deg", parse_degree( arg ));
627 fgSetDouble("/position/longitude-deg", parse_degree( arg ));
628 return FG_OPTIONS_OK;
632 fgOptLat( const char *arg )
635 fgSetDouble("/sim/presets/latitude-deg", parse_degree( arg ));
636 fgSetDouble("/position/latitude-deg", parse_degree( arg ));
637 return FG_OPTIONS_OK;
641 fgOptAltitude( const char *arg )
643 fgSetBool("/sim/presets/onground", false);
644 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
645 fgSetDouble("/sim/presets/altitude-ft", atof( arg ));
647 fgSetDouble("/sim/presets/altitude-ft",
648 atof( arg ) * SG_METER_TO_FEET);
649 return FG_OPTIONS_OK;
653 fgOptUBody( const char *arg )
655 fgSetString("/sim/presets/speed-set", "UVW");
656 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
657 fgSetDouble("/sim/presets/uBody-fps", atof( arg ));
659 fgSetDouble("/sim/presets/uBody-fps",
660 atof( arg ) * SG_METER_TO_FEET);
661 return FG_OPTIONS_OK;
665 fgOptVBody( const char *arg )
667 fgSetString("/sim/presets/speed-set", "UVW");
668 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
669 fgSetDouble("/sim/presets/vBody-fps", atof( arg ));
671 fgSetDouble("/sim/presets/vBody-fps",
672 atof( arg ) * SG_METER_TO_FEET);
673 return FG_OPTIONS_OK;
677 fgOptWBody( const char *arg )
679 fgSetString("/sim/presets/speed-set", "UVW");
680 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
681 fgSetDouble("/sim/presets/wBody-fps", atof(arg));
683 fgSetDouble("/sim/presets/wBody-fps",
684 atof(arg) * SG_METER_TO_FEET);
685 return FG_OPTIONS_OK;
689 fgOptVNorth( const char *arg )
691 fgSetString("/sim/presets/speed-set", "NED");
692 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
693 fgSetDouble("/sim/presets/speed-north-fps", atof( arg ));
695 fgSetDouble("/sim/presets/speed-north-fps",
696 atof( arg ) * SG_METER_TO_FEET);
697 return FG_OPTIONS_OK;
701 fgOptVEast( const char *arg )
703 fgSetString("/sim/presets/speed-set", "NED");
704 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
705 fgSetDouble("/sim/presets/speed-east-fps", atof(arg));
707 fgSetDouble("/sim/presets/speed-east-fps",
708 atof(arg) * SG_METER_TO_FEET);
709 return FG_OPTIONS_OK;
713 fgOptVDown( const char *arg )
715 fgSetString("/sim/presets/speed-set", "NED");
716 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
717 fgSetDouble("/sim/presets/speed-down-fps", atof(arg));
719 fgSetDouble("/sim/presets/speed-down-fps",
720 atof(arg) * SG_METER_TO_FEET);
721 return FG_OPTIONS_OK;
725 fgOptVc( const char *arg )
727 // fgSetString("/sim/presets/speed-set", "knots");
728 // fgSetDouble("/velocities/airspeed-kt", atof(arg.substr(5)));
729 fgSetString("/sim/presets/speed-set", "knots");
730 fgSetDouble("/sim/presets/airspeed-kt", atof(arg));
731 return FG_OPTIONS_OK;
735 fgOptMach( const char *arg )
737 fgSetString("/sim/presets/speed-set", "mach");
738 fgSetDouble("/sim/presets/mach", atof(arg));
739 return FG_OPTIONS_OK;
743 fgOptRoc( const char *arg )
745 fgSetDouble("/velocities/vertical-speed-fps", atof(arg)/60);
746 return FG_OPTIONS_OK;
750 fgOptFgScenery( const char *arg )
752 globals->append_fg_scenery(arg);
753 return FG_OPTIONS_OK;
757 fgOptFov( const char *arg )
760 return FG_OPTIONS_OK;
764 fgOptGeometry( const char *arg )
766 bool geometry_ok = true;
767 int xsize = 0, ysize = 0;
768 string geometry = arg;
769 string::size_type i = geometry.find('x');
771 if (i != string::npos) {
772 xsize = atoi(geometry.substr(0, i));
773 ysize = atoi(geometry.substr(i+1));
778 if ( xsize <= 0 || ysize <= 0 ) {
784 if ( !geometry_ok ) {
785 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown geometry: " << geometry );
786 SG_LOG( SG_GENERAL, SG_ALERT,
787 "Setting geometry to " << xsize << 'x' << ysize << '\n');
789 SG_LOG( SG_GENERAL, SG_INFO,
790 "Setting geometry to " << xsize << 'x' << ysize << '\n');
791 fgSetInt("/sim/startup/xsize", xsize);
792 fgSetInt("/sim/startup/ysize", ysize);
794 return FG_OPTIONS_OK;
798 fgOptBpp( const char *arg )
800 string bits_per_pix = arg;
801 if ( bits_per_pix == "16" ) {
802 fgSetInt("/sim/rendering/bits-per-pixel", 16);
803 } else if ( bits_per_pix == "24" ) {
804 fgSetInt("/sim/rendering/bits-per-pixel", 24);
805 } else if ( bits_per_pix == "32" ) {
806 fgSetInt("/sim/rendering/bits-per-pixel", 32);
808 SG_LOG(SG_GENERAL, SG_ALERT, "Unsupported bpp " << bits_per_pix);
810 return FG_OPTIONS_OK;
814 fgOptTimeOffset( const char *arg )
816 fgSetLong("/sim/startup/time-offset",
817 parse_time_offset( arg ));
818 fgSetString("/sim/startup/time-offset-type", "system-offset");
819 return FG_OPTIONS_OK;
823 fgOptStartDateSys( const char *arg )
825 long int theTime = parse_date( arg, "system" );
828 fgSetLong("/sim/startup/time-offset", theTime);
829 fgSetString("/sim/startup/time-offset-type", "system");
831 return FG_OPTIONS_OK;
835 fgOptStartDateLat( const char *arg )
837 long int theTime = parse_date( arg, "latitude" );
840 fgSetLong("/sim/startup/time-offset", theTime);
841 fgSetString("/sim/startup/time-offset-type", "latitude");
843 return FG_OPTIONS_OK;
847 fgOptStartDateGmt( const char *arg )
849 long int theTime = parse_date( arg, "gmt" );
852 fgSetLong("/sim/startup/time-offset", theTime);
853 fgSetString("/sim/startup/time-offset-type", "gmt");
855 return FG_OPTIONS_OK;
859 fgSetupProxy( const char *arg )
861 string options = simgear::strutils::strip( arg );
862 string host, port, auth;
863 string::size_type pos;
865 // this is NURLP - NURLP is not an url parser
866 if( simgear::strutils::starts_with( options, "http://" ) )
867 options = options.substr( 7 );
868 if( simgear::strutils::ends_with( options, "/" ) )
869 options = options.substr( 0, options.length() - 1 );
871 host = port = auth = "";
872 if ((pos = options.find("@")) != string::npos)
873 auth = options.substr(0, pos++);
877 host = options.substr(pos, options.size());
878 if ((pos = host.find(":")) != string::npos) {
879 port = host.substr(++pos, host.size());
880 host.erase(--pos, host.size());
883 fgSetString("/sim/presets/proxy/host", host.c_str());
884 fgSetString("/sim/presets/proxy/port", port.c_str());
885 fgSetString("/sim/presets/proxy/authentication", auth.c_str());
887 return FG_OPTIONS_OK;
891 fgOptTraceRead( const char *arg )
894 SG_LOG(SG_GENERAL, SG_INFO, "Tracing reads for property " << name);
895 fgGetNode(name.c_str(), true)
896 ->setAttribute(SGPropertyNode::TRACE_READ, true);
897 return FG_OPTIONS_OK;
901 fgOptLogLevel( const char *arg )
903 fgSetString("/sim/logging/priority", arg);
904 setLoggingPriority(arg);
906 return FG_OPTIONS_OK;
910 fgOptLogClasses( const char *arg )
912 fgSetString("/sim/logging/classes", arg);
913 setLoggingClasses (arg);
915 return FG_OPTIONS_OK;
919 fgOptTraceWrite( const char *arg )
922 SG_LOG(SG_GENERAL, SG_INFO, "Tracing writes for property " << name);
923 fgGetNode(name.c_str(), true)
924 ->setAttribute(SGPropertyNode::TRACE_WRITE, true);
925 return FG_OPTIONS_OK;
929 fgOptViewOffset( const char *arg )
931 // $$$ begin - added VS Renganathan, 14 Oct 2K
932 // for multi-window outside window imagery
933 string woffset = arg;
934 double default_view_offset = 0.0;
935 if ( woffset == "LEFT" ) {
936 default_view_offset = SGD_PI * 0.25;
937 } else if ( woffset == "RIGHT" ) {
938 default_view_offset = SGD_PI * 1.75;
939 } else if ( woffset == "CENTER" ) {
940 default_view_offset = 0.00;
942 default_view_offset = atof( woffset.c_str() ) * SGD_DEGREES_TO_RADIANS;
944 /* apparently not used (CLO, 11 Jun 2002)
945 FGViewer *pilot_view =
946 (FGViewer *)globals->get_viewmgr()->get_view( 0 ); */
947 // this will work without calls to the viewer...
948 fgSetDouble( "/sim/current-view/heading-offset-deg",
949 default_view_offset * SGD_RADIANS_TO_DEGREES );
950 // $$$ end - added VS Renganathan, 14 Oct 2K
951 return FG_OPTIONS_OK;
955 fgOptVisibilityMeters( const char *arg )
957 Environment::Presets::VisibilitySingleton::instance()->preset( atof( arg ) );
958 return FG_OPTIONS_OK;
962 fgOptVisibilityMiles( const char *arg )
964 Environment::Presets::VisibilitySingleton::instance()->preset( atof( arg ) * 5280.0 * SG_FEET_TO_METER );
965 return FG_OPTIONS_OK;
969 fgOptRandomWind( const char *arg )
971 double min_hdg = sg_random() * 360.0;
972 double max_hdg = min_hdg + (20 - sqrt(sg_random() * 400));
973 double speed = sg_random() * sg_random() * 40;
974 double gust = speed + (10 - sqrt(sg_random() * 100));
975 Environment::Presets::WindSingleton::instance()->preset(min_hdg, max_hdg, speed, gust);
976 return FG_OPTIONS_OK;
980 fgOptWind( const char *arg )
982 double min_hdg = 0.0, max_hdg = 0.0, speed = 0.0, gust = 0.0;
983 if (!parse_wind( arg, &min_hdg, &max_hdg, &speed, &gust)) {
984 SG_LOG( SG_GENERAL, SG_ALERT, "bad wind value " << arg );
985 return FG_OPTIONS_ERROR;
987 Environment::Presets::WindSingleton::instance()->preset(min_hdg, max_hdg, speed, gust);
988 return FG_OPTIONS_OK;
992 fgOptTurbulence( const char *arg )
994 Environment::Presets::TurbulenceSingleton::instance()->preset( atof(arg) );
995 return FG_OPTIONS_OK;
999 fgOptCeiling( const char *arg )
1001 double elevation, thickness;
1003 string::size_type pos = spec.find(':');
1004 if (pos == string::npos) {
1005 elevation = atof(spec.c_str());
1008 elevation = atof(spec.substr(0, pos).c_str());
1009 thickness = atof(spec.substr(pos + 1).c_str());
1011 Environment::Presets::CeilingSingleton::instance()->preset( elevation, thickness );
1012 return FG_OPTIONS_OK;
1016 fgOptWp( const char *arg )
1018 string_list *waypoints = globals->get_initial_waypoints();
1020 waypoints = new string_list;
1021 globals->set_initial_waypoints(waypoints);
1023 waypoints->push_back(arg);
1024 return FG_OPTIONS_OK;
1028 fgOptConfig( const char *arg )
1032 readProperties(file, globals->get_props());
1033 } catch (const sg_exception &e) {
1034 string message = "Error loading config file: ";
1035 message += e.getFormattedMessage() + e.getOrigin();
1036 SG_LOG(SG_INPUT, SG_ALERT, message);
1039 return FG_OPTIONS_OK;
1043 parse_colon (const string &s, double * val1, double * val2)
1045 string::size_type pos = s.find(':');
1046 if (pos == string::npos) {
1050 *val1 = atof(s.substr(0, pos).c_str());
1051 *val2 = atof(s.substr(pos+1).c_str());
1058 fgOptFailure( const char * arg )
1062 fgSetBool("/systems/pitot/serviceable", false);
1063 } else if (a == "static") {
1064 fgSetBool("/systems/static/serviceable", false);
1065 } else if (a == "vacuum") {
1066 fgSetBool("/systems/vacuum/serviceable", false);
1067 } else if (a == "electrical") {
1068 fgSetBool("/systems/electrical/serviceable", false);
1070 SG_LOG(SG_INPUT, SG_ALERT, "Unknown failure mode: " << a);
1071 return FG_OPTIONS_ERROR;
1074 return FG_OPTIONS_OK;
1079 fgOptNAV1( const char * arg )
1081 double radial, freq;
1082 if (parse_colon(arg, &radial, &freq))
1083 fgSetDouble("/instrumentation/nav[0]/radials/selected-deg", radial);
1084 fgSetDouble("/instrumentation/nav[0]/frequencies/selected-mhz", freq);
1085 return FG_OPTIONS_OK;
1089 fgOptNAV2( const char * arg )
1091 double radial, freq;
1092 if (parse_colon(arg, &radial, &freq))
1093 fgSetDouble("/instrumentation/nav[1]/radials/selected-deg", radial);
1094 fgSetDouble("/instrumentation/nav[1]/frequencies/selected-mhz", freq);
1095 return FG_OPTIONS_OK;
1099 fgOptADF1( const char * arg )
1102 if (parse_colon(arg, &rot, &freq))
1103 fgSetDouble("/instrumentation/adf[0]/rotation-deg", rot);
1104 fgSetDouble("/instrumentation/adf[0]/frequencies/selected-khz", freq);
1105 return FG_OPTIONS_OK;
1109 fgOptADF2( const char * arg )
1112 if (parse_colon(arg, &rot, &freq))
1113 fgSetDouble("/instrumentation/adf[1]/rotation-deg", rot);
1114 fgSetDouble("/instrumentation/adf[1]/frequencies/selected-khz", freq);
1115 return FG_OPTIONS_OK;
1119 fgOptDME( const char *arg )
1122 if (opt == "nav1") {
1123 fgSetInt("/instrumentation/dme/switch-position", 1);
1124 fgSetString("/instrumentation/dme/frequencies/source",
1125 "/instrumentation/nav[0]/frequencies/selected-mhz");
1126 } else if (opt == "nav2") {
1127 fgSetInt("/instrumentation/dme/switch-position", 3);
1128 fgSetString("/instrumentation/dme/frequencies/source",
1129 "/instrumentation/nav[1]/frequencies/selected-mhz");
1131 double frequency = atof(arg);
1134 SG_LOG(SG_INPUT, SG_ALERT, "Invalid DME frequency: '" << arg << "'.");
1135 return FG_OPTIONS_ERROR;
1137 fgSetInt("/instrumentation/dme/switch-position", 2);
1138 fgSetString("/instrumentation/dme/frequencies/source",
1139 "/instrumentation/dme/frequencies/selected-mhz");
1140 fgSetDouble("/instrumentation/dme/frequencies/selected-mhz", frequency);
1142 return FG_OPTIONS_OK;
1146 fgOptLivery( const char *arg )
1149 string livery_path = "livery/" + opt;
1150 fgSetString("/sim/model/texture-path", livery_path.c_str() );
1151 return FG_OPTIONS_OK;
1155 fgOptScenario( const char *arg )
1157 SGPropertyNode_ptr ai_node = fgGetNode( "/sim/ai", true );
1158 vector<SGPropertyNode_ptr> scenarii = ai_node->getChildren( "scenario" );
1160 for ( size_t i = 0; i < scenarii.size(); ++i ) {
1161 int ind = scenarii[i]->getIndex();
1162 if ( index < ind ) {
1166 SGPropertyNode_ptr scenario = ai_node->getNode( "scenario", index + 1, true );
1167 scenario->setStringValue( arg );
1168 ai_node->setBoolValue( "enabled", true );
1169 return FG_OPTIONS_OK;
1173 fgOptNoScenarios( const char *arg )
1175 SGPropertyNode_ptr ai_node = fgGetNode( "/sim/ai", true );
1176 ai_node->removeChildren("scenario",false);
1177 ai_node->setBoolValue( "enabled", false );
1178 return FG_OPTIONS_OK;
1182 fgOptRunway( const char *arg )
1184 fgSetString("/sim/presets/runway", arg );
1185 fgSetBool("/sim/presets/runway-requested", true );
1186 return FG_OPTIONS_OK;
1190 fgOptParking( const char *arg )
1192 cerr << "Processing argument " << arg << endl;
1193 fgSetString("/sim/presets/parking", arg );
1194 fgSetBool ("/sim/presets/parking-requested", true );
1195 return FG_OPTIONS_OK;
1199 fgOptVersion( const char *arg )
1201 cerr << "FlightGear version: " << FLIGHTGEAR_VERSION << endl;
1202 cerr << "Revision: " << REVISION << endl;
1203 cerr << "Build-Id: " << HUDSON_BUILD_ID << endl;
1204 cerr << "FG_ROOT=" << globals->get_fg_root() << endl;
1205 cerr << "FG_HOME=" << fgGetString("/sim/fg-home") << endl;
1206 cerr << "FG_SCENERY=";
1209 string_list scn = globals->get_fg_scenery();
1210 for (string_list::const_iterator it = scn.begin(); it != scn.end(); it++)
1212 if (didsome) cerr << ":";
1217 cerr << "SimGear version: " << SG_STRINGIZE(SIMGEAR_VERSION) << endl;
1218 cerr << "PLIB version: " << PLIB_VERSION << endl;
1219 return FG_OPTIONS_EXIT;
1223 fgOptCallSign(const char * arg)
1227 strncpy(callsign,arg,10);
1229 for (i=0;callsign[i];i++)
1231 char c = callsign[i];
1232 if (c >= 'A' && c <= 'Z') continue;
1233 if (c >= 'a' && c <= 'z') continue;
1234 if (c >= '0' && c <= '9') continue;
1235 if (c == '-' || c == '_') continue;
1236 // convert any other illegal characters
1239 fgSetString("sim/multiplay/callsign", callsign );
1240 return FG_OPTIONS_OK;
1244 // Set a property for the --prop: option. Syntax: --prop:[<type>:]<name>=<value>
1245 // <type> can be "double" etc. but also only the first letter "d".
1246 // Examples: --prop:alpha=1 --prop:bool:beta=true --prop:d:gamma=0.123
1248 fgOptSetProperty(const char* raw)
1251 string::size_type pos = arg.find('=');
1252 if (pos == arg.npos || pos == 0 || pos + 1 == arg.size())
1253 return FG_OPTIONS_ERROR;
1255 string name = arg.substr(0, pos);
1256 string value = arg.substr(pos + 1);
1258 pos = name.find(':');
1260 if (pos != name.npos && pos != 0 && pos + 1 != name.size()) {
1261 type = name.substr(0, pos);
1262 name = name.substr(pos + 1);
1264 SGPropertyNode *n = fgGetNode(name.c_str(), true);
1266 bool writable = n->getAttribute(SGPropertyNode::WRITE);
1268 n->setAttribute(SGPropertyNode::WRITE, true);
1272 ret = n->setUnspecifiedValue(value.c_str());
1273 else if (type == "s" || type == "string")
1274 ret = n->setStringValue(value.c_str());
1275 else if (type == "d" || type == "double")
1276 ret = n->setDoubleValue(strtod(value.c_str(), 0));
1277 else if (type == "f" || type == "float")
1278 ret = n->setFloatValue(atof(value.c_str()));
1279 else if (type == "l" || type == "long")
1280 ret = n->setLongValue(strtol(value.c_str(), 0, 0));
1281 else if (type == "i" || type == "int")
1282 ret = n->setIntValue(atoi(value.c_str()));
1283 else if (type == "b" || type == "bool")
1284 ret = n->setBoolValue(value == "true" || atoi(value.c_str()) != 0);
1287 n->setAttribute(SGPropertyNode::WRITE, false);
1288 return ret ? FG_OPTIONS_OK : FG_OPTIONS_ERROR;
1294 option has_param type property b_param s_param func
1297 option : name of the option
1298 has_param : option is --name=value if true or --name if false
1299 type : OPTION_BOOL - property is a boolean
1300 OPTION_STRING - property is a string
1301 OPTION_DOUBLE - property is a double
1302 OPTION_INT - property is an integer
1303 OPTION_CHANNEL - name of option is the name of a channel
1304 OPTION_FUNC - the option trigger a function
1305 b_param : if type==OPTION_BOOL,
1306 value set to the property (has_param is false for boolean)
1307 s_param : if type==OPTION_STRING,
1308 value set to the property if has_param is false
1309 func : function called if type==OPTION_FUNC. if has_param is true,
1310 the value is passed to the function as a string, otherwise,
1313 For OPTION_DOUBLE and OPTION_INT, the parameter value is converted into a
1314 double or an integer and set to the property.
1316 For OPTION_CHANNEL, add_channel is called with the parameter value as the
1320 enum OptionType { OPTION_BOOL = 0, OPTION_STRING, OPTION_DOUBLE, OPTION_INT, OPTION_CHANNEL, OPTION_FUNC, OPTION_IGNORE };
1321 const int OPTION_MULTI = 1 << 17;
1327 const char *property;
1329 const char *s_param;
1330 int (*func)( const char * );
1331 } fgOptionArray[] = {
1333 {"language", true, OPTION_FUNC, "", false, "", fgOptLanguage },
1334 {"disable-game-mode", false, OPTION_BOOL, "/sim/startup/game-mode", false, "", 0 },
1335 {"enable-game-mode", false, OPTION_BOOL, "/sim/startup/game-mode", true, "", 0 },
1336 {"disable-splash-screen", false, OPTION_BOOL, "/sim/startup/splash-screen", false, "", 0 },
1337 {"enable-splash-screen", false, OPTION_BOOL, "/sim/startup/splash-screen", true, "", 0 },
1338 {"disable-intro-music", false, OPTION_BOOL, "/sim/startup/intro-music", false, "", 0 },
1339 {"enable-intro-music", false, OPTION_BOOL, "/sim/startup/intro-music", true, "", 0 },
1340 {"disable-mouse-pointer", false, OPTION_STRING, "/sim/startup/mouse-pointer", false, "disabled", 0 },
1341 {"enable-mouse-pointer", false, OPTION_STRING, "/sim/startup/mouse-pointer", false, "enabled", 0 },
1342 {"disable-random-objects", false, OPTION_BOOL, "/sim/rendering/random-objects", false, "", 0 },
1343 {"enable-random-objects", false, OPTION_BOOL, "/sim/rendering/random-objects", true, "", 0 },
1344 {"disable-real-weather-fetch", false, OPTION_BOOL, "/environment/realwx/enabled", false, "", 0 },
1345 {"enable-real-weather-fetch", false, OPTION_BOOL, "/environment/realwx/enabled", true, "", 0 },
1346 {"metar", true, OPTION_STRING, "/environment/metar/data", false, "", 0 },
1347 {"disable-ai-models", false, OPTION_BOOL, "/sim/ai/enabled", false, "", 0 },
1348 {"enable-ai-models", false, OPTION_BOOL, "/sim/ai/enabled", true, "", 0 },
1349 {"disable-ai-traffic", false, OPTION_BOOL, "/sim/traffic-manager/enabled", false, "", 0 },
1350 {"enable-ai-traffic", false, OPTION_BOOL, "/sim/traffic-manager/enabled", true, "", 0 },
1351 {"disable-freeze", false, OPTION_BOOL, "/sim/freeze/master", false, "", 0 },
1352 {"enable-freeze", false, OPTION_BOOL, "/sim/freeze/master", true, "", 0 },
1353 {"disable-fuel-freeze", false, OPTION_BOOL, "/sim/freeze/fuel", false, "", 0 },
1354 {"enable-fuel-freeze", false, OPTION_BOOL, "/sim/freeze/fuel", true, "", 0 },
1355 {"disable-clock-freeze", false, OPTION_BOOL, "/sim/freeze/clock", false, "", 0 },
1356 {"enable-clock-freeze", false, OPTION_BOOL, "/sim/freeze/clock", true, "", 0 },
1357 {"disable-hud-3d", false, OPTION_BOOL, "/sim/hud/enable3d[1]", false, "", 0 },
1358 {"enable-hud-3d", false, OPTION_BOOL, "/sim/hud/enable3d[1]", true, "", 0 },
1359 {"disable-anti-alias-hud", false, OPTION_BOOL, "/sim/hud/color/antialiased", false, "", 0 },
1360 {"enable-anti-alias-hud", false, OPTION_BOOL, "/sim/hud/color/antialiased", true, "", 0 },
1361 {"control", true, OPTION_STRING, "/sim/control-mode", false, "", 0 },
1362 {"disable-auto-coordination", false, OPTION_BOOL, "/sim/auto-coordination", false, "", 0 },
1363 {"enable-auto-coordination", false, OPTION_BOOL, "/sim/auto-coordination", true, "", 0 },
1364 {"browser-app", true, OPTION_STRING, "/sim/startup/browser-app", false, "", 0 },
1365 {"disable-hud", false, OPTION_BOOL, "/sim/hud/visibility[1]", false, "", 0 },
1366 {"enable-hud", false, OPTION_BOOL, "/sim/hud/visibility[1]", true, "", 0 },
1367 {"disable-panel", false, OPTION_BOOL, "/sim/panel/visibility", false, "", 0 },
1368 {"enable-panel", false, OPTION_BOOL, "/sim/panel/visibility", true, "", 0 },
1369 {"disable-sound", false, OPTION_BOOL, "/sim/sound/working", false, "", 0 },
1370 {"enable-sound", false, OPTION_BOOL, "/sim/sound/working", true, "", 0 },
1371 {"sound-device", true, OPTION_STRING, "/sim/sound/device-name", false, "", 0 },
1372 {"airport", true, OPTION_STRING, "/sim/presets/airport-id", false, "", 0 },
1373 {"runway", true, OPTION_FUNC, "", false, "", fgOptRunway },
1374 {"vor", true, OPTION_FUNC, "", false, "", fgOptVOR },
1375 {"vor-frequency", true, OPTION_DOUBLE, "/sim/presets/vor-freq", false, "", fgOptVOR },
1376 {"ndb", true, OPTION_FUNC, "", false, "", fgOptNDB },
1377 {"ndb-frequency", true, OPTION_DOUBLE, "/sim/presets/ndb-freq", false, "", fgOptVOR },
1378 {"carrier", true, OPTION_FUNC, "", false, "", fgOptCarrier },
1379 {"parkpos", true, OPTION_FUNC, "", false, "", fgOptParkpos },
1380 {"fix", true, OPTION_FUNC, "", false, "", fgOptFIX },
1381 {"offset-distance", true, OPTION_DOUBLE, "/sim/presets/offset-distance-nm", false, "", 0 },
1382 {"offset-azimuth", true, OPTION_DOUBLE, "/sim/presets/offset-azimuth-deg", false, "", 0 },
1383 {"lon", true, OPTION_FUNC, "", false, "", fgOptLon },
1384 {"lat", true, OPTION_FUNC, "", false, "", fgOptLat },
1385 {"altitude", true, OPTION_FUNC, "", false, "", fgOptAltitude },
1386 {"uBody", true, OPTION_FUNC, "", false, "", fgOptUBody },
1387 {"vBody", true, OPTION_FUNC, "", false, "", fgOptVBody },
1388 {"wBody", true, OPTION_FUNC, "", false, "", fgOptWBody },
1389 {"vNorth", true, OPTION_FUNC, "", false, "", fgOptVNorth },
1390 {"vEast", true, OPTION_FUNC, "", false, "", fgOptVEast },
1391 {"vDown", true, OPTION_FUNC, "", false, "", fgOptVDown },
1392 {"vc", true, OPTION_FUNC, "", false, "", fgOptVc },
1393 {"mach", true, OPTION_FUNC, "", false, "", fgOptMach },
1394 {"heading", true, OPTION_DOUBLE, "/sim/presets/heading-deg", false, "", 0 },
1395 {"roll", true, OPTION_DOUBLE, "/sim/presets/roll-deg", false, "", 0 },
1396 {"pitch", true, OPTION_DOUBLE, "/sim/presets/pitch-deg", false, "", 0 },
1397 {"glideslope", true, OPTION_DOUBLE, "/sim/presets/glideslope-deg", false, "", 0 },
1398 {"roc", true, OPTION_FUNC, "", false, "", fgOptRoc },
1399 {"fg-root", true, OPTION_IGNORE, "", false, "", 0 },
1400 {"fg-scenery", true, OPTION_FUNC | OPTION_MULTI, "", false, "", fgOptFgScenery },
1401 {"fg-aircraft", true, OPTION_IGNORE | OPTION_MULTI, "", false, "", 0 },
1402 {"fdm", true, OPTION_STRING, "/sim/flight-model", false, "", 0 },
1403 {"aero", true, OPTION_STRING, "/sim/aero", false, "", 0 },
1404 {"aircraft-dir", true, OPTION_IGNORE, "", false, "", 0 },
1405 {"model-hz", true, OPTION_INT, "/sim/model-hz", false, "", 0 },
1406 {"speed", true, OPTION_INT, "/sim/speed-up", false, "", 0 },
1407 {"trim", false, OPTION_BOOL, "/sim/presets/trim", true, "", 0 },
1408 {"notrim", false, OPTION_BOOL, "/sim/presets/trim", false, "", 0 },
1409 {"on-ground", false, OPTION_BOOL, "/sim/presets/onground", true, "", 0 },
1410 {"in-air", false, OPTION_BOOL, "/sim/presets/onground", false, "", 0 },
1411 {"fog-disable", false, OPTION_STRING, "/sim/rendering/fog", false, "disabled", 0 },
1412 {"fog-fastest", false, OPTION_STRING, "/sim/rendering/fog", false, "fastest", 0 },
1413 {"fog-nicest", false, OPTION_STRING, "/sim/rendering/fog", false, "nicest", 0 },
1414 {"disable-horizon-effect", false, OPTION_BOOL, "/sim/rendering/horizon-effect", false, "", 0 },
1415 {"enable-horizon-effect", false, OPTION_BOOL, "/sim/rendering/horizon-effect", true, "", 0 },
1416 {"disable-enhanced-lighting", false, OPTION_BOOL, "/sim/rendering/enhanced-lighting", false, "", 0 },
1417 {"enable-enhanced-lighting", false, OPTION_BOOL, "/sim/rendering/enhanced-lighting", true, "", 0 },
1418 {"disable-distance-attenuation", false, OPTION_BOOL, "/sim/rendering/distance-attenuation", false, "", 0 },
1419 {"enable-distance-attenuation", false, OPTION_BOOL, "/sim/rendering/distance-attenuation", true, "", 0 },
1420 {"disable-specular-highlight", false, OPTION_BOOL, "/sim/rendering/specular-highlight", false, "", 0 },
1421 {"enable-specular-highlight", false, OPTION_BOOL, "/sim/rendering/specular-highlight", true, "", 0 },
1422 {"disable-clouds", false, OPTION_BOOL, "/environment/clouds/status", false, "", 0 },
1423 {"enable-clouds", false, OPTION_BOOL, "/environment/clouds/status", true, "", 0 },
1424 {"disable-clouds3d", false, OPTION_BOOL, "/sim/rendering/clouds3d-enable", false, "", 0 },
1425 {"enable-clouds3d", false, OPTION_BOOL, "/sim/rendering/clouds3d-enable", true, "", 0 },
1426 {"fov", true, OPTION_FUNC, "", false, "", fgOptFov },
1427 {"aspect-ratio-multiplier", true, OPTION_DOUBLE, "/sim/current-view/aspect-ratio-multiplier", false, "", 0 },
1428 {"disable-fullscreen", false, OPTION_BOOL, "/sim/startup/fullscreen", false, "", 0 },
1429 {"enable-fullscreen", false, OPTION_BOOL, "/sim/startup/fullscreen", true, "", 0 },
1430 {"disable-save-on-exit", false, OPTION_BOOL, "/sim/startup/save-on-exit", false, "", 0 },
1431 {"enable-save-on-exit", false, OPTION_BOOL, "/sim/startup/save-on-exit", true, "", 0 },
1432 {"shading-flat", false, OPTION_BOOL, "/sim/rendering/shading", false, "", 0 },
1433 {"shading-smooth", false, OPTION_BOOL, "/sim/rendering/shading", true, "", 0 },
1434 {"disable-skyblend", false, OPTION_BOOL, "/sim/rendering/skyblend", false, "", 0 },
1435 {"enable-skyblend", false, OPTION_BOOL, "/sim/rendering/skyblend", true, "", 0 },
1436 {"disable-textures", false, OPTION_BOOL, "/sim/rendering/textures", false, "", 0 },
1437 {"enable-textures", false, OPTION_BOOL, "/sim/rendering/textures", true, "", 0 },
1438 {"texture-filtering", false, OPTION_INT, "/sim/rendering/filtering", 1, "", 0 },
1439 {"disable-wireframe", false, OPTION_BOOL, "/sim/rendering/wireframe", false, "", 0 },
1440 {"enable-wireframe", false, OPTION_BOOL, "/sim/rendering/wireframe", true, "", 0 },
1441 {"materials-file", true, OPTION_STRING, "/sim/rendering/materials-file", false, "", 0 },
1442 {"disable-terrasync", false, OPTION_BOOL, "/sim/terrasync/enabled", false, "", 0 },
1443 {"enable-terrasync", false, OPTION_BOOL, "/sim/terrasync/enabled", true, "", 0 },
1444 {"terrasync-dir", true, OPTION_STRING, "/sim/terrasync/scenery-dir", false, "", 0 },
1445 {"geometry", true, OPTION_FUNC, "", false, "", fgOptGeometry },
1446 {"bpp", true, OPTION_FUNC, "", false, "", fgOptBpp },
1447 {"units-feet", false, OPTION_STRING, "/sim/startup/units", false, "feet", 0 },
1448 {"units-meters", false, OPTION_STRING, "/sim/startup/units", false, "meters", 0 },
1449 {"timeofday", true, OPTION_STRING, "/sim/startup/time-offset-type", false, "noon", 0 },
1450 {"season", true, OPTION_STRING, "/sim/startup/season", false, "summer", 0 },
1451 {"time-offset", true, OPTION_FUNC, "", false, "", fgOptTimeOffset },
1452 {"time-match-real", false, OPTION_STRING, "/sim/startup/time-offset-type", false, "system-offset", 0 },
1453 {"time-match-local", false, OPTION_STRING, "/sim/startup/time-offset-type", false, "latitude-offset", 0 },
1454 {"start-date-sys", true, OPTION_FUNC, "", false, "", fgOptStartDateSys },
1455 {"start-date-lat", true, OPTION_FUNC, "", false, "", fgOptStartDateLat },
1456 {"start-date-gmt", true, OPTION_FUNC, "", false, "", fgOptStartDateGmt },
1457 {"hud-tris", false, OPTION_STRING, "/sim/hud/frame-stat-type", false, "tris", 0 },
1458 {"hud-culled", false, OPTION_STRING, "/sim/hud/frame-stat-type", false, "culled", 0 },
1459 {"atcsim", true, OPTION_CHANNEL, "", false, "dummy", 0 },
1460 {"atlas", true, OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1461 {"httpd", true, OPTION_CHANNEL, "", false, "", 0 },
1462 #ifdef FG_JPEG_SERVER
1463 {"jpg-httpd", true, OPTION_CHANNEL, "", false, "", 0 },
1465 {"native", true, OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1466 {"native-ctrls", true, OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1467 {"native-fdm", true, OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1468 {"native-gui", true, OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1469 {"opengc", true, OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1470 {"AV400", true, OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1471 {"AV400Sim", true, OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1472 {"AV400WSimA", true, OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1473 {"AV400WSimB", true, OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1474 {"garmin", true, OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1475 {"nmea", true, OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1476 {"generic", true, OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1477 {"props", true, OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1478 {"telnet", true, OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1479 {"pve", true, OPTION_CHANNEL, "", false, "", 0 },
1480 {"ray", true, OPTION_CHANNEL, "", false, "", 0 },
1481 {"rul", true, OPTION_CHANNEL, "", false, "", 0 },
1482 {"joyclient", true, OPTION_CHANNEL, "", false, "", 0 },
1483 {"jsclient", true, OPTION_CHANNEL, "", false, "", 0 },
1484 {"proxy", true, OPTION_FUNC, "", false, "", fgSetupProxy },
1485 {"callsign", true, OPTION_FUNC, "", false, "", fgOptCallSign},
1486 {"multiplay", true, OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1488 {"hla", true, OPTION_CHANNEL, "", false, "", 0 },
1490 {"trace-read", true, OPTION_FUNC | OPTION_MULTI, "", false, "", fgOptTraceRead },
1491 {"trace-write", true, OPTION_FUNC | OPTION_MULTI, "", false, "", fgOptTraceWrite },
1492 {"log-level", true, OPTION_FUNC, "", false, "", fgOptLogLevel },
1493 {"log-class", true, OPTION_FUNC, "", false, "", fgOptLogClasses },
1494 {"view-offset", true, OPTION_FUNC | OPTION_MULTI, "", false, "", fgOptViewOffset },
1495 {"visibility", true, OPTION_FUNC, "", false, "", fgOptVisibilityMeters },
1496 {"visibility-miles", true, OPTION_FUNC, "", false, "", fgOptVisibilityMiles },
1497 {"random-wind", false, OPTION_FUNC, "", false, "", fgOptRandomWind },
1498 {"wind", true, OPTION_FUNC | OPTION_MULTI, "", false, "", fgOptWind },
1499 {"turbulence", true, OPTION_FUNC, "", false, "", fgOptTurbulence },
1500 {"ceiling", true, OPTION_FUNC, "", false, "", fgOptCeiling },
1501 {"wp", true, OPTION_FUNC | OPTION_MULTI, "", false, "", fgOptWp },
1502 {"flight-plan", true, OPTION_STRING, "/autopilot/route-manager/file-path", false, "", NULL },
1503 {"config", true, OPTION_FUNC | OPTION_MULTI, "", false, "", fgOptConfig },
1504 {"aircraft", true, OPTION_STRING, "/sim/aircraft", false, "", 0 },
1505 {"vehicle", true, OPTION_STRING, "/sim/aircraft", false, "", 0 },
1506 {"failure", true, OPTION_FUNC | OPTION_MULTI, "", false, "", fgOptFailure },
1507 {"com1", true, OPTION_DOUBLE, "/instrumentation/comm[0]/frequencies/selected-mhz", false, "", 0 },
1508 {"com2", true, OPTION_DOUBLE, "/instrumentation/comm[1]/frequencies/selected-mhz", false, "", 0 },
1509 {"nav1", true, OPTION_FUNC, "", false, "", fgOptNAV1 },
1510 {"nav2", true, OPTION_FUNC, "", false, "", fgOptNAV2 },
1511 {"adf", /*legacy*/ true, OPTION_FUNC, "", false, "", fgOptADF1 },
1512 {"adf1", true, OPTION_FUNC, "", false, "", fgOptADF1 },
1513 {"adf2", true, OPTION_FUNC, "", false, "", fgOptADF2 },
1514 {"dme", true, OPTION_FUNC, "", false, "", fgOptDME },
1515 {"min-status", true, OPTION_STRING, "/sim/aircraft-min-status", false, "all", 0 },
1516 {"livery", true, OPTION_FUNC, "", false, "", fgOptLivery },
1517 {"ai-scenario", true, OPTION_FUNC | OPTION_MULTI, "", false, "", fgOptScenario },
1518 {"disable-ai-scenarios", false, OPTION_FUNC, "", false, "", fgOptNoScenarios},
1519 {"parking-id", true, OPTION_FUNC, "", false, "", fgOptParking },
1520 {"version", false, OPTION_FUNC, "", false, "", fgOptVersion },
1521 {"enable-fpe", false, OPTION_IGNORE, "", false, "", 0},
1522 {"fgviewer", false, OPTION_IGNORE, "", false, "", 0},
1523 {"prop", true, OPTION_FUNC | OPTION_MULTI, "", false, "", fgOptSetProperty},
1528 namespace flightgear
1532 * internal storage of a value->option binding
1537 OptionValue(OptionDesc* d, const string& v) :
1545 typedef std::vector<OptionValue> OptionValueVec;
1546 typedef std::map<string, OptionDesc*> OptionDescDict;
1548 class Options::OptionsPrivate
1552 OptionValueVec::const_iterator findValue(const string& key) const
1554 OptionValueVec::const_iterator it = values.begin();
1555 for (; it != values.end(); ++it) {
1557 continue; // ignore markers
1560 if (it->desc->option == key) {
1563 } // of set values iteration
1565 return it; // not found
1568 OptionDesc* findOption(const string& key) const
1570 OptionDescDict::const_iterator it = options.find(key);
1571 if (it == options.end()) {
1578 int processOption(OptionDesc* desc, const string& arg_value)
1581 return FG_OPTIONS_OK; // tolerate marker options
1584 switch ( desc->type & 0xffff ) {
1586 fgSetBool( desc->property, desc->b_param );
1589 if ( desc->has_param && !arg_value.empty() ) {
1590 fgSetString( desc->property, arg_value.c_str() );
1591 } else if ( !desc->has_param && arg_value.empty() ) {
1592 fgSetString( desc->property, desc->s_param );
1593 } else if ( desc->has_param ) {
1594 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << desc->option << "' needs a parameter" );
1595 return FG_OPTIONS_ERROR;
1597 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << desc->option << "' does not have a parameter" );
1598 return FG_OPTIONS_ERROR;
1602 if ( !arg_value.empty() ) {
1603 fgSetDouble( desc->property, atof( arg_value ) );
1605 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << desc->option << "' needs a parameter" );
1606 return FG_OPTIONS_ERROR;
1610 if ( !arg_value.empty() ) {
1611 fgSetInt( desc->property, atoi( arg_value ) );
1613 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << desc->option << "' needs a parameter" );
1614 return FG_OPTIONS_ERROR;
1617 case OPTION_CHANNEL:
1618 // XXX return value of add_channel should be checked?
1619 if ( desc->has_param && !arg_value.empty() ) {
1620 add_channel( desc->option, arg_value );
1621 } else if ( !desc->has_param && arg_value.empty() ) {
1622 add_channel( desc->option, desc->s_param );
1623 } else if ( desc->has_param ) {
1624 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << desc->option << "' needs a parameter" );
1625 return FG_OPTIONS_ERROR;
1627 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << desc->option << "' does not have a parameter" );
1628 return FG_OPTIONS_ERROR;
1632 if ( desc->has_param && !arg_value.empty() ) {
1633 return desc->func( arg_value.c_str() );
1634 } else if ( !desc->has_param && arg_value.empty() ) {
1635 return desc->func( desc->s_param );
1636 } else if ( desc->has_param ) {
1637 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << desc->option << "' needs a parameter" );
1638 return FG_OPTIONS_ERROR;
1640 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << desc->option << "' does not have a parameter" );
1641 return FG_OPTIONS_ERROR;
1649 return FG_OPTIONS_OK;
1653 * insert a marker value into the values vector. This is necessary
1654 * when processing options, to ensure the correct ordering, where we scan
1655 * for marker values in reverse, and then forwards within each group.
1657 void insertGroupMarker()
1659 values.push_back(OptionValue(NULL, "-"));
1663 * given a current iterator into the values, find the preceeding group marker,
1664 * or return the beginning of the value vector.
1666 OptionValueVec::const_iterator rfindGroup(OptionValueVec::const_iterator pos) const
1668 while (--pos != values.begin()) {
1669 if (pos->desc == NULL) {
1670 return pos; // found a marker, we're done
1681 OptionDescDict options;
1682 OptionValueVec values;
1683 simgear::PathList propertyFiles;
1686 Options* Options::sharedInstance()
1688 if (shared_instance == NULL) {
1689 shared_instance = new Options;
1692 return shared_instance;
1695 Options::Options() :
1696 p(new OptionsPrivate())
1698 p->showHelp = false;
1700 p->showAircraft = false;
1703 OptionDesc *desc = &fgOptionArray[ 0 ];
1704 while ( desc->option != 0 ) {
1705 p->options[ desc->option ] = desc;
1714 void Options::init(int argc, char **argv, const SGPath& appDataPath)
1718 // first, process the command line
1719 bool inOptions = true;
1720 for (int i=1; i<argc; ++i) {
1721 if (inOptions && (argv[i][0] == '-')) {
1722 if (strcmp(argv[i], "--") == 0) { // end of options delimiter
1727 int result = parseOption(argv[i]);
1728 processArgResult(result);
1730 // XML properties file
1733 SG_LOG(SG_GENERAL, SG_ALERT, "config file not found:" << f.str());
1737 p->propertyFiles.push_back(f);
1739 } // of arguments iteration
1740 p->insertGroupMarker(); // command line is one group
1742 // then config files
1745 if( homedir && hostname && strlen(hostname) > 0 ) {
1746 // Check for ~/.fgfsrc.hostname
1747 config.set(homedir);
1748 config.append(".fgfsrc");
1749 config.concat( "." );
1750 config.concat( hostname );
1754 // Check for ~/.fgfsrc
1756 config.set(homedir);
1757 config.append(".fgfsrc");
1761 // check for a config file in app data
1762 SGPath appDataConfig(appDataPath);
1763 appDataConfig.append("fgfsrc");
1764 if (appDataConfig.exists()) {
1765 readConfig(appDataConfig);
1771 // system.fgfsrc handling
1772 if( hostname && strlen(hostname) > 0 ) {
1773 config.set(globals->get_fg_root());
1774 config.append( "system.fgfsrc" );
1775 config.concat( "." );
1776 config.concat( hostname );
1780 config.set(globals->get_fg_root());
1781 config.append( "system.fgfsrc" );
1785 void Options::initAircraft()
1787 BOOST_FOREACH(const string& paths, valuesForOption("fg-aircraft")) {
1788 globals->append_aircraft_paths(paths);
1791 const char* envp = ::getenv("FG_AIRCRAFT");
1793 globals->append_aircraft_paths(envp);
1797 if (isOptionSet("aircraft")) {
1798 aircraft = valueForOption("aircraft");
1799 } else if (isOptionSet("vehicle")) {
1800 aircraft = valueForOption("vehicle");
1803 if (!aircraft.empty()) {
1804 SG_LOG(SG_INPUT, SG_INFO, "aircraft = " << aircraft );
1805 fgSetString("/sim/aircraft", aircraft.c_str() );
1807 SG_LOG(SG_INPUT, SG_INFO, "No user specified aircraft, using default" );
1810 if (p->showAircraft) {
1811 fgOptLogLevel( "alert" );
1812 SGPath path( globals->get_fg_root() );
1813 path.append("Aircraft");
1814 fgShowAircraft(path);
1818 if (isOptionSet("aircraft-dir")) {
1819 // set this now, so it's available in FindAndCacheAircraft
1820 fgSetString("/sim/aircraft-dir", valueForOption("aircraft-dir"));
1824 void Options::processArgResult(int result)
1826 if ((result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR))
1828 else if (result == FG_OPTIONS_VERBOSE_HELP)
1830 else if (result == FG_OPTIONS_SHOW_AIRCRAFT) {
1831 p->showAircraft = true;
1832 } else if (result == FG_OPTIONS_SHOW_SOUND_DEVICES) {
1836 string vendor = smgr.get_vendor();
1837 string renderer = smgr.get_renderer();
1838 cout << renderer << " provided by " << vendor << endl;
1839 cout << endl << "No. Device" << endl;
1841 vector <const char*>devices = smgr.get_available_devices();
1842 for (vector <const char*>::size_type i=0; i<devices.size(); i++) {
1843 cout << i << ". \"" << devices[i] << "\"" << endl;
1847 } else if (result == FG_OPTIONS_EXIT) {
1852 void Options::readConfig(const SGPath& path)
1854 sg_gzifstream in( path.str() );
1855 if ( !in.is_open() ) {
1859 SG_LOG( SG_GENERAL, SG_INFO, "Processing config file: " << path.str() );
1862 while ( ! in.eof() ) {
1864 getline( in, line, '\n' );
1866 // catch extraneous (DOS) line ending character
1868 for (i = line.length(); i > 0; i--)
1869 if (line[i - 1] > 32)
1871 line = line.substr( 0, i );
1873 if ( parseOption( line ) == FG_OPTIONS_ERROR ) {
1874 cerr << endl << "Config file parse error: " << path.str() << " '"
1875 << line << "'" << endl;
1881 p->insertGroupMarker(); // each config file is a group
1884 int Options::parseOption(const string& s)
1886 if ((s == "--help") || (s=="-h")) {
1887 return FG_OPTIONS_HELP;
1888 } else if ( (s == "--verbose") || (s == "-v") ) {
1889 // verbose help/usage request
1890 return FG_OPTIONS_VERBOSE_HELP;
1891 } else if (s.find("-psn") == 0) {
1892 // on Mac, when launched from the GUI, we are passed the ProcessSerialNumber
1893 // as an argument (and no others). Silently ignore the argument here.
1894 return FG_OPTIONS_OK;
1895 } else if ( s.find( "--show-aircraft") == 0) {
1896 return(FG_OPTIONS_SHOW_AIRCRAFT);
1897 } else if ( s.find( "--show-sound-devices") == 0) {
1898 return(FG_OPTIONS_SHOW_SOUND_DEVICES);
1899 } else if ( s.find( "--prop:") == 0) {
1900 // property setting has a slightly different syntax, so fudge things
1901 OptionDesc* desc = p->findOption("prop");
1902 if (s.find("=", 7) == string::npos) { // no equals token
1903 SG_LOG(SG_GENERAL, SG_ALERT, "malformed property option:" << s);
1904 return FG_OPTIONS_ERROR;
1907 p->values.push_back(OptionValue(desc, s.substr(7)));
1908 return FG_OPTIONS_OK;
1909 } else if ( s.find( "--" ) == 0 ) {
1910 size_t eqPos = s.find( '=' );
1912 if (eqPos == string::npos) {
1915 key = s.substr( 2, eqPos - 2 );
1916 value = s.substr( eqPos + 1);
1919 return addOption(key, value);
1921 SG_LOG(SG_GENERAL, SG_ALERT, "unknown option:" << s);
1922 return FG_OPTIONS_ERROR;
1926 int Options::addOption(const string &key, const string &value)
1928 OptionDesc* desc = p->findOption(key);
1930 SG_LOG(SG_GENERAL, SG_ALERT, "unknown option:" << key);
1931 return FG_OPTIONS_ERROR;
1934 if (!(desc->type & OPTION_MULTI)) {
1935 OptionValueVec::const_iterator it = p->findValue(key);
1936 if (it != p->values.end()) {
1937 SG_LOG(SG_GENERAL, SG_INFO, "multiple values forbidden for option:" << key << ", ignoring:" << value);
1938 return FG_OPTIONS_OK;
1942 p->values.push_back(OptionValue(desc, value));
1943 return FG_OPTIONS_OK;
1946 bool Options::isOptionSet(const string &key) const
1948 OptionValueVec::const_iterator it = p->findValue(key);
1949 return (it != p->values.end());
1952 string Options::valueForOption(const string& key, const string& defValue) const
1954 OptionValueVec::const_iterator it = p->findValue(key);
1955 if (it == p->values.end()) {
1962 string_list Options::valuesForOption(const std::string& key) const
1965 OptionValueVec::const_iterator it = p->values.begin();
1966 for (; it != p->values.end(); ++it) {
1968 continue; // ignore marker values
1971 if (it->desc->option == key) {
1972 result.push_back(it->value);
1979 void Options::processOptions()
1981 // now FG_ROOT is setup, process various command line options that bail us
1982 // out quickly, but rely on aircraft / root settings
1988 // processing order is complicated. We must process groups LIFO, but the
1989 // values *within* each group in FIFO order, to retain consistency with
1990 // older versions of FG, and existing user configs.
1991 // in practice this means system.fgfsrc must be *processed* before
1992 // .fgfsrc, which must be processed before the command line args, and so on.
1993 OptionValueVec::const_iterator groupEnd = p->values.end();
1995 while (groupEnd != p->values.begin()) {
1996 OptionValueVec::const_iterator groupBegin = p->rfindGroup(groupEnd);
1997 // run over the group in FIFO order
1998 OptionValueVec::const_iterator it;
1999 for (it = groupBegin; it != groupEnd; ++it) {
2000 int result = p->processOption(it->desc, it->value);
2001 if (result == FG_OPTIONS_ERROR) {
2007 groupEnd = groupBegin;
2010 BOOST_FOREACH(const SGPath& file, p->propertyFiles) {
2011 if (!file.exists()) {
2012 SG_LOG(SG_GENERAL, SG_ALERT, "config file not found:" << file.str());
2016 SG_LOG(SG_GENERAL, SG_INFO,
2017 "Reading command-line property file " << file.str());
2018 readProperties(file.str(), globals->get_props());
2021 // now options are process, do supplemental fixup
2022 const char *envp = ::getenv( "FG_SCENERY" );
2024 globals->append_fg_scenery(envp);
2027 // terrasync directory fixup
2028 if (fgGetBool("/sim/terrasync/enabled")) {
2029 string terrasyncDir = fgGetString("/sim/terrasync/scenery-dir");
2030 if (terrasyncDir.empty()) {
2031 SGPath p(fgGetString("/sim/fg-home"));
2032 p.append("TerraSync");
2038 terrasyncDir = p.str();
2039 SG_LOG(SG_GENERAL, SG_INFO,
2040 "Using default TerraSync dir: " << terrasyncDir);
2041 fgSetString("/sim/terrasync/scenery-dir", terrasyncDir);
2044 const string_list& scenery_paths(globals->get_fg_scenery());
2045 if (std::find(scenery_paths.begin(), scenery_paths.end(), terrasyncDir) == scenery_paths.end()) {
2046 // terrasync dir is not in the scenery paths, add it
2047 globals->append_fg_scenery(terrasyncDir);
2051 if (globals->get_fg_scenery().empty()) {
2052 // no scenery paths set *at all*, use the data in FG_ROOT
2053 SGPath root(globals->get_fg_root());
2054 root.append("Scenery");
2055 globals->append_fg_scenery(root.str());
2059 void Options::showUsage() const
2061 fgOptLogLevel( "alert" );
2063 SGPropertyNode *locale = globals->get_locale();
2064 SGPropertyNode options_root;
2066 SG_LOG( SG_GENERAL, SG_ALERT, "" ); // To popup the console on Windows
2070 fgLoadProps("options.xml", &options_root);
2071 } catch (const sg_exception &) {
2072 cout << "Unable to read the help file." << endl;
2073 cout << "Make sure the file options.xml is located in the FlightGear base directory," << endl;
2074 cout << "and the location of the base directory is specified by setting $FG_ROOT or" << endl;
2075 cout << "by adding --fg-root=path as a program argument." << endl;
2080 SGPropertyNode *options = options_root.getNode("options");
2082 SG_LOG( SG_GENERAL, SG_ALERT,
2083 "Error reading options.xml: <options> directive not found." );
2087 SGPropertyNode *usage = locale->getNode(options->getStringValue("usage"));
2089 cout << "Usage: " << usage->getStringValue() << endl;
2092 vector<SGPropertyNode_ptr>section = options->getChildren("section");
2093 for (unsigned int j = 0; j < section.size(); j++) {
2096 vector<SGPropertyNode_ptr>option = section[j]->getChildren("option");
2097 for (unsigned int k = 0; k < option.size(); k++) {
2099 SGPropertyNode *name = option[k]->getNode("name");
2100 SGPropertyNode *short_name = option[k]->getNode("short");
2101 SGPropertyNode *key = option[k]->getNode("key");
2102 SGPropertyNode *arg = option[k]->getNode("arg");
2103 bool brief = option[k]->getNode("brief") != 0;
2105 if ((brief || p->verbose) && name) {
2106 string tmp = name->getStringValue();
2110 tmp.append(key->getStringValue());
2114 tmp.append(arg->getStringValue());
2118 tmp.append(short_name->getStringValue());
2121 if (tmp.size() <= 25) {
2124 msg.append( 27-tmp.size(), ' ');
2128 msg.append(32, ' ');
2130 // There may be more than one <description> tag assosiated
2133 vector<SGPropertyNode_ptr> desc;
2134 desc = option[k]->getChildren("description");
2135 if (desc.size() > 0) {
2136 for ( unsigned int l = 0; l < desc.size(); l++) {
2138 // There may be more than one translation line.
2140 string t = desc[l]->getStringValue();
2141 SGPropertyNode *n = locale->getNode("strings");
2142 vector<SGPropertyNode_ptr>trans_desc =
2143 n->getChildren(t.substr(8).c_str());
2145 for ( unsigned int m = 0; m < trans_desc.size(); m++ ) {
2146 string t_str = trans_desc[m]->getStringValue();
2148 if ((m > 0) || ((l > 0) && m == 0)) {
2149 msg.append( 32, ' ');
2152 // If the string is too large to fit on the screen,
2153 // then split it up in several pieces.
2155 while ( t_str.size() > 47 ) {
2157 string::size_type m = t_str.rfind(' ', 47);
2158 msg += t_str.substr(0, m) + '\n';
2159 msg.append( 32, ' ');
2161 t_str.erase(t_str.begin(), t_str.begin() + m + 1);
2163 msg += t_str + '\n';
2170 SGPropertyNode *name;
2171 name = locale->getNode(section[j]->getStringValue("name"));
2173 if (!msg.empty() && name) {
2174 cout << endl << name->getStringValue() << ":" << endl;
2180 if ( !p->verbose ) {
2182 cout << "For a complete list of options use --help --verbose" << endl;
2185 std::cout << "Hit a key to continue..." << std::endl;
2190 #if defined(__CYGWIN__)
2191 string Options::platformDefaultRoot() const
2196 #elif defined(_WIN32)
2197 string Options::platformDefaultRoot() const
2201 #elif defined(__APPLE__)
2202 string Options::platformDefaultRoot() const
2205 The following code looks for the base package inside the application
2206 bundle, in the standard Contents/Resources location.
2208 CFURLRef resourcesUrl = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
2210 // look for a 'data' subdir
2211 CFURLRef dataDir = CFURLCreateCopyAppendingPathComponent(NULL, resourcesUrl, CFSTR("data"), true);
2213 // now convert down to a path, and the a c-string
2214 CFStringRef path = CFURLCopyFileSystemPath(dataDir, kCFURLPOSIXPathStyle);
2215 string root = CFStringGetCStringPtr(path, CFStringGetSystemEncoding());
2217 CFRelease(resourcesUrl);
2224 string Options::platformDefaultRoot() const
2230 void Options::setupRoot()
2233 if (isOptionSet("fg-root")) {
2234 root = valueForOption("fg-root"); // easy!
2236 // Next check if fg-root is set as an env variable
2237 char *envp = ::getenv( "FG_ROOT" );
2238 if ( envp != NULL ) {
2241 root = platformDefaultRoot();
2245 SG_LOG(SG_INPUT, SG_INFO, "fg_root = " << root );
2246 globals->set_fg_root(root);
2249 static char required_version[] = "2.7.0";
2250 string base_version = fgBasePackageVersion();
2251 if ( !(base_version == required_version) ) {
2252 // tell the operator how to use this application
2254 SG_LOG( SG_GENERAL, SG_ALERT, "" ); // To popup the console on windows
2255 cerr << endl << "Base package check failed:" << endl \
2256 << " Version " << base_version << " found at: " \
2257 << globals->get_fg_root() << endl \
2258 << " Version " << required_version << " is required." << endl \
2259 << "Please upgrade/downgrade base package and set the path to your fgdata" << endl \
2260 << "with --fg-root=path_to_your_fgdata" << endl;
2262 cerr << "Hit a key to continue..." << endl;
2269 } // of namespace flightgear