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()
38 #include <simgear/math/sg_random.h>
39 #include <simgear/misc/sgstream.hxx>
40 #include <simgear/misc/sg_path.hxx>
41 #include <simgear/route/route.hxx>
42 #include <simgear/route/waypoint.hxx>
44 // #include <Include/general.hxx>
45 // #include <Airports/simple.hxx>
46 // #include <Cockpit/cockpit.hxx>
47 // #include <FDM/flight.hxx>
48 // #include <FDM/UIUCModel/uiuc_aircraftdir.h>
50 # include <NetworkOLK/network.h>
55 #include "globals.hxx"
56 #include "fg_init.hxx"
57 #include "fg_props.hxx"
58 #include "options.hxx"
59 #include "viewmgr.hxx"
62 SG_USING_NAMESPACE(std);
65 #define NEW_DEFAULT_MODEL_HZ 120
75 atof( const string& str )
79 // -dw- if ::atof is called, then we get an infinite loop
80 return std::atof( str.c_str() );
82 return ::atof( str.c_str() );
87 atoi( const string& str )
90 // -dw- if ::atoi is called, then we get an infinite loop
91 return std::atoi( str.c_str() );
93 return ::atoi( str.c_str() );
99 * Set a few fail-safe default property values.
101 * These should all be set in $FG_ROOT/preferences.xml, but just
102 * in case, we provide some initial sane values here. This method
103 * should be invoked *before* reading any init files.
108 // set a possibly independent location for scenery data
109 char *envp = ::getenv( "FG_SCENERY" );
111 if ( envp != NULL ) {
112 // fg_root could be anywhere, so default to environmental
113 // variable $FG_ROOT if it is set.
114 globals->set_fg_scenery(envp);
116 // Otherwise, default to Scenery being in $FG_ROOT/Scenery
117 globals->set_fg_scenery("");
119 // Position (deliberately out of range)
120 fgSetDouble("/position/longitude-deg", 9999.0);
121 fgSetDouble("/position/latitude-deg", 9999.0);
122 fgSetDouble("/position/altitude-ft", -9999.0);
125 fgSetDouble("/orientation/heading-deg", 270);
126 fgSetDouble("/orientation/roll-deg", 0);
127 fgSetDouble("/orientation/pitch-deg", 0.424);
130 fgSetString("/sim/startup/speed-set", "knots");
131 fgSetDouble("/velocities/uBody-fps", 0.0);
132 fgSetDouble("/velocities/vBody-fps", 0.0);
133 fgSetDouble("/velocities/wBody-fps", 0.0);
134 fgSetDouble("/velocities/speed-north-fps", 0.0);
135 fgSetDouble("/velocities/speed-east-fps", 0.0);
136 fgSetDouble("/velocities/speed-down-fps", 0.0);
137 fgSetDouble("/velocities/airspeed-kt", 0.0);
138 fgSetDouble("/velocities/mach", 0.0);
141 fgSetBool("/sim/startup/game-mode", false);
142 fgSetBool("/sim/startup/splash-screen", true);
143 fgSetBool("/sim/startup/intro-music", true);
144 // we want mouse-pointer to have an undefined value if nothing is
145 // specified so we can do the right thing for voodoo-1/2 cards.
146 // fgSetString("/sim/startup/mouse-pointer", "disabled");
147 fgSetString("/sim/control-mode", "joystick");
148 fgSetBool("/sim/auto-coordination", false);
150 fgSetString("/sim/startup/browser-app", "netscape");
152 fgSetString("/sim/startup/browser-app", "webrun.bat");
155 fgSetBool("/sim/hud/visibility", false);
156 fgSetBool("/sim/panel/visibility", true);
157 fgSetBool("/sim/sound/audible", true);
158 fgSetBool("/sim/hud/antialiased", false);
160 // Flight Model options
161 fgSetString("/sim/flight-model", "jsb");
162 fgSetString("/sim/aero", "c172");
163 fgSetInt("/sim/model-hz", NEW_DEFAULT_MODEL_HZ);
164 fgSetInt("/sim/speed-up", 1);
165 fgSetBool("/sim/startup/trim", false);
166 fgSetBool("/sim/startup/onground", true);
169 fgSetString("/sim/rendering/fog", "nicest");
170 fgSetBool("/environment/clouds/status", true);
171 fgSetBool("/sim/startup/fullscreen", false);
172 fgSetBool("/sim/rendering/shading", true);
173 fgSetBool("/sim/rendering/skyblend", true);
174 fgSetBool("/sim/rendering/textures", true);
175 fgSetBool("/sim/rendering/wireframe", false);
176 fgSetInt("/sim/startup/xsize", 800);
177 fgSetInt("/sim/startup/ysize", 600);
178 fgSetInt("/sim/rendering/bits-per-pixel", 16);
179 fgSetString("/sim/view-mode", "pilot");
180 fgSetDouble("/sim/current-view/heading-offset-deg", 0);
181 fgSetDouble("/environment/visibility-m", 20000);
184 fgSetString("/sim/startup/units", "feet");
185 fgSetString("/sim/hud/frame-stat-type", "tris");
188 fgSetInt("/sim/startup/time-offset", 0);
189 fgSetString("/sim/startup/time-offset-type", "system-offset");
190 fgSetLong("/sim/time/cur-time-override", 0);
192 fgSetBool("/sim/networking/network-olk", false);
193 fgSetString("/sim/networking/call-sign", "Johnny");
196 fgSetBool("/sim/freeze/master", false);
197 fgSetBool("/sim/freeze/position", false);
198 fgSetBool("/sim/freeze/clock", false);
199 fgSetBool("/sim/freeze/fuel", false);
204 parse_wind (const string &wind, double * min_hdg, double * max_hdg,
205 double * speed, double * gust)
207 string::size_type pos = wind.find('@');
208 if (pos == string::npos)
210 string dir = wind.substr(0, pos);
211 string spd = wind.substr(pos+1);
213 if (pos == string::npos) {
214 *min_hdg = *max_hdg = atof(dir.c_str());
216 *min_hdg = atof(dir.substr(0,pos).c_str());
217 *max_hdg = atof(dir.substr(pos+1).c_str());
220 if (pos == string::npos) {
221 *speed = *gust = atof(spd.c_str());
223 *speed = atof(spd.substr(0,pos).c_str());
224 *gust = atof(spd.substr(pos+1).c_str());
229 // parse a time string ([+/-]%f[:%f[:%f]]) into hours
231 parse_time(const string& time_in) {
232 char *time_str, num[256];
233 double hours, minutes, seconds;
238 time_str = (char *)time_in.c_str();
240 // printf("parse_time(): %s\n", time_str);
243 if ( strlen(time_str) ) {
244 if ( time_str[0] == '+' ) {
247 } else if ( time_str[0] == '-' ) {
252 // printf("sign = %d\n", sign);
255 if ( strlen(time_str) ) {
257 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
258 num[i] = time_str[0];
262 if ( time_str[0] == ':' ) {
267 // printf("hours = %.2lf\n", hours);
273 if ( strlen(time_str) ) {
275 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
276 num[i] = time_str[0];
280 if ( time_str[0] == ':' ) {
285 // printf("minutes = %.2lf\n", minutes);
287 result += minutes / 60.0;
291 if ( strlen(time_str) ) {
293 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
294 num[i] = time_str[0];
300 // printf("seconds = %.2lf\n", seconds);
302 result += seconds / 3600.0;
305 return(sign * result);
309 // parse a date string (yyyy:mm:dd:hh:mm:ss) into a time_t (seconds)
311 parse_date( const string& date)
314 char * date_str, num[256];
316 // initialize to zero
323 gmt.tm_isdst = 0; // ignore daylight savings time for the moment
324 date_str = (char *)date.c_str();
326 if ( strlen(date_str) ) {
328 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
329 num[i] = date_str[0];
333 if ( date_str[0] == ':' ) {
337 gmt.tm_year = atoi(num) - 1900;
340 if ( strlen(date_str) ) {
342 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
343 num[i] = date_str[0];
347 if ( date_str[0] == ':' ) {
351 gmt.tm_mon = atoi(num) -1;
354 if ( strlen(date_str) ) {
356 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
357 num[i] = date_str[0];
361 if ( date_str[0] == ':' ) {
365 gmt.tm_mday = atoi(num);
368 if ( strlen(date_str) ) {
370 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
371 num[i] = date_str[0];
375 if ( date_str[0] == ':' ) {
379 gmt.tm_hour = atoi(num);
382 if ( strlen(date_str) ) {
384 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
385 num[i] = date_str[0];
389 if ( date_str[0] == ':' ) {
393 gmt.tm_min = atoi(num);
396 if ( strlen(date_str) ) {
398 while ( (date_str[0] != ':') && (date_str[0] != '\0') ) {
399 num[i] = date_str[0];
403 if ( date_str[0] == ':' ) {
407 gmt.tm_sec = atoi(num);
409 time_t theTime = sgTimeGetGMT( gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
410 gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
411 //printf ("Date is %s\n", ctime(&theTime));
412 //printf ("in seconds that is %d\n", theTime);
418 // parse angle in the form of [+/-]ddd:mm:ss into degrees
420 parse_degree( const string& degree_str) {
421 double result = parse_time( degree_str );
423 // printf("Degree = %.4f\n", result);
429 // parse time offset string into seconds
431 parse_time_offset( const string& time_str) {
434 // printf("time offset = %s\n", time_str);
437 result = (int)rint(parse_time(time_str) * 3600.0);
439 result = (int)(parse_time(time_str) * 3600.0);
442 // printf("parse_time_offset(): %d\n", result);
448 // Parse --fov=x.xx type option
450 parse_fov( const string& arg ) {
451 double fov = atof(arg);
453 if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
454 if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
456 fgSetDouble("/sim/current-view/field-of-view", fov);
458 // printf("parse_fov(): result = %.4f\n", fov);
464 // Parse I/O channel option
466 // Format is "--protocol=medium,direction,hz,medium_options,..."
468 // protocol = { native, nmea, garmin, fgfs, rul, pve, etc. }
469 // medium = { serial, socket, file, etc. }
470 // direction = { in, out, bi }
471 // hz = number of times to process channel per second (floating
472 // point values are ok.
474 // Serial example "--nmea=serial,dir,hz,device,baud" where
476 // device = OS device name of serial line to be open()'ed
477 // baud = {300, 1200, 2400, ..., 230400}
479 // Socket exacmple "--native=socket,dir,hz,machine,port,style" where
481 // machine = machine name or ip address if client (leave empty if server)
482 // port = port, leave empty to let system choose
483 // style = tcp or udp
485 // File example "--garmin=file,dir,hz,filename" where
487 // filename = file system file name
490 add_channel( const string& type, const string& channel_str ) {
491 // cout << "Channel string = " << channel_str << endl;
493 globals->get_channel_options_list()->push_back( type + "," + channel_str );
500 setup_wind (double min_hdg, double max_hdg, double speed, double gust)
502 fgSetDouble("/environment/wind-from-heading-deg", min_hdg);
503 fgSetDouble("/environment/params/min-wind-from-heading-deg", min_hdg);
504 fgSetDouble("/environment/params/max-wind-from-heading-deg", max_hdg);
505 fgSetDouble("/environment/wind-speed-kt", speed);
506 fgSetDouble("/environment/params/base-wind-speed-kt", speed);
507 fgSetDouble("/environment/params/gust-wind-speed-kt", gust);
509 SG_LOG(SG_GENERAL, SG_INFO, "WIND: " << min_hdg << '@' <<
510 speed << " knots" << endl);
514 speed *= SG_NM_TO_METER * SG_METER_TO_FEET * (1.0/3600);
515 while (min_hdg > 360)
519 min_hdg *= SGD_DEGREES_TO_RADIANS;
520 fgSetDouble("/environment/wind-from-north-fps", speed * cos(dir));
521 fgSetDouble("/environment/wind-from-east-fps", speed * sin(dir));
522 #endif // FG_WEATHERCM
526 // Parse --wp=ID[@alt]
528 parse_wp( const string& arg ) {
532 string::size_type pos = arg.find( "@" );
533 if ( pos != string::npos ) {
534 id = arg.substr( 0, pos );
535 alt_str = arg.substr( pos + 1 );
536 // cout << "id str = " << id << " alt str = " << alt_str << endl;
537 alt = atof( alt_str.c_str() );
538 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") ) {
539 alt *= SG_FEET_TO_METER;
546 if ( fgFindAirportID( id, &a ) ) {
547 SGWayPoint wp( a.longitude, a.latitude, alt, SGWayPoint::WGS84, id );
548 globals->get_route()->add_waypoint( wp );
557 // Parse --flight-plan=[file]
559 parse_flightplan(const string& arg)
561 sg_gzifstream in(arg.c_str());
562 if ( !in.is_open() ) {
568 #if defined( macintosh )
569 getline( in, line, '\r' );
571 getline( in, line, '\n' );
574 // catch extraneous (DOS) line ending character
575 if ( line[line.length() - 1] < 32 ) {
576 line = line.substr( 0, line.length()-1 );
589 // Parse a single option
591 parse_option (const string& arg)
594 if ( (arg == "--help") || (arg == "-h") ) {
595 // help/usage request
596 return(FG_OPTIONS_HELP);
597 } else if ( arg == "--disable-game-mode") {
598 fgSetBool("/sim/startup/game-mode", false);
599 } else if ( arg == "--enable-game-mode" ) {
600 fgSetBool("/sim/startup/game-mode", true);
601 } else if ( arg == "--disable-splash-screen" ) {
602 fgSetBool("/sim/startup/splash-screen", false);
603 } else if ( arg == "--enable-splash-screen" ) {
604 fgSetBool("/sim/startup/splash-screen", true);
605 } else if ( arg == "--disable-intro-music" ) {
606 fgSetBool("/sim/startup/intro-music", false);
607 } else if ( arg == "--enable-intro-music" ) {
608 fgSetBool("/sim/startup/intro-music", true);
609 } else if ( arg == "--disable-mouse-pointer" ) {
610 fgSetString("/sim/startup/mouse-pointer", "disabled");
611 } else if ( arg == "--enable-mouse-pointer" ) {
612 fgSetString("/sim/startup/mouse-pointer", "enabled");
613 } else if ( arg == "--disable-random-objects" ) {
614 fgSetBool("/sim/rendering/random-objects", false);
615 } else if ( arg == "--enable-random-objects" ) {
616 fgSetBool("/sim/rendering/random-objects", true);
617 } else if ( arg == "--disable-freeze" ) {
618 fgSetBool("/sim/freeze/master", false);
619 } else if ( arg == "--enable-freeze" ) {
620 fgSetBool("/sim/freeze/master", true);
621 } else if ( arg == "--disable-fuel-freeze" ) {
622 fgSetBool("/sim/freeze/fuel", false);
623 } else if ( arg == "--enable-fuel-freeze" ) {
624 fgSetBool("/sim/freeze/fuel", true);
625 } else if ( arg == "--disable-clock-freeze" ) {
626 fgSetBool("/sim/freeze/clock", false);
627 } else if ( arg == "--enable-clock-freeze" ) {
628 fgSetBool("/sim/freeze/clock", true);
629 } else if ( arg == "--disable-anti-alias-hud" ) {
630 fgSetBool("/sim/hud/antialiased", false);
631 } else if ( arg == "--enable-anti-alias-hud" ) {
632 fgSetBool("/sim/hud/antialiased", true);
633 } else if ( arg.find( "--control=") == 0 ) {
634 fgSetString("/sim/control-mode", arg.substr(10).c_str());
635 } else if ( arg == "--disable-auto-coordination" ) {
636 fgSetBool("/sim/auto-coordination", false);
637 } else if ( arg == "--enable-auto-coordination" ) {
638 fgSetBool("/sim/auto-coordination", true);
639 } else if ( arg.find( "--browser-app=") == 0 ) {
640 fgSetString("/sim/startup/browser-app", arg.substr(14).c_str());
641 } else if ( arg == "--disable-hud" ) {
642 fgSetBool("/sim/hud/visibility", false);
643 } else if ( arg == "--enable-hud" ) {
644 fgSetBool("/sim/hud/visibility", true);
645 } else if ( arg == "--disable-panel" ) {
646 fgSetBool("/sim/panel/visibility", false);
647 } else if ( arg == "--enable-panel" ) {
648 fgSetBool("/sim/panel/visibility", true);
649 } else if ( arg == "--disable-sound" ) {
650 fgSetBool("/sim/sound/audible", false);
651 } else if ( arg == "--enable-sound" ) {
652 fgSetBool("/sim/sound/audible", true);
653 } else if ( arg.find( "--airport-id=") == 0 ) {
654 // NB: changed property name!!!
655 fgSetString("/sim/startup/airport-id", arg.substr(13).c_str());
656 } else if ( arg.find( "--offset-distance=") == 0 ) {
657 fgSetDouble("/sim/startup/offset-distance", atof(arg.substr(18)));
658 } else if ( arg.find( "--offset-azimuth=") == 0 ) {
659 fgSetDouble("/sim/startup/offset-azimuth", atof(arg.substr(17)));
660 } else if ( arg.find( "--lon=" ) == 0 ) {
661 fgSetDouble("/position/longitude-deg",
662 parse_degree(arg.substr(6)));
663 fgSetString("/sim/startup/airport-id", "");
664 } else if ( arg.find( "--lat=" ) == 0 ) {
665 fgSetDouble("/position/latitude-deg",
666 parse_degree(arg.substr(6)));
667 fgSetString("/sim/startup/airport-id", "");
668 } else if ( arg.find( "--altitude=" ) == 0 ) {
669 fgSetBool("/sim/startup/onground", false);
670 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
671 fgSetDouble("/position/altitude-ft", atof(arg.substr(11)));
673 fgSetDouble("/position/altitude-ft",
674 atof(arg.substr(11)) * SG_METER_TO_FEET);
675 } else if ( arg.find( "--uBody=" ) == 0 ) {
676 fgSetString("/sim/startup/speed-set", "UVW");
677 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
678 fgSetDouble("/velocities/uBody-fps", atof(arg.substr(8)));
680 fgSetDouble("/velocities/uBody-fps",
681 atof(arg.substr(8)) * SG_METER_TO_FEET);
682 } else if ( arg.find( "--vBody=" ) == 0 ) {
683 fgSetString("/sim/startup/speed-set", "UVW");
684 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
685 fgSetDouble("/velocities/vBody-fps", atof(arg.substr(8)));
687 fgSetDouble("/velocities/vBody-fps",
688 atof(arg.substr(8)) * SG_METER_TO_FEET);
689 } else if ( arg.find( "--wBody=" ) == 0 ) {
690 fgSetString("/sim/startup/speed-set", "UVW");
691 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
692 fgSetDouble("/velocities/wBody-fps", atof(arg.substr(8)));
694 fgSetDouble("/velocities/wBody-fps",
695 atof(arg.substr(8)) * SG_METER_TO_FEET);
696 } else if ( arg.find( "--vNorth=" ) == 0 ) {
697 fgSetString("/sim/startup/speed-set", "NED");
698 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
699 fgSetDouble("/velocities/speed-north-fps", atof(arg.substr(9)));
701 fgSetDouble("/velocities/speed-north-fps",
702 atof(arg.substr(9)) * SG_METER_TO_FEET);
703 } else if ( arg.find( "--vEast=" ) == 0 ) {
704 fgSetString("/sim/startup/speed-set", "NED");
705 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
706 fgSetDouble("/velocities/speed-east-fps", atof(arg.substr(8)));
708 fgSetDouble("/velocities/speed-east-fps",
709 atof(arg.substr(8)) * SG_METER_TO_FEET);
710 } else if ( arg.find( "--vDown=" ) == 0 ) {
711 fgSetString("/sim/startup/speed-set", "NED");
712 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
713 fgSetDouble("/velocities/speed-down-fps", atof(arg.substr(8)));
715 fgSetDouble("/velocities/speed-down-fps",
716 atof(arg.substr(8)) * SG_METER_TO_FEET);
717 } else if ( arg.find( "--vc=" ) == 0) {
718 fgSetString("/sim/startup/speed-set", "knots");
719 fgSetDouble("/velocities/airspeed-kt", atof(arg.substr(5)));
720 } else if ( arg.find( "--mach=" ) == 0) {
721 fgSetString("/sim/startup/speed-set", "mach");
722 fgSetDouble("/velocities/mach", atof(arg.substr(7)));
723 } else if ( arg.find( "--heading=" ) == 0 ) {
724 fgSetDouble("/orientation/heading-deg", atof(arg.substr(10)));
725 } else if ( arg.find( "--roll=" ) == 0 ) {
726 fgSetDouble("/orientation/roll-deg", atof(arg.substr(7)));
727 } else if ( arg.find( "--pitch=" ) == 0 ) {
728 fgSetDouble("/orientation/pitch-deg", atof(arg.substr(8)));
729 } else if ( arg.find( "--glideslope=" ) == 0 ) {
730 fgSetDouble("/velocities/glideslope", atof(arg.substr(13))
731 *SG_DEGREES_TO_RADIANS);
732 } else if ( arg.find( "--roc=" ) == 0 ) {
733 fgSetDouble("/velocities/vertical-speed-fps", atof(arg.substr(6))/60);
734 } else if ( arg.find( "--fg-root=" ) == 0 ) {
735 globals->set_fg_root(arg.substr( 10 ));
736 } else if ( arg.find( "--fg-scenery=" ) == 0 ) {
737 globals->set_fg_scenery(arg.substr( 13 ));
738 } else if ( arg.find( "--fdm=" ) == 0 ) {
739 fgSetString("/sim/flight-model", arg.substr(6).c_str());
740 } else if ( arg.find( "--aero=" ) == 0 ) {
741 fgSetString("/sim/aero", arg.substr(7).c_str());
742 } else if ( arg.find( "--aircraft-dir=" ) == 0 ) {
743 fgSetString("/sim/aircraft-dir", arg.substr(15).c_str());
744 } else if ( arg.find( "--model-hz=" ) == 0 ) {
745 fgSetInt("/sim/model-hz", atoi(arg.substr(11)));
746 } else if ( arg.find( "--speed=" ) == 0 ) {
747 fgSetInt("/sim/speed-up", atoi(arg.substr(8)));
748 } else if ( arg.find( "--trim") == 0) {
749 fgSetBool("/sim/startup/trim", true);
750 } else if ( arg.find( "--notrim") == 0) {
751 fgSetBool("/sim/startup/trim", false);
752 } else if ( arg.find( "--on-ground") == 0) {
753 fgSetBool("/sim/startup/onground", true);
754 } else if ( arg.find( "--in-air") == 0) {
755 fgSetBool("/sim/startup/onground", false);
756 } else if ( arg == "--fog-disable" ) {
757 fgSetString("/sim/rendering/fog", "disabled");
758 } else if ( arg == "--fog-fastest" ) {
759 fgSetString("/sim/rendering/fog", "fastest");
760 } else if ( arg == "--fog-nicest" ) {
761 fgSetString("/sim/fog", "nicest");
762 } else if ( arg == "--disable-clouds" ) {
763 fgSetBool("/environment/clouds/status", false);
764 } else if ( arg == "--enable-clouds" ) {
765 fgSetBool("/environment/clouds/status", true);
766 } else if ( arg.find( "--fov=" ) == 0 ) {
767 parse_fov( arg.substr(6) );
768 } else if ( arg == "--disable-fullscreen" ) {
769 fgSetBool("/sim/startup/fullscreen", false);
770 } else if ( arg== "--enable-fullscreen") {
771 fgSetBool("/sim/startup/fullscreen", true);
772 } else if ( arg == "--shading-flat") {
773 fgSetBool("/sim/rendering/shading", false);
774 } else if ( arg == "--shading-smooth") {
775 fgSetBool("/sim/rendering/shading", true);
776 } else if ( arg == "--disable-skyblend") {
777 fgSetBool("/sim/rendering/skyblend", false);
778 } else if ( arg== "--enable-skyblend" ) {
779 fgSetBool("/sim/rendering/skyblend", true);
780 } else if ( arg == "--disable-textures" ) {
781 fgSetBool("/sim/rendering/textures", false);
782 } else if ( arg == "--enable-textures" ) {
783 fgSetBool("/sim/rendering/textures", true);
784 } else if ( arg == "--disable-wireframe" ) {
785 fgSetBool("/sim/rendering/wireframe", false);
786 } else if ( arg == "--enable-wireframe" ) {
787 fgSetBool("/sim/rendering/wireframe", true);
788 } else if ( arg.find( "--geometry=" ) == 0 ) {
789 bool geometry_ok = true;
790 int xsize = 0, ysize = 0;
791 string geometry = arg.substr( 11 );
792 string::size_type i = geometry.find('x');
794 if (i != string::npos) {
795 xsize = atoi(geometry.substr(0, i));
796 ysize = atoi(geometry.substr(i+1));
801 if ( xsize <= 0 || ysize <= 0 ) {
807 if ( !geometry_ok ) {
808 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown geometry: " << geometry );
809 SG_LOG( SG_GENERAL, SG_ALERT,
810 "Setting geometry to " << xsize << 'x' << ysize << '\n');
812 SG_LOG( SG_GENERAL, SG_INFO,
813 "Setting geometry to " << xsize << 'x' << ysize << '\n');
814 fgSetInt("/sim/startup/xsize", xsize);
815 fgSetInt("/sim/startup/ysize", ysize);
817 } else if ( arg.find( "--bpp=" ) == 0 ) {
818 string bits_per_pix = arg.substr( 6 );
819 if ( bits_per_pix == "16" ) {
820 fgSetInt("/sim/rendering/bits-per-pixel", 16);
821 } else if ( bits_per_pix == "24" ) {
822 fgSetInt("/sim/rendering/bits-per-pixel", 24);
823 } else if ( bits_per_pix == "32" ) {
824 fgSetInt("/sim/rendering/bits-per-pixel", 32);
826 SG_LOG(SG_GENERAL, SG_ALERT, "Unsupported bpp " << bits_per_pix);
828 } else if ( arg == "--units-feet" ) {
829 fgSetString("/sim/startup/units", "feet");
830 } else if ( arg == "--units-meters" ) {
831 fgSetString("/sim/startup/units", "meters");
832 } else if ( arg.find( "--time-offset" ) == 0 ) {
833 fgSetInt("/sim/startup/time-offset",
834 parse_time_offset( (arg.substr(14)) ));
835 fgSetString("/sim/startup/time-offset-type", "system-offset");
836 } else if ( arg.find( "--time-match-real") == 0 ) {
837 fgSetString("/sim/startup/time-offset-type", "system-offset");
838 } else if ( arg.find( "--time-match-local") == 0 ) {
839 fgSetString("/sim/startup/time-offset-type", "latitude-offset");
840 } else if ( arg.find( "--start-date-sys=") == 0 ) {
841 fgSetInt("/sim/startup/time-offset", parse_date((arg.substr(17))));
842 fgSetString("/sim/startup/time-offset-type", "system");
843 } else if ( arg.find( "--start-date-lat=") == 0 ) {
844 fgSetInt("/sim/startup/time-offset", parse_date((arg.substr(17))));
845 fgSetString("/sim/startup/time-offset-type", "latitude");
846 } else if ( arg.find( "--start-date-gmt=") == 0 ) {
847 fgSetInt("/sim/startup/time-offset", parse_date((arg.substr(17))));
848 fgSetString("/sim/startup/time-offset-type", "gmt");
849 } else if ( arg == "--hud-tris" ) {
850 fgSetString("/sim/hud/frame-stat-type", "tris");
851 } else if ( arg == "--hud-culled" ) {
852 fgSetString("/sim/hud/frame-stat-type", "culled");
853 } else if ( arg.find( "--atc610x" ) == 0 ) {
854 add_channel( "atc610x", "dummy" );
855 } else if ( arg.find( "--atlas=" ) == 0 ) {
856 add_channel( "atlas", arg.substr(8) );
857 } else if ( arg.find( "--httpd=" ) == 0 ) {
858 add_channel( "httpd", arg.substr(8) );
859 #ifdef FG_JPEG_SERVER
860 } else if ( arg.find( "--jpg-httpd=" ) == 0 ) {
861 add_channel( "jpg-httpd", arg.substr(12) );
863 } else if ( arg.find( "--native=" ) == 0 ) {
864 add_channel( "native", arg.substr(9) );
865 } else if ( arg.find( "--native-ctrls=" ) == 0 ) {
866 add_channel( "native_ctrls", arg.substr(15) );
867 } else if ( arg.find( "--native-fdm=" ) == 0 ) {
868 add_channel( "native_fdm", arg.substr(13) );
869 } else if ( arg.find( "--opengc=" ) == 0 ) {
871 // cout << "Adding channel for OpenGC Display" << endl; cin >> stop;
872 add_channel( "opengc", arg.substr(9) );
873 } else if ( arg.find( "--garmin=" ) == 0 ) {
874 add_channel( "garmin", arg.substr(9) );
875 } else if ( arg.find( "--nmea=" ) == 0 ) {
876 add_channel( "nmea", arg.substr(7) );
877 } else if ( arg.find( "--props=" ) == 0 ) {
878 add_channel( "props", arg.substr(8) );
879 } else if ( arg.find( "--telnet=" ) == 0 ) {
880 add_channel( "telnet", arg.substr(9) );
881 } else if ( arg.find( "--pve=" ) == 0 ) {
882 add_channel( "pve", arg.substr(6) );
883 } else if ( arg.find( "--ray=" ) == 0 ) {
884 add_channel( "ray", arg.substr(6) );
885 } else if ( arg.find( "--rul=" ) == 0 ) {
886 add_channel( "rul", arg.substr(6) );
887 } else if ( arg.find( "--joyclient=" ) == 0 ) {
888 add_channel( "joyclient", arg.substr(12) );
889 #ifdef FG_NETWORK_OLK
890 } else if ( arg == "--disable-network-olk" ) {
891 fgSetBool("/sim/networking/olk", false);
892 } else if ( arg== "--enable-network-olk") {
893 fgSetBool("/sim/networking/olk", true);
894 } else if ( arg == "--net-hud" ) {
895 fgSetBool("/sim/hud/net-display", true);
896 net_hud_display = 1; // FIXME
897 } else if ( arg.find( "--net-id=") == 0 ) {
898 fgSetString("sim/networking/call-sign", arg.substr(9).c_str());
900 } else if ( arg.find( "--prop:" ) == 0 ) {
901 string assign = arg.substr(7);
902 string::size_type pos = assign.find('=');
903 if ( pos == arg.npos || pos == 0 ) {
904 SG_LOG( SG_GENERAL, SG_ALERT, "Bad property assignment: " << arg );
905 return FG_OPTIONS_ERROR;
907 string name = assign.substr(0, pos);
908 string value = assign.substr(pos + 1);
909 fgSetString(name.c_str(), value.c_str());
910 // SG_LOG(SG_GENERAL, SG_INFO, "Setting default value of property "
911 // << name << " to \"" << value << '"');
912 } else if ( arg.find("--trace-read=") == 0) {
913 string name = arg.substr(13);
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 } else if ( arg.find("--trace-write=") == 0) {
918 string name = arg.substr(14);
919 SG_LOG(SG_GENERAL, SG_INFO, "Tracing writes for property " << name);
920 fgGetNode(name.c_str(), true)
921 ->setAttribute(SGPropertyNode::TRACE_WRITE, true);
922 } else if ( arg.find( "--view-offset=" ) == 0 ) {
923 // $$$ begin - added VS Renganathan, 14 Oct 2K
924 // for multi-window outside window imagery
925 string woffset = arg.substr( 14 );
926 double default_view_offset = 0.0;
927 if ( woffset == "LEFT" ) {
928 default_view_offset = SGD_PI * 0.25;
929 } else if ( woffset == "RIGHT" ) {
930 default_view_offset = SGD_PI * 1.75;
931 } else if ( woffset == "CENTER" ) {
932 default_view_offset = 0.00;
934 default_view_offset = atof( woffset.c_str() ) * SGD_DEGREES_TO_RADIANS;
936 /* apparently not used (CLO, 11 Jun 2002)
937 FGViewer *pilot_view =
938 (FGViewer *)globals->get_viewmgr()->get_view( 0 ); */
939 // this will work without calls to the viewer...
940 fgSetDouble( "/sim/current-view/heading-offset-deg",
941 default_view_offset * SGD_RADIANS_TO_DEGREES );
942 // $$$ end - added VS Renganathan, 14 Oct 2K
943 } else if ( arg.find( "--visibility=" ) == 0 ) {
944 fgSetDouble("/environment/visibility-m", atof(arg.substr(13)));
945 } else if ( arg.find( "--visibility-miles=" ) == 0 ) {
946 double visibility = atof(arg.substr(19)) * 5280.0 * SG_FEET_TO_METER;
947 fgSetDouble("/environment/visibility-m", visibility);
948 } else if ( arg.find( "--random-wind" ) == 0 ) {
949 double min_hdg = sg_random() * 360.0;
950 double max_hdg = min_hdg + (20 - sqrt(sg_random() * 400));
951 double speed = 40 - sqrt(sg_random() * 1600.0);
952 double gust = speed + (10 - sqrt(sg_random() * 100));
953 setup_wind(min_hdg, max_hdg, speed, gust);
954 } else if ( arg.find( "--wind=" ) == 0 ) {
955 double min_hdg, max_hdg, speed, gust;
956 if (!parse_wind(arg.substr(7), &min_hdg, &max_hdg, &speed, &gust)) {
957 SG_LOG( SG_GENERAL, SG_ALERT, "bad wind value " << arg.substr(7) );
958 return FG_OPTIONS_ERROR;
960 setup_wind(min_hdg, max_hdg, speed, gust);
961 } else if ( arg.find( "--wp=" ) == 0 ) {
962 parse_wp( arg.substr( 5 ) );
963 } else if ( arg.find( "--flight-plan=") == 0) {
964 parse_flightplan ( arg.substr (14) );
965 } else if ( arg.find( "--config=" ) == 0 ) {
966 string file = arg.substr(9);
968 readProperties(file, globals->get_props());
969 } catch (const sg_exception &e) {
970 string message = "Error loading config file: ";
971 message += e.getFormattedMessage();
972 SG_LOG(SG_INPUT, SG_ALERT, message);
975 } else if ( arg.find( "--aircraft=" ) == 0 ) {
976 // read in the top level aircraft definition file
977 SGPath apath( globals->get_fg_root() );
978 apath.append( "Aircraft" );
979 apath.append( arg.substr(11) );
980 apath.concat( "-set.xml" );
981 SG_LOG(SG_INPUT, SG_INFO, "Reading aircraft: " << arg.substr(11)
982 << " from " << apath.str());
983 readProperties( apath.str(), globals->get_props() );
985 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" );
986 return FG_OPTIONS_ERROR;
989 return FG_OPTIONS_OK;
993 // Scan the command line options for an fg_root definition and set
996 fgScanForRoot (int argc, char **argv)
1000 SG_LOG(SG_GENERAL, SG_INFO, "Scanning for root: command line");
1002 while ( i < argc ) {
1003 SG_LOG( SG_GENERAL, SG_DEBUG, "argv[" << i << "] = " << argv[i] );
1005 string arg = argv[i];
1006 if ( arg.find( "--fg-root=" ) == 0 ) {
1007 return arg.substr( 10 );
1017 // Scan the config file for an fg_root definition and set just that.
1019 fgScanForRoot (const string& path)
1021 sg_gzifstream in( path );
1022 if ( !in.is_open() )
1025 SG_LOG( SG_GENERAL, SG_INFO, "Scanning for root: " << path );
1029 while ( ! in.eof() ) {
1032 while ( in.get(c) && c != '\0' ) {
1037 #if defined( macintosh )
1038 getline( in, line, '\r' );
1040 getline( in, line, '\n' );
1043 // catch extraneous (DOS) line ending character
1044 if ( line[line.length() - 1] < 32 ) {
1045 line = line.substr( 0, line.length()-1 );
1048 if ( line.find( "--fg-root=" ) == 0 ) {
1049 return line.substr( 10 );
1059 // Parse the command line options
1061 fgParseArgs (int argc, char **argv)
1063 bool in_options = true;
1065 SG_LOG(SG_GENERAL, SG_INFO, "Processing command line arguments");
1067 for (int i = 1; i < argc; i++) {
1068 string arg = argv[i];
1070 if (in_options && (arg.find('-') == 0)) {
1074 int result = parse_option(arg);
1075 if ( (result == FG_OPTIONS_HELP) ||
1076 (result == FG_OPTIONS_ERROR) ) {
1083 SG_LOG(SG_GENERAL, SG_INFO,
1084 "Reading command-line property file " << arg);
1085 readProperties(arg, globals->get_props());
1089 SG_LOG(SG_GENERAL, SG_INFO, "Finished command line arguments");
1093 // Parse config file options
1095 fgParseOptions (const string& path) {
1096 sg_gzifstream in( path );
1097 if ( !in.is_open() ) {
1101 SG_LOG( SG_GENERAL, SG_INFO, "Processing config file: " << path );
1105 while ( ! in.eof() ) {
1108 while ( in.get(c) && c != '\0' ) {
1113 #if defined( macintosh )
1114 getline( in, line, '\r' );
1116 getline( in, line, '\n' );
1119 // catch extraneous (DOS) line ending character
1120 if ( line[line.length() - 1] < 32 ) {
1121 line = line.substr( 0, line.length()-1 );
1124 if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
1125 SG_LOG( SG_GENERAL, SG_ALERT,
1126 "Config file parse error: " << path << " '"
1136 // Print usage message
1140 SGPropertyNode options_root;
1141 SGPath opath( globals->get_fg_root() );
1142 opath.append( "options.xml" );
1147 readProperties(opath.c_str(), &options_root);
1148 } catch (const sg_exception &ex) {
1149 cout << "Unable to read the help file." << endl;
1150 cout << "Make sure the file options.xml is located in the FlightGear base directory," << endl;
1151 cout << "and the location of the base directory is specified bij setting $FG_ROOT or" << endl;
1152 cout << "by adding --fg-root=path as a program argument." << endl;
1157 SGPropertyNode *options = options_root.getNode("options");
1159 SG_LOG( SG_GENERAL, SG_ALERT,
1160 "Error reading options.xml: <options> directive not found." );
1164 SGPropertyNode *usage = options->getNode("usage");
1166 cout << "Usage: " << usage->getStringValue() << endl;
1169 vector<SGPropertyNode_ptr>section = options->getChildren("section");
1170 for (unsigned int j = 0; j < section.size(); j++) {
1172 SGPropertyNode *name = section[j]->getNode("name");
1174 cout << endl << name->getStringValue() << ":" << endl;
1177 vector<SGPropertyNode_ptr>option = section[j]->getChildren("option");
1178 for (unsigned int k = 0; k < option.size(); k++) {
1180 SGPropertyNode *name = option[k]->getNode("name");
1181 SGPropertyNode *short_name = option[k]->getNode("short");
1182 SGPropertyNode *key = option[k]->getNode("key");
1183 SGPropertyNode *arg = option[k]->getNode("arg");
1186 string tmp = name->getStringValue();
1190 tmp.append(key->getStringValue());
1194 tmp.append(arg->getStringValue());
1198 tmp.append(short_name->getStringValue());
1202 if (tmp.size() <= 25) {
1203 snprintf(cstr, 96, " --%-27s", tmp.c_str());
1205 snprintf(cstr, 96, "\n --%s\n%32c", tmp.c_str(), ' ');
1209 SGPropertyNode *desc = option[k]->getNode("description");
1211 msg += desc->getStringValue();
1213 for ( unsigned int l = 1;
1214 (desc = option[k]->getNode("description", l, false));
1217 snprintf(cstr, 96, "\n%32c%s", ' ',
1218 desc->getStringValue());
1222 cout << msg << endl;