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., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #include <simgear/compiler.h>
29 #include <simgear/structure/exception.hxx>
30 #include <simgear/debug/logstream.hxx>
32 #include <math.h> // rint()
34 #include <stdlib.h> // atof(), atoi()
35 #include <string.h> // strcmp()
42 #include <simgear/math/sg_random.h>
43 #include <simgear/misc/sgstream.hxx>
44 #include <simgear/misc/sg_path.hxx>
46 // #include <Include/general.hxx>
47 // #include <Airports/simple.hxx>
48 // #include <Cockpit/cockpit.hxx>
49 // #include <FDM/flight.hxx>
51 #include <Autopilot/route_mgr.hxx>
54 #include "globals.hxx"
55 #include "fg_init.hxx"
56 #include "fg_props.hxx"
57 #include "options.hxx"
59 #include "viewmgr.hxx"
64 SG_USING_NAMESPACE(std);
67 #define NEW_DEFAULT_MODEL_HZ 120
74 FG_OPTIONS_VERBOSE_HELP = 3,
75 FG_OPTIONS_SHOW_AIRCRAFT = 4
79 atof( const string& str )
83 // -dw- if ::atof is called, then we get an infinite loop
84 return std::atof( str.c_str() );
86 return ::atof( str.c_str() );
91 atoi( const string& str )
94 // -dw- if ::atoi is called, then we get an infinite loop
95 return std::atoi( str.c_str() );
97 return ::atoi( str.c_str() );
103 * Set a few fail-safe default property values.
105 * These should all be set in $FG_ROOT/preferences.xml, but just
106 * in case, we provide some initial sane values here. This method
107 * should be invoked *before* reading any init files.
112 // set a possibly independent location for scenery data
113 char *envp = ::getenv( "FG_SCENERY" );
115 if ( envp != NULL ) {
116 // fg_root could be anywhere, so default to environmental
117 // variable $FG_ROOT if it is set.
118 globals->set_fg_scenery(envp);
120 // Otherwise, default to Scenery being in $FG_ROOT/Scenery
121 globals->set_fg_scenery("");
123 // Position (deliberately out of range)
124 fgSetDouble("/position/longitude-deg", 9999.0);
125 fgSetDouble("/position/latitude-deg", 9999.0);
126 fgSetDouble("/position/altitude-ft", -9999.0);
129 fgSetDouble("/orientation/heading-deg", 270);
130 fgSetDouble("/orientation/roll-deg", 0);
131 fgSetDouble("/orientation/pitch-deg", 0.424);
134 fgSetDouble("/velocities/uBody-fps", 0.0);
135 fgSetDouble("/velocities/vBody-fps", 0.0);
136 fgSetDouble("/velocities/wBody-fps", 0.0);
137 fgSetDouble("/velocities/speed-north-fps", 0.0);
138 fgSetDouble("/velocities/speed-east-fps", 0.0);
139 fgSetDouble("/velocities/speed-down-fps", 0.0);
140 fgSetDouble("/velocities/airspeed-kt", 0.0);
141 fgSetDouble("/velocities/mach", 0.0);
144 fgSetDouble("/sim/presets/longitude-deg", 9999.0);
145 fgSetDouble("/sim/presets/latitude-deg", 9999.0);
146 fgSetDouble("/sim/presets/altitude-ft", -9999.0);
148 fgSetDouble("/sim/presets/heading-deg", 270);
149 fgSetDouble("/sim/presets/roll-deg", 0);
150 fgSetDouble("/sim/presets/pitch-deg", 0.424);
152 fgSetString("/sim/presets/speed-set", "knots");
153 fgSetDouble("/sim/presets/airspeed-kt", 0.0);
154 fgSetDouble("/sim/presets/mach", 0.0);
155 fgSetDouble("/sim/presets/uBody-fps", 0.0);
156 fgSetDouble("/sim/presets/vBody-fps", 0.0);
157 fgSetDouble("/sim/presets/wBody-fps", 0.0);
158 fgSetDouble("/sim/presets/speed-north-fps", 0.0);
159 fgSetDouble("/sim/presets/speed-east-fps", 0.0);
160 fgSetDouble("/sim/presets/speed-down-fps", 0.0);
162 fgSetBool("/sim/presets/onground", true);
163 fgSetBool("/sim/presets/trim", false);
166 fgSetBool("/sim/startup/game-mode", false);
167 fgSetBool("/sim/startup/splash-screen", true);
168 fgSetBool("/sim/startup/intro-music", true);
169 // we want mouse-pointer to have an undefined value if nothing is
170 // specified so we can do the right thing for voodoo-1/2 cards.
171 // fgSetString("/sim/startup/mouse-pointer", "disabled");
172 fgSetString("/sim/control-mode", "joystick");
173 fgSetBool("/sim/auto-coordination", false);
175 fgSetString("/sim/startup/browser-app", "netscape");
177 fgSetString("/sim/startup/browser-app", "webrun.bat");
179 fgSetString("/sim/logging/priority", "alert");
182 fgSetBool("/sim/hud/antialiased", false);
183 fgSetBool("/sim/hud/enable3d", true);
184 fgSetBool("/sim/hud/visibility", false);
185 fgSetBool("/sim/panel/visibility", true);
186 fgSetBool("/sim/sound/pause", false);
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 fgSetBool("/sim/rendering/wireframe", false);
202 fgSetBool("/sim/rendering/horizon-effect", false);
203 fgSetBool("/sim/rendering/enhanced-lighting", false);
204 fgSetBool("/sim/rendering/distance-attenuation", false);
205 fgSetBool("/sim/rendering/specular-highlight", true);
206 fgSetInt("/sim/startup/xsize", 800);
207 fgSetInt("/sim/startup/ysize", 600);
208 fgSetInt("/sim/rendering/bits-per-pixel", 16);
209 fgSetString("/sim/view-mode", "pilot");
210 fgSetDouble("/sim/current-view/heading-offset-deg", 0);
213 fgSetString("/sim/startup/units", "feet");
214 fgSetString("/sim/hud/frame-stat-type", "tris");
217 fgSetInt("/sim/startup/time-offset", 0);
218 fgSetString("/sim/startup/time-offset-type", "system-offset");
219 fgSetLong("/sim/time/cur-time-override", 0);
222 fgSetBool("/sim/freeze/master", false);
223 fgSetBool("/sim/freeze/position", false);
224 fgSetBool("/sim/freeze/clock", false);
225 fgSetBool("/sim/freeze/fuel", false);
228 fgSetString("/sim/multiplay/callsign", "callsign");
229 fgSetString("/sim/multiplay/rxhost", "0");
230 fgSetString("/sim/multiplay/txhost", "0");
231 fgSetInt("/sim/multiplay/rxport", 0);
232 fgSetInt("/sim/multiplay/txport", 0);
238 parse_wind (const string &wind, double * min_hdg, double * max_hdg,
239 double * speed, double * gust)
241 string::size_type pos = wind.find('@');
242 if (pos == string::npos)
244 string dir = wind.substr(0, pos);
245 string spd = wind.substr(pos+1);
247 if (pos == string::npos) {
248 *min_hdg = *max_hdg = atof(dir.c_str());
250 *min_hdg = atof(dir.substr(0,pos).c_str());
251 *max_hdg = atof(dir.substr(pos+1).c_str());
254 if (pos == string::npos) {
255 *speed = *gust = atof(spd.c_str());
257 *speed = atof(spd.substr(0,pos).c_str());
258 *gust = atof(spd.substr(pos+1).c_str());
263 // parse a time string ([+/-]%f[:%f[:%f]]) into hours
265 parse_time(const string& time_in) {
266 char *time_str, num[256];
267 double hours, minutes, seconds;
272 time_str = (char *)time_in.c_str();
274 // printf("parse_time(): %s\n", time_str);
277 if ( strlen(time_str) ) {
278 if ( time_str[0] == '+' ) {
281 } else if ( time_str[0] == '-' ) {
286 // printf("sign = %d\n", sign);
289 if ( strlen(time_str) ) {
291 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
292 num[i] = time_str[0];
296 if ( time_str[0] == ':' ) {
301 // printf("hours = %.2lf\n", hours);
307 if ( strlen(time_str) ) {
309 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
310 num[i] = time_str[0];
314 if ( time_str[0] == ':' ) {
319 // printf("minutes = %.2lf\n", minutes);
321 result += minutes / 60.0;
325 if ( strlen(time_str) ) {
327 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
328 num[i] = time_str[0];
334 // printf("seconds = %.2lf\n", seconds);
336 result += seconds / 3600.0;
339 SG_LOG( SG_GENERAL, SG_INFO, " parse_time() = " << sign * result );
341 return(sign * result);
345 // parse a date string (yyyy:mm:dd:hh:mm:ss) into a time_t (seconds)
347 parse_date( const string& date)
350 char * date_str, num[256];
352 // initialize to zero
359 gmt.tm_isdst = 0; // ignore daylight savings time for the moment
360 date_str = (char *)date.c_str();
362 if ( strlen(date_str) ) {
364 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
365 num[i] = date_str[0];
369 if ( date_str[0] == ':' ) {
373 gmt.tm_year = atoi(num) - 1900;
376 if ( strlen(date_str) ) {
378 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
379 num[i] = date_str[0];
383 if ( date_str[0] == ':' ) {
387 gmt.tm_mon = atoi(num) -1;
390 if ( strlen(date_str) ) {
392 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
393 num[i] = date_str[0];
397 if ( date_str[0] == ':' ) {
401 gmt.tm_mday = atoi(num);
404 if ( strlen(date_str) ) {
406 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
407 num[i] = date_str[0];
411 if ( date_str[0] == ':' ) {
415 gmt.tm_hour = atoi(num);
418 if ( strlen(date_str) ) {
420 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
421 num[i] = date_str[0];
425 if ( date_str[0] == ':' ) {
429 gmt.tm_min = atoi(num);
432 if ( strlen(date_str) ) {
434 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
435 num[i] = date_str[0];
439 if ( date_str[0] == ':' ) {
443 gmt.tm_sec = atoi(num);
445 time_t theTime = sgTimeGetGMT( gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
446 gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
447 //printf ("Date is %s\n", ctime(&theTime));
448 //printf ("in seconds that is %d\n", theTime);
454 // parse angle in the form of [+/-]ddd:mm:ss into degrees
456 parse_degree( const string& degree_str) {
457 double result = parse_time( degree_str );
459 // printf("Degree = %.4f\n", result);
465 // parse time offset string into seconds
467 parse_time_offset( const string& time_str) {
470 // printf("time offset = %s\n", time_str);
473 result = (int)rint(parse_time(time_str) * 3600.0);
475 result = (int)(parse_time(time_str) * 3600.0);
478 // printf("parse_time_offset(): %d\n", result);
484 // Parse --fov=x.xx type option
486 parse_fov( const string& arg ) {
487 double fov = atof(arg);
489 if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
490 if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
492 fgSetDouble("/sim/current-view/field-of-view", fov);
494 // printf("parse_fov(): result = %.4f\n", fov);
500 // Parse I/O channel option
502 // Format is "--protocol=medium,direction,hz,medium_options,..."
504 // protocol = { native, nmea, garmin, fgfs, rul, pve, etc. }
505 // medium = { serial, socket, file, etc. }
506 // direction = { in, out, bi }
507 // hz = number of times to process channel per second (floating
508 // point values are ok.
510 // Serial example "--nmea=serial,dir,hz,device,baud" where
512 // device = OS device name of serial line to be open()'ed
513 // baud = {300, 1200, 2400, ..., 230400}
515 // Socket exacmple "--native=socket,dir,hz,machine,port,style" where
517 // machine = machine name or ip address if client (leave empty if server)
518 // port = port, leave empty to let system choose
519 // style = tcp or udp
521 // File example "--garmin=file,dir,hz,filename" where
523 // filename = file system file name
526 add_channel( const string& type, const string& channel_str ) {
527 SG_LOG(SG_GENERAL, SG_INFO, "Channel string = " << channel_str );
529 globals->get_channel_options_list()->push_back( type + "," + channel_str );
531 // cout << "here" << endl;
536 // The parse wp and parse flight-plan options don't work anymore, because
537 // the route manager and the airport subsystems have not yet been initialized
540 // Parse --wp=ID[@alt]
542 parse_wp( const string& arg ) {
543 string_list *waypoints = globals->get_initial_waypoints();
545 waypoints = new string_list;
547 waypoints->push_back(arg);
548 globals->set_initial_waypoints(waypoints);
552 // Parse --flight-plan=[file]
554 parse_flightplan(const string& arg)
556 string_list *waypoints = globals->get_initial_waypoints();
558 waypoints = new string_list;
559 sg_gzifstream in(arg.c_str());
560 if ( !in.is_open() ) {
566 #if defined( macintosh )
567 getline( in, line, '\r' );
569 getline( in, line, '\n' );
572 // catch extraneous (DOS) line ending character
573 if ( line[line.length() - 1] < 32 ) {
574 line = line.substr( 0, line.length()-1 );
580 waypoints->push_back(line);
582 globals->set_initial_waypoints(waypoints);
587 fgOptLanguage( const char *arg )
589 globals->set_locale( fgInitLocale( arg ) );
590 return FG_OPTIONS_OK;
596 fgSetString("/sim/presets/airport-id", "");
597 fgSetString("/sim/presets/vor-id", "");
598 fgSetString("/sim/presets/ndb-id", "");
599 fgSetString("/sim/presets/carrier", "");
600 fgSetString("/sim/presets/parkpos", "");
601 fgSetString("/sim/presets/fix", "");
605 fgOptVOR( const char * arg )
608 fgSetString("/sim/presets/vor-id", arg);
609 return FG_OPTIONS_OK;
613 fgOptNDB( const char * arg )
616 fgSetString("/sim/presets/ndb-id", arg);
617 return FG_OPTIONS_OK;
621 fgOptCarrier( const char * arg )
624 fgSetString("/sim/presets/carrier", arg);
625 return FG_OPTIONS_OK;
629 fgOptParkpos( const char * arg )
631 fgSetString("/sim/presets/parkpos", arg);
632 return FG_OPTIONS_OK;
636 fgOptFIX( const char * arg )
639 fgSetString("/sim/presets/fix", arg);
640 return FG_OPTIONS_OK;
644 fgOptLon( const char *arg )
647 fgSetDouble("/sim/presets/longitude-deg", parse_degree( arg ));
648 fgSetDouble("/position/longitude-deg", parse_degree( arg ));
649 return FG_OPTIONS_OK;
653 fgOptLat( const char *arg )
656 fgSetDouble("/sim/presets/latitude-deg", parse_degree( arg ));
657 fgSetDouble("/position/latitude-deg", parse_degree( arg ));
658 return FG_OPTIONS_OK;
662 fgOptAltitude( const char *arg )
664 fgSetBool("/sim/presets/onground", false);
665 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
666 fgSetDouble("/sim/presets/altitude-ft", atof( arg ));
668 fgSetDouble("/sim/presets/altitude-ft",
669 atof( arg ) * SG_METER_TO_FEET);
670 return FG_OPTIONS_OK;
674 fgOptUBody( const char *arg )
676 fgSetString("/sim/presets/speed-set", "UVW");
677 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
678 fgSetDouble("/sim/presets/uBody-fps", atof( arg ));
680 fgSetDouble("/sim/presets/uBody-fps",
681 atof( arg ) * SG_METER_TO_FEET);
682 return FG_OPTIONS_OK;
686 fgOptVBody( const char *arg )
688 fgSetString("/sim/presets/speed-set", "UVW");
689 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
690 fgSetDouble("/sim/presets/vBody-fps", atof( arg ));
692 fgSetDouble("/sim/presets/vBody-fps",
693 atof( arg ) * SG_METER_TO_FEET);
694 return FG_OPTIONS_OK;
698 fgOptWBody( const char *arg )
700 fgSetString("/sim/presets/speed-set", "UVW");
701 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
702 fgSetDouble("/sim/presets/wBody-fps", atof(arg));
704 fgSetDouble("/sim/presets/wBody-fps",
705 atof(arg) * SG_METER_TO_FEET);
706 return FG_OPTIONS_OK;
710 fgOptVNorth( const char *arg )
712 fgSetString("/sim/presets/speed-set", "NED");
713 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
714 fgSetDouble("/sim/presets/speed-north-fps", atof( arg ));
716 fgSetDouble("/sim/presets/speed-north-fps",
717 atof( arg ) * SG_METER_TO_FEET);
718 return FG_OPTIONS_OK;
722 fgOptVEast( const char *arg )
724 fgSetString("/sim/presets/speed-set", "NED");
725 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
726 fgSetDouble("/sim/presets/speed-east-fps", atof(arg));
728 fgSetDouble("/sim/presets/speed-east-fps",
729 atof(arg) * SG_METER_TO_FEET);
730 return FG_OPTIONS_OK;
734 fgOptVDown( const char *arg )
736 fgSetString("/sim/presets/speed-set", "NED");
737 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
738 fgSetDouble("/sim/presets/speed-down-fps", atof(arg));
740 fgSetDouble("/sim/presets/speed-down-fps",
741 atof(arg) * SG_METER_TO_FEET);
742 return FG_OPTIONS_OK;
746 fgOptVc( const char *arg )
748 // fgSetString("/sim/presets/speed-set", "knots");
749 // fgSetDouble("/velocities/airspeed-kt", atof(arg.substr(5)));
750 fgSetString("/sim/presets/speed-set", "knots");
751 fgSetDouble("/sim/presets/airspeed-kt", atof(arg));
752 return FG_OPTIONS_OK;
756 fgOptMach( const char *arg )
758 fgSetString("/sim/presets/speed-set", "mach");
759 fgSetDouble("/sim/presets/mach", atof(arg));
760 return FG_OPTIONS_OK;
764 fgOptRoc( const char *arg )
766 fgSetDouble("/velocities/vertical-speed-fps", atof(arg)/60);
767 return FG_OPTIONS_OK;
771 fgOptFgRoot( const char *arg )
773 globals->set_fg_root(arg);
774 return FG_OPTIONS_OK;
778 fgOptFgScenery( const char *arg )
780 globals->set_fg_scenery(arg);
781 return FG_OPTIONS_OK;
785 fgOptFov( const char *arg )
788 return FG_OPTIONS_OK;
792 fgOptGeometry( const char *arg )
794 bool geometry_ok = true;
795 int xsize = 0, ysize = 0;
796 string geometry = arg;
797 string::size_type i = geometry.find('x');
799 if (i != string::npos) {
800 xsize = atoi(geometry.substr(0, i));
801 ysize = atoi(geometry.substr(i+1));
806 if ( xsize <= 0 || ysize <= 0 ) {
812 if ( !geometry_ok ) {
813 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown geometry: " << geometry );
814 SG_LOG( SG_GENERAL, SG_ALERT,
815 "Setting geometry to " << xsize << 'x' << ysize << '\n');
817 SG_LOG( SG_GENERAL, SG_INFO,
818 "Setting geometry to " << xsize << 'x' << ysize << '\n');
819 fgSetInt("/sim/startup/xsize", xsize);
820 fgSetInt("/sim/startup/ysize", ysize);
822 return FG_OPTIONS_OK;
826 fgOptBpp( const char *arg )
828 string bits_per_pix = arg;
829 if ( bits_per_pix == "16" ) {
830 fgSetInt("/sim/rendering/bits-per-pixel", 16);
831 } else if ( bits_per_pix == "24" ) {
832 fgSetInt("/sim/rendering/bits-per-pixel", 24);
833 } else if ( bits_per_pix == "32" ) {
834 fgSetInt("/sim/rendering/bits-per-pixel", 32);
836 SG_LOG(SG_GENERAL, SG_ALERT, "Unsupported bpp " << bits_per_pix);
838 return FG_OPTIONS_OK;
842 fgOptTimeOffset( const char *arg )
844 fgSetInt("/sim/startup/time-offset",
845 parse_time_offset( arg ));
846 fgSetString("/sim/startup/time-offset-type", "system-offset");
847 return FG_OPTIONS_OK;
851 fgOptStartDateSys( const char *arg )
853 fgSetInt("/sim/startup/time-offset", parse_date( arg ) );
854 fgSetString("/sim/startup/time-offset-type", "system");
855 return FG_OPTIONS_OK;
859 fgOptStartDateLat( const char *arg )
861 fgSetInt("/sim/startup/time-offset", parse_date( arg ) );
862 fgSetString("/sim/startup/time-offset-type", "latitude");
863 return FG_OPTIONS_OK;
867 fgOptStartDateGmt( const char *arg )
869 fgSetInt("/sim/startup/time-offset", parse_date( arg ) );
870 fgSetString("/sim/startup/time-offset-type", "gmt");
871 return FG_OPTIONS_OK;
875 fgSetupProxy( const char *arg )
877 string options = arg;
878 string host, port, auth;
881 host = port = auth = "";
882 if ((pos = options.find("@")) != string::npos)
883 auth = options.substr(0, pos++);
887 host = options.substr(pos, options.size());
888 if ((pos = host.find(":")) != string::npos) {
889 port = host.substr(++pos, host.size());
890 host.erase(--pos, host.size());
893 fgSetString("/sim/presets/proxy/host", host.c_str());
894 fgSetString("/sim/presets/proxy/port", port.c_str());
895 fgSetString("/sim/presets/proxy/authentication", auth.c_str());
897 return FG_OPTIONS_OK;
901 fgOptTraceRead( const char *arg )
904 SG_LOG(SG_GENERAL, SG_INFO, "Tracing reads for property " << name);
905 fgGetNode(name.c_str(), true)
906 ->setAttribute(SGPropertyNode::TRACE_READ, true);
907 return FG_OPTIONS_OK;
911 fgOptLogLevel( const char *arg )
913 fgSetString("/sim/logging/classes", "all");
914 fgSetString("/sim/logging/priority", arg);
916 string priority = arg;
917 logbuf::set_log_classes(SG_ALL);
918 if (priority == "bulk") {
919 logbuf::set_log_priority(SG_BULK);
920 } else if (priority == "debug") {
921 logbuf::set_log_priority(SG_DEBUG);
922 } else if (priority == "info") {
923 logbuf::set_log_priority(SG_INFO);
924 } else if (priority == "warn") {
925 logbuf::set_log_priority(SG_WARN);
926 } else if (priority == "alert") {
927 logbuf::set_log_priority(SG_ALERT);
929 SG_LOG(SG_GENERAL, SG_WARN, "Unknown logging priority " << priority);
931 SG_LOG(SG_GENERAL, SG_DEBUG, "Logging priority is " << priority);
933 return FG_OPTIONS_OK;
938 fgOptTraceWrite( const char *arg )
941 SG_LOG(SG_GENERAL, SG_INFO, "Tracing writes for property " << name);
942 fgGetNode(name.c_str(), true)
943 ->setAttribute(SGPropertyNode::TRACE_WRITE, true);
944 return FG_OPTIONS_OK;
948 fgOptViewOffset( const char *arg )
950 // $$$ begin - added VS Renganathan, 14 Oct 2K
951 // for multi-window outside window imagery
952 string woffset = arg;
953 double default_view_offset = 0.0;
954 if ( woffset == "LEFT" ) {
955 default_view_offset = SGD_PI * 0.25;
956 } else if ( woffset == "RIGHT" ) {
957 default_view_offset = SGD_PI * 1.75;
958 } else if ( woffset == "CENTER" ) {
959 default_view_offset = 0.00;
961 default_view_offset = atof( woffset.c_str() ) * SGD_DEGREES_TO_RADIANS;
963 /* apparently not used (CLO, 11 Jun 2002)
964 FGViewer *pilot_view =
965 (FGViewer *)globals->get_viewmgr()->get_view( 0 ); */
966 // this will work without calls to the viewer...
967 fgSetDouble( "/sim/current-view/heading-offset-deg",
968 default_view_offset * SGD_RADIANS_TO_DEGREES );
969 // $$$ end - added VS Renganathan, 14 Oct 2K
970 return FG_OPTIONS_OK;
974 fgOptVisibilityMeters( const char *arg )
976 double visibility = atof( arg );
977 fgDefaultWeatherValue("visibility-m", visibility);
978 return FG_OPTIONS_OK;
982 fgOptVisibilityMiles( const char *arg )
984 double visibility = atof( arg ) * 5280.0 * SG_FEET_TO_METER;
985 fgDefaultWeatherValue("visibility-m", visibility);
986 return FG_OPTIONS_OK;
990 fgOptRandomWind( const char *arg )
992 double min_hdg = sg_random() * 360.0;
993 double max_hdg = min_hdg + (20 - sqrt(sg_random() * 400));
994 double speed = sg_random() * sg_random() * 40;
995 double gust = speed + (10 - sqrt(sg_random() * 100));
996 fgSetupWind(min_hdg, max_hdg, speed, gust);
997 return FG_OPTIONS_OK;
1001 fgOptWind( const char *arg )
1003 double min_hdg, max_hdg, speed, gust;
1004 if (!parse_wind( arg, &min_hdg, &max_hdg, &speed, &gust)) {
1005 SG_LOG( SG_GENERAL, SG_ALERT, "bad wind value " << arg );
1006 return FG_OPTIONS_ERROR;
1008 fgSetupWind(min_hdg, max_hdg, speed, gust);
1009 return FG_OPTIONS_OK;
1013 fgOptTurbulence( const char *arg )
1015 fgDefaultWeatherValue("turbulence/magnitude-norm", atof(arg));
1016 return FG_OPTIONS_OK;
1020 fgOptCeiling( const char *arg )
1022 double elevation, thickness;
1024 string::size_type pos = spec.find(':');
1025 if (pos == string::npos) {
1026 elevation = atof(spec.c_str());
1029 elevation = atof(spec.substr(0, pos).c_str());
1030 thickness = atof(spec.substr(pos + 1).c_str());
1032 fgSetDouble("/environment/clouds/layer[0]/elevation-ft", elevation);
1033 fgSetDouble("/environment/clouds/layer[0]/thickness-ft", thickness);
1034 fgSetString("/environment/clouds/layer[0]/coverage", "overcast");
1035 return FG_OPTIONS_OK;
1039 fgOptWp( const char *arg )
1042 return FG_OPTIONS_OK;
1046 fgOptFlightPlan( const char *arg )
1048 parse_flightplan ( arg );
1049 return FG_OPTIONS_OK;
1053 fgOptConfig( const char *arg )
1057 readProperties(file, globals->get_props());
1058 } catch (const sg_exception &e) {
1059 string message = "Error loading config file: ";
1060 message += e.getFormattedMessage();
1061 SG_LOG(SG_INPUT, SG_ALERT, message);
1064 return FG_OPTIONS_OK;
1068 parse_colon (const string &s, double * val1, double * val2)
1070 string::size_type pos = s.find(':');
1071 if (pos == string::npos) {
1075 *val1 = atof(s.substr(0, pos).c_str());
1076 *val2 = atof(s.substr(pos+1).c_str());
1083 fgOptFailure( const char * arg )
1087 fgSetBool("/systems/pitot/serviceable", false);
1088 } else if (a == "static") {
1089 fgSetBool("/systems/static/serviceable", false);
1090 } else if (a == "vacuum") {
1091 fgSetBool("/systems/vacuum/serviceable", false);
1092 } else if (a == "electrical") {
1093 fgSetBool("/systems/electrical/serviceable", false);
1095 SG_LOG(SG_INPUT, SG_ALERT, "Unknown failure mode: " << a);
1096 return FG_OPTIONS_ERROR;
1099 return FG_OPTIONS_OK;
1104 fgOptNAV1( const char * arg )
1106 double radial, freq;
1107 if (parse_colon(arg, &radial, &freq))
1108 fgSetDouble("/instrumentation/nav[0]/radials/selected-deg", radial);
1109 fgSetDouble("/instrumentation/nav[0]/frequencies/selected-mhz", freq);
1110 return FG_OPTIONS_OK;
1114 fgOptNAV2( const char * arg )
1116 double radial, freq;
1117 if (parse_colon(arg, &radial, &freq))
1118 fgSetDouble("/instrumentation/nav[1]/radials/selected-deg", radial);
1119 fgSetDouble("/instrumentation/nav[1]/frequencies/selected-mhz", freq);
1120 return FG_OPTIONS_OK;
1124 fgOptADF( const char * arg )
1127 if (parse_colon(arg, &rot, &freq))
1128 fgSetDouble("/instrumentation/adf/rotation-deg", rot);
1129 fgSetDouble("/instrumentation/adf/frequencies/selected-khz", freq);
1130 return FG_OPTIONS_OK;
1134 fgOptDME( const char *arg )
1137 if (opt == "nav1") {
1138 fgSetInt("/instrumentation/dme/switch-position", 1);
1139 fgSetString("/instrumentation/dme/frequencies/source",
1140 "/instrumentation/nav[0]/frequencies/selected-mhz");
1141 } else if (opt == "nav2") {
1142 fgSetInt("/instrumentation/dme/switch-position", 3);
1143 fgSetString("/instrumentation/dme/frequencies/source",
1144 "/instrumentation/nav[1]/frequencies/selected-mhz");
1146 fgSetInt("/instrumentation/dme/switch-position", 2);
1147 fgSetString("/instrumentation/dme/frequencies/source",
1148 "/instrumentation/dme/frequencies/selected-mhz");
1149 fgSetString("/instrumentation/dme/frequencies/selected-mhz", arg);
1151 return FG_OPTIONS_OK;
1155 fgOptLivery( const char *arg )
1158 string livery_path = "livery/" + opt;
1159 fgSetString("/sim/model/texture-path", livery_path.c_str() );
1160 return FG_OPTIONS_OK;
1163 static map<string,size_t> fgOptionMap;
1166 option has_param type property b_param s_param func
1169 option : name of the option
1170 has_param : option is --name=value if true or --name if false
1171 type : OPTION_BOOL - property is a boolean
1172 OPTION_STRING - property is a string
1173 OPTION_DOUBLE - property is a double
1174 OPTION_INT - property is an integer
1175 OPTION_CHANNEL - name of option is the name of a channel
1176 OPTION_FUNC - the option trigger a function
1177 b_param : if type==OPTION_BOOL,
1178 value set to the property (has_param is false for boolean)
1179 s_param : if type==OPTION_STRING,
1180 value set to the property if has_param is false
1181 func : function called if type==OPTION_FUNC. if has_param is true,
1182 the value is passed to the function as a string, otherwise,
1185 For OPTION_DOUBLE and OPTION_INT, the parameter value is converted into a
1186 double or an integer and set to the property.
1188 For OPTION_CHANNEL, add_channel is called with the parameter value as the
1192 enum OptionType { OPTION_BOOL, OPTION_STRING, OPTION_DOUBLE, OPTION_INT, OPTION_CHANNEL, OPTION_FUNC };
1196 enum OptionType type;
1200 int (*func)( const char * );
1201 } fgOptionArray[] = {
1203 {"language", true, OPTION_FUNC, "", false, "", fgOptLanguage },
1204 {"disable-game-mode", false, OPTION_BOOL, "/sim/startup/game-mode", false, "", 0 },
1205 {"enable-game-mode", false, OPTION_BOOL, "/sim/startup/game-mode", true, "", 0 },
1206 {"disable-splash-screen", false, OPTION_BOOL, "/sim/startup/splash-screen", false, "", 0 },
1207 {"enable-splash-screen", false, OPTION_BOOL, "/sim/startup/splash-screen", true, "", 0 },
1208 {"disable-intro-music", false, OPTION_BOOL, "/sim/startup/intro-music", false, "", 0 },
1209 {"enable-intro-music", false, OPTION_BOOL, "/sim/startup/intro-music", true, "", 0 },
1210 {"disable-mouse-pointer", false, OPTION_STRING, "/sim/startup/mouse-pointer", false, "disabled", 0 },
1211 {"enable-mouse-pointer", false, OPTION_STRING, "/sim/startup/mouse-pointer", false, "enabled", 0 },
1212 {"disable-random-objects", false, OPTION_BOOL, "/sim/rendering/random-objects", false, "", 0 },
1213 {"enable-random-objects", false, OPTION_BOOL, "/sim/rendering/random-objects", true, "", 0 },
1214 {"disable-real-weather-fetch", false, OPTION_BOOL, "/environment/params/real-world-weather-fetch", false, "", 0 },
1215 {"enable-real-weather-fetch", false, OPTION_BOOL, "/environment/params/real-world-weather-fetch", true, "", 0 },
1216 {"disable-ai-models", false, OPTION_BOOL, "/sim/ai/enabled", false, "", 0 },
1217 {"enable-ai-models", false, OPTION_BOOL, "/sim/ai/enabled", true, "", 0 },
1218 {"disable-freeze", false, OPTION_BOOL, "/sim/freeze/master", false, "", 0 },
1219 {"enable-freeze", false, OPTION_BOOL, "/sim/freeze/master", true, "", 0 },
1220 {"disable-fuel-freeze", false, OPTION_BOOL, "/sim/freeze/fuel", false, "", 0 },
1221 {"enable-fuel-freeze", false, OPTION_BOOL, "/sim/freeze/fuel", true, "", 0 },
1222 {"disable-clock-freeze", false, OPTION_BOOL, "/sim/freeze/clock", false, "", 0 },
1223 {"enable-clock-freeze", false, OPTION_BOOL, "/sim/freeze/clock", true, "", 0 },
1224 {"disable-hud-3d", false, OPTION_BOOL, "/sim/hud/enable3d", false, "", 0 },
1225 {"enable-hud-3d", false, OPTION_BOOL, "/sim/hud/enable3d", true, "", 0 },
1226 {"disable-anti-alias-hud", false, OPTION_BOOL, "/sim/hud/antialiased", false, "", 0 },
1227 {"enable-anti-alias-hud", false, OPTION_BOOL, "/sim/hud/antialiased", true, "", 0 },
1228 {"control", true, OPTION_STRING, "/sim/control-mode", false, "", 0 },
1229 {"disable-auto-coordination", false, OPTION_BOOL, "/sim/auto-coordination", false, "", 0 },
1230 {"enable-auto-coordination", false, OPTION_BOOL, "/sim/auto-coordination", true, "", 0 },
1231 {"browser-app", true, OPTION_STRING, "/sim/startup/browser-app", false, "", 0 },
1232 {"disable-hud", false, OPTION_BOOL, "/sim/hud/visibility", false, "", 0 },
1233 {"enable-hud", false, OPTION_BOOL, "/sim/hud/visibility", true, "", 0 },
1234 {"disable-panel", false, OPTION_BOOL, "/sim/panel/visibility", false, "", 0 },
1235 {"enable-panel", false, OPTION_BOOL, "/sim/panel/visibility", true, "", 0 },
1236 {"disable-sound", false, OPTION_BOOL, "/sim/sound/pause", true, "", 0 },
1237 {"enable-sound", false, OPTION_BOOL, "/sim/sound/pause", false, "", 0 },
1238 {"airport", true, OPTION_STRING, "/sim/presets/airport-id", false, "", 0 },
1239 {"airport-id", true, OPTION_STRING, "/sim/presets/airport-id", false, "", 0 },
1240 {"runway", true, OPTION_STRING, "/sim/presets/runway", false, "", 0 },
1241 {"vor", true, OPTION_FUNC, "", false, "", fgOptVOR },
1242 {"ndb", true, OPTION_FUNC, "", false, "", fgOptNDB },
1243 {"carrier", true, OPTION_FUNC, "", false, "", fgOptCarrier },
1244 {"parkpos", true, OPTION_FUNC, "", false, "", fgOptParkpos },
1245 {"fix", true, OPTION_FUNC, "", false, "", fgOptFIX },
1246 {"offset-distance", true, OPTION_DOUBLE, "/sim/presets/offset-distance", false, "", 0 },
1247 {"offset-azimuth", true, OPTION_DOUBLE, "/sim/presets/offset-azimuth", false, "", 0 },
1248 {"lon", true, OPTION_FUNC, "", false, "", fgOptLon },
1249 {"lat", true, OPTION_FUNC, "", false, "", fgOptLat },
1250 {"altitude", true, OPTION_FUNC, "", false, "", fgOptAltitude },
1251 {"uBody", true, OPTION_FUNC, "", false, "", fgOptUBody },
1252 {"vBody", true, OPTION_FUNC, "", false, "", fgOptVBody },
1253 {"wBody", true, OPTION_FUNC, "", false, "", fgOptWBody },
1254 {"vNorth", true, OPTION_FUNC, "", false, "", fgOptVNorth },
1255 {"vEast", true, OPTION_FUNC, "", false, "", fgOptVEast },
1256 {"vDown", true, OPTION_FUNC, "", false, "", fgOptVDown },
1257 {"vc", true, OPTION_FUNC, "", false, "", fgOptVc },
1258 {"mach", true, OPTION_FUNC, "", false, "", fgOptMach },
1259 {"heading", true, OPTION_DOUBLE, "/sim/presets/heading-deg", false, "", 0 },
1260 {"roll", true, OPTION_DOUBLE, "/sim/presets/roll-deg", false, "", 0 },
1261 {"pitch", true, OPTION_DOUBLE, "/sim/presets/pitch-deg", false, "", 0 },
1262 {"glideslope", true, OPTION_DOUBLE, "/sim/presets/glideslope-deg", false, "", 0 },
1263 {"roc", true, OPTION_FUNC, "", false, "", fgOptRoc },
1264 {"fg-root", true, OPTION_FUNC, "", false, "", fgOptFgRoot },
1265 {"fg-scenery", true, OPTION_FUNC, "", false, "", fgOptFgScenery },
1266 {"fdm", true, OPTION_STRING, "/sim/flight-model", false, "", 0 },
1267 {"aero", true, OPTION_STRING, "/sim/aero", false, "", 0 },
1268 {"aircraft-dir", true, OPTION_STRING, "/sim/aircraft-dir", false, "", 0 },
1269 {"model-hz", true, OPTION_INT, "/sim/model-hz", false, "", 0 },
1270 {"speed", true, OPTION_INT, "/sim/speed-up", false, "", 0 },
1271 {"trim", false, OPTION_BOOL, "/sim/presets/trim", true, "", 0 },
1272 {"notrim", false, OPTION_BOOL, "/sim/presets/trim", false, "", 0 },
1273 {"on-ground", false, OPTION_BOOL, "/sim/presets/onground", true, "", 0 },
1274 {"in-air", false, OPTION_BOOL, "/sim/presets/onground", false, "", 0 },
1275 {"fog-disable", false, OPTION_STRING, "/sim/rendering/fog", false, "disabled", 0 },
1276 {"fog-fastest", false, OPTION_STRING, "/sim/rendering/fog", false, "fastest", 0 },
1277 {"fog-nicest", false, OPTION_STRING, "/sim/rendering/fog", false, "nicest", 0 },
1278 {"disable-horizon-effect", false, OPTION_BOOL, "/sim/rendering/horizon-effect", false, "", 0 },
1279 {"enable-horizon-effect", false, OPTION_BOOL, "/sim/rendering/horizon-effect", true, "", 0 },
1280 {"disable-enhanced-lighting", false, OPTION_BOOL, "/sim/rendering/enhanced-lighting", false, "", 0 },
1281 {"enable-enhanced-lighting", false, OPTION_BOOL, "/sim/rendering/enhanced-lighting", true, "", 0 },
1282 {"disable-distance-attenuation", false, OPTION_BOOL, "/sim/rendering/distance-attenuation", false, "", 0 },
1283 {"enable-distance-attenuation", false, OPTION_BOOL, "/sim/rendering/distance-attenuation", true, "", 0 },
1284 {"disable-specular-highlight", false, OPTION_BOOL, "/sim/rendering/specular-highlight", false, "", 0 },
1285 {"enable-specular-highlight", false, OPTION_BOOL, "/sim/rendering/specular-highlight", true, "", 0 },
1286 {"disable-clouds", false, OPTION_BOOL, "/environment/clouds/status", false, "", 0 },
1287 {"enable-clouds", false, OPTION_BOOL, "/environment/clouds/status", true, "", 0 },
1288 {"disable-clouds3d", false, OPTION_BOOL, "/sim/rendering/clouds3d-enable", false, "", 0 },
1289 {"enable-clouds3d", false, OPTION_BOOL, "/sim/rendering/clouds3d-enable", true, "", 0 },
1290 {"fov", true, OPTION_FUNC, "", false, "", fgOptFov },
1291 {"aspect-ratio-multiplier", true, OPTION_DOUBLE, "/sim/current-view/aspect-ratio-multiplier", false, "", 0 },
1292 {"disable-fullscreen", false, OPTION_BOOL, "/sim/startup/fullscreen", false, "", 0 },
1293 {"enable-fullscreen", false, OPTION_BOOL, "/sim/startup/fullscreen", true, "", 0 },
1294 {"shading-flat", false, OPTION_BOOL, "/sim/rendering/shading", false, "", 0 },
1295 {"shading-smooth", false, OPTION_BOOL, "/sim/rendering/shading", true, "", 0 },
1296 {"disable-skyblend", false, OPTION_BOOL, "/sim/rendering/skyblend", false, "", 0 },
1297 {"enable-skyblend", false, OPTION_BOOL, "/sim/rendering/skyblend", true, "", 0 },
1298 {"disable-textures", false, OPTION_BOOL, "/sim/rendering/textures", false, "", 0 },
1299 {"enable-textures", false, OPTION_BOOL, "/sim/rendering/textures", true, "", 0 },
1300 {"disable-wireframe", false, OPTION_BOOL, "/sim/rendering/wireframe", false, "", 0 },
1301 {"enable-wireframe", false, OPTION_BOOL, "/sim/rendering/wireframe", true, "", 0 },
1302 {"geometry", true, OPTION_FUNC, "", false, "", fgOptGeometry },
1303 {"bpp", true, OPTION_FUNC, "", false, "", fgOptBpp },
1304 {"units-feet", false, OPTION_STRING, "/sim/startup/units", false, "feet", 0 },
1305 {"units-meters", false, OPTION_STRING, "/sim/startup/units", false, "meters", 0 },
1306 {"timeofday", true, OPTION_STRING, "/sim/startup/time-offset-type", false, "noon", 0 },
1307 {"time-offset", true, OPTION_FUNC, "", false, "", fgOptTimeOffset },
1308 {"time-match-real", false, OPTION_STRING, "/sim/startup/time-offset-type", false, "system-offset", 0 },
1309 {"time-match-local", false, OPTION_STRING, "/sim/startup/time-offset-type", false, "latitude-offset", 0 },
1310 {"start-date-sys", true, OPTION_FUNC, "", false, "", fgOptStartDateSys },
1311 {"start-date-lat", true, OPTION_FUNC, "", false, "", fgOptStartDateLat },
1312 {"start-date-gmt", true, OPTION_FUNC, "", false, "", fgOptStartDateGmt },
1313 {"hud-tris", false, OPTION_STRING, "/sim/hud/frame-stat-type", false, "tris", 0 },
1314 {"hud-culled", false, OPTION_STRING, "/sim/hud/frame-stat-type", false, "culled", 0 },
1315 {"atcsim", true, OPTION_CHANNEL, "", false, "dummy", 0 },
1316 {"atlas", true, OPTION_CHANNEL, "", false, "", 0 },
1317 {"httpd", true, OPTION_CHANNEL, "", false, "", 0 },
1318 #ifdef FG_JPEG_SERVER
1319 {"jpg-httpd", true, OPTION_CHANNEL, "", false, "", 0 },
1321 {"native", true, OPTION_CHANNEL, "", false, "", 0 },
1322 {"native-ctrls", true, OPTION_CHANNEL, "", false, "", 0 },
1323 {"native-fdm", true, OPTION_CHANNEL, "", false, "", 0 },
1324 {"native-gui", true, OPTION_CHANNEL, "", false, "", 0 },
1325 {"opengc", true, OPTION_CHANNEL, "", false, "", 0 },
1326 {"garmin", true, OPTION_CHANNEL, "", false, "", 0 },
1327 {"nmea", true, OPTION_CHANNEL, "", false, "", 0 },
1328 {"generic", true, OPTION_CHANNEL, "", false, "", 0 },
1329 {"props", true, OPTION_CHANNEL, "", false, "", 0 },
1330 {"telnet", true, OPTION_CHANNEL, "", false, "", 0 },
1331 {"pve", true, OPTION_CHANNEL, "", false, "", 0 },
1332 {"ray", true, OPTION_CHANNEL, "", false, "", 0 },
1333 {"rul", true, OPTION_CHANNEL, "", false, "", 0 },
1334 {"joyclient", true, OPTION_CHANNEL, "", false, "", 0 },
1335 {"jsclient", true, OPTION_CHANNEL, "", false, "", 0 },
1336 {"proxy", true, OPTION_FUNC, "", false, "", fgSetupProxy },
1337 #ifdef FG_MPLAYER_AS
1338 {"callsign", true, OPTION_STRING, "sim/multiplay/callsign", false, "", 0 },
1339 {"multiplay", true, OPTION_CHANNEL, "", false, "", 0 },
1341 {"trace-read", true, OPTION_FUNC, "", false, "", fgOptTraceRead },
1342 {"trace-write", true, OPTION_FUNC, "", false, "", fgOptTraceWrite },
1343 {"log-level", true, OPTION_FUNC, "", false, "", fgOptLogLevel },
1344 {"view-offset", true, OPTION_FUNC, "", false, "", fgOptViewOffset },
1345 {"visibility", true, OPTION_FUNC, "", false, "", fgOptVisibilityMeters },
1346 {"visibility-miles", true, OPTION_FUNC, "", false, "", fgOptVisibilityMiles },
1347 {"random-wind", false, OPTION_FUNC, "", false, "", fgOptRandomWind },
1348 {"wind", true, OPTION_FUNC, "", false, "", fgOptWind },
1349 {"turbulence", true, OPTION_FUNC, "", false, "", fgOptTurbulence },
1350 {"ceiling", true, OPTION_FUNC, "", false, "", fgOptCeiling },
1351 {"wp", true, OPTION_FUNC, "", false, "", fgOptWp },
1352 {"flight-plan", true, OPTION_FUNC, "", false, "", fgOptFlightPlan },
1353 {"config", true, OPTION_FUNC, "", false, "", fgOptConfig },
1354 {"aircraft", true, OPTION_STRING, "/sim/aircraft", false, "", 0 },
1355 {"failure", true, OPTION_FUNC, "", false, "", fgOptFailure },
1356 {"com1", true, OPTION_DOUBLE, "/instrumentation/comm[0]/frequencies/selected-mhz", false, "", 0 },
1357 {"com2", true, OPTION_DOUBLE, "/instrumentation/comm[1]/frequencies/selected-mhz", false, "", 0 },
1358 {"nav1", true, OPTION_FUNC, "", false, "", fgOptNAV1 },
1359 {"nav2", true, OPTION_FUNC, "", false, "", fgOptNAV2 },
1360 {"adf", true, OPTION_FUNC, "", false, "", fgOptADF },
1361 {"dme", true, OPTION_FUNC, "", false, "", fgOptDME },
1362 {"min-status", true, OPTION_STRING, "/sim/aircraft-min-status", false, "all", 0 },
1363 {"livery", true, OPTION_FUNC, "", false, "", fgOptLivery },
1368 // Parse a single option
1370 parse_option (const string& arg)
1372 if ( fgOptionMap.size() == 0 ) {
1374 OptionDesc *pt = &fgOptionArray[ 0 ];
1375 while ( pt->option != 0 ) {
1376 fgOptionMap[ pt->option ] = i;
1383 if ( (arg == "--help") || (arg == "-h") ) {
1384 // help/usage request
1385 return(FG_OPTIONS_HELP);
1386 } else if ( (arg == "--verbose") || (arg == "-v") ) {
1387 // verbose help/usage request
1388 return(FG_OPTIONS_VERBOSE_HELP);
1389 } else if ( arg.find( "--show-aircraft") == 0) {
1390 return(FG_OPTIONS_SHOW_AIRCRAFT);
1391 } else if ( arg.find( "--prop:" ) == 0 ) {
1392 string assign = arg.substr(7);
1393 string::size_type pos = assign.find('=');
1394 if ( pos == arg.npos || pos == 0 ) {
1395 SG_LOG( SG_GENERAL, SG_ALERT, "Bad property assignment: " << arg );
1396 return FG_OPTIONS_ERROR;
1398 string name = assign.substr(0, pos);
1399 string value = assign.substr(pos + 1);
1400 fgSetString(name.c_str(), value.c_str());
1401 // SG_LOG(SG_GENERAL, SG_INFO, "Setting default value of property "
1402 // << name << " to \"" << value << '"');
1403 } else if ( arg.find( "--" ) == 0 ) {
1404 size_t pos = arg.find( '=' );
1406 if ( pos == string::npos ) {
1407 arg_name = arg.substr( 2 );
1409 arg_name = arg.substr( 2, pos - 2 );
1411 map<string,size_t>::iterator it = fgOptionMap.find( arg_name );
1412 if ( it != fgOptionMap.end() ) {
1413 OptionDesc *pt = &fgOptionArray[ it->second ];
1414 switch ( pt->type ) {
1416 fgSetBool( pt->property, pt->b_param );
1419 if ( pt->has_param && pos != string::npos ) {
1420 fgSetString( pt->property, arg.substr( pos + 1 ).c_str() );
1421 } else if ( !pt->has_param && pos == string::npos ) {
1422 fgSetString( pt->property, pt->s_param );
1423 } else if ( pt->has_param ) {
1424 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1425 return FG_OPTIONS_ERROR;
1427 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' does not have a parameter" );
1428 return FG_OPTIONS_ERROR;
1432 if ( pos != string::npos ) {
1433 fgSetDouble( pt->property, atof( arg.substr( pos + 1 ) ) );
1435 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1436 return FG_OPTIONS_ERROR;
1440 if ( pos != string::npos ) {
1441 fgSetInt( pt->property, atoi( arg.substr( pos + 1 ) ) );
1443 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1444 return FG_OPTIONS_ERROR;
1447 case OPTION_CHANNEL:
1448 if ( pt->has_param && pos != string::npos ) {
1449 add_channel( pt->option, arg.substr( pos + 1 ) );
1450 } else if ( !pt->has_param && pos == string::npos ) {
1451 add_channel( pt->option, pt->s_param );
1452 } else if ( pt->has_param ) {
1453 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1454 return FG_OPTIONS_ERROR;
1456 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' does not have a parameter" );
1457 return FG_OPTIONS_ERROR;
1461 if ( pt->has_param && pos != string::npos ) {
1462 return pt->func( arg.substr( pos + 1 ).c_str() );
1463 } else if ( !pt->has_param && pos == string::npos ) {
1464 return pt->func( 0 );
1465 } else if ( pt->has_param ) {
1466 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1467 return FG_OPTIONS_ERROR;
1469 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' does not have a parameter" );
1470 return FG_OPTIONS_ERROR;
1475 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" );
1476 return FG_OPTIONS_ERROR;
1479 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" );
1480 return FG_OPTIONS_ERROR;
1483 return FG_OPTIONS_OK;
1487 // Parse the command line options
1489 fgParseArgs (int argc, char **argv)
1491 bool in_options = true;
1492 bool verbose = false;
1495 SG_LOG(SG_GENERAL, SG_INFO, "Processing command line arguments");
1497 for (int i = 1; i < argc; i++) {
1498 string arg = argv[i];
1500 if (in_options && (arg.find('-') == 0)) {
1504 int result = parse_option(arg);
1505 if ((result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR))
1508 else if (result == FG_OPTIONS_VERBOSE_HELP)
1511 else if (result == FG_OPTIONS_SHOW_AIRCRAFT) {
1512 fgOptLogLevel( "alert" );
1513 SGPath path( globals->get_fg_root() );
1514 path.append("Aircraft");
1515 fgShowAircraft(path, true);
1521 SG_LOG(SG_GENERAL, SG_INFO,
1522 "Reading command-line property file " << arg);
1523 readProperties(arg, globals->get_props());
1528 fgOptLogLevel( "alert" );
1533 SG_LOG(SG_GENERAL, SG_INFO, "Finished command line arguments");
1537 // Parse config file options
1539 fgParseOptions (const string& path) {
1540 sg_gzifstream in( path );
1541 if ( !in.is_open() ) {
1545 SG_LOG( SG_GENERAL, SG_INFO, "Processing config file: " << path );
1549 while ( ! in.eof() ) {
1552 while ( in.get(c) && c != '\0' ) {
1557 #if defined( macintosh )
1558 getline( in, line, '\r' );
1560 getline( in, line, '\n' );
1563 // catch extraneous (DOS) line ending character
1565 for (i = line.length(); i > 0; i--)
1566 if (line[i - 1] > 32)
1568 line = line.substr( 0, i );
1570 if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
1571 cerr << endl << "Config file parse error: " << path << " '"
1572 << line << "'" << endl;
1581 // Print usage message
1583 fgUsage (bool verbose)
1585 SGPropertyNode *locale = globals->get_locale();
1587 SGPropertyNode options_root;
1589 SG_LOG( SG_GENERAL, SG_ALERT, "" ); // To popup the console on Windows
1593 fgLoadProps("options.xml", &options_root);
1594 } catch (const sg_exception &ex) {
1595 cout << "Unable to read the help file." << endl;
1596 cout << "Make sure the file options.xml is located in the FlightGear base directory," << endl;
1597 cout << "and the location of the base directory is specified by setting $FG_ROOT or" << endl;
1598 cout << "by adding --fg-root=path as a program argument." << endl;
1603 SGPropertyNode *options = options_root.getNode("options");
1605 SG_LOG( SG_GENERAL, SG_ALERT,
1606 "Error reading options.xml: <options> directive not found." );
1610 SGPropertyNode *usage = locale->getNode(options->getStringValue("usage"));
1612 cout << "Usage: " << usage->getStringValue() << endl;
1615 vector<SGPropertyNode_ptr>section = options->getChildren("section");
1616 for (unsigned int j = 0; j < section.size(); j++) {
1619 vector<SGPropertyNode_ptr>option = section[j]->getChildren("option");
1620 for (unsigned int k = 0; k < option.size(); k++) {
1622 SGPropertyNode *name = option[k]->getNode("name");
1623 SGPropertyNode *short_name = option[k]->getNode("short");
1624 SGPropertyNode *key = option[k]->getNode("key");
1625 SGPropertyNode *arg = option[k]->getNode("arg");
1626 bool brief = option[k]->getNode("brief");
1628 if ((brief || verbose) && name) {
1629 string tmp = name->getStringValue();
1633 tmp.append(key->getStringValue());
1637 tmp.append(arg->getStringValue());
1641 tmp.append(short_name->getStringValue());
1645 if (tmp.size() <= 25) {
1646 snprintf(cstr, 96, " --%-27s", tmp.c_str());
1648 snprintf(cstr, 96, "\n --%s\n%32c", tmp.c_str(), ' ');
1651 // There may be more than one <description> tag assosiated
1655 vector<SGPropertyNode_ptr>desc =
1656 option[k]->getChildren("description");
1658 if (desc.size() > 0) {
1659 for ( unsigned int l = 0; l < desc.size(); l++) {
1661 // There may be more than one translation line.
1663 string t = desc[l]->getStringValue();
1664 SGPropertyNode *n = locale->getNode("strings");
1665 vector<SGPropertyNode_ptr>trans_desc =
1666 n->getChildren(t.substr(8).c_str());
1668 for ( unsigned int m = 0; m < trans_desc.size(); m++ ) {
1669 string t_str = trans_desc[m]->getStringValue();
1671 if ((m > 0) || ((l > 0) && m == 0)) {
1672 snprintf(cstr, 96, "%32c", ' ');
1677 // If the string is too large to fit on the screen,
1678 // then split it up in several pieces.
1680 while ( t_str.size() > 47 ) {
1682 unsigned int m = t_str.rfind(' ', 47);
1683 msg += t_str.substr(0, m);
1684 snprintf(cstr, 96, "\n%32c", ' ');
1687 t_str.erase(t_str.begin(), t_str.begin() + m + 1);
1689 msg += t_str + '\n';
1696 SGPropertyNode *name =
1697 locale->getNode(section[j]->getStringValue("name"));
1699 if (!msg.empty() && name) {
1700 cout << endl << name->getStringValue() << ":" << endl;
1708 cout << "For a complete list of options use --help --verbose" << endl;
1711 cout << "Hit a key to continue..." << endl;
1716 // A simple function to return an integer depending on the position
1717 // of the status string within the array in order to determine the hierarchy.
1718 unsigned int getNumMaturity(const char * str)
1720 // changes should also be reflected in $FG_ROOT/data/options.xml &
1721 // $FG_ROOT/data/Translations/string-default.xml
1722 const char levels[][20]= {"alpha","beta","early-production","production",0};
1724 for (unsigned int i=0; i<(sizeof(levels)/sizeof(levels[0])-1);i++)
1725 if (strcmp(str,levels[i])==0)
1732 static void fgSearchAircraft(const SGPath &path, string_list &aircraft,
1737 ulDir *dirp = ulOpenDir(path.str().c_str());
1739 cerr << "Unable to open aircraft directory '" << path.str() << '\'' << endl;
1743 while ((dire = ulReadDir(dirp)) != NULL) {
1746 if (dire->d_isdir) {
1747 if (recursive && strcmp("CVS", dire->d_name)
1748 && strcmp(".", dire->d_name) && strcmp("..", dire->d_name))
1751 next.append(dire->d_name);
1753 fgSearchAircraft(next, aircraft, true);
1755 } else if ((ptr = strstr(dire->d_name, "-set.xml")) && (ptr[8] == '\0')) {
1757 SGPath afile = path;
1758 afile.append(dire->d_name);
1762 SGPropertyNode root;
1764 readProperties(afile.str(), &root);
1769 SGPropertyNode *desc = NULL;
1770 SGPropertyNode *status = NULL;
1772 SGPropertyNode *node = root.getNode("sim");
1774 desc = node->getNode("description");
1775 // if a status tag is found, read it in
1776 if (node->hasValue("status"))
1777 status = node->getNode("status");
1781 //additionally display status information where it is available
1783 if (strlen(dire->d_name) <= 27) {
1784 snprintf(cstr, 96, " %-27s %s", dire->d_name,
1785 (desc) ? desc->getStringValue() : "");
1788 snprintf(cstr, 96, " %-27s\n%32c%s", dire->d_name, ' ',
1789 (desc) ? desc->getStringValue() : "");
1792 SGPropertyNode * required_status
1793 = fgGetNode ("/sim/aircraft-min-status", true);
1795 // If the node holds the value "all", then there wasn't any status
1796 // level specified, so we simply go ahead and output ALL aircraft
1797 if (strcmp(required_status->getStringValue(),"all")==0) {
1798 aircraft.push_back(cstr);
1802 // If the node doesn't hold "all" as its value, then we are supposed
1803 // to show only aircraft meeting specific status (development status)
1806 if (node->hasValue("status")) {
1807 //Compare (minimally) required status level with actual aircraft status:
1808 if ( getNumMaturity(status->getStringValue() ) >=
1809 getNumMaturity(required_status->getStringValue() ) )
1810 aircraft.push_back(cstr); }
1822 * Search in the current directory, and in on directory deeper
1823 * for <aircraft>-set.xml configuration files and show the aircaft name
1824 * and the contents of the<description> tag in a sorted manner.
1826 * @parampath the directory to search for configuration files
1827 * @param recursive defines whether the directory should be searched recursively
1829 void fgShowAircraft(const SGPath &path, bool recursive) {
1830 string_list aircraft;
1832 fgSearchAircraft( path, aircraft, recursive );
1834 sort(aircraft.begin(), aircraft.end());
1835 SG_LOG( SG_GENERAL, SG_ALERT, "" ); // To popup the console on Windows
1836 cout << "Available aircraft:" << endl;
1837 for ( unsigned int i = 0; i < aircraft.size(); i++ ) {
1838 cout << aircraft[i] << endl;
1841 cout << "Hit a key to continue..." << endl;