1 // options.cxx -- class to handle command line options
3 // Written by Curtis Olson, started April 1998.
5 // Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #include <simgear/compiler.h>
29 #include <simgear/misc/exception.hxx>
31 #include <math.h> // rint()
33 #include <stdlib.h> // atof(), atoi()
34 #include <string.h> // strcmp()
40 #include <simgear/math/sg_random.h>
41 #include <simgear/misc/sgstream.hxx>
42 #include <simgear/misc/sg_path.hxx>
43 #include <simgear/route/route.hxx>
44 #include <simgear/route/waypoint.hxx>
46 // #include <Include/general.hxx>
47 // #include <Airports/simple.hxx>
48 // #include <Cockpit/cockpit.hxx>
49 // #include <FDM/flight.hxx>
50 // #include <FDM/UIUCModel/uiuc_aircraftdir.h>
52 # include <NetworkOLK/network.h>
57 #include "globals.hxx"
58 #include "fg_init.hxx"
59 #include "fg_props.hxx"
60 #include "options.hxx"
61 #include "viewmgr.hxx"
65 SG_USING_NAMESPACE(std);
68 #define NEW_DEFAULT_MODEL_HZ 120
75 FG_OPTIONS_VERBOSE_HELP = 3,
76 FG_OPTIONS_SHOW_AIRCRAFT = 4
80 atof( const string& str )
84 // -dw- if ::atof is called, then we get an infinite loop
85 return std::atof( str.c_str() );
87 return ::atof( str.c_str() );
92 atoi( const string& str )
95 // -dw- if ::atoi is called, then we get an infinite loop
96 return std::atoi( str.c_str() );
98 return ::atoi( str.c_str() );
104 * Set a few fail-safe default property values.
106 * These should all be set in $FG_ROOT/preferences.xml, but just
107 * in case, we provide some initial sane values here. This method
108 * should be invoked *before* reading any init files.
113 // set a possibly independent location for scenery data
114 char *envp = ::getenv( "FG_SCENERY" );
116 if ( envp != NULL ) {
117 // fg_root could be anywhere, so default to environmental
118 // variable $FG_ROOT if it is set.
119 globals->set_fg_scenery(envp);
121 // Otherwise, default to Scenery being in $FG_ROOT/Scenery
122 globals->set_fg_scenery("");
124 // Position (deliberately out of range)
125 fgSetDouble("/position/longitude-deg", 9999.0);
126 fgSetDouble("/position/latitude-deg", 9999.0);
127 fgSetDouble("/position/altitude-ft", -9999.0);
130 fgSetDouble("/orientation/heading-deg", 270);
131 fgSetDouble("/orientation/roll-deg", 0);
132 fgSetDouble("/orientation/pitch-deg", 0.424);
135 fgSetDouble("/velocities/uBody-fps", 0.0);
136 fgSetDouble("/velocities/vBody-fps", 0.0);
137 fgSetDouble("/velocities/wBody-fps", 0.0);
138 fgSetDouble("/velocities/speed-north-fps", 0.0);
139 fgSetDouble("/velocities/speed-east-fps", 0.0);
140 fgSetDouble("/velocities/speed-down-fps", 0.0);
141 fgSetDouble("/velocities/airspeed-kt", 0.0);
142 fgSetDouble("/velocities/mach", 0.0);
145 fgSetDouble("/sim/presets/longitude-deg", 9999.0);
146 fgSetDouble("/sim/presets/latitude-deg", 9999.0);
147 fgSetDouble("/sim/presets/altitude-ft", -9999.0);
149 fgSetDouble("/sim/presets/heading-deg", 270);
150 fgSetDouble("/sim/presets/roll-deg", 0);
151 fgSetDouble("/sim/presets/pitch-deg", 0.424);
153 fgSetString("/sim/presets/speed-set", "knots");
154 fgSetDouble("/sim/presets/airspeed-kt", 0.0);
155 fgSetDouble("/sim/presets/mach", 0.0);
156 fgSetDouble("/sim/presets/uBody-fps", 0.0);
157 fgSetDouble("/sim/presets/vBody-fps", 0.0);
158 fgSetDouble("/sim/presets/wBody-fps", 0.0);
159 fgSetDouble("/sim/presets/speed-north-fps", 0.0);
160 fgSetDouble("/sim/presets/speed-east-fps", 0.0);
161 fgSetDouble("/sim/presets/speed-down-fps", 0.0);
163 fgSetBool("/sim/presets/onground", true);
164 fgSetBool("/sim/presets/trim", false);
167 fgSetBool("/sim/startup/game-mode", false);
168 fgSetBool("/sim/startup/splash-screen", true);
169 fgSetBool("/sim/startup/intro-music", true);
170 // we want mouse-pointer to have an undefined value if nothing is
171 // specified so we can do the right thing for voodoo-1/2 cards.
172 // fgSetString("/sim/startup/mouse-pointer", "disabled");
173 fgSetString("/sim/control-mode", "joystick");
174 fgSetBool("/sim/auto-coordination", false);
176 fgSetString("/sim/startup/browser-app", "netscape");
178 fgSetString("/sim/startup/browser-app", "webrun.bat");
181 fgSetBool("/sim/hud/visibility", false);
182 fgSetBool("/sim/panel/visibility", true);
183 fgSetBool("/sim/sound/audible", true);
184 fgSetBool("/sim/hud/antialiased", false);
186 // Flight Model options
187 fgSetString("/sim/flight-model", "jsb");
188 fgSetString("/sim/aero", "c172");
189 fgSetInt("/sim/model-hz", NEW_DEFAULT_MODEL_HZ);
190 fgSetInt("/sim/speed-up", 1);
193 fgSetString("/sim/rendering/fog", "nicest");
194 fgSetBool("/environment/clouds/status", true);
195 fgSetBool("/sim/startup/fullscreen", false);
196 fgSetBool("/sim/rendering/shading", true);
197 fgSetBool("/sim/rendering/skyblend", true);
198 fgSetBool("/sim/rendering/textures", true);
199 fgSetBool("/sim/rendering/wireframe", false);
200 fgSetInt("/sim/startup/xsize", 800);
201 fgSetInt("/sim/startup/ysize", 600);
202 fgSetInt("/sim/rendering/bits-per-pixel", 16);
203 fgSetString("/sim/view-mode", "pilot");
204 fgSetDouble("/sim/current-view/heading-offset-deg", 0);
205 fgSetDouble("/environment/visibility-m", 20000);
208 fgSetString("/sim/startup/units", "feet");
209 fgSetString("/sim/hud/frame-stat-type", "tris");
212 fgSetInt("/sim/startup/time-offset", 0);
213 fgSetString("/sim/startup/time-offset-type", "system-offset");
214 fgSetLong("/sim/time/cur-time-override", 0);
216 fgSetBool("/sim/networking/network-olk", false);
217 fgSetString("/sim/networking/call-sign", "Johnny");
220 fgSetBool("/sim/freeze/master", false);
221 fgSetBool("/sim/freeze/position", false);
222 fgSetBool("/sim/freeze/clock", false);
223 fgSetBool("/sim/freeze/fuel", false);
228 parse_wind (const string &wind, double * min_hdg, double * max_hdg,
229 double * speed, double * gust)
231 string::size_type pos = wind.find('@');
232 if (pos == string::npos)
234 string dir = wind.substr(0, pos);
235 string spd = wind.substr(pos+1);
237 if (pos == string::npos) {
238 *min_hdg = *max_hdg = atof(dir.c_str());
240 *min_hdg = atof(dir.substr(0,pos).c_str());
241 *max_hdg = atof(dir.substr(pos+1).c_str());
244 if (pos == string::npos) {
245 *speed = *gust = atof(spd.c_str());
247 *speed = atof(spd.substr(0,pos).c_str());
248 *gust = atof(spd.substr(pos+1).c_str());
253 // parse a time string ([+/-]%f[:%f[:%f]]) into hours
255 parse_time(const string& time_in) {
256 char *time_str, num[256];
257 double hours, minutes, seconds;
262 time_str = (char *)time_in.c_str();
264 // printf("parse_time(): %s\n", time_str);
267 if ( strlen(time_str) ) {
268 if ( time_str[0] == '+' ) {
271 } else if ( time_str[0] == '-' ) {
276 // printf("sign = %d\n", sign);
279 if ( strlen(time_str) ) {
281 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
282 num[i] = time_str[0];
286 if ( time_str[0] == ':' ) {
291 // printf("hours = %.2lf\n", hours);
297 if ( strlen(time_str) ) {
299 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
300 num[i] = time_str[0];
304 if ( time_str[0] == ':' ) {
309 // printf("minutes = %.2lf\n", minutes);
311 result += minutes / 60.0;
315 if ( strlen(time_str) ) {
317 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
318 num[i] = time_str[0];
324 // printf("seconds = %.2lf\n", seconds);
326 result += seconds / 3600.0;
329 cout << " parse_time() = " << sign * result << endl;
331 return(sign * result);
335 // parse a date string (yyyy:mm:dd:hh:mm:ss) into a time_t (seconds)
337 parse_date( const string& date)
340 char * date_str, num[256];
342 // initialize to zero
349 gmt.tm_isdst = 0; // ignore daylight savings time for the moment
350 date_str = (char *)date.c_str();
352 if ( strlen(date_str) ) {
354 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
355 num[i] = date_str[0];
359 if ( date_str[0] == ':' ) {
363 gmt.tm_year = atoi(num) - 1900;
366 if ( strlen(date_str) ) {
368 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
369 num[i] = date_str[0];
373 if ( date_str[0] == ':' ) {
377 gmt.tm_mon = atoi(num) -1;
380 if ( strlen(date_str) ) {
382 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
383 num[i] = date_str[0];
387 if ( date_str[0] == ':' ) {
391 gmt.tm_mday = atoi(num);
394 if ( strlen(date_str) ) {
396 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
397 num[i] = date_str[0];
401 if ( date_str[0] == ':' ) {
405 gmt.tm_hour = atoi(num);
408 if ( strlen(date_str) ) {
410 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
411 num[i] = date_str[0];
415 if ( date_str[0] == ':' ) {
419 gmt.tm_min = atoi(num);
422 if ( strlen(date_str) ) {
424 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
425 num[i] = date_str[0];
429 if ( date_str[0] == ':' ) {
433 gmt.tm_sec = atoi(num);
435 time_t theTime = sgTimeGetGMT( gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
436 gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
437 //printf ("Date is %s\n", ctime(&theTime));
438 //printf ("in seconds that is %d\n", theTime);
444 // parse angle in the form of [+/-]ddd:mm:ss into degrees
446 parse_degree( const string& degree_str) {
447 double result = parse_time( degree_str );
449 // printf("Degree = %.4f\n", result);
455 // parse time offset string into seconds
457 parse_time_offset( const string& time_str) {
460 // printf("time offset = %s\n", time_str);
463 result = (int)rint(parse_time(time_str) * 3600.0);
465 result = (int)(parse_time(time_str) * 3600.0);
468 // printf("parse_time_offset(): %d\n", result);
474 // Parse --fov=x.xx type option
476 parse_fov( const string& arg ) {
477 double fov = atof(arg);
479 if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
480 if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
482 fgSetDouble("/sim/current-view/field-of-view", fov);
484 // printf("parse_fov(): result = %.4f\n", fov);
490 // Parse I/O channel option
492 // Format is "--protocol=medium,direction,hz,medium_options,..."
494 // protocol = { native, nmea, garmin, fgfs, rul, pve, etc. }
495 // medium = { serial, socket, file, etc. }
496 // direction = { in, out, bi }
497 // hz = number of times to process channel per second (floating
498 // point values are ok.
500 // Serial example "--nmea=serial,dir,hz,device,baud" where
502 // device = OS device name of serial line to be open()'ed
503 // baud = {300, 1200, 2400, ..., 230400}
505 // Socket exacmple "--native=socket,dir,hz,machine,port,style" where
507 // machine = machine name or ip address if client (leave empty if server)
508 // port = port, leave empty to let system choose
509 // style = tcp or udp
511 // File example "--garmin=file,dir,hz,filename" where
513 // filename = file system file name
516 add_channel( const string& type, const string& channel_str ) {
517 // cout << "Channel string = " << channel_str << endl;
519 globals->get_channel_options_list()->push_back( type + "," + channel_str );
526 setup_wind (double min_hdg, double max_hdg, double speed, double gust)
528 fgSetDouble("/environment/wind-from-heading-deg", min_hdg);
529 fgSetDouble("/environment/params/min-wind-from-heading-deg", min_hdg);
530 fgSetDouble("/environment/params/max-wind-from-heading-deg", max_hdg);
531 fgSetDouble("/environment/wind-speed-kt", speed);
532 fgSetDouble("/environment/params/base-wind-speed-kt", speed);
533 fgSetDouble("/environment/params/gust-wind-speed-kt", gust);
535 SG_LOG(SG_GENERAL, SG_INFO, "WIND: " << min_hdg << '@' <<
536 speed << " knots" << endl);
540 speed *= SG_NM_TO_METER * SG_METER_TO_FEET * (1.0/3600);
541 while (min_hdg > 360)
545 min_hdg *= SGD_DEGREES_TO_RADIANS;
546 fgSetDouble("/environment/wind-from-north-fps", speed * cos(dir));
547 fgSetDouble("/environment/wind-from-east-fps", speed * sin(dir));
548 #endif // FG_WEATHERCM
552 // Parse --wp=ID[@alt]
554 parse_wp( const string& arg ) {
558 string::size_type pos = arg.find( "@" );
559 if ( pos != string::npos ) {
560 id = arg.substr( 0, pos );
561 alt_str = arg.substr( pos + 1 );
562 // cout << "id str = " << id << " alt str = " << alt_str << endl;
563 alt = atof( alt_str.c_str() );
564 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") ) {
565 alt *= SG_FEET_TO_METER;
572 if ( fgFindAirportID( id, &a ) ) {
573 SGWayPoint wp( a.longitude, a.latitude, alt, SGWayPoint::WGS84, id );
574 globals->get_route()->add_waypoint( wp );
583 // Parse --flight-plan=[file]
585 parse_flightplan(const string& arg)
587 sg_gzifstream in(arg.c_str());
588 if ( !in.is_open() ) {
594 #if defined( macintosh )
595 getline( in, line, '\r' );
597 getline( in, line, '\n' );
600 // catch extraneous (DOS) line ending character
601 if ( line[line.length() - 1] < 32 ) {
602 line = line.substr( 0, line.length()-1 );
615 // Parse a single option
617 parse_option (const string& arg)
620 if ( (arg == "--help") || (arg == "-h") ) {
621 // help/usage request
622 return(FG_OPTIONS_HELP);
623 } else if ( (arg == "--verbose") || (arg == "-v") ) {
624 // verbose help/usage request
625 return(FG_OPTIONS_VERBOSE_HELP);
626 } else if ( arg.find( "--language=") == 0 ) {
627 globals->set_locale( fgInitLocale( arg.substr( 11 ).c_str() ) );
628 } else if ( arg == "--disable-game-mode") {
629 fgSetBool("/sim/startup/game-mode", false);
630 } else if ( arg == "--enable-game-mode" ) {
631 fgSetBool("/sim/startup/game-mode", true);
632 } else if ( arg == "--disable-splash-screen" ) {
633 fgSetBool("/sim/startup/splash-screen", false);
634 } else if ( arg == "--enable-splash-screen" ) {
635 fgSetBool("/sim/startup/splash-screen", true);
636 } else if ( arg == "--disable-intro-music" ) {
637 fgSetBool("/sim/startup/intro-music", false);
638 } else if ( arg == "--enable-intro-music" ) {
639 fgSetBool("/sim/startup/intro-music", true);
640 } else if ( arg == "--disable-mouse-pointer" ) {
641 fgSetString("/sim/startup/mouse-pointer", "disabled");
642 } else if ( arg == "--enable-mouse-pointer" ) {
643 fgSetString("/sim/startup/mouse-pointer", "enabled");
644 } else if ( arg == "--disable-random-objects" ) {
645 fgSetBool("/sim/rendering/random-objects", false);
646 } else if ( arg == "--enable-random-objects" ) {
647 fgSetBool("/sim/rendering/random-objects", true);
648 } else if ( arg == "--disable-freeze" ) {
649 fgSetBool("/sim/freeze/master", false);
650 } else if ( arg == "--enable-freeze" ) {
651 fgSetBool("/sim/freeze/master", true);
652 } else if ( arg == "--disable-fuel-freeze" ) {
653 fgSetBool("/sim/freeze/fuel", false);
654 } else if ( arg == "--enable-fuel-freeze" ) {
655 fgSetBool("/sim/freeze/fuel", true);
656 } else if ( arg == "--disable-clock-freeze" ) {
657 fgSetBool("/sim/freeze/clock", false);
658 } else if ( arg == "--enable-clock-freeze" ) {
659 fgSetBool("/sim/freeze/clock", true);
660 } else if ( arg == "--disable-anti-alias-hud" ) {
661 fgSetBool("/sim/hud/antialiased", false);
662 } else if ( arg == "--enable-anti-alias-hud" ) {
663 fgSetBool("/sim/hud/antialiased", true);
664 } else if ( arg.find( "--control=") == 0 ) {
665 fgSetString("/sim/control-mode", arg.substr(10).c_str());
666 } else if ( arg == "--disable-auto-coordination" ) {
667 fgSetBool("/sim/auto-coordination", false);
668 } else if ( arg == "--enable-auto-coordination" ) {
669 fgSetBool("/sim/auto-coordination", true);
670 } else if ( arg.find( "--browser-app=") == 0 ) {
671 fgSetString("/sim/startup/browser-app", arg.substr(14).c_str());
672 } else if ( arg == "--disable-hud" ) {
673 fgSetBool("/sim/hud/visibility", false);
674 } else if ( arg == "--enable-hud" ) {
675 fgSetBool("/sim/hud/visibility", true);
676 } else if ( arg == "--disable-panel" ) {
677 fgSetBool("/sim/panel/visibility", false);
678 } else if ( arg == "--enable-panel" ) {
679 fgSetBool("/sim/panel/visibility", true);
680 } else if ( arg == "--disable-sound" ) {
681 fgSetBool("/sim/sound/audible", false);
682 } else if ( arg == "--enable-sound" ) {
683 fgSetBool("/sim/sound/audible", true);
684 } else if ( arg.find( "--airport=") == 0 ) {
685 fgSetString("/sim/presets/airport-id", arg.substr(10).c_str());
686 } else if ( arg.find( "--airport-id=") == 0 ) {
687 fgSetString("/sim/presets/airport-id", arg.substr(13).c_str());
688 } else if ( arg.find( "--runway=") == 0 ) {
689 fgSetString("/sim/presets/runway", arg.substr(9).c_str());
690 } else if ( arg.find( "--offset-distance=") == 0 ) {
691 fgSetDouble("/sim/presets/offset-distance", atof(arg.substr(18)));
692 } else if ( arg.find( "--offset-azimuth=") == 0 ) {
693 fgSetDouble("/sim/presets/offset-azimuth", atof(arg.substr(17)));
694 } else if ( arg.find( "--lon=" ) == 0 ) {
695 fgSetDouble("/sim/presets/longitude-deg", parse_degree(arg.substr(6)));
696 fgSetDouble("/position/longitude-deg", parse_degree(arg.substr(6)));
697 fgSetString("/sim/presets/airport-id", "");
698 } else if ( arg.find( "--lat=" ) == 0 ) {
699 fgSetDouble("/sim/presets/latitude-deg", parse_degree(arg.substr(6)));
700 fgSetDouble("/position/latitude-deg", parse_degree(arg.substr(6)));
701 fgSetString("/sim/presets/airport-id", "");
702 } else if ( arg.find( "--altitude=" ) == 0 ) {
703 fgSetBool("/sim/presets/onground", false);
704 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
705 fgSetDouble("/sim/presets/altitude-ft", atof(arg.substr(11)));
707 fgSetDouble("/sim/presets/altitude-ft",
708 atof(arg.substr(11)) * SG_METER_TO_FEET);
709 } else if ( arg.find( "--uBody=" ) == 0 ) {
710 fgSetString("/sim/presets/speed-set", "UVW");
711 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
712 fgSetDouble("/sim/presets/uBody-fps", atof(arg.substr(8)));
714 fgSetDouble("/sim/presets/uBody-fps",
715 atof(arg.substr(8)) * SG_METER_TO_FEET);
716 } else if ( arg.find( "--vBody=" ) == 0 ) {
717 fgSetString("/sim/presets/speed-set", "UVW");
718 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
719 fgSetDouble("/sim/presets/vBody-fps", atof(arg.substr(8)));
721 fgSetDouble("/sim/presets/vBody-fps",
722 atof(arg.substr(8)) * SG_METER_TO_FEET);
723 } else if ( arg.find( "--wBody=" ) == 0 ) {
724 fgSetString("/sim/presets/speed-set", "UVW");
725 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
726 fgSetDouble("/sim/presets/wBody-fps", atof(arg.substr(8)));
728 fgSetDouble("/sim/presets/wBody-fps",
729 atof(arg.substr(8)) * SG_METER_TO_FEET);
730 } else if ( arg.find( "--vNorth=" ) == 0 ) {
731 fgSetString("/sim/presets/speed-set", "NED");
732 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
733 fgSetDouble("/sim/presets/speed-north-fps", atof(arg.substr(9)));
735 fgSetDouble("/sim/presets/speed-north-fps",
736 atof(arg.substr(9)) * SG_METER_TO_FEET);
737 } else if ( arg.find( "--vEast=" ) == 0 ) {
738 fgSetString("/sim/presets/speed-set", "NED");
739 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
740 fgSetDouble("/sim/presets/speed-east-fps", atof(arg.substr(8)));
742 fgSetDouble("/sim/presets/speed-east-fps",
743 atof(arg.substr(8)) * SG_METER_TO_FEET);
744 } else if ( arg.find( "--vDown=" ) == 0 ) {
745 fgSetString("/sim/presets/speed-set", "NED");
746 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
747 fgSetDouble("/sim/presets/speed-down-fps", atof(arg.substr(8)));
749 fgSetDouble("/sim/presets/speed-down-fps",
750 atof(arg.substr(8)) * SG_METER_TO_FEET);
751 } else if ( arg.find( "--vc=" ) == 0) {
752 // fgSetString("/sim/presets/speed-set", "knots");
753 // fgSetDouble("/velocities/airspeed-kt", atof(arg.substr(5)));
754 fgSetString("/sim/presets/speed-set", "knots");
755 fgSetDouble("/sim/presets/airspeed-kt", atof(arg.substr(5)));
756 } else if ( arg.find( "--mach=" ) == 0) {
757 fgSetString("/sim/presets/speed-set", "mach");
758 fgSetDouble("/sim/presets/mach", atof(arg.substr(7)));
759 } else if ( arg.find( "--heading=" ) == 0 ) {
760 fgSetDouble("/sim/presets/heading-deg", atof(arg.substr(10)));
761 } else if ( arg.find( "--roll=" ) == 0 ) {
762 fgSetDouble("/sim/presets/roll-deg", atof(arg.substr(7)));
763 } else if ( arg.find( "--pitch=" ) == 0 ) {
764 fgSetDouble("/sim/presets/pitch-deg", atof(arg.substr(8)));
765 } else if ( arg.find( "--glideslope=" ) == 0 ) {
766 fgSetDouble("/sim/presets/glideslope-deg",
767 atof(arg.substr(13)));
768 } else if ( arg.find( "--roc=" ) == 0 ) {
769 fgSetDouble("/velocities/vertical-speed-fps", atof(arg.substr(6))/60);
770 } else if ( arg.find( "--fg-root=" ) == 0 ) {
771 globals->set_fg_root(arg.substr( 10 ));
772 } else if ( arg.find( "--fg-scenery=" ) == 0 ) {
773 globals->set_fg_scenery(arg.substr( 13 ));
774 } else if ( arg.find( "--fdm=" ) == 0 ) {
775 fgSetString("/sim/flight-model", arg.substr(6).c_str());
776 } else if ( arg.find( "--aero=" ) == 0 ) {
777 fgSetString("/sim/aero", arg.substr(7).c_str());
778 } else if ( arg.find( "--aircraft-dir=" ) == 0 ) {
779 fgSetString("/sim/aircraft-dir", arg.substr(15).c_str());
780 } else if ( arg.find( "--show-aircraft") == 0) {
781 return(FG_OPTIONS_SHOW_AIRCRAFT);
782 } else if ( arg.find( "--model-hz=" ) == 0 ) {
783 fgSetInt("/sim/model-hz", atoi(arg.substr(11)));
784 } else if ( arg.find( "--speed=" ) == 0 ) {
785 fgSetInt("/sim/speed-up", atoi(arg.substr(8)));
786 } else if ( arg.find( "--trim") == 0) {
787 fgSetBool("/sim/presets/trim", true);
788 } else if ( arg.find( "--notrim") == 0) {
789 fgSetBool("/sim/presets/trim", false);
790 } else if ( arg.find( "--on-ground") == 0) {
791 fgSetBool("/sim/presets/onground", true);
792 } else if ( arg.find( "--in-air") == 0) {
793 fgSetBool("/sim/presets/onground", false);
794 } else if ( arg == "--fog-disable" ) {
795 fgSetString("/sim/rendering/fog", "disabled");
796 } else if ( arg == "--fog-fastest" ) {
797 fgSetString("/sim/rendering/fog", "fastest");
798 } else if ( arg == "--fog-nicest" ) {
799 fgSetString("/sim/fog", "nicest");
800 } else if ( arg == "--disable-clouds" ) {
801 fgSetBool("/environment/clouds/status", false);
802 } else if ( arg == "--enable-clouds" ) {
803 fgSetBool("/environment/clouds/status", true);
804 } else if ( arg == "--disable-clouds3d" ) {
805 fgSetBool("/sim/rendering/clouds3d", false);
806 } else if ( arg == "--enable-clouds3d" ) {
807 fgSetBool("/sim/rendering/clouds3d", true);
808 } else if ( arg.find( "--fov=" ) == 0 ) {
809 parse_fov( arg.substr(6) );
810 } else if ( arg == "--disable-fullscreen" ) {
811 fgSetBool("/sim/startup/fullscreen", false);
812 } else if ( arg== "--enable-fullscreen") {
813 fgSetBool("/sim/startup/fullscreen", true);
814 } else if ( arg == "--shading-flat") {
815 fgSetBool("/sim/rendering/shading", false);
816 } else if ( arg == "--shading-smooth") {
817 fgSetBool("/sim/rendering/shading", true);
818 } else if ( arg == "--disable-skyblend") {
819 fgSetBool("/sim/rendering/skyblend", false);
820 } else if ( arg== "--enable-skyblend" ) {
821 fgSetBool("/sim/rendering/skyblend", true);
822 } else if ( arg == "--disable-textures" ) {
823 fgSetBool("/sim/rendering/textures", false);
824 } else if ( arg == "--enable-textures" ) {
825 fgSetBool("/sim/rendering/textures", true);
826 } else if ( arg == "--disable-wireframe" ) {
827 fgSetBool("/sim/rendering/wireframe", false);
828 } else if ( arg == "--enable-wireframe" ) {
829 fgSetBool("/sim/rendering/wireframe", true);
830 } else if ( arg.find( "--geometry=" ) == 0 ) {
831 bool geometry_ok = true;
832 int xsize = 0, ysize = 0;
833 string geometry = arg.substr( 11 );
834 string::size_type i = geometry.find('x');
836 if (i != string::npos) {
837 xsize = atoi(geometry.substr(0, i));
838 ysize = atoi(geometry.substr(i+1));
843 if ( xsize <= 0 || ysize <= 0 ) {
849 if ( !geometry_ok ) {
850 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown geometry: " << geometry );
851 SG_LOG( SG_GENERAL, SG_ALERT,
852 "Setting geometry to " << xsize << 'x' << ysize << '\n');
854 SG_LOG( SG_GENERAL, SG_INFO,
855 "Setting geometry to " << xsize << 'x' << ysize << '\n');
856 fgSetInt("/sim/startup/xsize", xsize);
857 fgSetInt("/sim/startup/ysize", ysize);
859 } else if ( arg.find( "--bpp=" ) == 0 ) {
860 string bits_per_pix = arg.substr( 6 );
861 if ( bits_per_pix == "16" ) {
862 fgSetInt("/sim/rendering/bits-per-pixel", 16);
863 } else if ( bits_per_pix == "24" ) {
864 fgSetInt("/sim/rendering/bits-per-pixel", 24);
865 } else if ( bits_per_pix == "32" ) {
866 fgSetInt("/sim/rendering/bits-per-pixel", 32);
868 SG_LOG(SG_GENERAL, SG_ALERT, "Unsupported bpp " << bits_per_pix);
870 } else if ( arg == "--units-feet" ) {
871 fgSetString("/sim/startup/units", "feet");
872 } else if ( arg == "--units-meters" ) {
873 fgSetString("/sim/startup/units", "meters");
874 } else if ( arg.find( "--time-offset" ) == 0 ) {
875 fgSetInt("/sim/startup/time-offset",
876 parse_time_offset( (arg.substr(14)) ));
877 fgSetString("/sim/startup/time-offset-type", "system-offset");
878 } else if ( arg.find( "--time-match-real") == 0 ) {
879 fgSetString("/sim/startup/time-offset-type", "system-offset");
880 } else if ( arg.find( "--time-match-local") == 0 ) {
881 fgSetString("/sim/startup/time-offset-type", "latitude-offset");
882 } else if ( arg.find( "--start-date-sys=") == 0 ) {
883 fgSetInt("/sim/startup/time-offset", parse_date((arg.substr(17))));
884 fgSetString("/sim/startup/time-offset-type", "system");
885 } else if ( arg.find( "--start-date-lat=") == 0 ) {
886 fgSetInt("/sim/startup/time-offset", parse_date((arg.substr(17))));
887 fgSetString("/sim/startup/time-offset-type", "latitude");
888 } else if ( arg.find( "--start-date-gmt=") == 0 ) {
889 fgSetInt("/sim/startup/time-offset", parse_date((arg.substr(17))));
890 fgSetString("/sim/startup/time-offset-type", "gmt");
891 } else if ( arg == "--hud-tris" ) {
892 fgSetString("/sim/hud/frame-stat-type", "tris");
893 } else if ( arg == "--hud-culled" ) {
894 fgSetString("/sim/hud/frame-stat-type", "culled");
895 } else if ( arg.find( "--atc610x" ) == 0 ) {
896 add_channel( "atc610x", "dummy" );
897 } else if ( arg.find( "--atlas=" ) == 0 ) {
898 add_channel( "atlas", arg.substr(8) );
899 } else if ( arg.find( "--httpd=" ) == 0 ) {
900 add_channel( "httpd", arg.substr(8) );
901 #ifdef FG_JPEG_SERVER
902 } else if ( arg.find( "--jpg-httpd=" ) == 0 ) {
903 add_channel( "jpg-httpd", arg.substr(12) );
905 } else if ( arg.find( "--native=" ) == 0 ) {
906 add_channel( "native", arg.substr(9) );
907 } else if ( arg.find( "--native-ctrls=" ) == 0 ) {
908 add_channel( "native_ctrls", arg.substr(15) );
909 } else if ( arg.find( "--native-fdm=" ) == 0 ) {
910 add_channel( "native_fdm", arg.substr(13) );
911 } else if ( arg.find( "--opengc=" ) == 0 ) {
913 // cout << "Adding channel for OpenGC Display" << endl; cin >> stop;
914 add_channel( "opengc", arg.substr(9) );
915 } else if ( arg.find( "--garmin=" ) == 0 ) {
916 add_channel( "garmin", arg.substr(9) );
917 } else if ( arg.find( "--nmea=" ) == 0 ) {
918 add_channel( "nmea", arg.substr(7) );
919 } else if ( arg.find( "--props=" ) == 0 ) {
920 add_channel( "props", arg.substr(8) );
921 } else if ( arg.find( "--telnet=" ) == 0 ) {
922 add_channel( "telnet", arg.substr(9) );
923 } else if ( arg.find( "--pve=" ) == 0 ) {
924 add_channel( "pve", arg.substr(6) );
925 } else if ( arg.find( "--ray=" ) == 0 ) {
926 add_channel( "ray", arg.substr(6) );
927 } else if ( arg.find( "--rul=" ) == 0 ) {
928 add_channel( "rul", arg.substr(6) );
929 } else if ( arg.find( "--joyclient=" ) == 0 ) {
930 add_channel( "joyclient", arg.substr(12) );
931 #ifdef FG_NETWORK_OLK
932 } else if ( arg == "--disable-network-olk" ) {
933 fgSetBool("/sim/networking/olk", false);
934 } else if ( arg== "--enable-network-olk") {
935 fgSetBool("/sim/networking/olk", true);
936 } else if ( arg == "--net-hud" ) {
937 fgSetBool("/sim/hud/net-display", true);
938 net_hud_display = 1; // FIXME
939 } else if ( arg.find( "--net-id=") == 0 ) {
940 fgSetString("sim/networking/call-sign", arg.substr(9).c_str());
942 } else if ( arg.find( "--prop:" ) == 0 ) {
943 string assign = arg.substr(7);
944 string::size_type pos = assign.find('=');
945 if ( pos == arg.npos || pos == 0 ) {
946 SG_LOG( SG_GENERAL, SG_ALERT, "Bad property assignment: " << arg );
947 return FG_OPTIONS_ERROR;
949 string name = assign.substr(0, pos);
950 string value = assign.substr(pos + 1);
951 fgSetString(name.c_str(), value.c_str());
952 // SG_LOG(SG_GENERAL, SG_INFO, "Setting default value of property "
953 // << name << " to \"" << value << '"');
954 } else if ( arg.find("--trace-read=") == 0) {
955 string name = arg.substr(13);
956 SG_LOG(SG_GENERAL, SG_INFO, "Tracing reads for property " << name);
957 fgGetNode(name.c_str(), true)
958 ->setAttribute(SGPropertyNode::TRACE_READ, true);
959 } else if ( arg.find("--trace-write=") == 0) {
960 string name = arg.substr(14);
961 SG_LOG(SG_GENERAL, SG_INFO, "Tracing writes for property " << name);
962 fgGetNode(name.c_str(), true)
963 ->setAttribute(SGPropertyNode::TRACE_WRITE, true);
964 } else if ( arg.find( "--view-offset=" ) == 0 ) {
965 // $$$ begin - added VS Renganathan, 14 Oct 2K
966 // for multi-window outside window imagery
967 string woffset = arg.substr( 14 );
968 double default_view_offset = 0.0;
969 if ( woffset == "LEFT" ) {
970 default_view_offset = SGD_PI * 0.25;
971 } else if ( woffset == "RIGHT" ) {
972 default_view_offset = SGD_PI * 1.75;
973 } else if ( woffset == "CENTER" ) {
974 default_view_offset = 0.00;
976 default_view_offset = atof( woffset.c_str() ) * SGD_DEGREES_TO_RADIANS;
978 /* apparently not used (CLO, 11 Jun 2002)
979 FGViewer *pilot_view =
980 (FGViewer *)globals->get_viewmgr()->get_view( 0 ); */
981 // this will work without calls to the viewer...
982 fgSetDouble( "/sim/current-view/heading-offset-deg",
983 default_view_offset * SGD_RADIANS_TO_DEGREES );
984 // $$$ end - added VS Renganathan, 14 Oct 2K
985 } else if ( arg.find( "--visibility=" ) == 0 ) {
986 fgSetDouble("/environment/visibility-m", atof(arg.substr(13)));
987 } else if ( arg.find( "--visibility-miles=" ) == 0 ) {
988 double visibility = atof(arg.substr(19)) * 5280.0 * SG_FEET_TO_METER;
989 fgSetDouble("/environment/visibility-m", visibility);
990 } else if ( arg.find( "--random-wind" ) == 0 ) {
991 double min_hdg = sg_random() * 360.0;
992 double max_hdg = min_hdg + (20 - sqrt(sg_random() * 400));
993 double speed = 40 - sqrt(sg_random() * 1600.0);
994 double gust = speed + (10 - sqrt(sg_random() * 100));
995 setup_wind(min_hdg, max_hdg, speed, gust);
996 } else if ( arg.find( "--wind=" ) == 0 ) {
997 double min_hdg, max_hdg, speed, gust;
998 if (!parse_wind(arg.substr(7), &min_hdg, &max_hdg, &speed, &gust)) {
999 SG_LOG( SG_GENERAL, SG_ALERT, "bad wind value " << arg.substr(7) );
1000 return FG_OPTIONS_ERROR;
1002 setup_wind(min_hdg, max_hdg, speed, gust);
1003 } else if ( arg.find( "--wp=" ) == 0 ) {
1004 parse_wp( arg.substr( 5 ) );
1005 } else if ( arg.find( "--flight-plan=") == 0) {
1006 parse_flightplan ( arg.substr (14) );
1007 } else if ( arg.find( "--config=" ) == 0 ) {
1008 string file = arg.substr(9);
1010 readProperties(file, globals->get_props());
1011 } catch (const sg_exception &e) {
1012 string message = "Error loading config file: ";
1013 message += e.getFormattedMessage();
1014 SG_LOG(SG_INPUT, SG_ALERT, message);
1017 } else if ( arg.find( "--aircraft=" ) == 0 ) {
1018 fgSetString("/sim/aircraft", arg.substr(11).c_str());
1020 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" );
1021 return FG_OPTIONS_ERROR;
1024 return FG_OPTIONS_OK;
1028 // Parse the command line options
1030 fgParseArgs (int argc, char **argv)
1032 bool in_options = true;
1033 bool verbose = false;
1036 SG_LOG(SG_GENERAL, SG_INFO, "Processing command line arguments");
1038 for (int i = 1; i < argc; i++) {
1039 string arg = argv[i];
1041 if (in_options && (arg.find('-') == 0)) {
1045 int result = parse_option(arg);
1046 if ((result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR))
1049 else if (result == FG_OPTIONS_VERBOSE_HELP)
1052 else if (result == FG_OPTIONS_SHOW_AIRCRAFT) {
1059 SG_LOG(SG_GENERAL, SG_INFO,
1060 "Reading command-line property file " << arg);
1061 readProperties(arg, globals->get_props());
1070 SG_LOG(SG_GENERAL, SG_INFO, "Finished command line arguments");
1074 // Parse config file options
1076 fgParseOptions (const string& path) {
1077 sg_gzifstream in( path );
1078 if ( !in.is_open() ) {
1082 SG_LOG( SG_GENERAL, SG_INFO, "Processing config file: " << path );
1086 while ( ! in.eof() ) {
1089 while ( in.get(c) && c != '\0' ) {
1094 #if defined( macintosh )
1095 getline( in, line, '\r' );
1097 getline( in, line, '\n' );
1100 // catch extraneous (DOS) line ending character
1101 if ( line[line.length() - 1] < 32 ) {
1102 line = line.substr( 0, line.length()-1 );
1105 if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
1106 cerr << endl << "Config file parse error: " << path << " '"
1107 << line << "'" << endl;
1116 // Print usage message
1118 fgUsage (bool verbose)
1120 SGPropertyNode *locale = globals->get_locale();
1122 SGPropertyNode options_root;
1127 fgLoadProps("options.xml", &options_root);
1128 } catch (const sg_exception &ex) {
1129 cout << "Unable to read the help file." << endl;
1130 cout << "Make sure the file options.xml is located in the FlightGear base directory," << endl;
1131 cout << "and the location of the base directory is specified by setting $FG_ROOT or" << endl;
1132 cout << "by adding --fg-root=path as a program argument." << endl;
1137 SGPropertyNode *options = options_root.getNode("options");
1139 SG_LOG( SG_GENERAL, SG_ALERT,
1140 "Error reading options.xml: <options> directive not found." );
1144 SGPropertyNode *usage = locale->getNode(options->getStringValue("usage"));
1146 cout << "Usage: " << usage->getStringValue() << endl;
1149 vector<SGPropertyNode_ptr>section = options->getChildren("section");
1150 for (unsigned int j = 0; j < section.size(); j++) {
1153 vector<SGPropertyNode_ptr>option = section[j]->getChildren("option");
1154 for (unsigned int k = 0; k < option.size(); k++) {
1156 SGPropertyNode *name = option[k]->getNode("name");
1157 SGPropertyNode *short_name = option[k]->getNode("short");
1158 SGPropertyNode *key = option[k]->getNode("key");
1159 SGPropertyNode *arg = option[k]->getNode("arg");
1160 bool brief = option[k]->getNode("brief");
1162 if ((brief || verbose) && name) {
1163 string tmp = name->getStringValue();
1167 tmp.append(key->getStringValue());
1171 tmp.append(arg->getStringValue());
1175 tmp.append(short_name->getStringValue());
1179 if (tmp.size() <= 25) {
1180 snprintf(cstr, 96, " --%-27s", tmp.c_str());
1182 snprintf(cstr, 96, "\n --%s\n%32c", tmp.c_str(), ' ');
1185 // There may be more than one <description> tag assosiated
1189 vector<SGPropertyNode_ptr>desc =
1190 option[k]->getChildren("description");
1192 if (desc.size() > 0) {
1193 for ( unsigned int l = 0; l < desc.size(); l++) {
1195 // There may be more than one translation line.
1197 string t = desc[l]->getStringValue();
1198 SGPropertyNode *n = locale->getNode("strings");
1199 vector<SGPropertyNode_ptr>trans_desc =
1200 n->getChildren(t.substr(8).c_str());
1202 for ( unsigned int m = 0; m < trans_desc.size(); m++ ) {
1203 string t_str = trans_desc[m]->getStringValue();
1205 if ((m > 0) || ((l > 0) && m == 0)) {
1206 snprintf(cstr, 96, "%32c", ' ');
1211 // If the string is too large to fit on the screen,
1212 // then split it up in several pieces.
1214 while ( t_str.size() > 47 ) {
1216 unsigned int m = t_str.rfind(' ', 47);
1217 msg += t_str.substr(0, m);
1218 snprintf(cstr, 96, "\n%32c", ' ');
1221 t_str.erase(t_str.begin(), t_str.begin() + m + 1);
1223 msg += t_str + '\n';
1230 SGPropertyNode *name =
1231 locale->getNode(section[j]->getStringValue("name"));
1233 if (!msg.empty() && name) {
1234 cout << endl << name->getStringValue() << ":" << endl;
1242 cout << "For a complete list of options use --help --verbose" << endl;
1246 // Show available aircraft types
1247 void fgShowAircraft(void) {
1248 SGPath path( globals->get_fg_root() );
1249 path.append("Aircraft");
1254 dirp = ulOpenDir(path.c_str());
1256 cerr << "Unable to open aircraft directory." << endl;
1260 cout << "Available aircraft:" << endl;
1261 while ((dire = ulReadDir(dirp)) != NULL) {
1264 if ((ptr = strstr(dire->d_name, "-set.xml")) && ptr[8] == '\0' ) {
1265 SGPath afile = path;
1266 afile.append(dire->d_name);
1270 SGPropertyNode root;
1272 readProperties(afile.str(), &root);
1277 SGPropertyNode *desc = NULL;
1278 SGPropertyNode *node = root.getNode("sim");
1280 desc = node->getNode("description");
1284 if (strlen(dire->d_name) <= 27)
1285 snprintf(cstr, 96, " %-27s %s", dire->d_name,
1286 (desc) ? desc->getStringValue() : "" );
1289 snprintf(cstr, 96, " %-27s\n%32c%s", dire->d_name, ' ',
1290 (desc) ? desc->getStringValue() : "" );
1292 cout << cstr << endl;