1 // options.cxx -- class to handle command line options
3 // Written by Curtis Olson, started April 1998.
5 // Copyright (C) 1998 Curtis L. Olson - http://www.flightgear.org/~curt
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28 #include <simgear/compiler.h>
29 #include <simgear/structure/exception.hxx>
30 #include <simgear/debug/logstream.hxx>
31 #include <simgear/timing/sg_time.hxx>
32 #include <simgear/misc/sg_dir.hxx>
34 #include <math.h> // rint()
36 #include <stdlib.h> // atof(), atoi()
37 #include <string.h> // strcmp()
43 #include <simgear/math/sg_random.h>
44 #include <simgear/props/props_io.hxx>
45 #include <simgear/misc/sgstream.hxx>
46 #include <simgear/misc/sg_path.hxx>
47 #include <simgear/scene/material/mat.hxx>
48 #include <simgear/sound/soundmgr_openal.hxx>
49 #include <Autopilot/route_mgr.hxx>
52 #include "globals.hxx"
53 #include "fg_init.hxx"
54 #include "fg_props.hxx"
55 #include "options.hxx"
57 #include "viewmgr.hxx"
58 #include <Main/viewer.hxx>
59 #include <simgear/version.h>
68 #define VERSION "CVS "__DATE__
71 #define NEW_DEFAULT_MODEL_HZ 120
79 FG_OPTIONS_VERBOSE_HELP = 4,
80 FG_OPTIONS_SHOW_AIRCRAFT = 5,
81 FG_OPTIONS_SHOW_SOUND_DEVICES = 6
85 atof( const string& str )
87 return ::atof( str.c_str() );
91 atoi( const string& str )
93 return ::atoi( str.c_str() );
97 * Set a few fail-safe default property values.
99 * These should all be set in $FG_ROOT/preferences.xml, but just
100 * in case, we provide some initial sane values here. This method
101 * should be invoked *before* reading any init files.
106 // set a possibly independent location for scenery data
107 const char *envp = ::getenv( "FG_SCENERY" );
109 if ( envp != NULL ) {
110 // fg_root could be anywhere, so default to environmental
111 // variable $FG_ROOT if it is set.
112 globals->set_fg_scenery(envp);
114 // Otherwise, default to Scenery being in $FG_ROOT/Scenery
115 globals->set_fg_scenery("");
118 // Position (deliberately out of range)
119 fgSetDouble("/position/longitude-deg", 9999.0);
120 fgSetDouble("/position/latitude-deg", 9999.0);
121 fgSetDouble("/position/altitude-ft", -9999.0);
124 fgSetDouble("/orientation/heading-deg", 9999.0);
125 fgSetDouble("/orientation/roll-deg", 0.0);
126 fgSetDouble("/orientation/pitch-deg", 0.424);
129 fgSetDouble("/velocities/uBody-fps", 0.0);
130 fgSetDouble("/velocities/vBody-fps", 0.0);
131 fgSetDouble("/velocities/wBody-fps", 0.0);
132 fgSetDouble("/velocities/speed-north-fps", 0.0);
133 fgSetDouble("/velocities/speed-east-fps", 0.0);
134 fgSetDouble("/velocities/speed-down-fps", 0.0);
135 fgSetDouble("/velocities/airspeed-kt", 0.0);
136 fgSetDouble("/velocities/mach", 0.0);
139 fgSetDouble("/sim/presets/longitude-deg", 9999.0);
140 fgSetDouble("/sim/presets/latitude-deg", 9999.0);
141 fgSetDouble("/sim/presets/altitude-ft", -9999.0);
143 fgSetDouble("/sim/presets/heading-deg", 9999.0);
144 fgSetDouble("/sim/presets/roll-deg", 0.0);
145 fgSetDouble("/sim/presets/pitch-deg", 0.424);
147 fgSetString("/sim/presets/speed-set", "knots");
148 fgSetDouble("/sim/presets/airspeed-kt", 0.0);
149 fgSetDouble("/sim/presets/mach", 0.0);
150 fgSetDouble("/sim/presets/uBody-fps", 0.0);
151 fgSetDouble("/sim/presets/vBody-fps", 0.0);
152 fgSetDouble("/sim/presets/wBody-fps", 0.0);
153 fgSetDouble("/sim/presets/speed-north-fps", 0.0);
154 fgSetDouble("/sim/presets/speed-east-fps", 0.0);
155 fgSetDouble("/sim/presets/speed-down-fps", 0.0);
157 fgSetBool("/sim/presets/onground", true);
158 fgSetBool("/sim/presets/trim", false);
161 fgSetBool("/sim/startup/game-mode", false);
162 fgSetBool("/sim/startup/splash-screen", true);
163 fgSetBool("/sim/startup/intro-music", true);
164 // we want mouse-pointer to have an undefined value if nothing is
165 // specified so we can do the right thing for voodoo-1/2 cards.
166 // fgSetString("/sim/startup/mouse-pointer", "disabled");
167 fgSetString("/sim/control-mode", "joystick");
168 fgSetBool("/sim/auto-coordination", false);
170 fgSetString("/sim/startup/browser-app", "webrun.bat");
171 #elif defined(__APPLE__)
172 fgSetString("/sim/startup/browser-app", "open");
174 fgSetString("/sim/startup/browser-app", "launchWebJumper");
176 envp = ::getenv( "WEBBROWSER" );
177 if (!envp) envp = "netscape";
178 fgSetString("/sim/startup/browser-app", envp);
180 fgSetString("/sim/logging/priority", "alert");
183 fgSetBool("/sim/hud/color/antialiased", false);
184 fgSetBool("/sim/hud/enable3d", true);
185 fgSetBool("/sim/hud/visibility", false);
186 fgSetBool("/sim/panel/visibility", true);
187 fgSetBool("/sim/sound/enabled", true);
188 fgSetBool("/sim/sound/working", true);
190 // Flight Model options
191 fgSetString("/sim/flight-model", "jsb");
192 fgSetString("/sim/aero", "c172");
193 fgSetInt("/sim/model-hz", NEW_DEFAULT_MODEL_HZ);
194 fgSetInt("/sim/speed-up", 1);
197 fgSetString("/sim/rendering/fog", "nicest");
198 fgSetBool("/environment/clouds/status", true);
199 fgSetBool("/sim/startup/fullscreen", false);
200 fgSetBool("/sim/rendering/shading", true);
201 fgSetBool("/sim/rendering/skyblend", true);
202 fgSetBool("/sim/rendering/textures", true);
203 fgTie( "/sim/rendering/filtering", SGGetTextureFilter, SGSetTextureFilter, false);
204 fgSetInt("/sim/rendering/filtering", 1);
205 fgSetBool("/sim/rendering/wireframe", false);
206 fgSetBool("/sim/rendering/horizon-effect", false);
207 fgSetBool("/sim/rendering/enhanced-lighting", false);
208 fgSetBool("/sim/rendering/distance-attenuation", false);
209 fgSetBool("/sim/rendering/specular-highlight", true);
210 fgSetInt("/sim/startup/xsize", 800);
211 fgSetInt("/sim/startup/ysize", 600);
212 fgSetInt("/sim/rendering/bits-per-pixel", 16);
213 fgSetString("/sim/view-mode", "pilot");
214 fgSetDouble("/sim/current-view/heading-offset-deg", 0);
217 fgSetString("/sim/startup/units", "feet");
218 fgSetString("/sim/hud/frame-stat-type", "tris");
221 fgSetInt("/sim/startup/time-offset", 0);
222 fgSetString("/sim/startup/time-offset-type", "system-offset");
223 fgSetLong("/sim/time/cur-time-override", 0);
226 fgSetBool("/sim/freeze/master", false);
227 fgSetBool("/sim/freeze/position", false);
228 fgSetBool("/sim/freeze/clock", false);
229 fgSetBool("/sim/freeze/fuel", false);
231 fgSetString("/sim/multiplay/callsign", "callsign");
232 fgSetString("/sim/multiplay/rxhost", "0");
233 fgSetString("/sim/multiplay/txhost", "0");
234 fgSetInt("/sim/multiplay/rxport", 0);
235 fgSetInt("/sim/multiplay/txport", 0);
239 parse_wind (const string &wind, double * min_hdg, double * max_hdg,
240 double * speed, double * gust)
242 string::size_type pos = wind.find('@');
243 if (pos == string::npos)
245 string dir = wind.substr(0, pos);
246 string spd = wind.substr(pos+1);
248 if (pos == string::npos) {
249 *min_hdg = *max_hdg = atof(dir.c_str());
251 *min_hdg = atof(dir.substr(0,pos).c_str());
252 *max_hdg = atof(dir.substr(pos+1).c_str());
255 if (pos == string::npos) {
256 *speed = *gust = atof(spd.c_str());
258 *speed = atof(spd.substr(0,pos).c_str());
259 *gust = atof(spd.substr(pos+1).c_str());
264 // parse a time string ([+/-]%f[:%f[:%f]]) into hours
266 parse_time(const string& time_in) {
267 char *time_str, num[256];
268 double hours, minutes, seconds;
273 time_str = (char *)time_in.c_str();
275 // printf("parse_time(): %s\n", time_str);
278 if ( strlen(time_str) ) {
279 if ( time_str[0] == '+' ) {
282 } else if ( time_str[0] == '-' ) {
287 // printf("sign = %d\n", sign);
290 if ( strlen(time_str) ) {
292 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
293 num[i] = time_str[0];
297 if ( time_str[0] == ':' ) {
302 // printf("hours = %.2lf\n", hours);
308 if ( strlen(time_str) ) {
310 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
311 num[i] = time_str[0];
315 if ( time_str[0] == ':' ) {
320 // printf("minutes = %.2lf\n", minutes);
322 result += minutes / 60.0;
326 if ( strlen(time_str) ) {
328 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
329 num[i] = time_str[0];
335 // printf("seconds = %.2lf\n", seconds);
337 result += seconds / 3600.0;
340 SG_LOG( SG_GENERAL, SG_INFO, " parse_time() = " << sign * result );
342 return(sign * result);
346 // parse a date string (yyyy:mm:dd:hh:mm:ss) into a time_t (seconds)
348 parse_date( const string& date)
351 char * date_str, num[256];
353 // initialize to zero
360 gmt.tm_isdst = 0; // ignore daylight savings time for the moment
361 date_str = (char *)date.c_str();
363 if ( strlen(date_str) ) {
365 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
366 num[i] = date_str[0];
370 if ( date_str[0] == ':' ) {
374 gmt.tm_year = atoi(num) - 1900;
377 if ( strlen(date_str) ) {
379 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
380 num[i] = date_str[0];
384 if ( date_str[0] == ':' ) {
388 gmt.tm_mon = atoi(num) -1;
391 if ( strlen(date_str) ) {
393 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
394 num[i] = date_str[0];
398 if ( date_str[0] == ':' ) {
402 gmt.tm_mday = atoi(num);
405 if ( strlen(date_str) ) {
407 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
408 num[i] = date_str[0];
412 if ( date_str[0] == ':' ) {
416 gmt.tm_hour = atoi(num);
419 if ( strlen(date_str) ) {
421 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
422 num[i] = date_str[0];
426 if ( date_str[0] == ':' ) {
430 gmt.tm_min = atoi(num);
433 if ( strlen(date_str) ) {
435 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
436 num[i] = date_str[0];
440 if ( date_str[0] == ':' ) {
444 gmt.tm_sec = atoi(num);
446 time_t theTime = sgTimeGetGMT( gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
447 gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
448 //printf ("Date is %s\n", ctime(&theTime));
449 //printf ("in seconds that is %d\n", theTime);
455 // parse angle in the form of [+/-]ddd:mm:ss into degrees
457 parse_degree( const string& degree_str) {
458 double result = parse_time( degree_str );
460 // printf("Degree = %.4f\n", result);
466 // parse time offset string into seconds
468 parse_time_offset( const string& time_str) {
471 // printf("time offset = %s\n", time_str);
474 result = (int)rint(parse_time(time_str) * 3600.0);
476 result = (int)(parse_time(time_str) * 3600.0);
479 // printf("parse_time_offset(): %d\n", result);
485 // Parse --fov=x.xx type option
487 parse_fov( const string& arg ) {
488 double fov = atof(arg);
490 if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
491 if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
493 fgSetDouble("/sim/view[0]/config/default-field-of-view-deg", fov);
495 // printf("parse_fov(): result = %.4f\n", fov);
501 // Parse I/O channel option
503 // Format is "--protocol=medium,direction,hz,medium_options,..."
505 // protocol = { native, nmea, garmin, AV400, AV400Sim, fgfs, rul, pve, etc. }
506 // medium = { serial, socket, file, etc. }
507 // direction = { in, out, bi }
508 // hz = number of times to process channel per second (floating
509 // point values are ok.
511 // Serial example "--nmea=serial,dir,hz,device,baud" where
513 // device = OS device name of serial line to be open()'ed
514 // baud = {300, 1200, 2400, ..., 230400}
516 // Socket exacmple "--native=socket,dir,hz,machine,port,style" where
518 // machine = machine name or ip address if client (leave empty if server)
519 // port = port, leave empty to let system choose
520 // style = tcp or udp
522 // File example "--garmin=file,dir,hz,filename" where
524 // filename = file system file name
527 add_channel( const string& type, const string& channel_str ) {
528 // This check is neccessary to prevent fgviewer from segfaulting when given
529 // weird options. (It doesn't run the full initailization)
530 if(!globals->get_channel_options_list())
532 SG_LOG(SG_GENERAL, SG_ALERT, "Option " << type << "=" << channel_str
536 SG_LOG(SG_GENERAL, SG_INFO, "Channel string = " << channel_str );
537 globals->get_channel_options_list()->push_back( type + "," + channel_str );
542 // The parse wp and parse flight-plan options don't work anymore, because
543 // the route manager and the airport subsystems have not yet been initialized
546 // Parse --wp=ID[@alt]
548 parse_wp( const string& arg ) {
549 string_list *waypoints = globals->get_initial_waypoints();
551 waypoints = new string_list;
552 globals->set_initial_waypoints(waypoints);
554 waypoints->push_back(arg);
558 // Parse --flight-plan=[file]
560 parse_flightplan(const string& arg)
562 string_list *waypoints = globals->get_initial_waypoints();
564 waypoints = new string_list;
565 globals->set_initial_waypoints(waypoints);
568 sg_gzifstream in(arg.c_str());
574 getline( in, line, '\n' );
576 // catch extraneous (DOS) line ending character
577 if ( line[line.length() - 1] < 32 )
578 line = line.substr( 0, line.length()-1 );
583 waypoints->push_back(line);
590 fgOptLanguage( const char *arg )
592 globals->set_locale( fgInitLocale( arg ) );
593 return FG_OPTIONS_OK;
599 fgSetString("/sim/presets/airport-id", "");
600 fgSetString("/sim/presets/vor-id", "");
601 fgSetString("/sim/presets/ndb-id", "");
602 fgSetString("/sim/presets/carrier", "");
603 fgSetString("/sim/presets/parkpos", "");
604 fgSetString("/sim/presets/fix", "");
608 fgOptVOR( const char * arg )
611 fgSetString("/sim/presets/vor-id", arg);
612 return FG_OPTIONS_OK;
616 fgOptNDB( const char * arg )
619 fgSetString("/sim/presets/ndb-id", arg);
620 return FG_OPTIONS_OK;
624 fgOptCarrier( const char * arg )
627 fgSetString("/sim/presets/carrier", arg);
628 return FG_OPTIONS_OK;
632 fgOptParkpos( const char * arg )
634 fgSetString("/sim/presets/parkpos", arg);
635 return FG_OPTIONS_OK;
639 fgOptFIX( const char * arg )
642 fgSetString("/sim/presets/fix", arg);
643 return FG_OPTIONS_OK;
647 fgOptLon( const char *arg )
650 fgSetDouble("/sim/presets/longitude-deg", parse_degree( arg ));
651 fgSetDouble("/position/longitude-deg", parse_degree( arg ));
652 return FG_OPTIONS_OK;
656 fgOptLat( const char *arg )
659 fgSetDouble("/sim/presets/latitude-deg", parse_degree( arg ));
660 fgSetDouble("/position/latitude-deg", parse_degree( arg ));
661 return FG_OPTIONS_OK;
665 fgOptAltitude( const char *arg )
667 fgSetBool("/sim/presets/onground", false);
668 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
669 fgSetDouble("/sim/presets/altitude-ft", atof( arg ));
671 fgSetDouble("/sim/presets/altitude-ft",
672 atof( arg ) * SG_METER_TO_FEET);
673 return FG_OPTIONS_OK;
677 fgOptUBody( const char *arg )
679 fgSetString("/sim/presets/speed-set", "UVW");
680 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
681 fgSetDouble("/sim/presets/uBody-fps", atof( arg ));
683 fgSetDouble("/sim/presets/uBody-fps",
684 atof( arg ) * SG_METER_TO_FEET);
685 return FG_OPTIONS_OK;
689 fgOptVBody( const char *arg )
691 fgSetString("/sim/presets/speed-set", "UVW");
692 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
693 fgSetDouble("/sim/presets/vBody-fps", atof( arg ));
695 fgSetDouble("/sim/presets/vBody-fps",
696 atof( arg ) * SG_METER_TO_FEET);
697 return FG_OPTIONS_OK;
701 fgOptWBody( const char *arg )
703 fgSetString("/sim/presets/speed-set", "UVW");
704 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
705 fgSetDouble("/sim/presets/wBody-fps", atof(arg));
707 fgSetDouble("/sim/presets/wBody-fps",
708 atof(arg) * SG_METER_TO_FEET);
709 return FG_OPTIONS_OK;
713 fgOptVNorth( const char *arg )
715 fgSetString("/sim/presets/speed-set", "NED");
716 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
717 fgSetDouble("/sim/presets/speed-north-fps", atof( arg ));
719 fgSetDouble("/sim/presets/speed-north-fps",
720 atof( arg ) * SG_METER_TO_FEET);
721 return FG_OPTIONS_OK;
725 fgOptVEast( const char *arg )
727 fgSetString("/sim/presets/speed-set", "NED");
728 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
729 fgSetDouble("/sim/presets/speed-east-fps", atof(arg));
731 fgSetDouble("/sim/presets/speed-east-fps",
732 atof(arg) * SG_METER_TO_FEET);
733 return FG_OPTIONS_OK;
737 fgOptVDown( const char *arg )
739 fgSetString("/sim/presets/speed-set", "NED");
740 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
741 fgSetDouble("/sim/presets/speed-down-fps", atof(arg));
743 fgSetDouble("/sim/presets/speed-down-fps",
744 atof(arg) * SG_METER_TO_FEET);
745 return FG_OPTIONS_OK;
749 fgOptVc( const char *arg )
751 // fgSetString("/sim/presets/speed-set", "knots");
752 // fgSetDouble("/velocities/airspeed-kt", atof(arg.substr(5)));
753 fgSetString("/sim/presets/speed-set", "knots");
754 fgSetDouble("/sim/presets/airspeed-kt", atof(arg));
755 return FG_OPTIONS_OK;
759 fgOptMach( const char *arg )
761 fgSetString("/sim/presets/speed-set", "mach");
762 fgSetDouble("/sim/presets/mach", atof(arg));
763 return FG_OPTIONS_OK;
767 fgOptRoc( const char *arg )
769 fgSetDouble("/velocities/vertical-speed-fps", atof(arg)/60);
770 return FG_OPTIONS_OK;
774 fgOptFgRoot( const char *arg )
776 // this option is dealt with by fgInitFGRoot
777 return FG_OPTIONS_OK;
781 fgOptFgScenery( const char *arg )
783 globals->set_fg_scenery(arg);
784 return FG_OPTIONS_OK;
788 fgOptFgAircraft(const char* arg)
790 // this option is dealt with by fgInitFGAircraft
791 return FG_OPTIONS_OK;
795 fgOptFov( const char *arg )
798 return FG_OPTIONS_OK;
802 fgOptGeometry( const char *arg )
804 bool geometry_ok = true;
805 int xsize = 0, ysize = 0;
806 string geometry = arg;
807 string::size_type i = geometry.find('x');
809 if (i != string::npos) {
810 xsize = atoi(geometry.substr(0, i));
811 ysize = atoi(geometry.substr(i+1));
816 if ( xsize <= 0 || ysize <= 0 ) {
822 if ( !geometry_ok ) {
823 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown geometry: " << geometry );
824 SG_LOG( SG_GENERAL, SG_ALERT,
825 "Setting geometry to " << xsize << 'x' << ysize << '\n');
827 SG_LOG( SG_GENERAL, SG_INFO,
828 "Setting geometry to " << xsize << 'x' << ysize << '\n');
829 fgSetInt("/sim/startup/xsize", xsize);
830 fgSetInt("/sim/startup/ysize", ysize);
832 return FG_OPTIONS_OK;
836 fgOptBpp( const char *arg )
838 string bits_per_pix = arg;
839 if ( bits_per_pix == "16" ) {
840 fgSetInt("/sim/rendering/bits-per-pixel", 16);
841 } else if ( bits_per_pix == "24" ) {
842 fgSetInt("/sim/rendering/bits-per-pixel", 24);
843 } else if ( bits_per_pix == "32" ) {
844 fgSetInt("/sim/rendering/bits-per-pixel", 32);
846 SG_LOG(SG_GENERAL, SG_ALERT, "Unsupported bpp " << bits_per_pix);
848 return FG_OPTIONS_OK;
852 fgOptTimeOffset( const char *arg )
854 fgSetInt("/sim/startup/time-offset",
855 parse_time_offset( arg ));
856 fgSetString("/sim/startup/time-offset-type", "system-offset");
857 return FG_OPTIONS_OK;
861 fgOptStartDateSys( const char *arg )
863 fgSetInt("/sim/startup/time-offset", parse_date( arg ) );
864 fgSetString("/sim/startup/time-offset-type", "system");
865 return FG_OPTIONS_OK;
869 fgOptStartDateLat( const char *arg )
871 fgSetInt("/sim/startup/time-offset", parse_date( arg ) );
872 fgSetString("/sim/startup/time-offset-type", "latitude");
873 return FG_OPTIONS_OK;
877 fgOptStartDateGmt( const char *arg )
879 fgSetInt("/sim/startup/time-offset", parse_date( arg ) );
880 fgSetString("/sim/startup/time-offset-type", "gmt");
881 return FG_OPTIONS_OK;
885 fgSetupProxy( const char *arg )
887 string options = arg;
888 string host, port, auth;
889 string::size_type pos;
891 host = port = auth = "";
892 if ((pos = options.find("@")) != string::npos)
893 auth = options.substr(0, pos++);
897 host = options.substr(pos, options.size());
898 if ((pos = host.find(":")) != string::npos) {
899 port = host.substr(++pos, host.size());
900 host.erase(--pos, host.size());
903 fgSetString("/sim/presets/proxy/host", host.c_str());
904 fgSetString("/sim/presets/proxy/port", port.c_str());
905 fgSetString("/sim/presets/proxy/authentication", auth.c_str());
907 return FG_OPTIONS_OK;
911 fgOptTraceRead( const char *arg )
914 SG_LOG(SG_GENERAL, SG_INFO, "Tracing reads for property " << name);
915 fgGetNode(name.c_str(), true)
916 ->setAttribute(SGPropertyNode::TRACE_READ, true);
917 return FG_OPTIONS_OK;
921 fgOptLogLevel( const char *arg )
923 fgSetString("/sim/logging/classes", "all");
924 fgSetString("/sim/logging/priority", arg);
926 string priority = arg;
927 logbuf::set_log_classes(SG_ALL);
928 if (priority == "bulk") {
929 logbuf::set_log_priority(SG_BULK);
930 } else if (priority == "debug") {
931 logbuf::set_log_priority(SG_DEBUG);
932 } else if (priority == "info") {
933 logbuf::set_log_priority(SG_INFO);
934 } else if (priority == "warn") {
935 logbuf::set_log_priority(SG_WARN);
936 } else if (priority == "alert") {
937 logbuf::set_log_priority(SG_ALERT);
939 SG_LOG(SG_GENERAL, SG_WARN, "Unknown logging priority " << priority);
941 SG_LOG(SG_GENERAL, SG_DEBUG, "Logging priority is " << priority);
943 return FG_OPTIONS_OK;
948 fgOptTraceWrite( const char *arg )
951 SG_LOG(SG_GENERAL, SG_INFO, "Tracing writes for property " << name);
952 fgGetNode(name.c_str(), true)
953 ->setAttribute(SGPropertyNode::TRACE_WRITE, true);
954 return FG_OPTIONS_OK;
958 fgOptViewOffset( const char *arg )
960 // $$$ begin - added VS Renganathan, 14 Oct 2K
961 // for multi-window outside window imagery
962 string woffset = arg;
963 double default_view_offset = 0.0;
964 if ( woffset == "LEFT" ) {
965 default_view_offset = SGD_PI * 0.25;
966 } else if ( woffset == "RIGHT" ) {
967 default_view_offset = SGD_PI * 1.75;
968 } else if ( woffset == "CENTER" ) {
969 default_view_offset = 0.00;
971 default_view_offset = atof( woffset.c_str() ) * SGD_DEGREES_TO_RADIANS;
973 /* apparently not used (CLO, 11 Jun 2002)
974 FGViewer *pilot_view =
975 (FGViewer *)globals->get_viewmgr()->get_view( 0 ); */
976 // this will work without calls to the viewer...
977 fgSetDouble( "/sim/current-view/heading-offset-deg",
978 default_view_offset * SGD_RADIANS_TO_DEGREES );
979 // $$$ end - added VS Renganathan, 14 Oct 2K
980 return FG_OPTIONS_OK;
984 fgOptVisibilityMeters( const char *arg )
986 double visibility = atof( arg );
987 fgDefaultWeatherValue("visibility-m", visibility);
988 return FG_OPTIONS_OK;
992 fgOptVisibilityMiles( const char *arg )
994 double visibility = atof( arg ) * 5280.0 * SG_FEET_TO_METER;
995 fgDefaultWeatherValue("visibility-m", visibility);
996 return FG_OPTIONS_OK;
1000 fgOptRandomWind( const char *arg )
1002 double min_hdg = sg_random() * 360.0;
1003 double max_hdg = min_hdg + (20 - sqrt(sg_random() * 400));
1004 double speed = sg_random() * sg_random() * 40;
1005 double gust = speed + (10 - sqrt(sg_random() * 100));
1006 fgSetupWind(min_hdg, max_hdg, speed, gust);
1007 return FG_OPTIONS_OK;
1011 fgOptWind( const char *arg )
1013 double min_hdg = 0.0, max_hdg = 0.0, speed = 0.0, gust = 0.0;
1014 if (!parse_wind( arg, &min_hdg, &max_hdg, &speed, &gust)) {
1015 SG_LOG( SG_GENERAL, SG_ALERT, "bad wind value " << arg );
1016 return FG_OPTIONS_ERROR;
1018 fgSetupWind(min_hdg, max_hdg, speed, gust);
1019 return FG_OPTIONS_OK;
1023 fgOptTurbulence( const char *arg )
1025 fgDefaultWeatherValue("turbulence/magnitude-norm", atof(arg));
1026 return FG_OPTIONS_OK;
1030 fgOptCeiling( const char *arg )
1032 double elevation, thickness;
1034 string::size_type pos = spec.find(':');
1035 if (pos == string::npos) {
1036 elevation = atof(spec.c_str());
1039 elevation = atof(spec.substr(0, pos).c_str());
1040 thickness = atof(spec.substr(pos + 1).c_str());
1042 fgSetDouble("/environment/clouds/layer[0]/elevation-ft", elevation);
1043 fgSetDouble("/environment/clouds/layer[0]/thickness-ft", thickness);
1044 fgSetString("/environment/clouds/layer[0]/coverage", "overcast");
1045 return FG_OPTIONS_OK;
1049 fgOptWp( const char *arg )
1052 return FG_OPTIONS_OK;
1056 fgOptFlightPlan( const char *arg )
1058 parse_flightplan ( arg );
1059 return FG_OPTIONS_OK;
1063 fgOptConfig( const char *arg )
1067 readProperties(file, globals->get_props());
1068 } catch (const sg_exception &e) {
1069 string message = "Error loading config file: ";
1070 message += e.getFormattedMessage() + e.getOrigin();
1071 SG_LOG(SG_INPUT, SG_ALERT, message);
1074 return FG_OPTIONS_OK;
1078 parse_colon (const string &s, double * val1, double * val2)
1080 string::size_type pos = s.find(':');
1081 if (pos == string::npos) {
1085 *val1 = atof(s.substr(0, pos).c_str());
1086 *val2 = atof(s.substr(pos+1).c_str());
1093 fgOptFailure( const char * arg )
1097 fgSetBool("/systems/pitot/serviceable", false);
1098 } else if (a == "static") {
1099 fgSetBool("/systems/static/serviceable", false);
1100 } else if (a == "vacuum") {
1101 fgSetBool("/systems/vacuum/serviceable", false);
1102 } else if (a == "electrical") {
1103 fgSetBool("/systems/electrical/serviceable", false);
1105 SG_LOG(SG_INPUT, SG_ALERT, "Unknown failure mode: " << a);
1106 return FG_OPTIONS_ERROR;
1109 return FG_OPTIONS_OK;
1114 fgOptNAV1( const char * arg )
1116 double radial, freq;
1117 if (parse_colon(arg, &radial, &freq))
1118 fgSetDouble("/instrumentation/nav[0]/radials/selected-deg", radial);
1119 fgSetDouble("/instrumentation/nav[0]/frequencies/selected-mhz", freq);
1120 return FG_OPTIONS_OK;
1124 fgOptNAV2( const char * arg )
1126 double radial, freq;
1127 if (parse_colon(arg, &radial, &freq))
1128 fgSetDouble("/instrumentation/nav[1]/radials/selected-deg", radial);
1129 fgSetDouble("/instrumentation/nav[1]/frequencies/selected-mhz", freq);
1130 return FG_OPTIONS_OK;
1134 fgOptADF( const char * arg )
1137 if (parse_colon(arg, &rot, &freq))
1138 fgSetDouble("/instrumentation/adf/rotation-deg", rot);
1139 fgSetDouble("/instrumentation/adf/frequencies/selected-khz", freq);
1140 return FG_OPTIONS_OK;
1144 fgOptDME( const char *arg )
1147 if (opt == "nav1") {
1148 fgSetInt("/instrumentation/dme/switch-position", 1);
1149 fgSetString("/instrumentation/dme/frequencies/source",
1150 "/instrumentation/nav[0]/frequencies/selected-mhz");
1151 } else if (opt == "nav2") {
1152 fgSetInt("/instrumentation/dme/switch-position", 3);
1153 fgSetString("/instrumentation/dme/frequencies/source",
1154 "/instrumentation/nav[1]/frequencies/selected-mhz");
1156 fgSetInt("/instrumentation/dme/switch-position", 2);
1157 fgSetString("/instrumentation/dme/frequencies/source",
1158 "/instrumentation/dme/frequencies/selected-mhz");
1159 fgSetString("/instrumentation/dme/frequencies/selected-mhz", arg);
1161 return FG_OPTIONS_OK;
1165 fgOptLivery( const char *arg )
1168 string livery_path = "livery/" + opt;
1169 fgSetString("/sim/model/texture-path", livery_path.c_str() );
1170 return FG_OPTIONS_OK;
1174 fgOptScenario( const char *arg )
1176 SGPropertyNode_ptr ai_node = fgGetNode( "/sim/ai", true );
1177 vector<SGPropertyNode_ptr> scenarii = ai_node->getChildren( "scenario" );
1179 for ( size_t i = 0; i < scenarii.size(); ++i ) {
1180 int ind = scenarii[i]->getIndex();
1181 if ( index < ind ) {
1185 SGPropertyNode_ptr scenario = ai_node->getNode( "scenario", index + 1, true );
1186 scenario->setStringValue( arg );
1187 ai_node->setBoolValue( "enabled", true );
1188 return FG_OPTIONS_OK;
1192 fgOptRunway( const char *arg )
1194 fgSetString("/sim/presets/runway", arg );
1195 fgSetBool("/sim/presets/runway-requested", true );
1196 return FG_OPTIONS_OK;
1200 fgOptParking( const char *arg )
1202 cerr << "Processing argument " << arg << endl;
1203 fgSetString("/sim/presets/parking", arg );
1204 fgSetBool ("/sim/presets/parking-requested", true );
1205 return FG_OPTIONS_OK;
1209 fgOptVersion( const char *arg )
1211 cerr << "FlightGear version: " << VERSION << endl;
1212 cerr << "FG_ROOT=" << globals->get_fg_root() << endl;
1213 cerr << "FG_HOME=" << fgGetString("/sim/fg-home") << endl;
1214 cerr << "FG_SCENERY=";
1217 string_list scn = globals->get_fg_scenery();
1218 for (string_list::const_iterator it = scn.begin(); it != scn.end(); it++)
1220 if (didsome) cerr << ":";
1225 cerr << "SimGear version: " << SG_STRINGIZE(SIMGEAR_VERSION) << endl;
1226 cerr << "PLIB version: " << PLIB_VERSION << endl;
1227 return FG_OPTIONS_EXIT;
1231 fgOptFpe(const char* arg)
1233 // Actually handled in bootstrap.cxx
1234 return FG_OPTIONS_OK;
1238 fgOptFgviewer(const char* arg)
1240 // Actually handled in bootstrap.cxx
1241 return FG_OPTIONS_OK;
1246 static map<string,size_t> fgOptionMap;
1249 option has_param type property b_param s_param func
1252 option : name of the option
1253 has_param : option is --name=value if true or --name if false
1254 type : OPTION_BOOL - property is a boolean
1255 OPTION_STRING - property is a string
1256 OPTION_DOUBLE - property is a double
1257 OPTION_INT - property is an integer
1258 OPTION_CHANNEL - name of option is the name of a channel
1259 OPTION_FUNC - the option trigger a function
1260 b_param : if type==OPTION_BOOL,
1261 value set to the property (has_param is false for boolean)
1262 s_param : if type==OPTION_STRING,
1263 value set to the property if has_param is false
1264 func : function called if type==OPTION_FUNC. if has_param is true,
1265 the value is passed to the function as a string, otherwise,
1268 For OPTION_DOUBLE and OPTION_INT, the parameter value is converted into a
1269 double or an integer and set to the property.
1271 For OPTION_CHANNEL, add_channel is called with the parameter value as the
1275 enum OptionType { OPTION_BOOL, OPTION_STRING, OPTION_DOUBLE, OPTION_INT, OPTION_CHANNEL, OPTION_FUNC };
1279 enum OptionType type;
1280 const char *property;
1282 const char *s_param;
1283 int (*func)( const char * );
1284 } fgOptionArray[] = {
1286 {"language", true, OPTION_FUNC, "", false, "", fgOptLanguage },
1287 {"disable-game-mode", false, OPTION_BOOL, "/sim/startup/game-mode", false, "", 0 },
1288 {"enable-game-mode", false, OPTION_BOOL, "/sim/startup/game-mode", true, "", 0 },
1289 {"disable-splash-screen", false, OPTION_BOOL, "/sim/startup/splash-screen", false, "", 0 },
1290 {"enable-splash-screen", false, OPTION_BOOL, "/sim/startup/splash-screen", true, "", 0 },
1291 {"disable-intro-music", false, OPTION_BOOL, "/sim/startup/intro-music", false, "", 0 },
1292 {"enable-intro-music", false, OPTION_BOOL, "/sim/startup/intro-music", true, "", 0 },
1293 {"disable-mouse-pointer", false, OPTION_STRING, "/sim/startup/mouse-pointer", false, "disabled", 0 },
1294 {"enable-mouse-pointer", false, OPTION_STRING, "/sim/startup/mouse-pointer", false, "enabled", 0 },
1295 {"disable-random-objects", false, OPTION_BOOL, "/sim/rendering/random-objects", false, "", 0 },
1296 {"enable-random-objects", false, OPTION_BOOL, "/sim/rendering/random-objects", true, "", 0 },
1297 {"disable-real-weather-fetch", false, OPTION_BOOL, "/environment/params/real-world-weather-fetch", false, "", 0 },
1298 {"enable-real-weather-fetch", false, OPTION_BOOL, "/environment/params/real-world-weather-fetch", true, "", 0 },
1299 {"metar", true, OPTION_STRING, "/environment/metar/data", false, "", 0 },
1300 {"disable-ai-models", false, OPTION_BOOL, "/sim/ai/enabled", false, "", 0 },
1301 {"enable-ai-models", false, OPTION_BOOL, "/sim/ai/enabled", true, "", 0 },
1302 {"disable-freeze", false, OPTION_BOOL, "/sim/freeze/master", false, "", 0 },
1303 {"enable-freeze", false, OPTION_BOOL, "/sim/freeze/master", true, "", 0 },
1304 {"disable-fuel-freeze", false, OPTION_BOOL, "/sim/freeze/fuel", false, "", 0 },
1305 {"enable-fuel-freeze", false, OPTION_BOOL, "/sim/freeze/fuel", true, "", 0 },
1306 {"disable-clock-freeze", false, OPTION_BOOL, "/sim/freeze/clock", false, "", 0 },
1307 {"enable-clock-freeze", false, OPTION_BOOL, "/sim/freeze/clock", true, "", 0 },
1308 {"disable-hud-3d", false, OPTION_BOOL, "/sim/hud/enable3d", false, "", 0 },
1309 {"enable-hud-3d", false, OPTION_BOOL, "/sim/hud/enable3d", true, "", 0 },
1310 {"disable-anti-alias-hud", false, OPTION_BOOL, "/sim/hud/color/antialiased", false, "", 0 },
1311 {"enable-anti-alias-hud", false, OPTION_BOOL, "/sim/hud/color/antialiased", true, "", 0 },
1312 {"control", true, OPTION_STRING, "/sim/control-mode", false, "", 0 },
1313 {"disable-auto-coordination", false, OPTION_BOOL, "/sim/auto-coordination", false, "", 0 },
1314 {"enable-auto-coordination", false, OPTION_BOOL, "/sim/auto-coordination", true, "", 0 },
1315 {"browser-app", true, OPTION_STRING, "/sim/startup/browser-app", false, "", 0 },
1316 {"disable-hud", false, OPTION_BOOL, "/sim/hud/visibility", false, "", 0 },
1317 {"enable-hud", false, OPTION_BOOL, "/sim/hud/visibility", true, "", 0 },
1318 {"disable-panel", false, OPTION_BOOL, "/sim/panel/visibility", false, "", 0 },
1319 {"enable-panel", false, OPTION_BOOL, "/sim/panel/visibility", true, "", 0 },
1320 {"disable-sound", false, OPTION_BOOL, "/sim/sound/working", false, "", 0 },
1321 {"enable-sound", false, OPTION_BOOL, "/sim/sound/working", true, "", 0 },
1322 {"sound-device", true, OPTION_STRING, "/sim/sound/device-name", false, "", 0 },
1323 {"airport", true, OPTION_STRING, "/sim/presets/airport-id", false, "", 0 },
1324 {"runway", true, OPTION_FUNC, "", false, "", fgOptRunway },
1325 {"vor", true, OPTION_FUNC, "", false, "", fgOptVOR },
1326 {"ndb", true, OPTION_FUNC, "", false, "", fgOptNDB },
1327 {"carrier", true, OPTION_FUNC, "", false, "", fgOptCarrier },
1328 {"parkpos", true, OPTION_FUNC, "", false, "", fgOptParkpos },
1329 {"fix", true, OPTION_FUNC, "", false, "", fgOptFIX },
1330 {"offset-distance", true, OPTION_DOUBLE, "/sim/presets/offset-distance-nm", false, "", 0 },
1331 {"offset-azimuth", true, OPTION_DOUBLE, "/sim/presets/offset-azimuth-deg", false, "", 0 },
1332 {"lon", true, OPTION_FUNC, "", false, "", fgOptLon },
1333 {"lat", true, OPTION_FUNC, "", false, "", fgOptLat },
1334 {"altitude", true, OPTION_FUNC, "", false, "", fgOptAltitude },
1335 {"uBody", true, OPTION_FUNC, "", false, "", fgOptUBody },
1336 {"vBody", true, OPTION_FUNC, "", false, "", fgOptVBody },
1337 {"wBody", true, OPTION_FUNC, "", false, "", fgOptWBody },
1338 {"vNorth", true, OPTION_FUNC, "", false, "", fgOptVNorth },
1339 {"vEast", true, OPTION_FUNC, "", false, "", fgOptVEast },
1340 {"vDown", true, OPTION_FUNC, "", false, "", fgOptVDown },
1341 {"vc", true, OPTION_FUNC, "", false, "", fgOptVc },
1342 {"mach", true, OPTION_FUNC, "", false, "", fgOptMach },
1343 {"heading", true, OPTION_DOUBLE, "/sim/presets/heading-deg", false, "", 0 },
1344 {"roll", true, OPTION_DOUBLE, "/sim/presets/roll-deg", false, "", 0 },
1345 {"pitch", true, OPTION_DOUBLE, "/sim/presets/pitch-deg", false, "", 0 },
1346 {"glideslope", true, OPTION_DOUBLE, "/sim/presets/glideslope-deg", false, "", 0 },
1347 {"roc", true, OPTION_FUNC, "", false, "", fgOptRoc },
1348 {"fg-root", true, OPTION_FUNC, "", false, "", fgOptFgRoot },
1349 {"fg-scenery", true, OPTION_FUNC, "", false, "", fgOptFgScenery },
1350 {"fg-aircraft", true, OPTION_FUNC, "", false, "", fgOptFgAircraft },
1351 {"fdm", true, OPTION_STRING, "/sim/flight-model", false, "", 0 },
1352 {"aero", true, OPTION_STRING, "/sim/aero", false, "", 0 },
1353 {"aircraft-dir", true, OPTION_STRING, "/sim/aircraft-dir", false, "", 0 },
1354 {"model-hz", true, OPTION_INT, "/sim/model-hz", false, "", 0 },
1355 {"speed", true, OPTION_INT, "/sim/speed-up", false, "", 0 },
1356 {"trim", false, OPTION_BOOL, "/sim/presets/trim", true, "", 0 },
1357 {"notrim", false, OPTION_BOOL, "/sim/presets/trim", false, "", 0 },
1358 {"on-ground", false, OPTION_BOOL, "/sim/presets/onground", true, "", 0 },
1359 {"in-air", false, OPTION_BOOL, "/sim/presets/onground", false, "", 0 },
1360 {"fog-disable", false, OPTION_STRING, "/sim/rendering/fog", false, "disabled", 0 },
1361 {"fog-fastest", false, OPTION_STRING, "/sim/rendering/fog", false, "fastest", 0 },
1362 {"fog-nicest", false, OPTION_STRING, "/sim/rendering/fog", false, "nicest", 0 },
1363 {"disable-horizon-effect", false, OPTION_BOOL, "/sim/rendering/horizon-effect", false, "", 0 },
1364 {"enable-horizon-effect", false, OPTION_BOOL, "/sim/rendering/horizon-effect", true, "", 0 },
1365 {"disable-enhanced-lighting", false, OPTION_BOOL, "/sim/rendering/enhanced-lighting", false, "", 0 },
1366 {"enable-enhanced-lighting", false, OPTION_BOOL, "/sim/rendering/enhanced-lighting", true, "", 0 },
1367 {"disable-distance-attenuation", false, OPTION_BOOL, "/sim/rendering/distance-attenuation", false, "", 0 },
1368 {"enable-distance-attenuation", false, OPTION_BOOL, "/sim/rendering/distance-attenuation", true, "", 0 },
1369 {"disable-specular-highlight", false, OPTION_BOOL, "/sim/rendering/specular-highlight", false, "", 0 },
1370 {"enable-specular-highlight", false, OPTION_BOOL, "/sim/rendering/specular-highlight", true, "", 0 },
1371 {"disable-clouds", false, OPTION_BOOL, "/environment/clouds/status", false, "", 0 },
1372 {"enable-clouds", false, OPTION_BOOL, "/environment/clouds/status", true, "", 0 },
1373 {"disable-clouds3d", false, OPTION_BOOL, "/sim/rendering/clouds3d-enable", false, "", 0 },
1374 {"enable-clouds3d", false, OPTION_BOOL, "/sim/rendering/clouds3d-enable", true, "", 0 },
1375 {"fov", true, OPTION_FUNC, "", false, "", fgOptFov },
1376 {"aspect-ratio-multiplier", true, OPTION_DOUBLE, "/sim/current-view/aspect-ratio-multiplier", false, "", 0 },
1377 {"disable-fullscreen", false, OPTION_BOOL, "/sim/startup/fullscreen", false, "", 0 },
1378 {"enable-fullscreen", false, OPTION_BOOL, "/sim/startup/fullscreen", true, "", 0 },
1379 {"disable-save-on-exit", false, OPTION_BOOL, "/sim/startup/save-on-exit", false, "", 0 },
1380 {"enable-save-on-exit", false, OPTION_BOOL, "/sim/startup/save-on-exit", true, "", 0 },
1381 {"shading-flat", false, OPTION_BOOL, "/sim/rendering/shading", false, "", 0 },
1382 {"shading-smooth", false, OPTION_BOOL, "/sim/rendering/shading", true, "", 0 },
1383 {"disable-skyblend", false, OPTION_BOOL, "/sim/rendering/skyblend", false, "", 0 },
1384 {"enable-skyblend", false, OPTION_BOOL, "/sim/rendering/skyblend", true, "", 0 },
1385 {"disable-textures", false, OPTION_BOOL, "/sim/rendering/textures", false, "", 0 },
1386 {"enable-textures", false, OPTION_BOOL, "/sim/rendering/textures", true, "", 0 },
1387 {"texture-filtering", false, OPTION_INT, "/sim/rendering/filtering", 1, "", 0 },
1388 {"disable-wireframe", false, OPTION_BOOL, "/sim/rendering/wireframe", false, "", 0 },
1389 {"enable-wireframe", false, OPTION_BOOL, "/sim/rendering/wireframe", true, "", 0 },
1390 {"geometry", true, OPTION_FUNC, "", false, "", fgOptGeometry },
1391 {"bpp", true, OPTION_FUNC, "", false, "", fgOptBpp },
1392 {"units-feet", false, OPTION_STRING, "/sim/startup/units", false, "feet", 0 },
1393 {"units-meters", false, OPTION_STRING, "/sim/startup/units", false, "meters", 0 },
1394 {"timeofday", true, OPTION_STRING, "/sim/startup/time-offset-type", false, "noon", 0 },
1395 {"season", true, OPTION_STRING, "/sim/startup/season", false, "summer", 0 },
1396 {"time-offset", true, OPTION_FUNC, "", false, "", fgOptTimeOffset },
1397 {"time-match-real", false, OPTION_STRING, "/sim/startup/time-offset-type", false, "system-offset", 0 },
1398 {"time-match-local", false, OPTION_STRING, "/sim/startup/time-offset-type", false, "latitude-offset", 0 },
1399 {"start-date-sys", true, OPTION_FUNC, "", false, "", fgOptStartDateSys },
1400 {"start-date-lat", true, OPTION_FUNC, "", false, "", fgOptStartDateLat },
1401 {"start-date-gmt", true, OPTION_FUNC, "", false, "", fgOptStartDateGmt },
1402 {"hud-tris", false, OPTION_STRING, "/sim/hud/frame-stat-type", false, "tris", 0 },
1403 {"hud-culled", false, OPTION_STRING, "/sim/hud/frame-stat-type", false, "culled", 0 },
1404 {"atcsim", true, OPTION_CHANNEL, "", false, "dummy", 0 },
1405 {"atlas", true, OPTION_CHANNEL, "", false, "", 0 },
1406 {"httpd", true, OPTION_CHANNEL, "", false, "", 0 },
1407 #ifdef FG_JPEG_SERVER
1408 {"jpg-httpd", true, OPTION_CHANNEL, "", false, "", 0 },
1410 {"native", true, OPTION_CHANNEL, "", false, "", 0 },
1411 {"native-ctrls", true, OPTION_CHANNEL, "", false, "", 0 },
1412 {"native-fdm", true, OPTION_CHANNEL, "", false, "", 0 },
1413 {"native-gui", true, OPTION_CHANNEL, "", false, "", 0 },
1414 {"opengc", true, OPTION_CHANNEL, "", false, "", 0 },
1415 {"AV400", true, OPTION_CHANNEL, "", false, "", 0 },
1416 {"AV400Sim", true, OPTION_CHANNEL, "", false, "", 0 },
1417 {"garmin", true, OPTION_CHANNEL, "", false, "", 0 },
1418 {"nmea", true, OPTION_CHANNEL, "", false, "", 0 },
1419 {"generic", true, OPTION_CHANNEL, "", false, "", 0 },
1420 {"props", true, OPTION_CHANNEL, "", false, "", 0 },
1421 {"telnet", true, OPTION_CHANNEL, "", false, "", 0 },
1422 {"pve", true, OPTION_CHANNEL, "", false, "", 0 },
1423 {"ray", true, OPTION_CHANNEL, "", false, "", 0 },
1424 {"rul", true, OPTION_CHANNEL, "", false, "", 0 },
1425 {"joyclient", true, OPTION_CHANNEL, "", false, "", 0 },
1426 {"jsclient", true, OPTION_CHANNEL, "", false, "", 0 },
1427 {"proxy", true, OPTION_FUNC, "", false, "", fgSetupProxy },
1428 {"callsign", true, OPTION_STRING, "sim/multiplay/callsign", false, "", 0 },
1429 {"multiplay", true, OPTION_CHANNEL, "", false, "", 0 },
1430 {"trace-read", true, OPTION_FUNC, "", false, "", fgOptTraceRead },
1431 {"trace-write", true, OPTION_FUNC, "", false, "", fgOptTraceWrite },
1432 {"log-level", true, OPTION_FUNC, "", false, "", fgOptLogLevel },
1433 {"view-offset", true, OPTION_FUNC, "", false, "", fgOptViewOffset },
1434 {"visibility", true, OPTION_FUNC, "", false, "", fgOptVisibilityMeters },
1435 {"visibility-miles", true, OPTION_FUNC, "", false, "", fgOptVisibilityMiles },
1436 {"random-wind", false, OPTION_FUNC, "", false, "", fgOptRandomWind },
1437 {"wind", true, OPTION_FUNC, "", false, "", fgOptWind },
1438 {"turbulence", true, OPTION_FUNC, "", false, "", fgOptTurbulence },
1439 {"ceiling", true, OPTION_FUNC, "", false, "", fgOptCeiling },
1440 {"wp", true, OPTION_FUNC, "", false, "", fgOptWp },
1441 {"flight-plan", true, OPTION_FUNC, "", false, "", fgOptFlightPlan },
1442 {"config", true, OPTION_FUNC, "", false, "", fgOptConfig },
1443 {"aircraft", true, OPTION_STRING, "/sim/aircraft", false, "", 0 },
1444 {"vehicle", true, OPTION_STRING, "/sim/aircraft", false, "", 0 },
1445 {"failure", true, OPTION_FUNC, "", false, "", fgOptFailure },
1446 {"com1", true, OPTION_DOUBLE, "/instrumentation/comm[0]/frequencies/selected-mhz", false, "", 0 },
1447 {"com2", true, OPTION_DOUBLE, "/instrumentation/comm[1]/frequencies/selected-mhz", false, "", 0 },
1448 {"nav1", true, OPTION_FUNC, "", false, "", fgOptNAV1 },
1449 {"nav2", true, OPTION_FUNC, "", false, "", fgOptNAV2 },
1450 {"adf", true, OPTION_FUNC, "", false, "", fgOptADF },
1451 {"dme", true, OPTION_FUNC, "", false, "", fgOptDME },
1452 {"min-status", true, OPTION_STRING, "/sim/aircraft-min-status", false, "all", 0 },
1453 {"livery", true, OPTION_FUNC, "", false, "", fgOptLivery },
1454 {"ai-scenario", true, OPTION_FUNC, "", false, "", fgOptScenario },
1455 {"parking-id", true, OPTION_FUNC, "", false, "", fgOptParking },
1456 {"version", false, OPTION_FUNC, "", false, "", fgOptVersion },
1457 {"enable-fpe", false, OPTION_FUNC, "", false, "", fgOptFpe},
1458 {"fgviewer", false, OPTION_FUNC, "", false, "", fgOptFgviewer},
1463 // Set a property for the --prop: option. Syntax: --prop:[<type>:]<name>=<value>
1464 // <type> can be "double" etc. but also only the first letter "d".
1465 // Examples: --prop:alpha=1 --prop:bool:beta=true --prop:d:gamma=0.123
1467 set_property(const string& arg)
1469 string::size_type pos = arg.find('=');
1470 if (pos == arg.npos || pos == 0 || pos + 1 == arg.size())
1473 string name = arg.substr(0, pos);
1474 string value = arg.substr(pos + 1);
1476 pos = name.find(':');
1478 if (pos != name.npos && pos != 0 && pos + 1 != name.size()) {
1479 type = name.substr(0, pos);
1480 name = name.substr(pos + 1);
1482 SGPropertyNode *n = fgGetNode(name.c_str(), true);
1484 bool writable = n->getAttribute(SGPropertyNode::WRITE);
1486 n->setAttribute(SGPropertyNode::WRITE, true);
1490 ret = n->setUnspecifiedValue(value.c_str());
1491 else if (type == "s" || type == "string")
1492 ret = n->setStringValue(value.c_str());
1493 else if (type == "d" || type == "double")
1494 ret = n->setDoubleValue(strtod(value.c_str(), 0));
1495 else if (type == "f" || type == "float")
1496 ret = n->setFloatValue(atof(value.c_str()));
1497 else if (type == "l" || type == "long")
1498 ret = n->setLongValue(strtol(value.c_str(), 0, 0));
1499 else if (type == "i" || type == "int")
1500 ret = n->setIntValue(atoi(value.c_str()));
1501 else if (type == "b" || type == "bool")
1502 ret = n->setBoolValue(value == "true" || atoi(value.c_str()) != 0);
1505 n->setAttribute(SGPropertyNode::WRITE, false);
1510 // Parse a single option
1512 parse_option (const string& arg)
1514 if ( fgOptionMap.size() == 0 ) {
1516 OptionDesc *pt = &fgOptionArray[ 0 ];
1517 while ( pt->option != 0 ) {
1518 fgOptionMap[ pt->option ] = i;
1525 if ( (arg == "--help") || (arg == "-h") ) {
1526 // help/usage request
1527 return(FG_OPTIONS_HELP);
1528 } else if ( (arg == "--verbose") || (arg == "-v") ) {
1529 // verbose help/usage request
1530 return(FG_OPTIONS_VERBOSE_HELP);
1531 } else if ( arg.find( "--show-aircraft") == 0) {
1532 return(FG_OPTIONS_SHOW_AIRCRAFT);
1533 } else if ( arg.find( "--show-sound-devices") == 0) {
1534 return(FG_OPTIONS_SHOW_SOUND_DEVICES);
1535 } else if ( arg.find( "--prop:" ) == 0 ) {
1536 if (!set_property(arg.substr(7))) {
1537 SG_LOG( SG_GENERAL, SG_ALERT, "Bad property assignment: " << arg );
1538 return FG_OPTIONS_ERROR;
1540 } else if ( arg.find( "--" ) == 0 ) {
1541 size_t pos = arg.find( '=' );
1542 string arg_name, arg_value;
1543 if ( pos == string::npos ) {
1544 arg_name = arg.substr( 2 );
1546 arg_name = arg.substr( 2, pos - 2 );
1547 arg_value = arg.substr( pos + 1);
1549 map<string,size_t>::iterator it = fgOptionMap.find( arg_name );
1550 if ( it != fgOptionMap.end() ) {
1551 OptionDesc *pt = &fgOptionArray[ it->second ];
1552 switch ( pt->type ) {
1554 fgSetBool( pt->property, pt->b_param );
1557 if ( pt->has_param && !arg_value.empty() ) {
1558 fgSetString( pt->property, arg_value.c_str() );
1559 } else if ( !pt->has_param && arg_value.empty() ) {
1560 fgSetString( pt->property, pt->s_param );
1561 } else if ( pt->has_param ) {
1562 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1563 return FG_OPTIONS_ERROR;
1565 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' does not have a parameter" );
1566 return FG_OPTIONS_ERROR;
1570 if ( !arg_value.empty() ) {
1571 fgSetDouble( pt->property, atof( arg_value ) );
1573 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1574 return FG_OPTIONS_ERROR;
1578 if ( !arg_value.empty() ) {
1579 fgSetInt( pt->property, atoi( arg_value ) );
1581 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1582 return FG_OPTIONS_ERROR;
1585 case OPTION_CHANNEL:
1586 // XXX return value of add_channel should be checked?
1587 if ( pt->has_param && !arg_value.empty() ) {
1588 add_channel( pt->option, arg_value );
1589 } else if ( !pt->has_param && arg_value.empty() ) {
1590 add_channel( pt->option, pt->s_param );
1591 } else if ( pt->has_param ) {
1592 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1593 return FG_OPTIONS_ERROR;
1595 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' does not have a parameter" );
1596 return FG_OPTIONS_ERROR;
1600 if ( pt->has_param && !arg_value.empty() ) {
1601 return pt->func( arg_value.c_str() );
1602 } else if ( !pt->has_param && arg_value.empty() ) {
1603 return pt->func( pt->s_param );
1604 } else if ( pt->has_param ) {
1605 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' needs a parameter" );
1606 return FG_OPTIONS_ERROR;
1608 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << arg << "' does not have a parameter" );
1609 return FG_OPTIONS_ERROR;
1614 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" );
1615 return FG_OPTIONS_ERROR;
1618 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" );
1619 return FG_OPTIONS_ERROR;
1622 return FG_OPTIONS_OK;
1626 // Parse the command line options
1628 fgParseArgs (int argc, char **argv)
1630 bool in_options = true;
1631 bool verbose = false;
1634 SG_LOG(SG_GENERAL, SG_ALERT, "Processing command line arguments");
1636 for (int i = 1; i < argc; i++) {
1637 string arg = argv[i];
1639 if (in_options && (arg.find('-') == 0)) {
1643 int result = parse_option(arg);
1644 if ((result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR))
1647 else if (result == FG_OPTIONS_VERBOSE_HELP)
1650 else if (result == FG_OPTIONS_SHOW_AIRCRAFT) {
1651 fgOptLogLevel( "alert" );
1652 SGPath path( globals->get_fg_root() );
1653 path.append("Aircraft");
1654 fgShowAircraft(path);
1657 } else if (result == FG_OPTIONS_SHOW_SOUND_DEVICES) {
1661 string vendor = smgr.get_vendor();
1662 string renderer = smgr.get_renderer();
1663 cout << renderer << " provided by " << vendor << endl;
1664 cout << endl << "No. Device" << endl;
1666 vector <const char*>devices = smgr.get_available_devices();
1667 for (vector <const char*>::size_type i=0; i<devices.size(); i++) {
1668 cout << i << ". \"" << devices[i] << "\"" << endl;
1674 else if (result == FG_OPTIONS_EXIT)
1679 SG_LOG(SG_GENERAL, SG_INFO,
1680 "Reading command-line property file " << arg);
1681 readProperties(arg, globals->get_props());
1686 fgOptLogLevel( "alert" );
1691 SG_LOG(SG_GENERAL, SG_INFO, "Finished command line arguments");
1695 // Parse config file options
1697 fgParseOptions (const string& path) {
1698 sg_gzifstream in( path );
1699 if ( !in.is_open() ) {
1703 SG_LOG( SG_GENERAL, SG_INFO, "Processing config file: " << path );
1706 while ( ! in.eof() ) {
1708 getline( in, line, '\n' );
1710 // catch extraneous (DOS) line ending character
1712 for (i = line.length(); i > 0; i--)
1713 if (line[i - 1] > 32)
1715 line = line.substr( 0, i );
1717 if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
1718 cerr << endl << "Config file parse error: " << path << " '"
1719 << line << "'" << endl;
1728 // Print usage message
1730 fgUsage (bool verbose)
1732 SGPropertyNode *locale = globals->get_locale();
1734 SGPropertyNode options_root;
1736 SG_LOG( SG_GENERAL, SG_ALERT, "" ); // To popup the console on Windows
1740 fgLoadProps("options.xml", &options_root);
1741 } catch (const sg_exception &) {
1742 cout << "Unable to read the help file." << endl;
1743 cout << "Make sure the file options.xml is located in the FlightGear base directory," << endl;
1744 cout << "and the location of the base directory is specified by setting $FG_ROOT or" << endl;
1745 cout << "by adding --fg-root=path as a program argument." << endl;
1750 SGPropertyNode *options = options_root.getNode("options");
1752 SG_LOG( SG_GENERAL, SG_ALERT,
1753 "Error reading options.xml: <options> directive not found." );
1757 SGPropertyNode *usage = locale->getNode(options->getStringValue("usage"));
1759 cout << "Usage: " << usage->getStringValue() << endl;
1762 vector<SGPropertyNode_ptr>section = options->getChildren("section");
1763 for (unsigned int j = 0; j < section.size(); j++) {
1766 vector<SGPropertyNode_ptr>option = section[j]->getChildren("option");
1767 for (unsigned int k = 0; k < option.size(); k++) {
1769 SGPropertyNode *name = option[k]->getNode("name");
1770 SGPropertyNode *short_name = option[k]->getNode("short");
1771 SGPropertyNode *key = option[k]->getNode("key");
1772 SGPropertyNode *arg = option[k]->getNode("arg");
1773 bool brief = option[k]->getNode("brief") != 0;
1775 if ((brief || verbose) && name) {
1776 string tmp = name->getStringValue();
1780 tmp.append(key->getStringValue());
1784 tmp.append(arg->getStringValue());
1788 tmp.append(short_name->getStringValue());
1791 if (tmp.size() <= 25) {
1794 msg.append( 27-tmp.size(), ' ');
1798 msg.append(32, ' ');
1800 // There may be more than one <description> tag assosiated
1803 vector<SGPropertyNode_ptr> desc;
1804 desc = option[k]->getChildren("description");
1805 if (desc.size() > 0) {
1806 for ( unsigned int l = 0; l < desc.size(); l++) {
1808 // There may be more than one translation line.
1810 string t = desc[l]->getStringValue();
1811 SGPropertyNode *n = locale->getNode("strings");
1812 vector<SGPropertyNode_ptr>trans_desc =
1813 n->getChildren(t.substr(8).c_str());
1815 for ( unsigned int m = 0; m < trans_desc.size(); m++ ) {
1816 string t_str = trans_desc[m]->getStringValue();
1818 if ((m > 0) || ((l > 0) && m == 0)) {
1819 msg.append( 32, ' ');
1822 // If the string is too large to fit on the screen,
1823 // then split it up in several pieces.
1825 while ( t_str.size() > 47 ) {
1827 unsigned int m = t_str.rfind(' ', 47);
1828 msg += t_str.substr(0, m) + '\n';
1829 msg.append( 32, ' ');
1831 t_str.erase(t_str.begin(), t_str.begin() + m + 1);
1833 msg += t_str + '\n';
1840 SGPropertyNode *name;
1841 name = locale->getNode(section[j]->getStringValue("name"));
1843 if (!msg.empty() && name) {
1844 cout << endl << name->getStringValue() << ":" << endl;
1852 cout << "For a complete list of options use --help --verbose" << endl;
1855 cout << "Hit a key to continue..." << endl;