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 fgSetBool("/sim/rendering/distance-attenuation", false);
201 fgSetInt("/sim/startup/xsize", 800);
202 fgSetInt("/sim/startup/ysize", 600);
203 fgSetInt("/sim/rendering/bits-per-pixel", 16);
204 fgSetString("/sim/view-mode", "pilot");
205 fgSetDouble("/sim/current-view/heading-offset-deg", 0);
206 fgSetDouble("/environment/visibility-m", 20000);
209 fgSetString("/sim/startup/units", "feet");
210 fgSetString("/sim/hud/frame-stat-type", "tris");
213 fgSetInt("/sim/startup/time-offset", 0);
214 fgSetString("/sim/startup/time-offset-type", "system-offset");
215 fgSetLong("/sim/time/cur-time-override", 0);
217 fgSetBool("/sim/networking/network-olk", false);
218 fgSetString("/sim/networking/call-sign", "Johnny");
221 fgSetBool("/sim/freeze/master", false);
222 fgSetBool("/sim/freeze/position", false);
223 fgSetBool("/sim/freeze/clock", false);
224 fgSetBool("/sim/freeze/fuel", false);
229 parse_wind (const string &wind, double * min_hdg, double * max_hdg,
230 double * speed, double * gust)
232 string::size_type pos = wind.find('@');
233 if (pos == string::npos)
235 string dir = wind.substr(0, pos);
236 string spd = wind.substr(pos+1);
238 if (pos == string::npos) {
239 *min_hdg = *max_hdg = atof(dir.c_str());
241 *min_hdg = atof(dir.substr(0,pos).c_str());
242 *max_hdg = atof(dir.substr(pos+1).c_str());
245 if (pos == string::npos) {
246 *speed = *gust = atof(spd.c_str());
248 *speed = atof(spd.substr(0,pos).c_str());
249 *gust = atof(spd.substr(pos+1).c_str());
254 // parse a time string ([+/-]%f[:%f[:%f]]) into hours
256 parse_time(const string& time_in) {
257 char *time_str, num[256];
258 double hours, minutes, seconds;
263 time_str = (char *)time_in.c_str();
265 // printf("parse_time(): %s\n", time_str);
268 if ( strlen(time_str) ) {
269 if ( time_str[0] == '+' ) {
272 } else if ( time_str[0] == '-' ) {
277 // printf("sign = %d\n", sign);
280 if ( strlen(time_str) ) {
282 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
283 num[i] = time_str[0];
287 if ( time_str[0] == ':' ) {
292 // printf("hours = %.2lf\n", hours);
298 if ( strlen(time_str) ) {
300 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
301 num[i] = time_str[0];
305 if ( time_str[0] == ':' ) {
310 // printf("minutes = %.2lf\n", minutes);
312 result += minutes / 60.0;
316 if ( strlen(time_str) ) {
318 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
319 num[i] = time_str[0];
325 // printf("seconds = %.2lf\n", seconds);
327 result += seconds / 3600.0;
330 cout << " parse_time() = " << sign * result << endl;
332 return(sign * result);
336 // parse a date string (yyyy:mm:dd:hh:mm:ss) into a time_t (seconds)
338 parse_date( const string& date)
341 char * date_str, num[256];
343 // initialize to zero
350 gmt.tm_isdst = 0; // ignore daylight savings time for the moment
351 date_str = (char *)date.c_str();
353 if ( strlen(date_str) ) {
355 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
356 num[i] = date_str[0];
360 if ( date_str[0] == ':' ) {
364 gmt.tm_year = atoi(num) - 1900;
367 if ( strlen(date_str) ) {
369 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
370 num[i] = date_str[0];
374 if ( date_str[0] == ':' ) {
378 gmt.tm_mon = atoi(num) -1;
381 if ( strlen(date_str) ) {
383 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
384 num[i] = date_str[0];
388 if ( date_str[0] == ':' ) {
392 gmt.tm_mday = atoi(num);
395 if ( strlen(date_str) ) {
397 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
398 num[i] = date_str[0];
402 if ( date_str[0] == ':' ) {
406 gmt.tm_hour = atoi(num);
409 if ( strlen(date_str) ) {
411 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
412 num[i] = date_str[0];
416 if ( date_str[0] == ':' ) {
420 gmt.tm_min = atoi(num);
423 if ( strlen(date_str) ) {
425 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
426 num[i] = date_str[0];
430 if ( date_str[0] == ':' ) {
434 gmt.tm_sec = atoi(num);
436 time_t theTime = sgTimeGetGMT( gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
437 gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
438 //printf ("Date is %s\n", ctime(&theTime));
439 //printf ("in seconds that is %d\n", theTime);
445 // parse angle in the form of [+/-]ddd:mm:ss into degrees
447 parse_degree( const string& degree_str) {
448 double result = parse_time( degree_str );
450 // printf("Degree = %.4f\n", result);
456 // parse time offset string into seconds
458 parse_time_offset( const string& time_str) {
461 // printf("time offset = %s\n", time_str);
464 result = (int)rint(parse_time(time_str) * 3600.0);
466 result = (int)(parse_time(time_str) * 3600.0);
469 // printf("parse_time_offset(): %d\n", result);
475 // Parse --fov=x.xx type option
477 parse_fov( const string& arg ) {
478 double fov = atof(arg);
480 if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
481 if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
483 fgSetDouble("/sim/current-view/field-of-view", fov);
485 // printf("parse_fov(): result = %.4f\n", fov);
491 // Parse I/O channel option
493 // Format is "--protocol=medium,direction,hz,medium_options,..."
495 // protocol = { native, nmea, garmin, fgfs, rul, pve, etc. }
496 // medium = { serial, socket, file, etc. }
497 // direction = { in, out, bi }
498 // hz = number of times to process channel per second (floating
499 // point values are ok.
501 // Serial example "--nmea=serial,dir,hz,device,baud" where
503 // device = OS device name of serial line to be open()'ed
504 // baud = {300, 1200, 2400, ..., 230400}
506 // Socket exacmple "--native=socket,dir,hz,machine,port,style" where
508 // machine = machine name or ip address if client (leave empty if server)
509 // port = port, leave empty to let system choose
510 // style = tcp or udp
512 // File example "--garmin=file,dir,hz,filename" where
514 // filename = file system file name
517 add_channel( const string& type, const string& channel_str ) {
518 // cout << "Channel string = " << channel_str << endl;
520 globals->get_channel_options_list()->push_back( type + "," + channel_str );
527 setup_wind (double min_hdg, double max_hdg, double speed, double gust)
529 fgSetDouble("/environment/wind-from-heading-deg", min_hdg);
530 fgSetDouble("/environment/params/min-wind-from-heading-deg", min_hdg);
531 fgSetDouble("/environment/params/max-wind-from-heading-deg", max_hdg);
532 fgSetDouble("/environment/wind-speed-kt", speed);
533 fgSetDouble("/environment/params/base-wind-speed-kt", speed);
534 fgSetDouble("/environment/params/gust-wind-speed-kt", gust);
536 SG_LOG(SG_GENERAL, SG_INFO, "WIND: " << min_hdg << '@' <<
537 speed << " knots" << endl);
541 speed *= SG_NM_TO_METER * SG_METER_TO_FEET * (1.0/3600);
542 while (min_hdg > 360)
546 min_hdg *= SGD_DEGREES_TO_RADIANS;
547 fgSetDouble("/environment/wind-from-north-fps", speed * cos(dir));
548 fgSetDouble("/environment/wind-from-east-fps", speed * sin(dir));
549 #endif // FG_WEATHERCM
553 // Parse --wp=ID[@alt]
555 parse_wp( const string& arg ) {
559 string::size_type pos = arg.find( "@" );
560 if ( pos != string::npos ) {
561 id = arg.substr( 0, pos );
562 alt_str = arg.substr( pos + 1 );
563 // cout << "id str = " << id << " alt str = " << alt_str << endl;
564 alt = atof( alt_str.c_str() );
565 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") ) {
566 alt *= SG_FEET_TO_METER;
573 if ( fgFindAirportID( id, &a ) ) {
574 SGWayPoint wp( a.longitude, a.latitude, alt, SGWayPoint::WGS84, id );
575 globals->get_route()->add_waypoint( wp );
584 // Parse --flight-plan=[file]
586 parse_flightplan(const string& arg)
588 sg_gzifstream in(arg.c_str());
589 if ( !in.is_open() ) {
595 #if defined( macintosh )
596 getline( in, line, '\r' );
598 getline( in, line, '\n' );
601 // catch extraneous (DOS) line ending character
602 if ( line[line.length() - 1] < 32 ) {
603 line = line.substr( 0, line.length()-1 );
616 // Parse a single option
618 parse_option (const string& arg)
621 if ( (arg == "--help") || (arg == "-h") ) {
622 // help/usage request
623 return(FG_OPTIONS_HELP);
624 } else if ( (arg == "--verbose") || (arg == "-v") ) {
625 // verbose help/usage request
626 return(FG_OPTIONS_VERBOSE_HELP);
627 } else if ( arg.find( "--language=") == 0 ) {
628 globals->set_locale( fgInitLocale( arg.substr( 11 ).c_str() ) );
629 } else if ( arg == "--disable-game-mode") {
630 fgSetBool("/sim/startup/game-mode", false);
631 } else if ( arg == "--enable-game-mode" ) {
632 fgSetBool("/sim/startup/game-mode", true);
633 } else if ( arg == "--disable-splash-screen" ) {
634 fgSetBool("/sim/startup/splash-screen", false);
635 } else if ( arg == "--enable-splash-screen" ) {
636 fgSetBool("/sim/startup/splash-screen", true);
637 } else if ( arg == "--disable-intro-music" ) {
638 fgSetBool("/sim/startup/intro-music", false);
639 } else if ( arg == "--enable-intro-music" ) {
640 fgSetBool("/sim/startup/intro-music", true);
641 } else if ( arg == "--disable-mouse-pointer" ) {
642 fgSetString("/sim/startup/mouse-pointer", "disabled");
643 } else if ( arg == "--enable-mouse-pointer" ) {
644 fgSetString("/sim/startup/mouse-pointer", "enabled");
645 } else if ( arg == "--disable-random-objects" ) {
646 fgSetBool("/sim/rendering/random-objects", false);
647 } else if ( arg == "--enable-random-objects" ) {
648 fgSetBool("/sim/rendering/random-objects", true);
649 } else if ( arg == "--disable-freeze" ) {
650 fgSetBool("/sim/freeze/master", false);
651 } else if ( arg == "--enable-freeze" ) {
652 fgSetBool("/sim/freeze/master", true);
653 } else if ( arg == "--disable-fuel-freeze" ) {
654 fgSetBool("/sim/freeze/fuel", false);
655 } else if ( arg == "--enable-fuel-freeze" ) {
656 fgSetBool("/sim/freeze/fuel", true);
657 } else if ( arg == "--disable-clock-freeze" ) {
658 fgSetBool("/sim/freeze/clock", false);
659 } else if ( arg == "--enable-clock-freeze" ) {
660 fgSetBool("/sim/freeze/clock", true);
661 } else if ( arg == "--disable-anti-alias-hud" ) {
662 fgSetBool("/sim/hud/antialiased", false);
663 } else if ( arg == "--enable-anti-alias-hud" ) {
664 fgSetBool("/sim/hud/antialiased", true);
665 } else if ( arg.find( "--control=") == 0 ) {
666 fgSetString("/sim/control-mode", arg.substr(10).c_str());
667 } else if ( arg == "--disable-auto-coordination" ) {
668 fgSetBool("/sim/auto-coordination", false);
669 } else if ( arg == "--enable-auto-coordination" ) {
670 fgSetBool("/sim/auto-coordination", true);
671 } else if ( arg.find( "--browser-app=") == 0 ) {
672 fgSetString("/sim/startup/browser-app", arg.substr(14).c_str());
673 } else if ( arg == "--disable-hud" ) {
674 fgSetBool("/sim/hud/visibility", false);
675 } else if ( arg == "--enable-hud" ) {
676 fgSetBool("/sim/hud/visibility", true);
677 } else if ( arg == "--disable-panel" ) {
678 fgSetBool("/sim/panel/visibility", false);
679 } else if ( arg == "--enable-panel" ) {
680 fgSetBool("/sim/panel/visibility", true);
681 } else if ( arg == "--disable-sound" ) {
682 fgSetBool("/sim/sound/audible", false);
683 } else if ( arg == "--enable-sound" ) {
684 fgSetBool("/sim/sound/audible", true);
685 } else if ( arg.find( "--airport=") == 0 ) {
686 fgSetString("/sim/presets/airport-id", arg.substr(10).c_str());
687 } else if ( arg.find( "--airport-id=") == 0 ) {
688 fgSetString("/sim/presets/airport-id", arg.substr(13).c_str());
689 } else if ( arg.find( "--runway=") == 0 ) {
690 fgSetString("/sim/presets/runway", arg.substr(9).c_str());
691 } else if ( arg.find( "--offset-distance=") == 0 ) {
692 fgSetDouble("/sim/presets/offset-distance", atof(arg.substr(18)));
693 } else if ( arg.find( "--offset-azimuth=") == 0 ) {
694 fgSetDouble("/sim/presets/offset-azimuth", atof(arg.substr(17)));
695 } else if ( arg.find( "--lon=" ) == 0 ) {
696 fgSetDouble("/sim/presets/longitude-deg", parse_degree(arg.substr(6)));
697 fgSetDouble("/position/longitude-deg", parse_degree(arg.substr(6)));
698 fgSetString("/sim/presets/airport-id", "");
699 } else if ( arg.find( "--lat=" ) == 0 ) {
700 fgSetDouble("/sim/presets/latitude-deg", parse_degree(arg.substr(6)));
701 fgSetDouble("/position/latitude-deg", parse_degree(arg.substr(6)));
702 fgSetString("/sim/presets/airport-id", "");
703 } else if ( arg.find( "--altitude=" ) == 0 ) {
704 fgSetBool("/sim/presets/onground", false);
705 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
706 fgSetDouble("/sim/presets/altitude-ft", atof(arg.substr(11)));
708 fgSetDouble("/sim/presets/altitude-ft",
709 atof(arg.substr(11)) * SG_METER_TO_FEET);
710 } else if ( arg.find( "--uBody=" ) == 0 ) {
711 fgSetString("/sim/presets/speed-set", "UVW");
712 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
713 fgSetDouble("/sim/presets/uBody-fps", atof(arg.substr(8)));
715 fgSetDouble("/sim/presets/uBody-fps",
716 atof(arg.substr(8)) * SG_METER_TO_FEET);
717 } else if ( arg.find( "--vBody=" ) == 0 ) {
718 fgSetString("/sim/presets/speed-set", "UVW");
719 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
720 fgSetDouble("/sim/presets/vBody-fps", atof(arg.substr(8)));
722 fgSetDouble("/sim/presets/vBody-fps",
723 atof(arg.substr(8)) * SG_METER_TO_FEET);
724 } else if ( arg.find( "--wBody=" ) == 0 ) {
725 fgSetString("/sim/presets/speed-set", "UVW");
726 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
727 fgSetDouble("/sim/presets/wBody-fps", atof(arg.substr(8)));
729 fgSetDouble("/sim/presets/wBody-fps",
730 atof(arg.substr(8)) * SG_METER_TO_FEET);
731 } else if ( arg.find( "--vNorth=" ) == 0 ) {
732 fgSetString("/sim/presets/speed-set", "NED");
733 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
734 fgSetDouble("/sim/presets/speed-north-fps", atof(arg.substr(9)));
736 fgSetDouble("/sim/presets/speed-north-fps",
737 atof(arg.substr(9)) * SG_METER_TO_FEET);
738 } else if ( arg.find( "--vEast=" ) == 0 ) {
739 fgSetString("/sim/presets/speed-set", "NED");
740 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
741 fgSetDouble("/sim/presets/speed-east-fps", atof(arg.substr(8)));
743 fgSetDouble("/sim/presets/speed-east-fps",
744 atof(arg.substr(8)) * SG_METER_TO_FEET);
745 } else if ( arg.find( "--vDown=" ) == 0 ) {
746 fgSetString("/sim/presets/speed-set", "NED");
747 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
748 fgSetDouble("/sim/presets/speed-down-fps", atof(arg.substr(8)));
750 fgSetDouble("/sim/presets/speed-down-fps",
751 atof(arg.substr(8)) * SG_METER_TO_FEET);
752 } else if ( arg.find( "--vc=" ) == 0) {
753 // fgSetString("/sim/presets/speed-set", "knots");
754 // fgSetDouble("/velocities/airspeed-kt", atof(arg.substr(5)));
755 fgSetString("/sim/presets/speed-set", "knots");
756 fgSetDouble("/sim/presets/airspeed-kt", atof(arg.substr(5)));
757 } else if ( arg.find( "--mach=" ) == 0) {
758 fgSetString("/sim/presets/speed-set", "mach");
759 fgSetDouble("/sim/presets/mach", atof(arg.substr(7)));
760 } else if ( arg.find( "--heading=" ) == 0 ) {
761 fgSetDouble("/sim/presets/heading-deg", atof(arg.substr(10)));
762 } else if ( arg.find( "--roll=" ) == 0 ) {
763 fgSetDouble("/sim/presets/roll-deg", atof(arg.substr(7)));
764 } else if ( arg.find( "--pitch=" ) == 0 ) {
765 fgSetDouble("/sim/presets/pitch-deg", atof(arg.substr(8)));
766 } else if ( arg.find( "--glideslope=" ) == 0 ) {
767 fgSetDouble("/sim/presets/glideslope-deg",
768 atof(arg.substr(13)));
769 } else if ( arg.find( "--roc=" ) == 0 ) {
770 fgSetDouble("/velocities/vertical-speed-fps", atof(arg.substr(6))/60);
771 } else if ( arg.find( "--fg-root=" ) == 0 ) {
772 globals->set_fg_root(arg.substr( 10 ));
773 } else if ( arg.find( "--fg-scenery=" ) == 0 ) {
774 globals->set_fg_scenery(arg.substr( 13 ));
775 } else if ( arg.find( "--fdm=" ) == 0 ) {
776 fgSetString("/sim/flight-model", arg.substr(6).c_str());
777 } else if ( arg.find( "--aero=" ) == 0 ) {
778 fgSetString("/sim/aero", arg.substr(7).c_str());
779 } else if ( arg.find( "--aircraft-dir=" ) == 0 ) {
780 fgSetString("/sim/aircraft-dir", arg.substr(15).c_str());
781 } else if ( arg.find( "--show-aircraft") == 0) {
782 return(FG_OPTIONS_SHOW_AIRCRAFT);
783 } else if ( arg.find( "--model-hz=" ) == 0 ) {
784 fgSetInt("/sim/model-hz", atoi(arg.substr(11)));
785 } else if ( arg.find( "--speed=" ) == 0 ) {
786 fgSetInt("/sim/speed-up", atoi(arg.substr(8)));
787 } else if ( arg.find( "--trim") == 0) {
788 fgSetBool("/sim/presets/trim", true);
789 } else if ( arg.find( "--notrim") == 0) {
790 fgSetBool("/sim/presets/trim", false);
791 } else if ( arg.find( "--on-ground") == 0) {
792 fgSetBool("/sim/presets/onground", true);
793 } else if ( arg.find( "--in-air") == 0) {
794 fgSetBool("/sim/presets/onground", false);
795 } else if ( arg == "--fog-disable" ) {
796 fgSetString("/sim/rendering/fog", "disabled");
797 } else if ( arg == "--fog-fastest" ) {
798 fgSetString("/sim/rendering/fog", "fastest");
799 } else if ( arg == "--fog-nicest" ) {
800 fgSetString("/sim/fog", "nicest");
801 } else if ( arg == "--disable-distance-attenuation" ) {
802 fgSetBool("/environment/distance-attenuation", false);
803 } else if ( arg == "--enable-distance-attenuation" ) {
804 fgSetBool("/environment/distance-attenuation", true);
805 } else if ( arg == "--disable-clouds" ) {
806 fgSetBool("/environment/clouds/status", false);
807 } else if ( arg == "--enable-clouds" ) {
808 fgSetBool("/environment/clouds/status", true);
809 #ifdef FG_USE_CLOUDS_3D
810 } else if ( arg == "--disable-clouds3d" ) {
811 fgSetBool("/sim/rendering/clouds3d", false);
812 } else if ( arg == "--enable-clouds3d" ) {
813 fgSetBool("/sim/rendering/clouds3d", true);
815 } else if ( arg.find( "--fov=" ) == 0 ) {
816 parse_fov( arg.substr(6) );
817 } else if ( arg == "--disable-fullscreen" ) {
818 fgSetBool("/sim/startup/fullscreen", false);
819 } else if ( arg== "--enable-fullscreen") {
820 fgSetBool("/sim/startup/fullscreen", true);
821 } else if ( arg == "--shading-flat") {
822 fgSetBool("/sim/rendering/shading", false);
823 } else if ( arg == "--shading-smooth") {
824 fgSetBool("/sim/rendering/shading", true);
825 } else if ( arg == "--disable-skyblend") {
826 fgSetBool("/sim/rendering/skyblend", false);
827 } else if ( arg== "--enable-skyblend" ) {
828 fgSetBool("/sim/rendering/skyblend", true);
829 } else if ( arg == "--disable-textures" ) {
830 fgSetBool("/sim/rendering/textures", false);
831 } else if ( arg == "--enable-textures" ) {
832 fgSetBool("/sim/rendering/textures", true);
833 } else if ( arg == "--disable-wireframe" ) {
834 fgSetBool("/sim/rendering/wireframe", false);
835 } else if ( arg == "--enable-wireframe" ) {
836 fgSetBool("/sim/rendering/wireframe", true);
837 } else if ( arg.find( "--geometry=" ) == 0 ) {
838 bool geometry_ok = true;
839 int xsize = 0, ysize = 0;
840 string geometry = arg.substr( 11 );
841 string::size_type i = geometry.find('x');
843 if (i != string::npos) {
844 xsize = atoi(geometry.substr(0, i));
845 ysize = atoi(geometry.substr(i+1));
850 if ( xsize <= 0 || ysize <= 0 ) {
856 if ( !geometry_ok ) {
857 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown geometry: " << geometry );
858 SG_LOG( SG_GENERAL, SG_ALERT,
859 "Setting geometry to " << xsize << 'x' << ysize << '\n');
861 SG_LOG( SG_GENERAL, SG_INFO,
862 "Setting geometry to " << xsize << 'x' << ysize << '\n');
863 fgSetInt("/sim/startup/xsize", xsize);
864 fgSetInt("/sim/startup/ysize", ysize);
866 } else if ( arg.find( "--bpp=" ) == 0 ) {
867 string bits_per_pix = arg.substr( 6 );
868 if ( bits_per_pix == "16" ) {
869 fgSetInt("/sim/rendering/bits-per-pixel", 16);
870 } else if ( bits_per_pix == "24" ) {
871 fgSetInt("/sim/rendering/bits-per-pixel", 24);
872 } else if ( bits_per_pix == "32" ) {
873 fgSetInt("/sim/rendering/bits-per-pixel", 32);
875 SG_LOG(SG_GENERAL, SG_ALERT, "Unsupported bpp " << bits_per_pix);
877 } else if ( arg == "--units-feet" ) {
878 fgSetString("/sim/startup/units", "feet");
879 } else if ( arg == "--units-meters" ) {
880 fgSetString("/sim/startup/units", "meters");
881 } else if ( arg.find( "--time-offset" ) == 0 ) {
882 fgSetInt("/sim/startup/time-offset",
883 parse_time_offset( (arg.substr(14)) ));
884 fgSetString("/sim/startup/time-offset-type", "system-offset");
885 } else if ( arg.find( "--time-match-real") == 0 ) {
886 fgSetString("/sim/startup/time-offset-type", "system-offset");
887 } else if ( arg.find( "--time-match-local") == 0 ) {
888 fgSetString("/sim/startup/time-offset-type", "latitude-offset");
889 } else if ( arg.find( "--start-date-sys=") == 0 ) {
890 fgSetInt("/sim/startup/time-offset", parse_date((arg.substr(17))));
891 fgSetString("/sim/startup/time-offset-type", "system");
892 } else if ( arg.find( "--start-date-lat=") == 0 ) {
893 fgSetInt("/sim/startup/time-offset", parse_date((arg.substr(17))));
894 fgSetString("/sim/startup/time-offset-type", "latitude");
895 } else if ( arg.find( "--start-date-gmt=") == 0 ) {
896 fgSetInt("/sim/startup/time-offset", parse_date((arg.substr(17))));
897 fgSetString("/sim/startup/time-offset-type", "gmt");
898 } else if ( arg == "--hud-tris" ) {
899 fgSetString("/sim/hud/frame-stat-type", "tris");
900 } else if ( arg == "--hud-culled" ) {
901 fgSetString("/sim/hud/frame-stat-type", "culled");
902 } else if ( arg.find( "--atc610x" ) == 0 ) {
903 add_channel( "atc610x", "dummy" );
904 } else if ( arg.find( "--atlas=" ) == 0 ) {
905 add_channel( "atlas", arg.substr(8) );
906 } else if ( arg.find( "--httpd=" ) == 0 ) {
907 add_channel( "httpd", arg.substr(8) );
908 #ifdef FG_JPEG_SERVER
909 } else if ( arg.find( "--jpg-httpd=" ) == 0 ) {
910 add_channel( "jpg-httpd", arg.substr(12) );
912 } else if ( arg.find( "--native=" ) == 0 ) {
913 add_channel( "native", arg.substr(9) );
914 } else if ( arg.find( "--native-ctrls=" ) == 0 ) {
915 add_channel( "native_ctrls", arg.substr(15) );
916 } else if ( arg.find( "--native-fdm=" ) == 0 ) {
917 add_channel( "native_fdm", arg.substr(13) );
918 } else if ( arg.find( "--mini-fdm=" ) == 0 ) {
919 add_channel( "mini_fdm", arg.substr(13) );
920 } else if ( arg.find( "--opengc=" ) == 0 ) {
922 // cout << "Adding channel for OpenGC Display" << endl; cin >> stop;
923 add_channel( "opengc", arg.substr(9) );
924 } else if ( arg.find( "--garmin=" ) == 0 ) {
925 add_channel( "garmin", arg.substr(9) );
926 } else if ( arg.find( "--nmea=" ) == 0 ) {
927 add_channel( "nmea", arg.substr(7) );
928 } else if ( arg.find( "--props=" ) == 0 ) {
929 add_channel( "props", arg.substr(8) );
930 } else if ( arg.find( "--telnet=" ) == 0 ) {
931 add_channel( "telnet", arg.substr(9) );
932 } else if ( arg.find( "--pve=" ) == 0 ) {
933 add_channel( "pve", arg.substr(6) );
934 } else if ( arg.find( "--ray=" ) == 0 ) {
935 add_channel( "ray", arg.substr(6) );
936 } else if ( arg.find( "--rul=" ) == 0 ) {
937 add_channel( "rul", arg.substr(6) );
938 } else if ( arg.find( "--joyclient=" ) == 0 ) {
939 add_channel( "joyclient", arg.substr(12) );
940 #ifdef FG_NETWORK_OLK
941 } else if ( arg == "--disable-network-olk" ) {
942 fgSetBool("/sim/networking/olk", false);
943 } else if ( arg== "--enable-network-olk") {
944 fgSetBool("/sim/networking/olk", true);
945 } else if ( arg == "--net-hud" ) {
946 fgSetBool("/sim/hud/net-display", true);
947 net_hud_display = 1; // FIXME
948 } else if ( arg.find( "--net-id=") == 0 ) {
949 fgSetString("sim/networking/call-sign", arg.substr(9).c_str());
951 } else if ( arg.find( "--prop:" ) == 0 ) {
952 string assign = arg.substr(7);
953 string::size_type pos = assign.find('=');
954 if ( pos == arg.npos || pos == 0 ) {
955 SG_LOG( SG_GENERAL, SG_ALERT, "Bad property assignment: " << arg );
956 return FG_OPTIONS_ERROR;
958 string name = assign.substr(0, pos);
959 string value = assign.substr(pos + 1);
960 fgSetString(name.c_str(), value.c_str());
961 // SG_LOG(SG_GENERAL, SG_INFO, "Setting default value of property "
962 // << name << " to \"" << value << '"');
963 } else if ( arg.find("--trace-read=") == 0) {
964 string name = arg.substr(13);
965 SG_LOG(SG_GENERAL, SG_INFO, "Tracing reads for property " << name);
966 fgGetNode(name.c_str(), true)
967 ->setAttribute(SGPropertyNode::TRACE_READ, true);
968 } else if ( arg.find("--trace-write=") == 0) {
969 string name = arg.substr(14);
970 SG_LOG(SG_GENERAL, SG_INFO, "Tracing writes for property " << name);
971 fgGetNode(name.c_str(), true)
972 ->setAttribute(SGPropertyNode::TRACE_WRITE, true);
973 } else if ( arg.find( "--view-offset=" ) == 0 ) {
974 // $$$ begin - added VS Renganathan, 14 Oct 2K
975 // for multi-window outside window imagery
976 string woffset = arg.substr( 14 );
977 double default_view_offset = 0.0;
978 if ( woffset == "LEFT" ) {
979 default_view_offset = SGD_PI * 0.25;
980 } else if ( woffset == "RIGHT" ) {
981 default_view_offset = SGD_PI * 1.75;
982 } else if ( woffset == "CENTER" ) {
983 default_view_offset = 0.00;
985 default_view_offset = atof( woffset.c_str() ) * SGD_DEGREES_TO_RADIANS;
987 /* apparently not used (CLO, 11 Jun 2002)
988 FGViewer *pilot_view =
989 (FGViewer *)globals->get_viewmgr()->get_view( 0 ); */
990 // this will work without calls to the viewer...
991 fgSetDouble( "/sim/current-view/heading-offset-deg",
992 default_view_offset * SGD_RADIANS_TO_DEGREES );
993 // $$$ end - added VS Renganathan, 14 Oct 2K
994 } else if ( arg.find( "--visibility=" ) == 0 ) {
995 fgSetDouble("/environment/visibility-m", atof(arg.substr(13)));
996 } else if ( arg.find( "--visibility-miles=" ) == 0 ) {
997 double visibility = atof(arg.substr(19)) * 5280.0 * SG_FEET_TO_METER;
998 fgSetDouble("/environment/visibility-m", visibility);
999 } else if ( arg.find( "--random-wind" ) == 0 ) {
1000 double min_hdg = sg_random() * 360.0;
1001 double max_hdg = min_hdg + (20 - sqrt(sg_random() * 400));
1002 double speed = 40 - sqrt(sg_random() * 1600.0);
1003 double gust = speed + (10 - sqrt(sg_random() * 100));
1004 setup_wind(min_hdg, max_hdg, speed, gust);
1005 } else if ( arg.find( "--wind=" ) == 0 ) {
1006 double min_hdg, max_hdg, speed, gust;
1007 if (!parse_wind(arg.substr(7), &min_hdg, &max_hdg, &speed, &gust)) {
1008 SG_LOG( SG_GENERAL, SG_ALERT, "bad wind value " << arg.substr(7) );
1009 return FG_OPTIONS_ERROR;
1011 setup_wind(min_hdg, max_hdg, speed, gust);
1012 } else if ( arg.find( "--wp=" ) == 0 ) {
1013 parse_wp( arg.substr( 5 ) );
1014 } else if ( arg.find( "--flight-plan=") == 0) {
1015 parse_flightplan ( arg.substr (14) );
1016 } else if ( arg.find( "--config=" ) == 0 ) {
1017 string file = arg.substr(9);
1019 readProperties(file, globals->get_props());
1020 } catch (const sg_exception &e) {
1021 string message = "Error loading config file: ";
1022 message += e.getFormattedMessage();
1023 SG_LOG(SG_INPUT, SG_ALERT, message);
1026 } else if ( arg.find( "--aircraft=" ) == 0 ) {
1027 fgSetString("/sim/aircraft", arg.substr(11).c_str());
1029 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" );
1030 return FG_OPTIONS_ERROR;
1033 return FG_OPTIONS_OK;
1037 // Parse the command line options
1039 fgParseArgs (int argc, char **argv)
1041 bool in_options = true;
1042 bool verbose = false;
1045 SG_LOG(SG_GENERAL, SG_INFO, "Processing command line arguments");
1047 for (int i = 1; i < argc; i++) {
1048 string arg = argv[i];
1050 if (in_options && (arg.find('-') == 0)) {
1054 int result = parse_option(arg);
1055 if ((result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR))
1058 else if (result == FG_OPTIONS_VERBOSE_HELP)
1061 else if (result == FG_OPTIONS_SHOW_AIRCRAFT) {
1068 SG_LOG(SG_GENERAL, SG_INFO,
1069 "Reading command-line property file " << arg);
1070 readProperties(arg, globals->get_props());
1079 SG_LOG(SG_GENERAL, SG_INFO, "Finished command line arguments");
1083 // Parse config file options
1085 fgParseOptions (const string& path) {
1086 sg_gzifstream in( path );
1087 if ( !in.is_open() ) {
1091 SG_LOG( SG_GENERAL, SG_INFO, "Processing config file: " << path );
1095 while ( ! in.eof() ) {
1098 while ( in.get(c) && c != '\0' ) {
1103 #if defined( macintosh )
1104 getline( in, line, '\r' );
1106 getline( in, line, '\n' );
1109 // catch extraneous (DOS) line ending character
1110 if ( line[line.length() - 1] < 32 ) {
1111 line = line.substr( 0, line.length()-1 );
1114 if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
1115 cerr << endl << "Config file parse error: " << path << " '"
1116 << line << "'" << endl;
1125 // Print usage message
1127 fgUsage (bool verbose)
1129 SGPropertyNode *locale = globals->get_locale();
1131 SGPropertyNode options_root;
1136 fgLoadProps("options.xml", &options_root);
1137 } catch (const sg_exception &ex) {
1138 cout << "Unable to read the help file." << endl;
1139 cout << "Make sure the file options.xml is located in the FlightGear base directory," << endl;
1140 cout << "and the location of the base directory is specified by setting $FG_ROOT or" << endl;
1141 cout << "by adding --fg-root=path as a program argument." << endl;
1146 SGPropertyNode *options = options_root.getNode("options");
1148 SG_LOG( SG_GENERAL, SG_ALERT,
1149 "Error reading options.xml: <options> directive not found." );
1153 SGPropertyNode *usage = locale->getNode(options->getStringValue("usage"));
1155 cout << "Usage: " << usage->getStringValue() << endl;
1158 vector<SGPropertyNode_ptr>section = options->getChildren("section");
1159 for (unsigned int j = 0; j < section.size(); j++) {
1162 vector<SGPropertyNode_ptr>option = section[j]->getChildren("option");
1163 for (unsigned int k = 0; k < option.size(); k++) {
1165 SGPropertyNode *name = option[k]->getNode("name");
1166 SGPropertyNode *short_name = option[k]->getNode("short");
1167 SGPropertyNode *key = option[k]->getNode("key");
1168 SGPropertyNode *arg = option[k]->getNode("arg");
1169 bool brief = option[k]->getNode("brief");
1171 if ((brief || verbose) && name) {
1172 string tmp = name->getStringValue();
1176 tmp.append(key->getStringValue());
1180 tmp.append(arg->getStringValue());
1184 tmp.append(short_name->getStringValue());
1188 if (tmp.size() <= 25) {
1189 snprintf(cstr, 96, " --%-27s", tmp.c_str());
1191 snprintf(cstr, 96, "\n --%s\n%32c", tmp.c_str(), ' ');
1194 // There may be more than one <description> tag assosiated
1198 vector<SGPropertyNode_ptr>desc =
1199 option[k]->getChildren("description");
1201 if (desc.size() > 0) {
1202 for ( unsigned int l = 0; l < desc.size(); l++) {
1204 // There may be more than one translation line.
1206 string t = desc[l]->getStringValue();
1207 SGPropertyNode *n = locale->getNode("strings");
1208 vector<SGPropertyNode_ptr>trans_desc =
1209 n->getChildren(t.substr(8).c_str());
1211 for ( unsigned int m = 0; m < trans_desc.size(); m++ ) {
1212 string t_str = trans_desc[m]->getStringValue();
1214 if ((m > 0) || ((l > 0) && m == 0)) {
1215 snprintf(cstr, 96, "%32c", ' ');
1220 // If the string is too large to fit on the screen,
1221 // then split it up in several pieces.
1223 while ( t_str.size() > 47 ) {
1225 unsigned int m = t_str.rfind(' ', 47);
1226 msg += t_str.substr(0, m);
1227 snprintf(cstr, 96, "\n%32c", ' ');
1230 t_str.erase(t_str.begin(), t_str.begin() + m + 1);
1232 msg += t_str + '\n';
1239 SGPropertyNode *name =
1240 locale->getNode(section[j]->getStringValue("name"));
1242 if (!msg.empty() && name) {
1243 cout << endl << name->getStringValue() << ":" << endl;
1251 cout << "For a complete list of options use --help --verbose" << endl;
1255 // Show available aircraft types
1256 void fgShowAircraft(void) {
1257 SGPath path( globals->get_fg_root() );
1258 path.append("Aircraft");
1263 dirp = ulOpenDir(path.c_str());
1265 cerr << "Unable to open aircraft directory." << endl;
1269 cout << "Available aircraft:" << endl;
1270 while ((dire = ulReadDir(dirp)) != NULL) {
1273 if ((ptr = strstr(dire->d_name, "-set.xml")) && ptr[8] == '\0' ) {
1274 SGPath afile = path;
1275 afile.append(dire->d_name);
1279 SGPropertyNode root;
1281 readProperties(afile.str(), &root);
1286 SGPropertyNode *desc = NULL;
1287 SGPropertyNode *node = root.getNode("sim");
1289 desc = node->getNode("description");
1293 if (strlen(dire->d_name) <= 27)
1294 snprintf(cstr, 96, " %-27s %s", dire->d_name,
1295 (desc) ? desc->getStringValue() : "" );
1298 snprintf(cstr, 96, " %-27s\n%32c%s", dire->d_name, ' ',
1299 (desc) ? desc->getStringValue() : "" );
1301 cout << cstr << endl;