1 // options.cxx -- class to handle command line options
3 // Written by Curtis Olson, started April 1998.
5 // Copyright (C) 1998 Curtis L. Olson - http://www.flightgear.org/~curt
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28 #include <simgear/compiler.h>
29 #include <simgear/structure/exception.hxx>
30 #include <simgear/debug/logstream.hxx>
32 #include <math.h> // rint()
34 #include <stdlib.h> // atof(), atoi()
35 #include <string.h> // strcmp()
42 #include <simgear/math/sg_random.h>
43 #include <simgear/props/props_io.hxx>
44 #include <simgear/misc/sgstream.hxx>
45 #include <simgear/misc/sg_path.hxx>
46 #include <simgear/scene/material/mat.hxx>
48 // #include <Include/general.hxx>
49 // #include <Airports/simple.hxx>
50 // #include <Cockpit/cockpit.hxx>
51 // #include <FDM/flight.hxx>
53 #include <Autopilot/route_mgr.hxx>
56 #include "globals.hxx"
57 #include "fg_init.hxx"
58 #include "fg_props.hxx"
59 #include "options.hxx"
61 #include "viewmgr.hxx"
68 #define VERSION "CVS "__DATE__
71 #define NEW_DEFAULT_MODEL_HZ 120
79 FG_OPTIONS_VERBOSE_HELP = 4,
80 FG_OPTIONS_SHOW_AIRCRAFT = 5
84 atof( const string& str )
86 return ::atof( str.c_str() );
90 atoi( const string& str )
92 return ::atoi( str.c_str() );
96 * Set a few fail-safe default property values.
98 * These should all be set in $FG_ROOT/preferences.xml, but just
99 * in case, we provide some initial sane values here. This method
100 * should be invoked *before* reading any init files.
105 // set a possibly independent location for scenery data
106 char *envp = ::getenv( "FG_SCENERY" );
108 if ( envp != NULL ) {
109 // fg_root could be anywhere, so default to environmental
110 // variable $FG_ROOT if it is set.
111 globals->set_fg_scenery(envp);
113 // Otherwise, default to Scenery being in $FG_ROOT/Scenery
114 globals->set_fg_scenery("");
116 // Position (deliberately out of range)
117 fgSetDouble("/position/longitude-deg", 9999.0);
118 fgSetDouble("/position/latitude-deg", 9999.0);
119 fgSetDouble("/position/altitude-ft", -9999.0);
122 fgSetDouble("/orientation/heading-deg", 9999.0);
123 fgSetDouble("/orientation/roll-deg", 0.0);
124 fgSetDouble("/orientation/pitch-deg", 0.424);
127 fgSetDouble("/velocities/uBody-fps", 0.0);
128 fgSetDouble("/velocities/vBody-fps", 0.0);
129 fgSetDouble("/velocities/wBody-fps", 0.0);
130 fgSetDouble("/velocities/speed-north-fps", 0.0);
131 fgSetDouble("/velocities/speed-east-fps", 0.0);
132 fgSetDouble("/velocities/speed-down-fps", 0.0);
133 fgSetDouble("/velocities/airspeed-kt", 0.0);
134 fgSetDouble("/velocities/mach", 0.0);
137 fgSetDouble("/sim/presets/longitude-deg", 9999.0);
138 fgSetDouble("/sim/presets/latitude-deg", 9999.0);
139 fgSetDouble("/sim/presets/altitude-ft", -9999.0);
141 fgSetDouble("/sim/presets/heading-deg", 9999.0);
142 fgSetDouble("/sim/presets/roll-deg", 0.0);
143 fgSetDouble("/sim/presets/pitch-deg", 0.424);
145 fgSetString("/sim/presets/speed-set", "knots");
146 fgSetDouble("/sim/presets/airspeed-kt", 0.0);
147 fgSetDouble("/sim/presets/mach", 0.0);
148 fgSetDouble("/sim/presets/uBody-fps", 0.0);
149 fgSetDouble("/sim/presets/vBody-fps", 0.0);
150 fgSetDouble("/sim/presets/wBody-fps", 0.0);
151 fgSetDouble("/sim/presets/speed-north-fps", 0.0);
152 fgSetDouble("/sim/presets/speed-east-fps", 0.0);
153 fgSetDouble("/sim/presets/speed-down-fps", 0.0);
155 fgSetBool("/sim/presets/onground", true);
156 fgSetBool("/sim/presets/trim", false);
159 fgSetBool("/sim/startup/game-mode", false);
160 fgSetBool("/sim/startup/splash-screen", true);
161 fgSetBool("/sim/startup/intro-music", true);
162 // we want mouse-pointer to have an undefined value if nothing is
163 // specified so we can do the right thing for voodoo-1/2 cards.
164 // fgSetString("/sim/startup/mouse-pointer", "disabled");
165 fgSetString("/sim/control-mode", "joystick");
166 fgSetBool("/sim/auto-coordination", false);
168 fgSetString("/sim/startup/browser-app", "webrun.bat");
169 #elif defined(__APPLE__)
170 fgSetString("/sim/startup/browser-app", "open");
172 fgSetString("/sim/startup/browser-app", "launchWebJumper");
174 envp = ::getenv( "WEBBROWSER" );
175 if (!envp) envp = "netscape";
176 fgSetString("/sim/startup/browser-app", envp);
178 fgSetString("/sim/logging/priority", "alert");
181 fgSetBool("/sim/hud/color/antialiased", false);
182 fgSetBool("/sim/hud/enable3d", true);
183 fgSetBool("/sim/hud/visibility", false);
184 fgSetBool("/sim/panel/visibility", true);
185 fgSetBool("/sim/sound/pause", false);
187 // Flight Model options
188 fgSetString("/sim/flight-model", "jsb");
189 fgSetString("/sim/aero", "c172");
190 fgSetInt("/sim/model-hz", NEW_DEFAULT_MODEL_HZ);
191 fgSetInt("/sim/speed-up", 1);
194 fgSetString("/sim/rendering/fog", "nicest");
195 fgSetBool("/environment/clouds/status", true);
196 fgSetBool("/sim/startup/fullscreen", false);
197 fgSetBool("/sim/rendering/shading", true);
198 fgSetBool("/sim/rendering/skyblend", true);
199 fgSetBool("/sim/rendering/textures", true);
200 fgTie( "/sim/rendering/filtering", SGGetTextureFilter, SGSetTextureFilter, false);
201 fgSetInt("/sim/rendering/filtering", 1);
202 fgSetBool("/sim/rendering/wireframe", false);
203 fgSetBool("/sim/rendering/horizon-effect", false);
204 fgSetBool("/sim/rendering/enhanced-lighting", false);
205 fgSetBool("/sim/rendering/distance-attenuation", false);
206 fgSetBool("/sim/rendering/specular-highlight", true);
207 fgSetInt("/sim/startup/xsize", 800);
208 fgSetInt("/sim/startup/ysize", 600);
209 fgSetInt("/sim/rendering/bits-per-pixel", 16);
210 fgSetString("/sim/view-mode", "pilot");
211 fgSetDouble("/sim/current-view/heading-offset-deg", 0);
214 fgSetString("/sim/startup/units", "feet");
215 fgSetString("/sim/hud/frame-stat-type", "tris");
218 fgSetInt("/sim/startup/time-offset", 0);
219 fgSetString("/sim/startup/time-offset-type", "system-offset");
220 fgSetLong("/sim/time/cur-time-override", 0);
223 fgSetBool("/sim/freeze/master", false);
224 fgSetBool("/sim/freeze/position", false);
225 fgSetBool("/sim/freeze/clock", false);
226 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);
236 parse_wind (const string &wind, double * min_hdg, double * max_hdg,
237 double * speed, double * gust)
239 string::size_type pos = wind.find('@');
240 if (pos == string::npos)
242 string dir = wind.substr(0, pos);
243 string spd = wind.substr(pos+1);
245 if (pos == string::npos) {
246 *min_hdg = *max_hdg = atof(dir.c_str());
248 *min_hdg = atof(dir.substr(0,pos).c_str());
249 *max_hdg = atof(dir.substr(pos+1).c_str());
252 if (pos == string::npos) {
253 *speed = *gust = atof(spd.c_str());
255 *speed = atof(spd.substr(0,pos).c_str());
256 *gust = atof(spd.substr(pos+1).c_str());
261 // parse a time string ([+/-]%f[:%f[:%f]]) into hours
263 parse_time(const string& time_in) {
264 char *time_str, num[256];
265 double hours, minutes, seconds;
270 time_str = (char *)time_in.c_str();
272 // printf("parse_time(): %s\n", time_str);
275 if ( strlen(time_str) ) {
276 if ( time_str[0] == '+' ) {
279 } else if ( time_str[0] == '-' ) {
284 // printf("sign = %d\n", sign);
287 if ( strlen(time_str) ) {
289 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
290 num[i] = time_str[0];
294 if ( time_str[0] == ':' ) {
299 // printf("hours = %.2lf\n", hours);
305 if ( strlen(time_str) ) {
307 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
308 num[i] = time_str[0];
312 if ( time_str[0] == ':' ) {
317 // printf("minutes = %.2lf\n", minutes);
319 result += minutes / 60.0;
323 if ( strlen(time_str) ) {
325 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
326 num[i] = time_str[0];
332 // printf("seconds = %.2lf\n", seconds);
334 result += seconds / 3600.0;
337 SG_LOG( SG_GENERAL, SG_INFO, " parse_time() = " << sign * result );
339 return(sign * result);
343 // parse a date string (yyyy:mm:dd:hh:mm:ss) into a time_t (seconds)
345 parse_date( const string& date)
348 char * date_str, num[256];
350 // initialize to zero
357 gmt.tm_isdst = 0; // ignore daylight savings time for the moment
358 date_str = (char *)date.c_str();
360 if ( strlen(date_str) ) {
362 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
363 num[i] = date_str[0];
367 if ( date_str[0] == ':' ) {
371 gmt.tm_year = atoi(num) - 1900;
374 if ( strlen(date_str) ) {
376 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
377 num[i] = date_str[0];
381 if ( date_str[0] == ':' ) {
385 gmt.tm_mon = atoi(num) -1;
388 if ( strlen(date_str) ) {
390 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
391 num[i] = date_str[0];
395 if ( date_str[0] == ':' ) {
399 gmt.tm_mday = atoi(num);
402 if ( strlen(date_str) ) {
404 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
405 num[i] = date_str[0];
409 if ( date_str[0] == ':' ) {
413 gmt.tm_hour = atoi(num);
416 if ( strlen(date_str) ) {
418 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
419 num[i] = date_str[0];
423 if ( date_str[0] == ':' ) {
427 gmt.tm_min = atoi(num);
430 if ( strlen(date_str) ) {
432 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
433 num[i] = date_str[0];
437 if ( date_str[0] == ':' ) {
441 gmt.tm_sec = atoi(num);
443 time_t theTime = sgTimeGetGMT( gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
444 gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
445 //printf ("Date is %s\n", ctime(&theTime));
446 //printf ("in seconds that is %d\n", theTime);
452 // parse angle in the form of [+/-]ddd:mm:ss into degrees
454 parse_degree( const string& degree_str) {
455 double result = parse_time( degree_str );
457 // printf("Degree = %.4f\n", result);
463 // parse time offset string into seconds
465 parse_time_offset( const string& time_str) {
468 // printf("time offset = %s\n", time_str);
471 result = (int)rint(parse_time(time_str) * 3600.0);
473 result = (int)(parse_time(time_str) * 3600.0);
476 // printf("parse_time_offset(): %d\n", result);
482 // Parse --fov=x.xx type option
484 parse_fov( const string& arg ) {
485 double fov = atof(arg);
487 if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
488 if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
490 fgSetDouble("/sim/view[0]/config/default-field-of-view-deg", fov);
492 // printf("parse_fov(): result = %.4f\n", fov);
498 // Parse I/O channel option
500 // Format is "--protocol=medium,direction,hz,medium_options,..."
502 // protocol = { native, nmea, garmin, AV400, fgfs, rul, pve, etc. }
503 // medium = { serial, socket, file, etc. }
504 // direction = { in, out, bi }
505 // hz = number of times to process channel per second (floating
506 // point values are ok.
508 // Serial example "--nmea=serial,dir,hz,device,baud" where
510 // device = OS device name of serial line to be open()'ed
511 // baud = {300, 1200, 2400, ..., 230400}
513 // Socket exacmple "--native=socket,dir,hz,machine,port,style" where
515 // machine = machine name or ip address if client (leave empty if server)
516 // port = port, leave empty to let system choose
517 // style = tcp or udp
519 // File example "--garmin=file,dir,hz,filename" where
521 // filename = file system file name
524 add_channel( const string& type, const string& channel_str ) {
525 SG_LOG(SG_GENERAL, SG_INFO, "Channel string = " << channel_str );
526 globals->get_channel_options_list()->push_back( type + "," + channel_str );
531 // The parse wp and parse flight-plan options don't work anymore, because
532 // the route manager and the airport subsystems have not yet been initialized
535 // Parse --wp=ID[@alt]
537 parse_wp( const string& arg ) {
538 string_list *waypoints = globals->get_initial_waypoints();
540 waypoints = new string_list;
541 globals->set_initial_waypoints(waypoints);
543 waypoints->push_back(arg);
547 // Parse --flight-plan=[file]
549 parse_flightplan(const string& arg)
551 string_list *waypoints = globals->get_initial_waypoints();
553 waypoints = new string_list;
554 globals->set_initial_waypoints(waypoints);
557 sg_gzifstream in(arg.c_str());
563 getline( in, line, '\n' );
565 // catch extraneous (DOS) line ending character
566 if ( line[line.length() - 1] < 32 )
567 line = line.substr( 0, line.length()-1 );
572 waypoints->push_back(line);
579 fgOptLanguage( const char *arg )
581 globals->set_locale( fgInitLocale( arg ) );
582 return FG_OPTIONS_OK;
588 fgSetString("/sim/presets/airport-id", "");
589 fgSetString("/sim/presets/vor-id", "");
590 fgSetString("/sim/presets/ndb-id", "");
591 fgSetString("/sim/presets/carrier", "");
592 fgSetString("/sim/presets/parkpos", "");
593 fgSetString("/sim/presets/fix", "");
597 fgOptVOR( const char * arg )
600 fgSetString("/sim/presets/vor-id", arg);
601 return FG_OPTIONS_OK;
605 fgOptNDB( const char * arg )
608 fgSetString("/sim/presets/ndb-id", arg);
609 return FG_OPTIONS_OK;
613 fgOptCarrier( const char * arg )
616 fgSetString("/sim/presets/carrier", arg);
617 return FG_OPTIONS_OK;
621 fgOptParkpos( const char * arg )
623 fgSetString("/sim/presets/parkpos", arg);
624 return FG_OPTIONS_OK;
628 fgOptFIX( const char * arg )
631 fgSetString("/sim/presets/fix", arg);
632 return FG_OPTIONS_OK;
636 fgOptLon( const char *arg )
639 fgSetDouble("/sim/presets/longitude-deg", parse_degree( arg ));
640 fgSetDouble("/position/longitude-deg", parse_degree( arg ));
641 return FG_OPTIONS_OK;
645 fgOptLat( const char *arg )
648 fgSetDouble("/sim/presets/latitude-deg", parse_degree( arg ));
649 fgSetDouble("/position/latitude-deg", parse_degree( arg ));
650 return FG_OPTIONS_OK;
654 fgOptAltitude( const char *arg )
656 fgSetBool("/sim/presets/onground", false);
657 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
658 fgSetDouble("/sim/presets/altitude-ft", atof( arg ));
660 fgSetDouble("/sim/presets/altitude-ft",
661 atof( arg ) * SG_METER_TO_FEET);
662 return FG_OPTIONS_OK;
666 fgOptUBody( const char *arg )
668 fgSetString("/sim/presets/speed-set", "UVW");
669 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
670 fgSetDouble("/sim/presets/uBody-fps", atof( arg ));
672 fgSetDouble("/sim/presets/uBody-fps",
673 atof( arg ) * SG_METER_TO_FEET);
674 return FG_OPTIONS_OK;
678 fgOptVBody( const char *arg )
680 fgSetString("/sim/presets/speed-set", "UVW");
681 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
682 fgSetDouble("/sim/presets/vBody-fps", atof( arg ));
684 fgSetDouble("/sim/presets/vBody-fps",
685 atof( arg ) * SG_METER_TO_FEET);
686 return FG_OPTIONS_OK;
690 fgOptWBody( const char *arg )
692 fgSetString("/sim/presets/speed-set", "UVW");
693 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
694 fgSetDouble("/sim/presets/wBody-fps", atof(arg));
696 fgSetDouble("/sim/presets/wBody-fps",
697 atof(arg) * SG_METER_TO_FEET);
698 return FG_OPTIONS_OK;
702 fgOptVNorth( const char *arg )
704 fgSetString("/sim/presets/speed-set", "NED");
705 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
706 fgSetDouble("/sim/presets/speed-north-fps", atof( arg ));
708 fgSetDouble("/sim/presets/speed-north-fps",
709 atof( arg ) * SG_METER_TO_FEET);
710 return FG_OPTIONS_OK;
714 fgOptVEast( const char *arg )
716 fgSetString("/sim/presets/speed-set", "NED");
717 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
718 fgSetDouble("/sim/presets/speed-east-fps", atof(arg));
720 fgSetDouble("/sim/presets/speed-east-fps",
721 atof(arg) * SG_METER_TO_FEET);
722 return FG_OPTIONS_OK;
726 fgOptVDown( const char *arg )
728 fgSetString("/sim/presets/speed-set", "NED");
729 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
730 fgSetDouble("/sim/presets/speed-down-fps", atof(arg));
732 fgSetDouble("/sim/presets/speed-down-fps",
733 atof(arg) * SG_METER_TO_FEET);
734 return FG_OPTIONS_OK;
738 fgOptVc( const char *arg )
740 // fgSetString("/sim/presets/speed-set", "knots");
741 // fgSetDouble("/velocities/airspeed-kt", atof(arg.substr(5)));
742 fgSetString("/sim/presets/speed-set", "knots");
743 fgSetDouble("/sim/presets/airspeed-kt", atof(arg));
744 return FG_OPTIONS_OK;
748 fgOptMach( const char *arg )
750 fgSetString("/sim/presets/speed-set", "mach");
751 fgSetDouble("/sim/presets/mach", atof(arg));
752 return FG_OPTIONS_OK;
756 fgOptRoc( const char *arg )
758 fgSetDouble("/velocities/vertical-speed-fps", atof(arg)/60);
759 return FG_OPTIONS_OK;
763 fgOptFgRoot( const char *arg )
765 globals->set_fg_root(arg);
766 return FG_OPTIONS_OK;
770 fgOptFgScenery( const char *arg )
772 globals->set_fg_scenery(arg);
773 return FG_OPTIONS_OK;
777 fgOptFov( const char *arg )
780 return FG_OPTIONS_OK;
784 fgOptGeometry( const char *arg )
786 bool geometry_ok = true;
787 int xsize = 0, ysize = 0;
788 string geometry = arg;
789 string::size_type i = geometry.find('x');
791 if (i != string::npos) {
792 xsize = atoi(geometry.substr(0, i));
793 ysize = atoi(geometry.substr(i+1));
798 if ( xsize <= 0 || ysize <= 0 ) {
804 if ( !geometry_ok ) {
805 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown geometry: " << geometry );
806 SG_LOG( SG_GENERAL, SG_ALERT,
807 "Setting geometry to " << xsize << 'x' << ysize << '\n');
809 SG_LOG( SG_GENERAL, SG_INFO,
810 "Setting geometry to " << xsize << 'x' << ysize << '\n');
811 fgSetInt("/sim/startup/xsize", xsize);
812 fgSetInt("/sim/startup/ysize", ysize);
814 return FG_OPTIONS_OK;
818 fgOptBpp( const char *arg )
820 string bits_per_pix = arg;
821 if ( bits_per_pix == "16" ) {
822 fgSetInt("/sim/rendering/bits-per-pixel", 16);
823 } else if ( bits_per_pix == "24" ) {
824 fgSetInt("/sim/rendering/bits-per-pixel", 24);
825 } else if ( bits_per_pix == "32" ) {
826 fgSetInt("/sim/rendering/bits-per-pixel", 32);
828 SG_LOG(SG_GENERAL, SG_ALERT, "Unsupported bpp " << bits_per_pix);
830 return FG_OPTIONS_OK;
834 fgOptTimeOffset( const char *arg )
836 fgSetInt("/sim/startup/time-offset",
837 parse_time_offset( arg ));
838 fgSetString("/sim/startup/time-offset-type", "system-offset");
839 return FG_OPTIONS_OK;
843 fgOptStartDateSys( const char *arg )
845 fgSetInt("/sim/startup/time-offset", parse_date( arg ) );
846 fgSetString("/sim/startup/time-offset-type", "system");
847 return FG_OPTIONS_OK;
851 fgOptStartDateLat( const char *arg )
853 fgSetInt("/sim/startup/time-offset", parse_date( arg ) );
854 fgSetString("/sim/startup/time-offset-type", "latitude");
855 return FG_OPTIONS_OK;
859 fgOptStartDateGmt( const char *arg )
861 fgSetInt("/sim/startup/time-offset", parse_date( arg ) );
862 fgSetString("/sim/startup/time-offset-type", "gmt");
863 return FG_OPTIONS_OK;
867 fgSetupProxy( const char *arg )
869 string options = arg;
870 string host, port, auth;
871 string::size_type pos;
873 host = port = auth = "";
874 if ((pos = options.find("@")) != string::npos)
875 auth = options.substr(0, pos++);
879 host = options.substr(pos, options.size());
880 if ((pos = host.find(":")) != string::npos) {
881 port = host.substr(++pos, host.size());
882 host.erase(--pos, host.size());
885 fgSetString("/sim/presets/proxy/host", host.c_str());
886 fgSetString("/sim/presets/proxy/port", port.c_str());
887 fgSetString("/sim/presets/proxy/authentication", auth.c_str());
889 return FG_OPTIONS_OK;
893 fgOptTraceRead( const char *arg )
896 SG_LOG(SG_GENERAL, SG_INFO, "Tracing reads for property " << name);
897 fgGetNode(name.c_str(), true)
898 ->setAttribute(SGPropertyNode::TRACE_READ, true);
899 return FG_OPTIONS_OK;
903 fgOptLogLevel( const char *arg )
905 fgSetString("/sim/logging/classes", "all");
906 fgSetString("/sim/logging/priority", arg);
908 string priority = arg;
909 logbuf::set_log_classes(SG_ALL);
910 if (priority == "bulk") {
911 logbuf::set_log_priority(SG_BULK);
912 } else if (priority == "debug") {
913 logbuf::set_log_priority(SG_DEBUG);
914 } else if (priority == "info") {
915 logbuf::set_log_priority(SG_INFO);
916 } else if (priority == "warn") {
917 logbuf::set_log_priority(SG_WARN);
918 } else if (priority == "alert") {
919 logbuf::set_log_priority(SG_ALERT);
921 SG_LOG(SG_GENERAL, SG_WARN, "Unknown logging priority " << priority);
923 SG_LOG(SG_GENERAL, SG_DEBUG, "Logging priority is " << priority);
925 return FG_OPTIONS_OK;
930 fgOptTraceWrite( const char *arg )
933 SG_LOG(SG_GENERAL, SG_INFO, "Tracing writes for property " << name);
934 fgGetNode(name.c_str(), true)
935 ->setAttribute(SGPropertyNode::TRACE_WRITE, true);
936 return FG_OPTIONS_OK;
940 fgOptViewOffset( const char *arg )
942 // $$$ begin - added VS Renganathan, 14 Oct 2K
943 // for multi-window outside window imagery
944 string woffset = arg;
945 double default_view_offset = 0.0;
946 if ( woffset == "LEFT" ) {
947 default_view_offset = SGD_PI * 0.25;
948 } else if ( woffset == "RIGHT" ) {
949 default_view_offset = SGD_PI * 1.75;
950 } else if ( woffset == "CENTER" ) {
951 default_view_offset = 0.00;
953 default_view_offset = atof( woffset.c_str() ) * SGD_DEGREES_TO_RADIANS;
955 /* apparently not used (CLO, 11 Jun 2002)
956 FGViewer *pilot_view =
957 (FGViewer *)globals->get_viewmgr()->get_view( 0 ); */
958 // this will work without calls to the viewer...
959 fgSetDouble( "/sim/current-view/heading-offset-deg",
960 default_view_offset * SGD_RADIANS_TO_DEGREES );
961 // $$$ end - added VS Renganathan, 14 Oct 2K
962 return FG_OPTIONS_OK;
966 fgOptVisibilityMeters( const char *arg )
968 double visibility = atof( arg );
969 fgDefaultWeatherValue("visibility-m", visibility);
970 return FG_OPTIONS_OK;
974 fgOptVisibilityMiles( const char *arg )
976 double visibility = atof( arg ) * 5280.0 * SG_FEET_TO_METER;
977 fgDefaultWeatherValue("visibility-m", visibility);
978 return FG_OPTIONS_OK;
982 fgOptRandomWind( const char *arg )
984 double min_hdg = sg_random() * 360.0;
985 double max_hdg = min_hdg + (20 - sqrt(sg_random() * 400));
986 double speed = sg_random() * sg_random() * 40;
987 double gust = speed + (10 - sqrt(sg_random() * 100));
988 fgSetupWind(min_hdg, max_hdg, speed, gust);
989 return FG_OPTIONS_OK;
993 fgOptWind( const char *arg )
995 double min_hdg, max_hdg, speed, gust;
996 if (!parse_wind( arg, &min_hdg, &max_hdg, &speed, &gust)) {
997 SG_LOG( SG_GENERAL, SG_ALERT, "bad wind value " << arg );
998 return FG_OPTIONS_ERROR;
1000 fgSetupWind(min_hdg, max_hdg, speed, gust);
1001 return FG_OPTIONS_OK;
1005 fgOptTurbulence( const char *arg )
1007 fgDefaultWeatherValue("turbulence/magnitude-norm", atof(arg));
1008 return FG_OPTIONS_OK;
1012 fgOptCeiling( const char *arg )
1014 double elevation, thickness;
1016 string::size_type pos = spec.find(':');
1017 if (pos == string::npos) {
1018 elevation = atof(spec.c_str());
1021 elevation = atof(spec.substr(0, pos).c_str());
1022 thickness = atof(spec.substr(pos + 1).c_str());
1024 fgSetDouble("/environment/clouds/layer[0]/elevation-ft", elevation);
1025 fgSetDouble("/environment/clouds/layer[0]/thickness-ft", thickness);
1026 fgSetString("/environment/clouds/layer[0]/coverage", "overcast");
1027 return FG_OPTIONS_OK;
1031 fgOptWp( const char *arg )
1034 return FG_OPTIONS_OK;
1038 fgOptFlightPlan( const char *arg )
1040 parse_flightplan ( arg );
1041 return FG_OPTIONS_OK;
1045 fgOptConfig( const char *arg )
1049 readProperties(file, globals->get_props());
1050 } catch (const sg_exception &e) {
1051 string message = "Error loading config file: ";
1052 message += e.getFormattedMessage() + e.getOrigin();
1053 SG_LOG(SG_INPUT, SG_ALERT, message);
1056 return FG_OPTIONS_OK;
1060 parse_colon (const string &s, double * val1, double * val2)
1062 string::size_type pos = s.find(':');
1063 if (pos == string::npos) {
1067 *val1 = atof(s.substr(0, pos).c_str());
1068 *val2 = atof(s.substr(pos+1).c_str());
1075 fgOptFailure( const char * arg )
1079 fgSetBool("/systems/pitot/serviceable", false);
1080 } else if (a == "static") {
1081 fgSetBool("/systems/static/serviceable", false);
1082 } else if (a == "vacuum") {
1083 fgSetBool("/systems/vacuum/serviceable", false);
1084 } else if (a == "electrical") {
1085 fgSetBool("/systems/electrical/serviceable", false);
1087 SG_LOG(SG_INPUT, SG_ALERT, "Unknown failure mode: " << a);
1088 return FG_OPTIONS_ERROR;
1091 return FG_OPTIONS_OK;
1096 fgOptNAV1( const char * arg )
1098 double radial, freq;
1099 if (parse_colon(arg, &radial, &freq))
1100 fgSetDouble("/instrumentation/nav[0]/radials/selected-deg", radial);
1101 fgSetDouble("/instrumentation/nav[0]/frequencies/selected-mhz", freq);
1102 return FG_OPTIONS_OK;
1106 fgOptNAV2( const char * arg )
1108 double radial, freq;
1109 if (parse_colon(arg, &radial, &freq))
1110 fgSetDouble("/instrumentation/nav[1]/radials/selected-deg", radial);
1111 fgSetDouble("/instrumentation/nav[1]/frequencies/selected-mhz", freq);
1112 return FG_OPTIONS_OK;
1116 fgOptADF( const char * arg )
1119 if (parse_colon(arg, &rot, &freq))
1120 fgSetDouble("/instrumentation/adf/rotation-deg", rot);
1121 fgSetDouble("/instrumentation/adf/frequencies/selected-khz", freq);
1122 return FG_OPTIONS_OK;
1126 fgOptDME( const char *arg )
1129 if (opt == "nav1") {
1130 fgSetInt("/instrumentation/dme/switch-position", 1);
1131 fgSetString("/instrumentation/dme/frequencies/source",
1132 "/instrumentation/nav[0]/frequencies/selected-mhz");
1133 } else if (opt == "nav2") {
1134 fgSetInt("/instrumentation/dme/switch-position", 3);
1135 fgSetString("/instrumentation/dme/frequencies/source",
1136 "/instrumentation/nav[1]/frequencies/selected-mhz");
1138 fgSetInt("/instrumentation/dme/switch-position", 2);
1139 fgSetString("/instrumentation/dme/frequencies/source",
1140 "/instrumentation/dme/frequencies/selected-mhz");
1141 fgSetString("/instrumentation/dme/frequencies/selected-mhz", arg);
1143 return FG_OPTIONS_OK;
1147 fgOptLivery( const char *arg )
1150 string livery_path = "livery/" + opt;
1151 fgSetString("/sim/model/texture-path", livery_path.c_str() );
1152 return FG_OPTIONS_OK;
1156 fgOptScenario( const char *arg )
1158 SGPropertyNode_ptr ai_node = fgGetNode( "/sim/ai", true );
1159 vector<SGPropertyNode_ptr> scenarii = ai_node->getChildren( "scenario" );
1161 for ( size_t i = 0; i < scenarii.size(); ++i ) {
1162 int ind = scenarii[i]->getIndex();
1163 if ( index < ind ) {
1167 SGPropertyNode_ptr scenario = ai_node->getNode( "scenario", index + 1, true );
1168 scenario->setStringValue( arg );
1169 ai_node->setBoolValue( "enabled", true );
1170 return FG_OPTIONS_OK;
1174 fgOptRunway( const char *arg )
1176 fgSetString("/sim/presets/runway", arg );
1177 fgSetBool("/sim/presets/runway-requested", true );
1178 return FG_OPTIONS_OK;
1182 fgOptParking( const char *arg )
1184 cerr << "Processing argument " << arg << endl;
1185 fgSetString("/sim/presets/parking", arg );
1186 fgSetBool ("/sim/presets/parking-requested", true );
1187 return FG_OPTIONS_OK;
1191 fgOptVersion( const char *arg )
1193 cerr << VERSION << endl;
1194 cerr << "FG_ROOT=" << globals->get_fg_root() << endl;
1195 cerr << "FG_HOME=" << fgGetString("/sim/fg-home") << endl;
1196 return FG_OPTIONS_EXIT;
1199 static map<string,size_t> fgOptionMap;
1202 option has_param type property b_param s_param func
1205 option : name of the option
1206 has_param : option is --name=value if true or --name if false
1207 type : OPTION_BOOL - property is a boolean
1208 OPTION_STRING - property is a string
1209 OPTION_DOUBLE - property is a double
1210 OPTION_INT - property is an integer
1211 OPTION_CHANNEL - name of option is the name of a channel
1212 OPTION_FUNC - the option trigger a function
1213 b_param : if type==OPTION_BOOL,
1214 value set to the property (has_param is false for boolean)
1215 s_param : if type==OPTION_STRING,
1216 value set to the property if has_param is false
1217 func : function called if type==OPTION_FUNC. if has_param is true,
1218 the value is passed to the function as a string, otherwise,
1221 For OPTION_DOUBLE and OPTION_INT, the parameter value is converted into a
1222 double or an integer and set to the property.
1224 For OPTION_CHANNEL, add_channel is called with the parameter value as the
1228 enum OptionType { OPTION_BOOL, OPTION_STRING, OPTION_DOUBLE, OPTION_INT, OPTION_CHANNEL, OPTION_FUNC };
1232 enum OptionType type;
1233 const char *property;
1235 const char *s_param;
1236 int (*func)( const char * );
1237 } fgOptionArray[] = {
1239 {"language", true, OPTION_FUNC, "", false, "", fgOptLanguage },
1240 {"disable-game-mode", false, OPTION_BOOL, "/sim/startup/game-mode", false, "", 0 },
1241 {"enable-game-mode", false, OPTION_BOOL, "/sim/startup/game-mode", true, "", 0 },
1242 {"disable-splash-screen", false, OPTION_BOOL, "/sim/startup/splash-screen", false, "", 0 },
1243 {"enable-splash-screen", false, OPTION_BOOL, "/sim/startup/splash-screen", true, "", 0 },
1244 {"disable-intro-music", false, OPTION_BOOL, "/sim/startup/intro-music", false, "", 0 },
1245 {"enable-intro-music", false, OPTION_BOOL, "/sim/startup/intro-music", true, "", 0 },
1246 {"disable-mouse-pointer", false, OPTION_STRING, "/sim/startup/mouse-pointer", false, "disabled", 0 },
1247 {"enable-mouse-pointer", false, OPTION_STRING, "/sim/startup/mouse-pointer", false, "enabled", 0 },
1248 {"disable-random-objects", false, OPTION_BOOL, "/sim/rendering/random-objects", false, "", 0 },
1249 {"enable-random-objects", false, OPTION_BOOL, "/sim/rendering/random-objects", true, "", 0 },
1250 {"disable-real-weather-fetch", false, OPTION_BOOL, "/environment/params/real-world-weather-fetch", false, "", 0 },
1251 {"enable-real-weather-fetch", false, OPTION_BOOL, "/environment/params/real-world-weather-fetch", true, "", 0 },
1252 {"disable-ai-models", false, OPTION_BOOL, "/sim/ai/enabled", false, "", 0 },
1253 {"enable-ai-models", false, OPTION_BOOL, "/sim/ai/enabled", true, "", 0 },
1254 {"disable-freeze", false, OPTION_BOOL, "/sim/freeze/master", false, "", 0 },
1255 {"enable-freeze", false, OPTION_BOOL, "/sim/freeze/master", true, "", 0 },
1256 {"disable-fuel-freeze", false, OPTION_BOOL, "/sim/freeze/fuel", false, "", 0 },
1257 {"enable-fuel-freeze", false, OPTION_BOOL, "/sim/freeze/fuel", true, "", 0 },
1258 {"disable-clock-freeze", false, OPTION_BOOL, "/sim/freeze/clock", false, "", 0 },
1259 {"enable-clock-freeze", false, OPTION_BOOL, "/sim/freeze/clock", true, "", 0 },
1260 {"disable-hud-3d", false, OPTION_BOOL, "/sim/hud/enable3d", false, "", 0 },
1261 {"enable-hud-3d", false, OPTION_BOOL, "/sim/hud/enable3d", true, "", 0 },
1262 {"disable-anti-alias-hud", false, OPTION_BOOL, "/sim/hud/color/antialiased", false, "", 0 },
1263 {"enable-anti-alias-hud", false, OPTION_BOOL, "/sim/hud/color/antialiased", true, "", 0 },
1264 {"control", true, OPTION_STRING, "/sim/control-mode", false, "", 0 },
1265 {"disable-auto-coordination", false, OPTION_BOOL, "/sim/auto-coordination", false, "", 0 },
1266 {"enable-auto-coordination", false, OPTION_BOOL, "/sim/auto-coordination", true, "", 0 },
1267 {"browser-app", true, OPTION_STRING, "/sim/startup/browser-app", false, "", 0 },
1268 {"disable-hud", false, OPTION_BOOL, "/sim/hud/visibility", false, "", 0 },
1269 {"enable-hud", false, OPTION_BOOL, "/sim/hud/visibility", true, "", 0 },
1270 {"disable-panel", false, OPTION_BOOL, "/sim/panel/visibility", false, "", 0 },
1271 {"enable-panel", false, OPTION_BOOL, "/sim/panel/visibility", true, "", 0 },
1272 {"disable-sound", false, OPTION_BOOL, "/sim/sound/pause", true, "", 0 },
1273 {"enable-sound", false, OPTION_BOOL, "/sim/sound/pause", false, "", 0 },
1274 {"airport", true, OPTION_STRING, "/sim/presets/airport-id", false, "", 0 },
1275 {"runway", true, OPTION_FUNC, "", false, "", fgOptRunway },
1276 {"vor", true, OPTION_FUNC, "", false, "", fgOptVOR },
1277 {"ndb", true, OPTION_FUNC, "", false, "", fgOptNDB },
1278 {"carrier", true, OPTION_FUNC, "", false, "", fgOptCarrier },
1279 {"parkpos", true, OPTION_FUNC, "", false, "", fgOptParkpos },
1280 {"fix", true, OPTION_FUNC, "", false, "", fgOptFIX },
1281 {"offset-distance", true, OPTION_DOUBLE, "/sim/presets/offset-distance-nm", false, "", 0 },
1282 {"offset-azimuth", true, OPTION_DOUBLE, "/sim/presets/offset-azimuth-deg", false, "", 0 },
1283 {"lon", true, OPTION_FUNC, "", false, "", fgOptLon },
1284 {"lat", true, OPTION_FUNC, "", false, "", fgOptLat },
1285 {"altitude", true, OPTION_FUNC, "", false, "", fgOptAltitude },
1286 {"uBody", true, OPTION_FUNC, "", false, "", fgOptUBody },
1287 {"vBody", true, OPTION_FUNC, "", false, "", fgOptVBody },
1288 {"wBody", true, OPTION_FUNC, "", false, "", fgOptWBody },
1289 {"vNorth", true, OPTION_FUNC, "", false, "", fgOptVNorth },
1290 {"vEast", true, OPTION_FUNC, "", false, "", fgOptVEast },
1291 {"vDown", true, OPTION_FUNC, "", false, "", fgOptVDown },
1292 {"vc", true, OPTION_FUNC, "", false, "", fgOptVc },
1293 {"mach", true, OPTION_FUNC, "", false, "", fgOptMach },
1294 {"heading", true, OPTION_DOUBLE, "/sim/presets/heading-deg", false, "", 0 },
1295 {"roll", true, OPTION_DOUBLE, "/sim/presets/roll-deg", false, "", 0 },
1296 {"pitch", true, OPTION_DOUBLE, "/sim/presets/pitch-deg", false, "", 0 },
1297 {"glideslope", true, OPTION_DOUBLE, "/sim/presets/glideslope-deg", false, "", 0 },
1298 {"roc", true, OPTION_FUNC, "", false, "", fgOptRoc },
1299 {"fg-root", true, OPTION_FUNC, "", false, "", fgOptFgRoot },
1300 {"fg-scenery", true, OPTION_FUNC, "", false, "", fgOptFgScenery },
1301 {"fdm", true, OPTION_STRING, "/sim/flight-model", false, "", 0 },
1302 {"aero", true, OPTION_STRING, "/sim/aero", false, "", 0 },
1303 {"aircraft-dir", true, OPTION_STRING, "/sim/aircraft-dir", false, "", 0 },
1304 {"model-hz", true, OPTION_INT, "/sim/model-hz", false, "", 0 },
1305 {"speed", true, OPTION_INT, "/sim/speed-up", false, "", 0 },
1306 {"trim", false, OPTION_BOOL, "/sim/presets/trim", true, "", 0 },
1307 {"notrim", false, OPTION_BOOL, "/sim/presets/trim", false, "", 0 },
1308 {"on-ground", false, OPTION_BOOL, "/sim/presets/onground", true, "", 0 },
1309 {"in-air", false, OPTION_BOOL, "/sim/presets/onground", false, "", 0 },
1310 {"fog-disable", false, OPTION_STRING, "/sim/rendering/fog", false, "disabled", 0 },
1311 {"fog-fastest", false, OPTION_STRING, "/sim/rendering/fog", false, "fastest", 0 },
1312 {"fog-nicest", false, OPTION_STRING, "/sim/rendering/fog", false, "nicest", 0 },
1313 {"disable-horizon-effect", false, OPTION_BOOL, "/sim/rendering/horizon-effect", false, "", 0 },
1314 {"enable-horizon-effect", false, OPTION_BOOL, "/sim/rendering/horizon-effect", true, "", 0 },
1315 {"disable-enhanced-lighting", false, OPTION_BOOL, "/sim/rendering/enhanced-lighting", false, "", 0 },
1316 {"enable-enhanced-lighting", false, OPTION_BOOL, "/sim/rendering/enhanced-lighting", true, "", 0 },
1317 {"disable-distance-attenuation", false, OPTION_BOOL, "/sim/rendering/distance-attenuation", false, "", 0 },
1318 {"enable-distance-attenuation", false, OPTION_BOOL, "/sim/rendering/distance-attenuation", true, "", 0 },
1319 {"disable-specular-highlight", false, OPTION_BOOL, "/sim/rendering/specular-highlight", false, "", 0 },
1320 {"enable-specular-highlight", false, OPTION_BOOL, "/sim/rendering/specular-highlight", true, "", 0 },
1321 {"disable-clouds", false, OPTION_BOOL, "/environment/clouds/status", false, "", 0 },
1322 {"enable-clouds", false, OPTION_BOOL, "/environment/clouds/status", true, "", 0 },
1323 {"disable-clouds3d", false, OPTION_BOOL, "/sim/rendering/clouds3d-enable", false, "", 0 },
1324 {"enable-clouds3d", false, OPTION_BOOL, "/sim/rendering/clouds3d-enable", true, "", 0 },
1325 {"fov", true, OPTION_FUNC, "", false, "", fgOptFov },
1326 {"aspect-ratio-multiplier", true, OPTION_DOUBLE, "/sim/current-view/aspect-ratio-multiplier", false, "", 0 },
1327 {"disable-fullscreen", false, OPTION_BOOL, "/sim/startup/fullscreen", false, "", 0 },
1328 {"enable-fullscreen", false, OPTION_BOOL, "/sim/startup/fullscreen", true, "", 0 },
1329 {"disable-save-on-exit", false, OPTION_BOOL, "/sim/startup/save-on-exit", false, "", 0 },
1330 {"enable-save-on-exit", false, OPTION_BOOL, "/sim/startup/save-on-exit", true, "", 0 },
1331 {"shading-flat", false, OPTION_BOOL, "/sim/rendering/shading", false, "", 0 },
1332 {"shading-smooth", false, OPTION_BOOL, "/sim/rendering/shading", true, "", 0 },
1333 {"disable-skyblend", false, OPTION_BOOL, "/sim/rendering/skyblend", false, "", 0 },
1334 {"enable-skyblend", false, OPTION_BOOL, "/sim/rendering/skyblend", true, "", 0 },
1335 {"disable-textures", false, OPTION_BOOL, "/sim/rendering/textures", false, "", 0 },
1336 {"enable-textures", false, OPTION_BOOL, "/sim/rendering/textures", true, "", 0 },
1337 {"texture-filtering", false, OPTION_INT, "/sim/rendering/filtering", 1, "", 0 },
1338 {"disable-wireframe", false, OPTION_BOOL, "/sim/rendering/wireframe", false, "", 0 },
1339 {"enable-wireframe", false, OPTION_BOOL, "/sim/rendering/wireframe", true, "", 0 },
1340 {"geometry", true, OPTION_FUNC, "", false, "", fgOptGeometry },
1341 {"bpp", true, OPTION_FUNC, "", false, "", fgOptBpp },
1342 {"units-feet", false, OPTION_STRING, "/sim/startup/units", false, "feet", 0 },
1343 {"units-meters", false, OPTION_STRING, "/sim/startup/units", false, "meters", 0 },
1344 {"timeofday", true, OPTION_STRING, "/sim/startup/time-offset-type", false, "noon", 0 },
1345 {"season", true, OPTION_STRING, "/sim/startup/season", false, "summer", 0 },
1346 {"time-offset", true, OPTION_FUNC, "", false, "", fgOptTimeOffset },
1347 {"time-match-real", false, OPTION_STRING, "/sim/startup/time-offset-type", false, "system-offset", 0 },
1348 {"time-match-local", false, OPTION_STRING, "/sim/startup/time-offset-type", false, "latitude-offset", 0 },
1349 {"start-date-sys", true, OPTION_FUNC, "", false, "", fgOptStartDateSys },
1350 {"start-date-lat", true, OPTION_FUNC, "", false, "", fgOptStartDateLat },
1351 {"start-date-gmt", true, OPTION_FUNC, "", false, "", fgOptStartDateGmt },
1352 {"hud-tris", false, OPTION_STRING, "/sim/hud/frame-stat-type", false, "tris", 0 },
1353 {"hud-culled", false, OPTION_STRING, "/sim/hud/frame-stat-type", false, "culled", 0 },
1354 {"atcsim", true, OPTION_CHANNEL, "", false, "dummy", 0 },
1355 {"atlas", true, OPTION_CHANNEL, "", false, "", 0 },
1356 {"httpd", true, OPTION_CHANNEL, "", false, "", 0 },
1357 #ifdef FG_JPEG_SERVER
1358 {"jpg-httpd", true, OPTION_CHANNEL, "", false, "", 0 },
1360 {"native", true, OPTION_CHANNEL, "", false, "", 0 },
1361 {"native-ctrls", true, OPTION_CHANNEL, "", false, "", 0 },
1362 {"native-fdm", true, OPTION_CHANNEL, "", false, "", 0 },
1363 {"native-gui", true, OPTION_CHANNEL, "", false, "", 0 },
1364 {"opengc", true, OPTION_CHANNEL, "", false, "", 0 },
1365 {"AV400", true, OPTION_CHANNEL, "", false, "", 0 },
1366 {"garmin", true, OPTION_CHANNEL, "", false, "", 0 },
1367 {"nmea", true, OPTION_CHANNEL, "", false, "", 0 },
1368 {"generic", true, OPTION_CHANNEL, "", false, "", 0 },
1369 {"props", true, OPTION_CHANNEL, "", false, "", 0 },
1370 {"telnet", true, OPTION_CHANNEL, "", false, "", 0 },
1371 {"pve", true, OPTION_CHANNEL, "", false, "", 0 },
1372 {"ray", true, OPTION_CHANNEL, "", false, "", 0 },
1373 {"rul", true, OPTION_CHANNEL, "", false, "", 0 },
1374 {"joyclient", true, OPTION_CHANNEL, "", false, "", 0 },
1375 {"jsclient", true, OPTION_CHANNEL, "", false, "", 0 },
1376 {"proxy", true, OPTION_FUNC, "", false, "", fgSetupProxy },
1377 {"callsign", true, OPTION_STRING, "sim/multiplay/callsign", false, "", 0 },
1378 {"multiplay", true, OPTION_CHANNEL, "", false, "", 0 },
1379 {"trace-read", true, OPTION_FUNC, "", false, "", fgOptTraceRead },
1380 {"trace-write", true, OPTION_FUNC, "", false, "", fgOptTraceWrite },
1381 {"log-level", true, OPTION_FUNC, "", false, "", fgOptLogLevel },
1382 {"view-offset", true, OPTION_FUNC, "", false, "", fgOptViewOffset },
1383 {"visibility", true, OPTION_FUNC, "", false, "", fgOptVisibilityMeters },
1384 {"visibility-miles", true, OPTION_FUNC, "", false, "", fgOptVisibilityMiles },
1385 {"random-wind", false, OPTION_FUNC, "", false, "", fgOptRandomWind },
1386 {"wind", true, OPTION_FUNC, "", false, "", fgOptWind },
1387 {"turbulence", true, OPTION_FUNC, "", false, "", fgOptTurbulence },
1388 {"ceiling", true, OPTION_FUNC, "", false, "", fgOptCeiling },
1389 {"wp", true, OPTION_FUNC, "", false, "", fgOptWp },
1390 {"flight-plan", true, OPTION_FUNC, "", false, "", fgOptFlightPlan },
1391 {"config", true, OPTION_FUNC, "", false, "", fgOptConfig },
1392 {"aircraft", true, OPTION_STRING, "/sim/aircraft", false, "", 0 },
1393 {"vehicle", true, OPTION_STRING, "/sim/aircraft", false, "", 0 },
1394 {"failure", true, OPTION_FUNC, "", false, "", fgOptFailure },
1395 {"com1", true, OPTION_DOUBLE, "/instrumentation/comm[0]/frequencies/selected-mhz", false, "", 0 },
1396 {"com2", true, OPTION_DOUBLE, "/instrumentation/comm[1]/frequencies/selected-mhz", false, "", 0 },
1397 {"nav1", true, OPTION_FUNC, "", false, "", fgOptNAV1 },
1398 {"nav2", true, OPTION_FUNC, "", false, "", fgOptNAV2 },
1399 {"adf", true, OPTION_FUNC, "", false, "", fgOptADF },
1400 {"dme", true, OPTION_FUNC, "", false, "", fgOptDME },
1401 {"min-status", true, OPTION_STRING, "/sim/aircraft-min-status", false, "all", 0 },
1402 {"livery", true, OPTION_FUNC, "", false, "", fgOptLivery },
1403 {"ai-scenario", true, OPTION_FUNC, "", false, "", fgOptScenario },
1404 {"parking-id", true, OPTION_FUNC, "", false, "", fgOptParking },
1405 {"version", false, OPTION_FUNC, "", false, "", fgOptVersion },
1410 // Set a property for the --prop: option. Syntax: --prop:[<type>:]<name>=<value>
1411 // <type> can be "double" etc. but also only the first letter "d".
1412 // Examples: --prop:alpha=1 --prop:bool:beta=true --prop:d:gamma=0.123
1414 set_property(const string& arg)
1416 string::size_type pos = arg.find('=');
1417 if (pos == arg.npos || pos == 0 || pos + 1 == arg.size())
1420 string name = arg.substr(0, pos);
1421 string value = arg.substr(pos + 1);
1423 pos = name.find(':');
1425 if (pos != name.npos && pos != 0 && pos + 1 != name.size()) {
1426 type = name.substr(0, pos);
1427 name = name.substr(pos + 1);
1429 SGPropertyNode *n = fgGetNode(name.c_str(), true);
1431 bool writable = n->getAttribute(SGPropertyNode::WRITE);
1433 n->setAttribute(SGPropertyNode::WRITE, true);
1437 ret = n->setUnspecifiedValue(value.c_str());
1438 else if (type == "s" || type == "string")
1439 ret = n->setStringValue(value.c_str());
1440 else if (type == "d" || type == "double")
1441 ret = n->setDoubleValue(strtod(value.c_str(), 0));
1442 else if (type == "f" || type == "float")
1443 ret = n->setFloatValue(atof(value.c_str()));
1444 else if (type == "l" || type == "long")
1445 ret = n->setLongValue(strtol(value.c_str(), 0, 0));
1446 else if (type == "i" || type == "int")
1447 ret = n->setIntValue(atoi(value.c_str()));
1448 else if (type == "b" || type == "bool")
1449 ret = n->setBoolValue(value == "true" || atoi(value.c_str()) != 0);
1452 n->setAttribute(SGPropertyNode::WRITE, false);
1457 // Parse a single option
1459 parse_option (const string& arg)
1461 if ( fgOptionMap.size() == 0 ) {
1463 OptionDesc *pt = &fgOptionArray[ 0 ];
1464 while ( pt->option != 0 ) {
1465 fgOptionMap[ pt->option ] = i;
1472 if ( (arg == "--help") || (arg == "-h") ) {
1473 // help/usage request
1474 return(FG_OPTIONS_HELP);
1475 } else if ( (arg == "--verbose") || (arg == "-v") ) {
1476 // verbose help/usage request
1477 return(FG_OPTIONS_VERBOSE_HELP);
1478 } else if ( arg.find( "--show-aircraft") == 0) {
1479 return(FG_OPTIONS_SHOW_AIRCRAFT);
1480 } else if ( arg.find( "--prop:" ) == 0 ) {
1481 if (!set_property(arg.substr(7))) {
1482 SG_LOG( SG_GENERAL, SG_ALERT, "Bad property assignment: " << arg );
1483 return FG_OPTIONS_ERROR;
1485 } else if ( arg.find( "--" ) == 0 ) {
1486 size_t pos = arg.find( '=' );
1487 string arg_name, arg_value;
1488 if ( pos == string::npos ) {
1489 arg_name = arg.substr( 2 );
1491 arg_name = arg.substr( 2, pos - 2 );
1492 arg_value = arg.substr( pos + 1);
1494 map<string,size_t>::iterator it = fgOptionMap.find( arg_name );
1495 if ( it != fgOptionMap.end() ) {
1496 OptionDesc *pt = &fgOptionArray[ it->second ];
1497 switch ( pt->type ) {
1499 fgSetBool( pt->property, pt->b_param );
1502 if ( pt->has_param && !arg_value.empty() ) {
1503 fgSetString( pt->property, arg_value.c_str() );
1504 } else if ( !pt->has_param && arg_value.empty() ) {
1505 fgSetString( pt->property, pt->s_param );
1506 } else if ( pt->has_param ) {
1507 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1508 return FG_OPTIONS_ERROR;
1510 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' does not have a parameter" );
1511 return FG_OPTIONS_ERROR;
1515 if ( !arg_value.empty() ) {
1516 fgSetDouble( pt->property, atof( arg_value ) );
1518 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1519 return FG_OPTIONS_ERROR;
1523 if ( !arg_value.empty() ) {
1524 fgSetInt( pt->property, atoi( arg_value ) );
1526 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1527 return FG_OPTIONS_ERROR;
1530 case OPTION_CHANNEL:
1531 if ( pt->has_param && !arg_value.empty() ) {
1532 add_channel( pt->option, arg_value );
1533 } else if ( !pt->has_param && arg_value.empty() ) {
1534 add_channel( pt->option, pt->s_param );
1535 } else if ( pt->has_param ) {
1536 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1537 return FG_OPTIONS_ERROR;
1539 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' does not have a parameter" );
1540 return FG_OPTIONS_ERROR;
1544 if ( pt->has_param && !arg_value.empty() ) {
1545 return pt->func( arg_value.c_str() );
1546 } else if ( !pt->has_param && arg_value.empty() ) {
1547 return pt->func( 0 );
1548 } else if ( pt->has_param ) {
1549 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1550 return FG_OPTIONS_ERROR;
1552 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' does not have a parameter" );
1553 return FG_OPTIONS_ERROR;
1558 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" );
1559 return FG_OPTIONS_ERROR;
1562 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" );
1563 return FG_OPTIONS_ERROR;
1566 return FG_OPTIONS_OK;
1570 // Parse the command line options
1572 fgParseArgs (int argc, char **argv)
1574 bool in_options = true;
1575 bool verbose = false;
1578 SG_LOG(SG_GENERAL, SG_INFO, "Processing command line arguments");
1580 for (int i = 1; i < argc; i++) {
1581 string arg = argv[i];
1583 if (in_options && (arg.find('-') == 0)) {
1587 int result = parse_option(arg);
1588 if ((result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR))
1591 else if (result == FG_OPTIONS_VERBOSE_HELP)
1594 else if (result == FG_OPTIONS_SHOW_AIRCRAFT) {
1595 fgOptLogLevel( "alert" );
1596 SGPath path( globals->get_fg_root() );
1597 path.append("Aircraft");
1598 fgShowAircraft(path, true);
1602 else if (result == FG_OPTIONS_EXIT)
1607 SG_LOG(SG_GENERAL, SG_INFO,
1608 "Reading command-line property file " << arg);
1609 readProperties(arg, globals->get_props());
1614 fgOptLogLevel( "alert" );
1619 SG_LOG(SG_GENERAL, SG_INFO, "Finished command line arguments");
1623 // Parse config file options
1625 fgParseOptions (const string& path) {
1626 sg_gzifstream in( path );
1627 if ( !in.is_open() ) {
1631 SG_LOG( SG_GENERAL, SG_INFO, "Processing config file: " << path );
1634 while ( ! in.eof() ) {
1636 getline( in, line, '\n' );
1638 // catch extraneous (DOS) line ending character
1640 for (i = line.length(); i > 0; i--)
1641 if (line[i - 1] > 32)
1643 line = line.substr( 0, i );
1645 if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
1646 cerr << endl << "Config file parse error: " << path << " '"
1647 << line << "'" << endl;
1656 // Print usage message
1658 fgUsage (bool verbose)
1660 SGPropertyNode *locale = globals->get_locale();
1662 SGPropertyNode options_root;
1664 SG_LOG( SG_GENERAL, SG_ALERT, "" ); // To popup the console on Windows
1668 fgLoadProps("options.xml", &options_root);
1669 } catch (const sg_exception &) {
1670 cout << "Unable to read the help file." << endl;
1671 cout << "Make sure the file options.xml is located in the FlightGear base directory," << endl;
1672 cout << "and the location of the base directory is specified by setting $FG_ROOT or" << endl;
1673 cout << "by adding --fg-root=path as a program argument." << endl;
1678 SGPropertyNode *options = options_root.getNode("options");
1680 SG_LOG( SG_GENERAL, SG_ALERT,
1681 "Error reading options.xml: <options> directive not found." );
1685 SGPropertyNode *usage = locale->getNode(options->getStringValue("usage"));
1687 cout << "Usage: " << usage->getStringValue() << endl;
1690 vector<SGPropertyNode_ptr>section = options->getChildren("section");
1691 for (unsigned int j = 0; j < section.size(); j++) {
1694 vector<SGPropertyNode_ptr>option = section[j]->getChildren("option");
1695 for (unsigned int k = 0; k < option.size(); k++) {
1697 SGPropertyNode *name = option[k]->getNode("name");
1698 SGPropertyNode *short_name = option[k]->getNode("short");
1699 SGPropertyNode *key = option[k]->getNode("key");
1700 SGPropertyNode *arg = option[k]->getNode("arg");
1701 bool brief = option[k]->getNode("brief") != 0;
1703 if ((brief || verbose) && name) {
1704 string tmp = name->getStringValue();
1708 tmp.append(key->getStringValue());
1712 tmp.append(arg->getStringValue());
1716 tmp.append(short_name->getStringValue());
1719 if (tmp.size() <= 25) {
1722 msg.append( 27-tmp.size(), ' ');
1726 msg.append(32, ' ');
1728 // There may be more than one <description> tag assosiated
1731 vector<SGPropertyNode_ptr> desc;
1732 desc = option[k]->getChildren("description");
1733 if (desc.size() > 0) {
1734 for ( unsigned int l = 0; l < desc.size(); l++) {
1736 // There may be more than one translation line.
1738 string t = desc[l]->getStringValue();
1739 SGPropertyNode *n = locale->getNode("strings");
1740 vector<SGPropertyNode_ptr>trans_desc =
1741 n->getChildren(t.substr(8).c_str());
1743 for ( unsigned int m = 0; m < trans_desc.size(); m++ ) {
1744 string t_str = trans_desc[m]->getStringValue();
1746 if ((m > 0) || ((l > 0) && m == 0)) {
1747 msg.append( 32, ' ');
1750 // If the string is too large to fit on the screen,
1751 // then split it up in several pieces.
1753 while ( t_str.size() > 47 ) {
1755 unsigned int m = t_str.rfind(' ', 47);
1756 msg += t_str.substr(0, m) + '\n';
1757 msg.append( 32, ' ');
1759 t_str.erase(t_str.begin(), t_str.begin() + m + 1);
1761 msg += t_str + '\n';
1768 SGPropertyNode *name;
1769 name = locale->getNode(section[j]->getStringValue("name"));
1771 if (!msg.empty() && name) {
1772 cout << endl << name->getStringValue() << ":" << endl;
1780 cout << "For a complete list of options use --help --verbose" << endl;
1783 cout << "Hit a key to continue..." << endl;
1788 // A simple function to return an integer depending on the position
1789 // of the status string within the array in order to determine the hierarchy.
1790 unsigned int getNumMaturity(const char * str)
1792 // changes should also be reflected in $FG_ROOT/data/options.xml &
1793 // $FG_ROOT/data/Translations/string-default.xml
1794 const char levels[][20]= {"alpha","beta","early-production","production",0};
1796 for (unsigned int i=0; i<(sizeof(levels)/sizeof(levels[0])-1);i++)
1797 if (strcmp(str,levels[i])==0)
1804 static void fgSearchAircraft(const SGPath &path, string_list &aircraft,
1809 ulDir *dirp = ulOpenDir(path.str().c_str());
1811 cerr << "Unable to open aircraft directory '" << path.str() << '\'' << endl;
1815 while ((dire = ulReadDir(dirp)) != NULL) {
1818 if (dire->d_isdir) {
1819 if (recursive && strcmp("CVS", dire->d_name)
1820 && strcmp(".", dire->d_name) && strcmp("..", dire->d_name))
1823 next.append(dire->d_name);
1825 fgSearchAircraft(next, aircraft, true);
1827 } else if ((ptr = strstr(dire->d_name, "-set.xml")) && (ptr[8] == '\0')) {
1829 SGPath afile = path;
1830 afile.append(dire->d_name);
1834 SGPropertyNode root;
1836 readProperties(afile.str(), &root);
1841 SGPropertyNode *desc = NULL;
1842 SGPropertyNode *status = NULL;
1844 SGPropertyNode *node = root.getNode("sim");
1846 desc = node->getNode("description");
1847 // if a status tag is found, read it in
1848 if (node->hasValue("status"))
1849 status = node->getNode("status");
1852 //additionally display status information where it is available
1854 string descStr(" ");
1855 descStr += dire->d_name;
1857 if (descStr.size() <= 27+3) {
1858 descStr.append(29+3-descStr.size(), ' ');
1861 descStr.append( 32, ' ');
1863 descStr += desc->getStringValue();
1866 SGPropertyNode * required_status
1867 = fgGetNode ("/sim/aircraft-min-status", true);
1869 // If the node holds the value "all", then there wasn't any status
1870 // level specified, so we simply go ahead and output ALL aircraft
1871 if (strcmp(required_status->getStringValue(),"all")==0) {
1872 aircraft.push_back(descStr);
1876 // If the node doesn't hold "all" as its value, then we are supposed
1877 // to show only aircraft meeting specific status (development status)
1880 if (node->hasValue("status")) {
1881 //Compare (minimally) required status level with actual aircraft status:
1882 if ( getNumMaturity(status->getStringValue() ) >=
1883 getNumMaturity(required_status->getStringValue() ) )
1884 aircraft.push_back(descStr); }
1896 * Search in the current directory, and in on directory deeper
1897 * for <aircraft>-set.xml configuration files and show the aircaft name
1898 * and the contents of the<description> tag in a sorted manner.
1900 * @parampath the directory to search for configuration files
1901 * @param recursive defines whether the directory should be searched recursively
1903 void fgShowAircraft(const SGPath &path, bool recursive) {
1904 string_list aircraft;
1906 fgSearchAircraft( path, aircraft, recursive );
1908 sort(aircraft.begin(), aircraft.end());
1909 SG_LOG( SG_GENERAL, SG_ALERT, "" ); // To popup the console on Windows
1910 cout << "Available aircraft:" << endl;
1911 for ( unsigned int i = 0; i < aircraft.size(); i++ ) {
1912 cout << aircraft[i] << endl;
1915 cout << "Hit a key to continue..." << endl;