FlightGear next
options.cxx
Go to the documentation of this file.
1// options.cxx -- class to handle command line options
2//
3// Written by Curtis Olson, started April 1998.
4//
5// Copyright (C) 1998 Curtis L. Olson - http://www.flightgear.org/~curt
6//
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.
11//
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.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program; if not, write to the Free Software
19// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20//
21// $Id$
22
23
24#include <config.h>
25
26#include <ostream>
27#include <simgear/compiler.h>
28#include <simgear/structure/exception.hxx>
29#include <simgear/debug/logstream.hxx>
30#include <simgear/timing/sg_time.hxx>
31#include <simgear/misc/sg_dir.hxx>
32
33#include <cJSON.h>
34
35#include <cmath> // rint()
36#include <cstdio>
37#include <cstdlib> // atof(), atoi()
38#include <cstring> // strcmp()
39#include <algorithm>
40#include <map>
41
42#include <iostream>
43#include <string>
44#include <sstream>
45
46#include <simgear/io/HTTPClient.hxx>
47#include <simgear/io/HTTPFileRequest.hxx>
48#include <simgear/math/sg_random.hxx>
49#include <simgear/props/props_io.hxx>
50#include <simgear/io/iostreams/sgstream.hxx>
51#include <simgear/misc/sg_path.hxx>
52#include <simgear/misc/sg_dir.hxx>
53#include <simgear/scene/material/mat.hxx>
54#include <simgear/sound/soundmgr.hxx>
55#include <simgear/misc/strutils.hxx>
56#include <simgear/timing/timestamp.hxx>
57
59#include <Aircraft/replay.hxx>
61
62#include <GUI/gui.h>
63#include <GUI/MessageBox.hxx>
64
65#if defined(HAVE_QT)
66#include <GUI/QtLauncher.hxx>
67#endif
68
70#include "fg_init.hxx"
71#include "fg_os.hxx"
72#include "fg_props.hxx"
73#include "globals.hxx"
74#include "locale.hxx"
75#include "main.hxx"
76#include "options.hxx"
77#include <AIModel/AIManager.hxx>
80#include <Main/locale.hxx>
85#include <Viewer/view.hxx>
86#include <Viewer/viewmgr.hxx>
87
88#include <osg/Version>
89#include <flightgearBuildId.h>
90#include <simgear/version.h>
91
92using std::string;
93using std::sort;
94using std::cout;
95using std::cerr;
96using std::endl;
97using std::vector;
98using std::cin;
99
100using namespace flightgear;
101
102#define NEW_DEFAULT_MODEL_HZ 120
103
105
106static double
107atof( const string& str )
108{
109 return ::atof( str.c_str() );
110}
111
112static int
113atoi( const string& str )
114{
115 return ::atoi( str.c_str() );
116}
117
118static int fgSetupProxy( const char *arg );
119
128{
129
130 // Position (deliberately out of range)
131 fgSetDouble("/position/longitude-deg", 9999.0);
132 fgSetDouble("/position/latitude-deg", 9999.0);
133 fgSetDouble("/position/altitude-ft", -9999.0);
134
135 // Orientation
136 fgSetDouble("/orientation/heading-deg", 9999.0);
137 fgSetDouble("/orientation/roll-deg", 0.0);
138 fgSetDouble("/orientation/pitch-deg", 0.424);
139
140 // Velocities
141 fgSetDouble("/velocities/uBody-fps", 0.0);
142 fgSetDouble("/velocities/vBody-fps", 0.0);
143 fgSetDouble("/velocities/wBody-fps", 0.0);
144 fgSetDouble("/velocities/speed-north-fps", 0.0);
145 fgSetDouble("/velocities/speed-east-fps", 0.0);
146 fgSetDouble("/velocities/speed-down-fps", 0.0);
147 fgSetDouble("/velocities/airspeed-kt", 0.0);
148 fgSetDouble("/velocities/mach", 0.0);
149
150 // Presets
151 fgSetDouble("/sim/presets/longitude-deg", 9999.0);
152 fgSetDouble("/sim/presets/latitude-deg", 9999.0);
153 fgSetDouble("/sim/presets/altitude-ft", -9999.0);
154
155 fgSetDouble("/sim/presets/heading-deg", 9999.0);
156 fgSetDouble("/sim/presets/roll-deg", 0.0);
157 fgSetDouble("/sim/presets/pitch-deg", 0.424);
158
159 fgSetString("/sim/presets/speed-set", "knots");
160 fgSetDouble("/sim/presets/airspeed-kt", 0.0);
161 fgSetDouble("/sim/presets/mach", 0.0);
162 fgSetDouble("/sim/presets/uBody-fps", 0.0);
163 fgSetDouble("/sim/presets/vBody-fps", 0.0);
164 fgSetDouble("/sim/presets/wBody-fps", 0.0);
165 fgSetDouble("/sim/presets/speed-north-fps", 0.0);
166 fgSetDouble("/sim/presets/speed-east-fps", 0.0);
167 fgSetDouble("/sim/presets/speed-down-fps", 0.0);
168 fgSetDouble("/sim/presets/offset-distance-nm", 0.0);
169
170 fgSetBool("/sim/presets/runway-requested", false);
171
172 fgSetBool("/sim/presets/onground", true);
173 fgSetBool("/sim/presets/trim", false);
174
175 // Miscellaneous
176 fgSetBool("/sim/startup/splash-screen", true);
177 // we want mouse-pointer to have an undefined value if nothing is
178 // specified so we can do the right thing for voodoo-1/2 cards.
179 // fgSetString("/sim/startup/mouse-pointer", "false");
180 fgSetBool("/controls/flight/auto-coordination", false);
181 fgSetString("/sim/logging/priority", "alert");
182
183 // Features
184 fgSetBool("/sim/hud/color/antialiased", false);
185 fgSetBool("/sim/hud/enable3d[1]", true);
186 fgSetBool("/sim/hud/visibility[1]", false);
187 fgSetBool("/sim/panel/visibility", true);
188 fgSetBool("/sim/sound/enabled", true);
189 fgSetBool("/sim/sound/working", true);
190 fgSetBool("/sim/fgcom/enabled", false);
191
192 // Flight Model options
193 fgSetString("/sim/flight-model", "jsb");
194 fgSetString("/sim/aero", "c172");
195 fgSetInt("/sim/model-hz", NEW_DEFAULT_MODEL_HZ);
196 fgSetDouble("/sim/speed-up", 1.0);
197
198 // Scenery
199 fgSetString("/sim/scenery/engine", "tilecache");
200
201 // ( scenery = pagedLOD )
202 fgSetString("/sim/scenery/lod-levels", "1 3 5 7 9");
203 fgSetString("/sim/scenery/lod-res", "1");
204 fgSetString("/sim/scenery/lod-texturing", "bluemarble");
205
206 // Rendering options
207 fgSetString("/sim/rendering/fog", "nicest");
208 fgSetBool("/environment/clouds/status", true);
209 fgSetBool("/sim/startup/fullscreen", false);
210 fgSetBool("/sim/rendering/shading", true);
211 fgTie( "/sim/rendering/filtering", SGGetTextureFilter, SGSetTextureFilter, false);
212 fgSetInt("/sim/rendering/filtering", 1);
213 fgSetBool("/sim/rendering/wireframe", false);
214 fgSetBool("/sim/rendering/horizon-effect", false);
215 fgSetBool("/sim/rendering/distance-attenuation", false);
216 fgSetBool("/sim/rendering/specular-highlight", true);
217 fgSetString("/sim/rendering/materials-file", "materials.xml");
218 fgSetInt("/sim/startup/xsize", 1024);
219 fgSetInt("/sim/startup/ysize", 768);
220 fgSetInt("/sim/rendering/bits-per-pixel", 32);
221 fgSetString("/sim/view-mode", "pilot");
222 fgSetDouble("/sim/current-view/heading-offset-deg", 0);
223
224 // HUD options
225 fgSetString("/sim/startup/units", "feet");
226 fgSetString("/sim/hud/frame-stat-type", "tris");
227
228 // Time options
229 fgSetInt("/sim/startup/time-offset", 0);
230 fgSetString("/sim/startup/time-offset-type", "system-offset");
231 fgSetLong("/sim/time/cur-time-override", 0);
232
233 // Freeze options
234 fgSetBool("/sim/freeze/master", false);
235 fgSetBool("/sim/freeze/position", false);
236 fgSetBool("/sim/freeze/clock", false);
237 fgSetBool("/sim/freeze/fuel", false);
238
239 fgSetString("/sim/multiplay/callsign", "callsign");
240 fgSetString("/sim/multiplay/rxhost", "");
241 fgSetString("/sim/multiplay/txhost", "");
242 fgSetInt("/sim/multiplay/rxport", 0);
243 fgSetInt("/sim/multiplay/txport", 0);
244
245 SGPropertyNode* v = globals->get_props()->getNode("/sim/version", true);
246 v->setValueReadOnly("flightgear", FLIGHTGEAR_VERSION);
247 v->setValueReadOnly("simgear", SG_STRINGIZE(SIMGEAR_VERSION));
248 v->setValueReadOnly("openscenegraph", osgGetVersion());
249 v->setValueReadOnly("revision", REVISION);
250 v->setValueReadOnly("build-date", BUILD_DATE);
251 v->setValueReadOnly("hla-support", bool(FG_HAVE_HLA));
252 v->setValueReadOnly("build-type", FG_BUILD_TYPE);
253
254 char* envp = ::getenv( "http_proxy" );
255 if( envp != nullptr )
256 fgSetupProxy( envp );
257}
258
260// helper object to implement the --show-aircraft command.
261// resides here so we can share the fgFindAircraftInDir template above,
262// and hence ensure this command lists exectly the same aircraft as the normal
263// loading path.
265{
266public:
268 {
269 _minStatus = getNumMaturity(fgGetString("/sim/aircraft-min-status", "all"));
270 }
271
272
273 void show(const vector<SGPath> & path_list)
274 {
275 for (vector<SGPath>::const_iterator p = path_list.begin();
276 p != path_list.end(); ++p)
277 visitDir(*p, 0);
278
279 simgear::requestConsole(false); // ensure console is shown on Windows
280
281 std::sort(_aircraft.begin(), _aircraft.end(),
282 [](const std::string& lhs, const std::string& rhs) {
283 return strcasecmp(lhs.c_str(), rhs.c_str()) < 0 ? 1 : 0;
284 });
285
286 cout << "Available aircraft:" << endl;
287 for ( unsigned int i = 0; i < _aircraft.size(); i++ ) {
288 cout << _aircraft[i] << endl;
289 }
290 }
291
292private:
293 virtual VisitResult visit(const SGPath& path)
294 {
295 SGPropertyNode root;
296 try {
297 readProperties(path, &root);
298 } catch (sg_exception& ) {
299 return VISIT_CONTINUE;
300 }
301
302 int maturity = 0;
303 string descStr(" ");
304 descStr += path.file();
305 // trim common suffix from file names
306 int nPos = descStr.rfind("-set.xml");
307 if (nPos == (int)(descStr.size() - 8)) {
308 descStr.resize(nPos);
309 }
310
311 SGPropertyNode *node = root.getNode("sim");
312 if (node) {
313 SGPropertyNode* desc = node->getNode("description");
314 // if a status tag is found, read it in
315 if (node->hasValue("status")) {
316 maturity = getNumMaturity(node->getStringValue("status"));
317 }
318
319 if (desc) {
320 if (descStr.size() <= 27+3) {
321 descStr.append(29+3-descStr.size(), ' ');
322 } else {
323 descStr += '\n';
324 descStr.append( 32, ' ');
325 }
326 descStr += desc->getStringValue();
327 }
328 } // of have 'sim' node
329
330 if (maturity >= _minStatus) {
331 _aircraft.push_back(descStr);
332 }
333
334 return VISIT_CONTINUE;
335 }
336
337
338 int getNumMaturity(const std::string& str)
339 {
340 // Changes should also be reflected in $FG_ROOT/options.xml
341 const char* levels[] = {"alpha","beta","early-production","production"};
342
343 if (str == "all") {
344 return 0;
345 }
346
347 for (size_t i=0; i<(sizeof(levels)/sizeof(levels[0]));i++)
348 if (str == levels[i])
349 return i;
350
351 return 0;
352 }
353
354 int _minStatus;
355 string_list _aircraft;
356};
357
358/*
359 * Search in the current directory, and in on directory deeper
360 * for <aircraft>-set.xml configuration files and show the aircaft name
361 * and the contents of the<description> tag in a sorted manner.
362 *
363 * @parampath the directory to search for configuration files
364 */
365void fgShowAircraft(const vector<SGPath> &path_list)
366{
367 ShowAircraft s;
368 s.show(path_list);
369
370#ifdef _MSC_VER
371 cout << "Hit a key to continue..." << endl;
372 std::cin.get();
373#endif
374}
375
376
377static bool
378parse_wind (const string &wind, double * min_hdg, double * max_hdg,
379 double * speed, double * gust)
380{
381 string::size_type pos = wind.find('@');
382 if (pos == string::npos)
383 return false;
384 string dir = wind.substr(0, pos);
385 string spd = wind.substr(pos+1);
386 pos = dir.find(':');
387 if (pos == string::npos) {
388 *min_hdg = *max_hdg = atof(dir.c_str());
389 } else {
390 *min_hdg = atof(dir.substr(0,pos).c_str());
391 *max_hdg = atof(dir.substr(pos+1).c_str());
392 }
393 pos = spd.find(':');
394 if (pos == string::npos) {
395 *speed = *gust = atof(spd.c_str());
396 } else {
397 *speed = atof(spd.substr(0,pos).c_str());
398 *gust = atof(spd.substr(pos+1).c_str());
399 }
400 return true;
401}
402
403static bool
404parseIntValue(char** ppParserPos, int* pValue,int min, int max, const char* field, const char* argument)
405{
406 if ( !strlen(*ppParserPos) )
407 return true;
408
409 char num[256];
410 int i = 0;
411
412 while ( isdigit((*ppParserPos)[0]) && (i<255) )
413 {
414 num[i] = (*ppParserPos)[0];
415 (*ppParserPos)++;
416 i++;
417 }
418 num[i] = '\0';
419
420 switch ((*ppParserPos)[0])
421 {
422 case 0:
423 break;
424 case ':':
425 (*ppParserPos)++;
426 break;
427 default:
428 SG_LOG(SG_GENERAL, SG_ALERT, "Illegal character in time string for " << field << ": '" <<
429 (*ppParserPos)[0] << "'.");
430 // invalid field - skip rest of string to avoid further errors
431 while ((*ppParserPos)[0])
432 (*ppParserPos)++;
433 return false;
434 }
435
436 if (i<=0)
437 return true;
438
439 int value = atoi(num);
440 if ((value < min)||(value > max))
441 {
442 SG_LOG(SG_GENERAL, SG_ALERT, "Invalid " << field << " in '" << argument <<
443 "'. Valid range is " << min << "-" << max << ".");
444 return false;
445 }
446 else
447 {
448 *pValue = value;
449 return true;
450 }
451}
452
453// parse a time string ([+/-]%f[:%f[:%f]]) into hours
454static double
455parse_time(const string& time_in) {
456 char *time_str, num[256];
457 double hours, minutes, seconds;
458 double result = 0.0;
459 int sign = 1;
460 int i;
461
462 time_str = (char *)time_in.c_str();
463
464 // printf("parse_time(): %s\n", time_str);
465
466 // check for sign
467 if ( strlen(time_str) ) {
468 if ( time_str[0] == '+' ) {
469 sign = 1;
470 time_str++;
471 } else if ( time_str[0] == '-' ) {
472 sign = -1;
473 time_str++;
474 }
475 }
476 // printf("sign = %d\n", sign);
477
478 // get hours
479 if ( strlen(time_str) ) {
480 i = 0;
481 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
482 num[i] = time_str[0];
483 time_str++;
484 i++;
485 }
486 if ( time_str[0] == ':' ) {
487 time_str++;
488 }
489 num[i] = '\0';
490 hours = atof(num);
491 // printf("hours = %.2lf\n", hours);
492
493 result += hours;
494 }
495
496 // get minutes
497 if ( strlen(time_str) ) {
498 i = 0;
499 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
500 num[i] = time_str[0];
501 time_str++;
502 i++;
503 }
504 if ( time_str[0] == ':' ) {
505 time_str++;
506 }
507 num[i] = '\0';
508 minutes = atof(num);
509 // printf("minutes = %.2lf\n", minutes);
510
511 result += minutes / 60.0;
512 }
513
514 // get seconds
515 if ( strlen(time_str) ) {
516 i = 0;
517 while ( (time_str[0] != ':') && (time_str[0] != '\0') ) {
518 num[i] = time_str[0];
519 time_str++;
520 i++;
521 }
522 num[i] = '\0';
523 seconds = atof(num);
524 // printf("seconds = %.2lf\n", seconds);
525
526 result += seconds / 3600.0;
527 }
528
529 SG_LOG( SG_GENERAL, SG_INFO, " parse_time() = " << sign * result );
530
531 return(sign * result);
532}
533
534// parse a date string (yyyy:mm:dd:hh:mm:ss) into a time_t (seconds)
535static long int
536parse_date( const string& date, const char* timeType)
537{
538 struct tm gmt,*pCurrentTime;
539 int year,month,day,hour,minute,second;
540 char *argument, *date_str;
541
542 SGTime CurrentTime;
543 CurrentTime.update(SGGeod(),0,0);
544
545 // FIXME This should obtain system/aircraft/GMT time depending on timeType
546 pCurrentTime = CurrentTime.getGmt();
547
548 // initialize all fields with current time
549 year = pCurrentTime->tm_year + 1900;
550 month = pCurrentTime->tm_mon + 1;
551 day = pCurrentTime->tm_mday;
552 hour = pCurrentTime->tm_hour;
553 minute = pCurrentTime->tm_min;
554 second = pCurrentTime->tm_sec;
555
556 argument = (char *)date.c_str();
557 date_str = argument;
558
559 // start with parsing year
560 if (!strlen(date_str) ||
561 !parseIntValue(&date_str,&year,0,9999,"year",argument))
562 {
563 return -1;
564 }
565
566 if (year < 1970)
567 {
568 SG_LOG(SG_GENERAL, SG_ALERT, "Invalid year '" << year << "'. Use 1970 or later.");
569 return -1;
570 }
571
572 parseIntValue(&date_str, &month, 1, 12, "month", argument);
573 parseIntValue(&date_str, &day, 1, 31, "day", argument);
574 parseIntValue(&date_str, &hour, 0, 23, "hour", argument);
575 parseIntValue(&date_str, &minute, 0, 59, "minute", argument);
576 parseIntValue(&date_str, &second, 0, 59, "second", argument);
577
578 gmt.tm_sec = second;
579 gmt.tm_min = minute;
580 gmt.tm_hour = hour;
581 gmt.tm_mday = day;
582 gmt.tm_mon = month - 1;
583 gmt.tm_year = year -1900;
584 gmt.tm_isdst = 0; // ignore daylight savings time for the moment
585
586 time_t theTime = sgTimeGetGMT( gmt.tm_year, gmt.tm_mon, gmt.tm_mday,
587 gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
588
589 SG_LOG(SG_GENERAL, SG_INFO, "Configuring startup time to " << ctime(&theTime));
590
591 return (theTime);
592}
593
594
595// parse angle in the form of [+/-]ddd:mm:ss into degrees
596static double
597parse_degree( const string& degree_str) {
598 double result = parse_time( degree_str );
599
600 // printf("Degree = %.4f\n", result);
601
602 return(result);
603}
604
605
606// parse time offset string into seconds
607static long int
608parse_time_offset( const string& time_str) {
609 long int result;
610
611 // printf("time offset = %s\n", time_str);
612
613#ifdef HAVE_RINT
614 result = (int)rint(parse_time(time_str) * 3600.0);
615#else
616 result = (int)(parse_time(time_str) * 3600.0);
617#endif
618
619 // printf("parse_time_offset(): %d\n", result);
620
621 return( result );
622}
623
624
625// Parse --fov=x.xx type option
626static double
627parse_fov( const string& arg ) {
628 double fov = atof(arg);
629
630 if ( fov < FG_FOV_MIN ) { fov = FG_FOV_MIN; }
631 if ( fov > FG_FOV_MAX ) { fov = FG_FOV_MAX; }
632
633 fgSetDouble("/sim/view[0]/config/default-field-of-view-deg", fov);
634
635 // printf("parse_fov(): result = %.4f\n", fov);
636
637 return fov;
638}
639
640
641// Parse I/O channel option
642//
643// Format is "--protocol=medium,direction,hz,medium_options,..."
644//
645// protocol = { native, nmea, garmin, AV400, AV400Sim, fgfs, rul, pve, etc. }
646// medium = { serial, socket, file, etc. }
647// direction = { in, out, bi }
648// hz = number of times to process channel per second (floating
649// point values are ok.
650//
651// Serial example "--nmea=serial,dir,hz,device,baud" where
652//
653// device = OS device name of serial line to be open()'ed
654// baud = {300, 1200, 2400, ..., 230400}
655//
656// Socket example "--native=socket,dir,hz,machine,port,style" where
657//
658// machine = machine name or ip address if client (leave empty if server)
659// port = port, leave empty to let system choose
660// style = tcp or udp
661//
662// File example "--garmin=file,dir,hz,filename" where
663//
664// filename = file system file name
665
666static bool
667add_channel( const string& type, const string& channel_str ) {
668 // This check is necessary to prevent fgviewer from segfaulting when given
669 // weird options. (It doesn't run the full initialization)
670 if(!globals->get_channel_options_list())
671 {
672 SG_LOG(SG_GENERAL, SG_ALERT, "Option " << type << "=" << channel_str
673 << " ignored.");
674 return false;
675 }
676 SG_LOG(SG_GENERAL, SG_INFO, "Channel string = " << channel_str );
677 globals->get_channel_options_list()->push_back( type + "," + channel_str );
678 return true;
679}
680
681static void
683{
684 fgSetString("/sim/presets/airport-id", "");
685 fgSetString("/sim/presets/vor-id", "");
686 fgSetString("/sim/presets/ndb-id", "");
687 fgSetString("/sim/presets/carrier", "");
688 fgSetString("/sim/presets/parkpos", "");
689 fgSetString("/sim/presets/carrier-position", "");
690 fgSetString("/sim/presets/fix", "");
691 fgSetString("/sim/presets/tacan-id", "");
692}
693
694/*
695 Using --addon=/foo/bar does:
696 - register the add-on with the AddonManager (enabling, among other things,
697 add-on-specific resources for simgear::ResourceManager);
698 - load /foo/bar/addon-config.xml into the Global Property Tree;
699 - add /foo/bar to the list of aircraft paths to provide read access:
700 - set various properties related to the add-on under /addons;
701 - load /foo/bar/addon-main.nas into namespace __addon[ADDON_ID]__
702 (see $FG_ROOT/Nasal/addons.nas);
703 - call the main() function defined in that file.
704
705 For more details, see $FG_ROOT/Docs/README.add-ons.
706*/
707static int
708fgOptAddon(const char *arg)
709{
710 const SGPath addonPath = SGPath::fromUtf8(arg);
711 const auto& addonManager = addons::AddonManager::instance();
712
713 try {
714 addonManager->registerAddon(addonPath);
715 } catch (const sg_exception &e) {
716 string msg = "Error registering an add-on: " + e.getFormattedMessage();
717 SG_LOG(SG_GENERAL, SG_ALERT, msg);
719 "FlightGear", "Unable to register an add-on.", msg);
720 }
721
722 return FG_OPTIONS_OK;
723}
724
725static int
727{
728 const SGPath dataPath = SGPath::fromUtf8(arg);
729 if (!dataPath.exists()) {
730 SG_LOG(SG_GENERAL, SG_ALERT, "--data path not found:'" << dataPath << "'");
732 "FlightGear", "Data path not found: '" + dataPath.utf8Str() + "'.");
733 return FG_OPTIONS_EXIT;
734 }
735
736 globals->append_data_path(dataPath, false /* = before FG_ROOT */);
737 return FG_OPTIONS_OK;
738}
739
740static int
741fgOptVOR( const char * arg )
742{
744 fgSetString("/sim/presets/vor-id", arg);
745 return FG_OPTIONS_OK;
746}
747
748static int
749fgOptNDB( const char * arg )
750{
752 fgSetString("/sim/presets/ndb-id", arg);
753 return FG_OPTIONS_OK;
754}
755
756static int
757fgOptCarrier( const char * arg )
758{
760 fgSetString("/sim/presets/carrier", arg);
761 return FG_OPTIONS_OK;
762}
763
764static int
765fgOptCarrierPos( const char * arg )
766{
767 fgSetString("/sim/presets/carrier-position", arg);
768 return FG_OPTIONS_OK;
769}
770
771static int
772fgOptParkpos( const char * arg )
773{
774 fgSetString("/sim/presets/parkpos", arg);
775 fgSetBool("/sim/presets/parking-requested", true);
776 return FG_OPTIONS_OK;
777}
778
779static int
780fgOptFIX( const char * arg )
781{
783 fgSetString("/sim/presets/fix", arg);
784 return FG_OPTIONS_OK;
785}
786
787static int
788fgOptLon( const char *arg )
789{
791 fgSetDouble("/sim/presets/longitude-deg", parse_degree( arg ));
792 fgSetDouble("/position/longitude-deg", parse_degree( arg ));
793 return FG_OPTIONS_OK;
794}
795
796static int
797fgOptLat( const char *arg )
798{
800 fgSetDouble("/sim/presets/latitude-deg", parse_degree( arg ));
801 fgSetDouble("/position/latitude-deg", parse_degree( arg ));
802 return FG_OPTIONS_OK;
803}
804
805static int
806fgOptTACAN(const char* arg)
807{
809 fgSetString("/sim/presets/tacan-id", arg);
810 return FG_OPTIONS_OK;
811}
812
813static int
814fgOptAltitude( const char *arg )
815{
816 fgSetBool("/sim/presets/onground", false);
817 if ( fgGetString("/sim/startup/units") == "feet" )
818 fgSetDouble("/sim/presets/altitude-ft", atof( arg ));
819 else
820 fgSetDouble("/sim/presets/altitude-ft",
821 atof( arg ) * SG_METER_TO_FEET);
822 return FG_OPTIONS_OK;
823}
824
825static int
826fgOptUBody( const char *arg )
827{
828 fgSetString("/sim/presets/speed-set", "UVW");
829 if ( fgGetString("/sim/startup/units") == "feet" )
830 fgSetDouble("/sim/presets/uBody-fps", atof( arg ));
831 else
832 fgSetDouble("/sim/presets/uBody-fps",
833 atof( arg ) * SG_METER_TO_FEET);
834 return FG_OPTIONS_OK;
835}
836
837static int
838fgOptVBody( const char *arg )
839{
840 fgSetString("/sim/presets/speed-set", "UVW");
841 if ( fgGetString("/sim/startup/units") == "feet" )
842 fgSetDouble("/sim/presets/vBody-fps", atof( arg ));
843 else
844 fgSetDouble("/sim/presets/vBody-fps",
845 atof( arg ) * SG_METER_TO_FEET);
846 return FG_OPTIONS_OK;
847}
848
849static int
850fgOptWBody( const char *arg )
851{
852 fgSetString("/sim/presets/speed-set", "UVW");
853 if ( fgGetString("/sim/startup/units") == "feet" )
854 fgSetDouble("/sim/presets/wBody-fps", atof(arg));
855 else
856 fgSetDouble("/sim/presets/wBody-fps",
857 atof(arg) * SG_METER_TO_FEET);
858 return FG_OPTIONS_OK;
859}
860
861static int
862fgOptVNorth( const char *arg )
863{
864 fgSetString("/sim/presets/speed-set", "NED");
865 if ( fgGetString("/sim/startup/units") == "feet" )
866 fgSetDouble("/sim/presets/speed-north-fps", atof( arg ));
867 else
868 fgSetDouble("/sim/presets/speed-north-fps",
869 atof( arg ) * SG_METER_TO_FEET);
870 return FG_OPTIONS_OK;
871}
872
873static int
874fgOptVEast( const char *arg )
875{
876 fgSetString("/sim/presets/speed-set", "NED");
877 if ( fgGetString("/sim/startup/units") == "feet" )
878 fgSetDouble("/sim/presets/speed-east-fps", atof(arg));
879 else
880 fgSetDouble("/sim/presets/speed-east-fps",
881 atof(arg) * SG_METER_TO_FEET);
882 return FG_OPTIONS_OK;
883}
884
885static int
886fgOptVDown( const char *arg )
887{
888 fgSetString("/sim/presets/speed-set", "NED");
889 if ( fgGetString("/sim/startup/units") == "feet" )
890 fgSetDouble("/sim/presets/speed-down-fps", atof(arg));
891 else
892 fgSetDouble("/sim/presets/speed-down-fps",
893 atof(arg) * SG_METER_TO_FEET);
894 return FG_OPTIONS_OK;
895}
896
897static int
898fgOptVc( const char *arg )
899{
900 // fgSetString("/sim/presets/speed-set", "knots");
901 // fgSetDouble("/velocities/airspeed-kt", atof(arg.substr(5)));
902 fgSetString("/sim/presets/speed-set", "knots");
903 fgSetDouble("/sim/presets/airspeed-kt", atof(arg));
904 return FG_OPTIONS_OK;
905}
906
907static int
908fgOptMach( const char *arg )
909{
910 fgSetString("/sim/presets/speed-set", "mach");
911 fgSetDouble("/sim/presets/mach", atof(arg));
912 return FG_OPTIONS_OK;
913}
914
915static int
916fgOptRoc( const char *arg )
917{
918 fgSetDouble("/sim/presets/vertical-speed-fps", atof(arg)/60);
919 return FG_OPTIONS_OK;
920}
921
922static int
923fgOptFgScenery( const char *arg )
924{
925 globals->append_fg_scenery(SGPath::pathsFromUtf8(arg));
926 return FG_OPTIONS_OK;
927}
928
929static int
930fgOptAllowNasalRead( const char *arg )
931{
932 PathList paths = SGPath::pathsFromUtf8(arg);
933 if(paths.size() == 0) {
934 SG_LOG(SG_GENERAL, SG_WARN, "--allow-nasal-read requires a list of directories to allow");
935 }
936 for( PathList::const_iterator it = paths.begin(); it != paths.end(); ++it ) {
937 globals->append_read_allowed_paths(*it);
938 }
939 return FG_OPTIONS_OK;
940}
941
942static int
943fgOptFov( const char *arg )
944{
945 parse_fov( arg );
946 return FG_OPTIONS_OK;
947}
948
949static int
950fgOptGeometry( const char *arg )
951{
952 bool geometry_ok = true;
953 int xsize = 0, ysize = 0;
954 string geometry = arg;
955 string::size_type i = geometry.find('x');
956
957 if (i != string::npos) {
958 xsize = atoi(geometry.substr(0, i));
959 ysize = atoi(geometry.substr(i+1));
960 } else {
961 geometry_ok = false;
962 }
963
964 if ( xsize <= 0 || ysize <= 0 ) {
965 xsize = 640;
966 ysize = 480;
967 geometry_ok = false;
968 }
969
970 if ( !geometry_ok ) {
971 SG_LOG( SG_GENERAL, SG_ALERT, "Unknown geometry: " << geometry );
972 SG_LOG( SG_GENERAL, SG_ALERT,
973 "Setting geometry to " << xsize << 'x' << ysize << '\n');
974 } else {
975 SG_LOG( SG_GENERAL, SG_INFO,
976 "Setting geometry to " << xsize << 'x' << ysize << '\n');
977 fgSetInt("/sim/startup/xsize", xsize);
978 fgSetInt("/sim/startup/ysize", ysize);
979 }
980 return FG_OPTIONS_OK;
981}
982
983static int
984fgOptBpp( const char *arg )
985{
986 string bits_per_pix = arg;
987 if ( bits_per_pix == "16" ) {
988 fgSetInt("/sim/rendering/bits-per-pixel", 16);
989 } else if ( bits_per_pix == "24" ) {
990 fgSetInt("/sim/rendering/bits-per-pixel", 24);
991 } else if ( bits_per_pix == "32" ) {
992 fgSetInt("/sim/rendering/bits-per-pixel", 32);
993 } else {
994 SG_LOG(SG_GENERAL, SG_ALERT, "Unsupported bpp " << bits_per_pix);
995 }
996 return FG_OPTIONS_OK;
997}
998
999static int
1000fgOptTimeOffset( const char *arg )
1001{
1002 fgSetLong("/sim/startup/time-offset",
1003 parse_time_offset( arg ));
1004 fgSetString("/sim/startup/time-offset-type", "system-offset");
1005 return FG_OPTIONS_OK;
1006}
1007
1008static int
1009fgOptStartDateSys( const char *arg )
1010{
1011 long int theTime = parse_date( arg, "system" );
1012 if (theTime>=0)
1013 {
1014 fgSetLong("/sim/startup/time-offset", theTime);
1015 fgSetString("/sim/startup/time-offset-type", "system");
1016 }
1017 return FG_OPTIONS_OK;
1018}
1019
1020static int
1021fgOptStartDateLat( const char *arg )
1022{
1023 long int theTime = parse_date( arg, "latitude" );
1024 if (theTime>=0)
1025 {
1026 fgSetLong("/sim/startup/time-offset", theTime);
1027 fgSetString("/sim/startup/time-offset-type", "latitude");
1028 }
1029 return FG_OPTIONS_OK;
1030}
1031
1032static int
1033fgOptStartDateGmt( const char *arg )
1034{
1035 long int theTime = parse_date( arg, "gmt" );
1036 if (theTime>=0)
1037 {
1038 fgSetLong("/sim/startup/time-offset", theTime);
1039 fgSetString("/sim/startup/time-offset-type", "gmt");
1040 }
1041 return FG_OPTIONS_OK;
1042}
1043
1044static int
1045fgOptJpgHttpd( const char * arg )
1046{
1047 SG_LOG(SG_ALL,SG_ALERT,
1048 "the option --jpg-httpd is no longer supported! Please use --httpd instead."
1049 " URL for the screenshot within the new httpd is http://YourFgServer:xxxx/screenshot");
1050 return FG_OPTIONS_EXIT;
1051}
1052
1053static int
1054fgOptHttpd( const char * arg )
1055{
1056 // port may be any valid address:port notation
1057 // like 127.0.0.1:8080
1058 // or just the port 8080
1059 string port = simgear::strutils::strip(string(arg));
1060 if( port.empty() ) return FG_OPTIONS_ERROR;
1061 fgSetString( string(flightgear::http::PROPERTY_ROOT).append("/options/listening-port").c_str(), port );
1062 return FG_OPTIONS_OK;
1063}
1064
1065static int
1066fgSetupProxy( const char *arg )
1067{
1068 string options = simgear::strutils::strip( arg );
1069 string host, port, auth;
1070 string::size_type pos;
1071
1072 // this is NURLP - NURLP is not an url parser
1073 if( simgear::strutils::starts_with( options, "http://" ) )
1074 options = options.substr( 7 );
1075 if( simgear::strutils::ends_with( options, "/" ) )
1076 options = options.substr( 0, options.length() - 1 );
1077
1078 host = port = auth = "";
1079 if ((pos = options.find("@")) != string::npos)
1080 auth = options.substr(0, pos++);
1081 else
1082 pos = 0;
1083
1084 host = options.substr(pos, options.size());
1085 if ((pos = host.find(":")) != string::npos) {
1086 port = host.substr(++pos, host.size());
1087 host.erase(--pos, host.size());
1088 }
1089
1090 fgSetString("/sim/presets/proxy/host", host.c_str());
1091 fgSetString("/sim/presets/proxy/port", port.c_str());
1092 fgSetString("/sim/presets/proxy/authentication", auth.c_str());
1093
1094 return FG_OPTIONS_OK;
1095}
1096
1097static int
1098fgOptTraceRead( const char *arg )
1099{
1100 string name = arg;
1101 SG_LOG(SG_GENERAL, SG_INFO, "Tracing reads for property " << name);
1102 fgGetNode(name.c_str(), true)
1103 ->setAttribute(SGPropertyNode::TRACE_READ, true);
1104 return FG_OPTIONS_OK;
1105}
1106
1107static int
1108fgOptLogLevel( const char *arg )
1109{
1110 fgSetString("/sim/logging/priority", arg);
1111 setLoggingPriority(arg);
1112
1113 return FG_OPTIONS_OK;
1114}
1115
1116static int
1117fgOptLogClasses( const char *arg )
1118{
1119 fgSetString("/sim/logging/classes", arg);
1120 setLoggingClasses (arg);
1121
1122 return FG_OPTIONS_OK;
1123}
1124
1125static int
1126fgOptLogDir(const char* arg)
1127{
1128 SGPath dirPath;
1129 if (!strcmp(arg, "desktop")) {
1130 dirPath = SGPath::desktop();
1131 } else {
1132 dirPath = SGPath::fromUtf8(arg);
1133 }
1134
1135 if (!dirPath.isDir()) {
1136 SG_LOG(SG_GENERAL, SG_ALERT, "cannot find logging location " << dirPath);
1137 return FG_OPTIONS_ERROR;
1138 }
1139
1140 if (!dirPath.canWrite()) {
1141 SG_LOG(SG_GENERAL, SG_ALERT, "cannot write to logging location " << dirPath);
1142 return FG_OPTIONS_ERROR;
1143 }
1144
1145 // generate the log file name
1146 SGPath logFile;
1147 {
1148 char fileNameBuffer[100];
1149 time_t now;
1150 time(&now);
1151 strftime(fileNameBuffer, 99, "FlightGear_%F", localtime(&now));
1152
1153 unsigned int logsTodayCount = 0;
1154 while (true) {
1155 std::ostringstream os;
1156 os << fileNameBuffer << "_" << logsTodayCount++ << ".log";
1157 logFile = dirPath / os.str();
1158 if (!logFile.exists()) {
1159 break;
1160 }
1161 }
1162 }
1163
1164 sglog().logToFile(logFile, sglog().get_log_classes(), sglog().get_log_priority());
1165
1166 return FG_OPTIONS_OK;
1167}
1168
1169static int
1170fgOptTraceWrite( const char *arg )
1171{
1172 string name = arg;
1173 SG_LOG(SG_GENERAL, SG_INFO, "Tracing writes for property " << name);
1174 fgGetNode(name.c_str(), true)
1175 ->setAttribute(SGPropertyNode::TRACE_WRITE, true);
1176 return FG_OPTIONS_OK;
1177}
1178
1179static int
1180fgOptViewOffset( const char *arg )
1181{
1182 // $$$ begin - added VS Renganathan, 14 Oct 2K
1183 // for multi-window outside window imagery
1184 string woffset = arg;
1185 double default_view_offset = 0.0;
1186 if ( woffset == "LEFT" ) {
1187 default_view_offset = SGD_PI * 0.25;
1188 } else if ( woffset == "RIGHT" ) {
1189 default_view_offset = SGD_PI * 1.75;
1190 } else if ( woffset == "CENTER" ) {
1191 default_view_offset = 0.00;
1192 } else {
1193 default_view_offset = atof( woffset.c_str() ) * SGD_DEGREES_TO_RADIANS;
1194 }
1195 /* apparently not used (CLO, 11 Jun 2002)
1196 FGViewer *pilot_view =
1197 (FGViewer *)globals->get_viewmgr()->get_view( 0 ); */
1198 // this will work without calls to the viewer...
1199 fgSetDouble("/sim/view[0]/config/heading-offset-deg",
1200 default_view_offset * SGD_RADIANS_TO_DEGREES);
1201 // $$$ end - added VS Renganathan, 14 Oct 2K
1202 return FG_OPTIONS_OK;
1203}
1204
1205static int
1206fgOptVisibilityMeters( const char *arg )
1207{
1208 Environment::Presets::VisibilitySingleton::instance()->preset( atof( arg ) );
1209 return FG_OPTIONS_OK;
1210}
1211
1212static int
1213fgOptVisibilityMiles( const char *arg )
1214{
1215 Environment::Presets::VisibilitySingleton::instance()->preset( atof( arg ) * 5280.0 * SG_FEET_TO_METER );
1216 return FG_OPTIONS_OK;
1217}
1218
1219static int
1220fgOptMetar(const char *arg)
1221{
1222 // The given METAR string cannot be effective without disabling
1223 // real weather fetching.
1224 fgSetBool("/environment/realwx/enabled", false);
1225 // The user-supplied METAR string
1226 fgSetString("/environment/metar/data", arg);
1227
1228 return FG_OPTIONS_OK;
1229}
1230static int
1231fgOptConsole(const char *arg)
1232{
1233 static bool already_done = false;
1234 if (!already_done && Options::paramToBool(arg))
1235 {
1236 already_done = true;
1237 simgear::requestConsole(false);
1238 }
1239 return FG_OPTIONS_OK;
1240}
1241
1242static int
1243fgOptRandomWind( const char *arg )
1244{
1245 double min_hdg = sg_random() * 360.0;
1246 double max_hdg = min_hdg + (20 - sqrt(sg_random() * 400));
1247 double speed = sg_random() * sg_random() * 40;
1248 double gust = speed + (10 - sqrt(sg_random() * 100));
1249 Environment::Presets::WindSingleton::instance()->preset(min_hdg, max_hdg, speed, gust);
1250 return FG_OPTIONS_OK;
1251}
1252
1253static int
1254fgOptWind( const char *arg )
1255{
1256 double min_hdg = 0.0, max_hdg = 0.0, speed = 0.0, gust = 0.0;
1257 if (!parse_wind( arg, &min_hdg, &max_hdg, &speed, &gust)) {
1258 SG_LOG( SG_GENERAL, SG_ALERT, "bad wind value " << arg );
1259 return FG_OPTIONS_ERROR;
1260 }
1261 Environment::Presets::WindSingleton::instance()->preset(min_hdg, max_hdg, speed, gust);
1262 return FG_OPTIONS_OK;
1263}
1264
1265static int
1266fgOptTurbulence( const char *arg )
1267{
1268 Environment::Presets::TurbulenceSingleton::instance()->preset( atof(arg) );
1269 return FG_OPTIONS_OK;
1270}
1271
1272static int
1273fgOptCeiling( const char *arg )
1274{
1275 double elevation, thickness;
1276 string spec = arg;
1277 string::size_type pos = spec.find(':');
1278 if (pos == string::npos) {
1279 elevation = atof(spec.c_str());
1280 thickness = 2000;
1281 } else {
1282 elevation = atof(spec.substr(0, pos).c_str());
1283 thickness = atof(spec.substr(pos + 1).c_str());
1284 }
1285 Environment::Presets::CeilingSingleton::instance()->preset( elevation, thickness );
1286 return FG_OPTIONS_OK;
1287}
1288
1289static int
1290fgOptWp( const char *arg )
1291{
1292 string_list *waypoints = globals->get_initial_waypoints();
1293 if (!waypoints) {
1294 waypoints = new string_list;
1295 globals->set_initial_waypoints(waypoints);
1296 }
1297 waypoints->push_back(arg);
1298 return FG_OPTIONS_OK;
1299}
1300
1301static bool
1302parse_colon (const string &s, double * val1, double * val2)
1303{
1304 string::size_type pos = s.find(':');
1305 if (pos == string::npos) {
1306 *val2 = atof(s);
1307 return false;
1308 } else {
1309 *val1 = atof(s.substr(0, pos).c_str());
1310 *val2 = atof(s.substr(pos+1).c_str());
1311 return true;
1312 }
1313}
1314
1315
1316static int
1317fgOptFailure( const char * arg )
1318{
1319 string a = arg;
1320 if (a == "pitot") {
1321 fgSetBool("/systems/pitot/serviceable", false);
1322 } else if (a == "static") {
1323 fgSetBool("/systems/static/serviceable", false);
1324 } else if (a == "vacuum") {
1325 fgSetBool("/systems/vacuum/serviceable", false);
1326 } else if (a == "electrical") {
1327 fgSetBool("/systems/electrical/serviceable", false);
1328 } else {
1329 SG_LOG(SG_INPUT, SG_ALERT, "Unknown failure mode: " << a);
1330 return FG_OPTIONS_ERROR;
1331 }
1332
1333 return FG_OPTIONS_OK;
1334}
1335
1336
1337static int
1338fgOptNAV1( const char * arg )
1339{
1340 double radial, freq;
1341 if (parse_colon(arg, &radial, &freq))
1342 fgSetDouble("/instrumentation/nav[0]/radials/selected-deg", radial);
1343 fgSetDouble("/instrumentation/nav[0]/frequencies/selected-mhz", freq);
1344 return FG_OPTIONS_OK;
1345}
1346
1347static int
1348fgOptNAV2( const char * arg )
1349{
1350 double radial, freq;
1351 if (parse_colon(arg, &radial, &freq))
1352 fgSetDouble("/instrumentation/nav[1]/radials/selected-deg", radial);
1353 fgSetDouble("/instrumentation/nav[1]/frequencies/selected-mhz", freq);
1354 return FG_OPTIONS_OK;
1355}
1356
1357static int
1358fgOptADF( const char * arg )
1359{
1360 SG_LOG(SG_ALL,SG_ALERT,
1361 "the option --adf is no longer supported! Please use --adf1 "
1362 "instead.");
1363 return FG_OPTIONS_EXIT;
1364}
1365
1366static int
1367fgOptADF1( const char * arg )
1368{
1369 double rot, freq;
1370 if (parse_colon(arg, &rot, &freq))
1371 fgSetDouble("/instrumentation/adf[0]/rotation-deg", rot);
1372 fgSetDouble("/instrumentation/adf[0]/frequencies/selected-khz", freq);
1373 return FG_OPTIONS_OK;
1374}
1375
1376static int
1377fgOptADF2( const char * arg )
1378{
1379 double rot, freq;
1380 if (parse_colon(arg, &rot, &freq))
1381 fgSetDouble("/instrumentation/adf[1]/rotation-deg", rot);
1382 fgSetDouble("/instrumentation/adf[1]/frequencies/selected-khz", freq);
1383 return FG_OPTIONS_OK;
1384}
1385
1386static int
1387fgOptDME( const char *arg )
1388{
1389 string opt = arg;
1390 if (opt == "nav1") {
1391 fgSetInt("/instrumentation/dme/switch-position", 1);
1392 fgSetString("/instrumentation/dme/frequencies/source",
1393 "/instrumentation/nav[0]/frequencies/selected-mhz");
1394 } else if (opt == "nav2") {
1395 fgSetInt("/instrumentation/dme/switch-position", 3);
1396 fgSetString("/instrumentation/dme/frequencies/source",
1397 "/instrumentation/nav[1]/frequencies/selected-mhz");
1398 } else {
1399 double frequency = atof(arg);
1400 if (frequency==0.0)
1401 {
1402 SG_LOG(SG_INPUT, SG_ALERT, "Invalid DME frequency: '" << arg << "'.");
1403 return FG_OPTIONS_ERROR;
1404 }
1405 fgSetInt("/instrumentation/dme/switch-position", 2);
1406 fgSetString("/instrumentation/dme/frequencies/source",
1407 "/instrumentation/dme/frequencies/selected-mhz");
1408 fgSetDouble("/instrumentation/dme/frequencies/selected-mhz", frequency);
1409 }
1410 return FG_OPTIONS_OK;
1411}
1412
1413static int
1414fgOptLivery( const char *arg )
1415{
1416 string opt = arg;
1417 string livery_path = "livery/" + opt;
1418 fgSetString("/sim/model/texture-path", livery_path.c_str() );
1419 return FG_OPTIONS_OK;
1420}
1421
1422static int
1423fgOptScenario( const char *arg )
1424{
1425 SGPath path(arg);
1426 std::string name(arg);
1427 if (path.exists()) {
1428 if (path.isRelative()) {
1429 // make absolute
1430 path = simgear::Dir::current().path() / arg;
1431 }
1432
1433 // create description node
1434 auto n = FGAIManager::registerScenarioFile(globals->get_props(), path);
1435 if (!n) {
1436 SG_LOG(SG_GENERAL, SG_WARN, "failed to read scenario file at:" << path);
1437 return FG_OPTIONS_ERROR;
1438 }
1439
1440 // also set the /sim/ai/scenario entry so we load it on startup
1441 name = path.file_base();
1442 }
1443
1444 // add the 'load it' node
1445 SGPropertyNode_ptr ai_node = fgGetNode( "/sim/ai", true );
1446 ai_node->addChild("scenario")->setStringValue(name);
1447
1448 return FG_OPTIONS_OK;
1449}
1450
1451static int
1452fgOptAirport( const char *arg )
1453{
1454 fgSetString("/sim/presets/airport-id", simgear::strutils::uppercase({arg}) );
1455 fgSetBool("/sim/presets/airport-requested", true );
1456 return FG_OPTIONS_OK;
1457}
1458
1459static int
1460fgOptRunway( const char *arg )
1461{
1462 fgSetString("/sim/presets/runway", simgear::strutils::uppercase({arg}) );
1463 fgSetBool("/sim/presets/runway-requested", true );
1464 return FG_OPTIONS_OK;
1465}
1466
1467static int
1468fgOptCallSign(const char * arg)
1469{
1470 int i;
1471 char callsign[11];
1472 strncpy(callsign,arg,10);
1473 callsign[10]=0;
1474 for (i=0;callsign[i];i++)
1475 {
1476 char c = callsign[i];
1477 if (c >= 'A' && c <= 'Z') continue;
1478 if (c >= 'a' && c <= 'z') continue;
1479 if (c >= '0' && c <= '9') continue;
1480 if (c == '-' || c == '_') continue;
1481 // convert any other illegal characters
1482 callsign[i]='-';
1483 }
1484 fgSetString("sim/multiplay/callsign", callsign );
1485 return FG_OPTIONS_OK;
1486}
1487
1488static int
1489fgOptIgnoreAutosave(const char* arg)
1490{
1491 const bool param = Options::paramToBool(arg);
1492
1493 fgSetBool("/sim/startup/ignore-autosave", param);
1494 // don't overwrite autosave on exit
1495 fgSetBool("/sim/startup/save-on-exit", !param);
1496 return FG_OPTIONS_OK;
1497}
1498
1499static int
1500fgOptFreeze(const char* arg)
1501{
1502 const bool param = Options::paramToBool(arg);
1503
1504 fgSetBool("/sim/freeze/master", param);
1505 fgSetBool("/sim/freeze/clock", param);
1506 return FG_OPTIONS_OK;
1507}
1508
1509// Set a property for the --prop: option. Syntax: --prop:[<type>:]<name>=<value>
1510// <type> can be "double" etc. but also only the first letter "d".
1511// Examples: --prop:alpha=1 --prop:bool:beta=true --prop:d:gamma=0.123
1512static int
1513fgOptSetProperty(const char* raw)
1514{
1515 string arg(raw);
1516 string::size_type pos = arg.find('=');
1517 if (pos == arg.npos || pos == 0 || pos + 1 == arg.size())
1518 return FG_OPTIONS_ERROR;
1519
1520 string name = arg.substr(0, pos);
1521 string value = arg.substr(pos + 1);
1522 string type;
1523 pos = name.find(':');
1524
1525 if (pos != name.npos && pos != 0 && pos + 1 != name.size()) {
1526 type = name.substr(0, pos);
1527 name = name.substr(pos + 1);
1528 }
1529 SGPropertyNode *n = fgGetNode(name.c_str(), true);
1530
1531 bool writable = n->getAttribute(SGPropertyNode::WRITE);
1532 if (!writable)
1533 n->setAttribute(SGPropertyNode::WRITE, true);
1534
1535 bool ret = false;
1536 if (type.empty())
1537 ret = n->setUnspecifiedValue(value.c_str());
1538 else if (type == "s" || type == "string")
1539 ret = n->setStringValue(value.c_str());
1540 else if (type == "d" || type == "double")
1541 ret = n->setDoubleValue(strtod(value.c_str(), 0));
1542 else if (type == "f" || type == "float")
1543 ret = n->setFloatValue(atof(value.c_str()));
1544 else if (type == "l" || type == "long")
1545 ret = n->setLongValue(strtol(value.c_str(), 0, 0));
1546 else if (type == "i" || type == "int")
1547 ret = n->setIntValue(atoi(value.c_str()));
1548 else if (type == "b" || type == "bool")
1549 ret = n->setBoolValue(value == "true" || atoi(value.c_str()) != 0);
1550
1551 if (!writable)
1552 n->setAttribute(SGPropertyNode::WRITE, false);
1553 return ret ? FG_OPTIONS_OK : FG_OPTIONS_ERROR;
1554}
1555
1556/* If <url> is a URL, return suitable name for downloaded file. */
1557static std::string urlToLocalPath(const char* url)
1558{
1559 bool http = simgear::strutils::starts_with(url, "http://");
1560 bool https = simgear::strutils::starts_with(url, "https://");
1561 if (!http && !https) {
1562 return "";
1563 }
1564 // e.g. http://fg.com/foo/bar/wibble.fgtape
1565 const char* s2 = (http) ? url+7 : url+8; // fg.com/foo/bar/wibble.fgtape
1566 const char* s3 = strchr(s2, '/'); // /foo/bar/wibble.fgtape
1567 const char* s4 = (s3) ? strrchr(s3, '/') : NULL; // /wibble.fgtape
1568 std::string path = "url_";
1569 if (s3) path += std::string(s2, s3-s2); // url_fg.com
1570 path += '_'; // url_fg.com_
1571 if (s3 && s4 > s3) {
1572 path += simgear::strutils::md5(s3, s4-s3).substr(0, 8);
1573 path += '_'; // url_fg.com_12345678_
1574 }
1575 if (s4) path += (s4+1); // url_fg.com_12345678_wibble.fgtape
1576 if (!simgear::strutils::ends_with(path, ".fgtape")) path += ".fgtape";
1577 std::string dir = fgGetString("/sim/replay/tape-directory");
1578 if (dir != "") {
1579 SGPath path2 = dir;
1580 path2.append(path);
1581 path = path2.str();
1582 }
1583 return path;
1584}
1585
1586// When loading a Continuous recording at startup, we need to override the
1587// aircraft and airport. Unfortunately we can't simply set /sim/aircraft
1588// because there may be --aircraft options later on in the command line. Also
1589// fgMainInit() ends up calling Options::initAircraft() after we have processed
1590// all options, and Options::initAircraft() seems to look directly at the
1591// options again, instead of using /sim/aircraft.
1592//
1593// So we store any aircraft/airport override here, so that
1594// Options::initAircraft() can use them if they are set, instead of going back
1595// to any user-specified aircraft.
1596//
1597static std::string g_load_tape_aircraft;
1598static std::string g_load_tape_airport;
1599
1600static int
1601fgOptLoadTape(const char* arg)
1602{
1603 // load a flight recorder tape but wait until the fdm is initialized.
1604 //
1605 struct DelayedTapeLoader : SGPropertyChangeListener {
1606
1607 DelayedTapeLoader( const char * tape, simgear::HTTP::FileRequestRef filerequest) :
1608 _tape(SGPath::fromUtf8(tape)),
1609 _filerequest(filerequest)
1610 {
1611 fgGetNode("/sim/signals/fdm-initialized", true)->addChangeListener( this );
1612 }
1613
1614 virtual ~ DelayedTapeLoader() {}
1615
1616 void valueChanged(SGPropertyNode* node) override
1617 {
1618 if (!fgGetBool("/sim/signals/fdm-initialized")) {
1619 return;
1620 }
1621 fgGetNode("/sim/signals/fdm-initialized", true)->removeChangeListener( this );
1622
1623 // tell the replay subsystem to load the tape
1624 auto replay = globals->get_subsystem<FGReplay>();
1625 assert(replay);
1626 SGPropertyNode_ptr arg = new SGPropertyNode();
1627 arg->setStringValue("tape", _tape.utf8Str() );
1628 arg->setBoolValue( "same-aircraft", 0 );
1629 if (!replay->loadTape(
1630 _tape,
1631 false /*preview*/,
1632 fgGetBool("/sim/startup/load-tape/create-video"),
1633 fgGetDouble("/sim/startup/load-tape/fixed-dt", 0),
1634 *arg,
1635 _filerequest
1636 ))
1637 {
1638 // Force shutdown if we can't load tape specified on command-line.
1639 SG_LOG(SG_GENERAL, SG_POPUP, "Exiting because unable to load fgtape: " << _tape.str());
1640 flightgear::modalMessageBox("Exiting because unable to load fgtape", _tape.str(), "");
1641 fgOSExit(1);
1642 }
1643 delete this; // commence suicide
1644 }
1645 private:
1646 SGPath _tape;
1647 simgear::HTTP::FileRequestRef _filerequest;
1648 };
1649
1650 SGPropertyNode_ptr properties(new SGPropertyNode);
1651 simgear::HTTP::FileRequestRef filerequest;
1652 SGTimeStamp timeout;
1653
1654 std::string path = urlToLocalPath(arg);
1655 if (path.empty()) {
1656 // <arg> is a local file.
1657 //
1658 // Load the recording's header if it is a Continuous recording.
1659 //
1660 path = FGReplay::makeTapePath(arg);
1661 (void) FGReplay::loadContinuousHeader(path.c_str(), nullptr /*in*/, properties);
1662 } else {
1663 // <arg> is a URL. Start download.
1664 //
1665 // Load the recording's header if it is a Continuous recording.
1666 //
1667 // This is a little messy - we need to create a FGHTTPClient subsystem
1668 // in order to do the download, and we call its update() method
1669 // directly in order to download at least the header.
1670 //
1671 const char* url = arg;
1673 SG_LOG(SG_GENERAL, SG_MANDATORY_INFO, "Replaying url " << url << " using local path: " << path);
1674 filerequest.reset(new simgear::HTTP::FileRequest(url, path, true /*append*/));
1675 filerequest->setAcceptEncoding(""); // "" means request any supported compression.
1676
1677 long max_download_speed = fgGetLong("/sim/replay/download-max-bytes-per-sec");
1678 if (max_download_speed != 0) {
1679 // Can be useful to limite download speed for testing background
1680 // download.
1681 //
1682 SG_LOG(SG_GENERAL, SG_MANDATORY_INFO, "Limiting download speed"
1683 << " /sim/replay/download-max-bytes-per-sec=" << max_download_speed);
1684 filerequest->setMaxBytesPerSec(max_download_speed);
1685 }
1686 http->client()->makeRequest(filerequest);
1687 SG_LOG(SG_GENERAL, SG_DEBUG, ""
1688 << " filerequest->responseCode()=" << filerequest->responseCode()
1689 << " filerequest->responseReason()=" << filerequest->responseReason()
1690 );
1691
1692 // Load recording header, looping so that we wait for the initial
1693 // portion of the recording to be downloaded. We give up after a fixed
1694 // timeout.
1695 //
1696 timeout.stamp();
1697 for(;;) {
1698 // Run http client's update() to download any pending data.
1699 http->update(0);
1700
1701 // Try to load properties from recording header.
1702 int e = FGReplay::loadContinuousHeader(path, nullptr /*in*/, properties);
1703 if (e == 0) {
1704 // Success. We leave <filerequest> active - it will carry
1705 // on downloading when the main update loop gets going
1706 // later. Hopefully the delay before that happens will not
1707 // cause a server timeout.
1708 //
1709 break;
1710 }
1711 if (e == -1) {
1712 SG_LOG(SG_GENERAL, SG_POPUP, "Not a Continuous recording: url=" << url << " local filename=" << path);
1713 // Replay from URL only works with Continuous recordings.
1714 return FG_OPTIONS_EXIT;
1715 }
1716
1717 // If we get here, need to download some more.
1718 if (timeout.elapsedMSec() > (30 * 1000)) {
1719 SG_LOG(SG_GENERAL, SG_POPUP, "Timeout while reading downloaded recording from " << url << ". local path=" << path);
1720 return FG_OPTIONS_EXIT;
1721 }
1722 SGTimeStamp::sleepForMSec(1000);
1723 }
1724 }
1725
1726 // Set aircraft from recording header if we loaded it above; this has to
1727 // happen now, before the FDM is initialised. Also set the airport; we
1728 // don't actually have to do this because the replay doesn't need terrain
1729 // to work, but we might as well load the correct terrain.
1730 //
1731 std::string aircraft = properties->getStringValue("meta/aircraft-type");
1732 std::string airport = properties->getStringValue("meta/closest-airport-id");
1733 SG_LOG(SG_GENERAL, SG_MANDATORY_INFO, "From recording header: aircraft=" << aircraft << " airport=" << airport);
1734 // Override aircraft and airport settings to match what is in the
1735 // recording.
1736 //
1737 g_load_tape_aircraft = aircraft;
1738 g_load_tape_airport = airport;
1739
1740 // Arrange to load the recording after FDM has initialised.
1741 new DelayedTapeLoader(path.c_str(), filerequest);
1742
1743 return FG_OPTIONS_OK;
1744}
1745
1746static int fgOptGUI(const char* arg)
1747{
1748 const bool param = Options::paramToBool(arg);
1749
1750 // Reverse logic, headless is enabled when --gui is false
1751 globals->set_headless(!param);
1752 return FG_OPTIONS_OK;
1753}
1754
1755static int fgOptHoldShort(const char* arg)
1756{
1757 const bool param = Options::paramToBool(arg);
1758
1759 // Reverse logic, this property set to true disables hold short
1760 fgSetBool("/sim/presets/mp-hold-short-override", !param);
1761 return FG_OPTIONS_OK;
1762}
1763
1764static int fgOptNoTrim(const char* arg)
1765{
1766 const bool param = Options::paramToBool(arg);
1767
1768 // Reverse logic, param = true means NO trim
1769 fgSetBool("/sim/presets/trim", !param);
1770 return FG_OPTIONS_OK;
1771}
1772
1773static int fgOptInAir(const char* arg)
1774{
1775 const bool param = Options::paramToBool(arg);
1776
1777 // Reverse logic, param = true means on ground = false
1778 fgSetBool("/sim/presets/onground", !param);
1779 return FG_OPTIONS_OK;
1780}
1781
1782/*
1783 option param_type type property b_param s_param func
1784
1785where:
1786 option : name of the option
1787 param_type: ParamType::NONE - option has not parameter: --option
1788 ParamType::VAL_BOOL - option accept only boolean params true/false/1/0/yes/no
1789 or no parameter (default true): --option=true
1790 ParamType::REGULAR - option requires a parameter but it is none of the
1791 above cases: --option=value
1792 type : OptionType::OPT_BOOL - property is a boolean
1793 OptionType::OPT_STRING - property is a string
1794 OptionType::OPT_DOUBLE - property is a double
1795 OptionType::OPT_INT - property is an integer
1796 OptionType::OPT_CHANNEL - name of option is the name of a channel
1797 OptionType::OPT_FUNC - the option trigger a function
1798 property :
1799 b_param : if type==OptionType::OPT_BOOL,
1800 value set to the property (param_type is ParamType::NONE for boolean)
1801 s_param : if type==OptionType::OPT_STRING,
1802 value set to the property if param_type is ParamType::NONE
1803 func : function called if type==OptionType::OPT_FUNC. if param_type is ParamType::VAL_BOOL
1804 or ParamType::REGULAR, the value is passed to the function as a string,
1805 otherwise, s_param is passed.
1806
1807 For OptionType::OPT_DOUBLE and OptionType::OPT_INT, the parameter value is converted into a
1808 double or an integer and set to the property.
1809
1810 For OptionType::OPT_CHANNEL, add_channel is called with the parameter value as the
1811 argument.
1812*/
1813
1816const int OPTION_MULTI = 1 << 17;
1817
1819 const char *option;
1821 int type;
1822 const char *property;
1824 const char *s_param;
1825 int (*func)( const char * );
1826};
1827
1828const std::initializer_list<OptionDesc> fgOptionArray = {
1829 // clang-format off
1830 {"language", ParamType::REGULAR, OptionType::OPT_IGNORE, "", false, "", 0 },
1831 {"console", ParamType::VAL_BOOL, OptionType::OPT_FUNC, "", false, "true", fgOptConsole },
1832 {"compositor", ParamType::REGULAR, OptionType::OPT_STRING, "/sim/rendering/default-compositor", false, "", 0 },
1833 {"metar", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptMetar },
1834 {"browser-app", ParamType::REGULAR, OptionType::OPT_STRING, "/sim/startup/browser-app", false, "", 0 },
1835 {"sound-device", ParamType::REGULAR, OptionType::OPT_STRING, "/sim/sound/device-name", false, "", 0 },
1836 {"airport", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptAirport },
1837 {"runway", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptRunway },
1838 {"vor", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptVOR },
1839 {"vor-frequency", ParamType::REGULAR, OptionType::OPT_DOUBLE, "/sim/presets/vor-freq", false, "", fgOptVOR },
1840 {"ndb", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptNDB },
1841 {"ndb-frequency", ParamType::REGULAR, OptionType::OPT_DOUBLE, "/sim/presets/ndb-freq", false, "", fgOptVOR },
1842 {"carrier", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptCarrier },
1843 {"carrier-position", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptCarrierPos },
1844 {"fix", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptFIX },
1845 {"tacan", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptTACAN },
1846 {"offset-distance", ParamType::REGULAR, OptionType::OPT_DOUBLE, "/sim/presets/offset-distance-nm", false, "", 0 },
1847 {"offset-azimuth", ParamType::REGULAR, OptionType::OPT_DOUBLE, "/sim/presets/offset-azimuth-deg", false, "", 0 },
1848 {"lon", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptLon },
1849 {"lat", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptLat },
1850 {"altitude", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptAltitude },
1851 {"uBody", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptUBody },
1852 {"vBody", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptVBody },
1853 {"wBody", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptWBody },
1854 {"vNorth", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptVNorth },
1855 {"vEast", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptVEast },
1856 {"vDown", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptVDown },
1857 {"vc", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptVc },
1858 {"mach", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptMach },
1859 {"heading", ParamType::REGULAR, OptionType::OPT_DOUBLE, "/sim/presets/heading-deg", false, "", 0 },
1860 {"roll", ParamType::REGULAR, OptionType::OPT_DOUBLE, "/sim/presets/roll-deg", false, "", 0 },
1861 {"pitch", ParamType::REGULAR, OptionType::OPT_DOUBLE, "/sim/presets/pitch-deg", false, "", 0 },
1862 {"glideslope", ParamType::REGULAR, OptionType::OPT_DOUBLE, "/sim/presets/glideslope-deg", false, "", 0 },
1863 {"roc", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptRoc },
1864 {"fg-root", ParamType::REGULAR, OptionType::OPT_IGNORE, "", false, "", 0 },
1865 {"fg-scenery", ParamType::REGULAR, OptionType::OPT_FUNC | OPTION_MULTI, "", false, "", fgOptFgScenery },
1866 {"terrain-engine", ParamType::REGULAR, OptionType::OPT_STRING, "/sim/scenery/engine", false, "tilecache", 0 },
1867 {"lod-levels", ParamType::REGULAR, OptionType::OPT_STRING, "/sim/scenery/lod-levels", false, "1 3 5 7", 0 },
1868 {"lod-res", ParamType::REGULAR, OptionType::OPT_STRING, "/sim/scenery/lod-res", false, "1", 0 },
1869 {"lod-texturing", ParamType::REGULAR, OptionType::OPT_STRING, "/sim/scenery/lod-texturing", false, "bluemarble", 0 },
1870 {"lod-range-mult", ParamType::REGULAR, OptionType::OPT_STRING, "/sim/scenery/lod-range-mult", false, "2", 0 },
1871 {"fg-aircraft", ParamType::REGULAR, OptionType::OPT_IGNORE | OPTION_MULTI, "", false, "", 0 },
1872 {"fdm", ParamType::REGULAR, OptionType::OPT_STRING, "/sim/flight-model", false, "", 0 },
1873 {"aero", ParamType::REGULAR, OptionType::OPT_STRING, "/sim/aero", false, "", 0 },
1874 {"aircraft-dir", ParamType::REGULAR, OptionType::OPT_IGNORE, "", false, "", 0 },
1875 {"state", ParamType::REGULAR, OptionType::OPT_IGNORE, "", false, "", 0 },
1876 {"model-hz", ParamType::REGULAR, OptionType::OPT_INT, "/sim/model-hz", false, "", 0 },
1877 {"max-fps", ParamType::REGULAR, OptionType::OPT_DOUBLE, "/sim/frame-rate-throttle-hz", false, "", 0 },
1878 {"speed", ParamType::REGULAR, OptionType::OPT_DOUBLE, "/sim/speed-up", false, "", 0 },
1879 {"trim", ParamType::VAL_BOOL, OptionType::OPT_BOOL, "/sim/presets/trim", true, "", 0 },
1880 {"notrim", ParamType::VAL_BOOL, OptionType::OPT_FUNC, "", false, "true", fgOptNoTrim },
1881 {"on-ground", ParamType::VAL_BOOL, OptionType::OPT_BOOL, "/sim/presets/onground", true, "", 0 },
1882 {"in-air", ParamType::VAL_BOOL, OptionType::OPT_FUNC, "", false, "true", fgOptInAir },
1883 {"fog-disable", ParamType::NONE, OptionType::OPT_STRING, "/sim/rendering/fog", false, "disabled", 0 },
1884 {"fog-fastest", ParamType::NONE, OptionType::OPT_STRING, "/sim/rendering/fog", false, "fastest", 0 },
1885 {"fog-nicest", ParamType::NONE, OptionType::OPT_STRING, "/sim/rendering/fog", false, "nicest", 0 },
1886 {"fov", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptFov },
1887 {"aspect-ratio-multiplier", ParamType::REGULAR, OptionType::OPT_DOUBLE, "/sim/current-view/aspect-ratio-multiplier", false, "", 0 },
1888 {"shading-flat", ParamType::NONE, OptionType::OPT_BOOL, "/sim/rendering/shading", false, "", 0 },
1889 {"shading-smooth", ParamType::NONE, OptionType::OPT_BOOL, "/sim/rendering/shading", true, "", 0 },
1890 {"texture-filtering", ParamType::NONE, OptionType::OPT_INT, "/sim/rendering/filtering", 1, "", 0 },
1891 {"materials-file", ParamType::REGULAR, OptionType::OPT_STRING, "/sim/rendering/materials-file", false, "", 0 },
1892 {"terrasync-dir", ParamType::REGULAR, OptionType::OPT_IGNORE, "", false, "", 0 },
1893 {"download-dir", ParamType::REGULAR, OptionType::OPT_IGNORE, "", false, "", 0 },
1894 {"texture-cache-dir", ParamType::REGULAR, OptionType::OPT_IGNORE, "", false, "", 0 },
1895 {"allow-nasal-read", ParamType::REGULAR, OptionType::OPT_FUNC | OPTION_MULTI, "", false, "", fgOptAllowNasalRead },
1896 {"geometry", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptGeometry },
1897 {"bpp", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptBpp },
1898 {"units-feet", ParamType::NONE, OptionType::OPT_STRING, "/sim/startup/units", false, "feet", 0 },
1899 {"units-meters", ParamType::NONE, OptionType::OPT_STRING, "/sim/startup/units", false, "meters", 0 },
1900 {"timeofday", ParamType::REGULAR, OptionType::OPT_STRING, "/sim/startup/time-offset-type", false, "noon", 0 },
1901 {"time-offset", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptTimeOffset },
1902 {"time-match-real", ParamType::NONE, OptionType::OPT_STRING, "/sim/startup/time-offset-type", false, "system-offset", 0 },
1903 {"time-match-local", ParamType::NONE, OptionType::OPT_STRING, "/sim/startup/time-offset-type", false, "latitude-offset", 0 },
1904 {"start-date-sys", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptStartDateSys },
1905 {"start-date-lat", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptStartDateLat },
1906 {"start-date-gmt", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptStartDateGmt },
1907 {"hud-tris", ParamType::NONE, OptionType::OPT_STRING, "/sim/hud/frame-stat-type", false, "tris", 0 },
1908 {"hud-culled", ParamType::NONE, OptionType::OPT_STRING, "/sim/hud/frame-stat-type", false, "culled", 0 },
1909 {"atcsim", ParamType::REGULAR, OptionType::OPT_CHANNEL, "", false, "dummy", 0 },
1910 {"atlas", ParamType::REGULAR, OptionType::OPT_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1911 {"httpd", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptHttpd },
1912 {"jpg-httpd", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptJpgHttpd },
1913 {"native", ParamType::REGULAR, OptionType::OPT_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1914 {"native-ctrls", ParamType::REGULAR, OptionType::OPT_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1915 {"native-fdm", ParamType::REGULAR, OptionType::OPT_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1916 {"native-gui", ParamType::REGULAR, OptionType::OPT_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1917 {"dds-props", ParamType::REGULAR, OptionType::OPT_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1918 {"opengc", ParamType::REGULAR, OptionType::OPT_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1919 {"AV400", ParamType::REGULAR, OptionType::OPT_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1920 {"AV400Sim", ParamType::REGULAR, OptionType::OPT_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1921 {"AV400WSimA", ParamType::REGULAR, OptionType::OPT_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1922 {"AV400WSimB", ParamType::REGULAR, OptionType::OPT_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1923 {"flarm", ParamType::REGULAR, OptionType::OPT_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1924 {"garmin", ParamType::REGULAR, OptionType::OPT_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1925 {"igc", ParamType::REGULAR, OptionType::OPT_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1926 {"nmea", ParamType::REGULAR, OptionType::OPT_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1927 {"generic", ParamType::REGULAR, OptionType::OPT_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1928 {"props", ParamType::REGULAR, OptionType::OPT_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1929 {"telnet", ParamType::REGULAR, OptionType::OPT_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1930 {"pve", ParamType::REGULAR, OptionType::OPT_CHANNEL, "", false, "", 0 },
1931 {"ray", ParamType::REGULAR, OptionType::OPT_CHANNEL, "", false, "", 0 },
1932 {"rul", ParamType::REGULAR, OptionType::OPT_CHANNEL, "", false, "", 0 },
1933 {"joyclient", ParamType::REGULAR, OptionType::OPT_CHANNEL, "", false, "", 0 },
1934 {"jsclient", ParamType::REGULAR, OptionType::OPT_CHANNEL, "", false, "", 0 },
1935 {"proxy", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgSetupProxy },
1936 {"callsign", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptCallSign},
1937 {"multiplay", ParamType::REGULAR, OptionType::OPT_CHANNEL | OPTION_MULTI, "", false, "", 0 },
1938#if FG_HAVE_HLA
1939 {"hla", ParamType::REGULAR, OptionType::OPT_CHANNEL, "", false, "", 0 },
1940 {"hla-local", ParamType::REGULAR, OptionType::OPT_CHANNEL, "", false, "", 0 },
1941#endif
1942 {"trace-read", ParamType::REGULAR, OptionType::OPT_FUNC | OPTION_MULTI, "", false, "", fgOptTraceRead },
1943 {"trace-write", ParamType::REGULAR, OptionType::OPT_FUNC | OPTION_MULTI, "", false, "", fgOptTraceWrite },
1944 {"log-level", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptLogLevel },
1945 {"log-class", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptLogClasses },
1946 {"log-dir", ParamType::REGULAR, OptionType::OPT_FUNC | OPTION_MULTI, "", false, "", fgOptLogDir },
1947 {"view-offset", ParamType::REGULAR, OptionType::OPT_FUNC | OPTION_MULTI, "", false, "", fgOptViewOffset },
1948 {"visibility", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptVisibilityMeters },
1949 {"visibility-miles", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptVisibilityMiles },
1950 {"random-wind", ParamType::NONE, OptionType::OPT_FUNC, "", false, "", fgOptRandomWind },
1951 {"wind", ParamType::REGULAR, OptionType::OPT_FUNC | OPTION_MULTI, "", false, "", fgOptWind },
1952 {"turbulence", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptTurbulence },
1953 {"ceiling", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptCeiling },
1954 {"wp", ParamType::REGULAR, OptionType::OPT_FUNC | OPTION_MULTI, "", false, "", fgOptWp },
1955 {"flight-plan", ParamType::REGULAR, OptionType::OPT_STRING, "/autopilot/route-manager/file-path", false, "", NULL },
1956 {"config", ParamType::REGULAR, OptionType::OPT_IGNORE | OPTION_MULTI, "", false, "", 0 },
1957 {"addon", ParamType::REGULAR, OptionType::OPT_FUNC | OPTION_MULTI, "", false, "", fgOptAddon },
1959 {"aircraft", ParamType::REGULAR, OptionType::OPT_STRING, "/sim/aircraft", false, "", 0 },
1960 {"vehicle", ParamType::REGULAR, OptionType::OPT_STRING, "/sim/aircraft", false, "", 0 },
1961 {"failure", ParamType::REGULAR, OptionType::OPT_FUNC | OPTION_MULTI, "", false, "", fgOptFailure },
1962 {"com1", ParamType::REGULAR, OptionType::OPT_DOUBLE, "/instrumentation/comm[0]/frequencies/selected-mhz", false, "", 0 },
1963 {"com2", ParamType::REGULAR, OptionType::OPT_DOUBLE, "/instrumentation/comm[1]/frequencies/selected-mhz", false, "", 0 },
1964 {"nav1", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptNAV1 },
1965 {"nav2", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptNAV2 },
1966 {"adf", /*legacy*/ ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptADF },
1967 {"adf1", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptADF1 },
1968 {"adf2", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptADF2 },
1969 {"dme", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptDME },
1970 {"min-status", ParamType::REGULAR, OptionType::OPT_STRING, "/sim/aircraft-min-status", false, "all", 0 },
1971 {"livery", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptLivery },
1972 {"ai-scenario", ParamType::REGULAR, OptionType::OPT_FUNC | OPTION_MULTI, "", false, "", fgOptScenario },
1973 {"parking-id", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptParkpos },
1974 {"parkpos", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptParkpos },
1975 {"version", ParamType::VAL_BOOL, OptionType::OPT_BOOL, "", true, "", nullptr },
1976 {"info", ParamType::VAL_BOOL, OptionType::OPT_BOOL, "", true, "", nullptr },
1977 {"json-report", ParamType::VAL_BOOL, OptionType::OPT_BOOL, "", true, "", nullptr },
1978 {"fgviewer", ParamType::NONE, OptionType::OPT_IGNORE, "", false, "", 0},
1979 {"no-default-config", ParamType::VAL_BOOL, OptionType::OPT_IGNORE, "", false, "", 0},
1981 {"load-tape", ParamType::REGULAR, OptionType::OPT_FUNC, "", false, "", fgOptLoadTape },
1982 {"load-tape-fixed-dt", ParamType::REGULAR, OptionType::OPT_DOUBLE, "/sim/startup/load-tape/fixed-dt", false, "", nullptr },
1983 {"jsbsim-output-directive-file", ParamType::REGULAR, OptionType::OPT_STRING, "/sim/jsbsim/output-directive-file", false, "", nullptr },
1984 {"graphics-preset", ParamType::REGULAR, OptionType::OPT_STRING, "/sim/rendering/preset", false, "", nullptr},
1985 {"show-aircraft", ParamType::VAL_BOOL, OptionType::OPT_IGNORE, "", true, "", nullptr },
1986 {"show-sound-devices", ParamType::VAL_BOOL, OptionType::OPT_IGNORE, "", true, "", nullptr },
1987
1988 // Enable/disable options that can be used in many ways,
1989 // with enable/disable prefixes as well as without, but with a value of 1/0 or true/false or yes/no.
1990 // Examples of use:
1991 // --enable-fullscreen (enable)
1992 // --disable-fullscreen (disable)
1993 // --fullscreen (enable)
1994 // --fullscreen=true (enable)
1995 // --fullscreen=false (disable)
1996 // --fullscreen=1 (enable)
1997 // --fullscreen=0 (disable)
1998 // --fullscreen=yes (enable)
1999 // --fullscreen=no (disable)
2000 // --fullscreen true (enable)
2001 // --fullscreen false (disable)
2002 // --fullscreen 1 (enable)
2003 // --fullscreen 0 (disable)
2004 // --fullscreen yes (enable)
2005 // --fullscreen no (disable)
2006
2007 {"ai-models", ParamType::VAL_BOOL, OptionType::OPT_BOOL, "/sim/ai/enabled", true, "", nullptr },
2008 {"disable-ai-models", ParamType::NONE, OptionType::OPT_BOOL, "/sim/ai/enabled", false, "", nullptr },
2009 {"enable-ai-models", ParamType::NONE, OptionType::OPT_BOOL, "/sim/ai/enabled", true, "", nullptr },
2010 {"ai-traffic", ParamType::VAL_BOOL, OptionType::OPT_BOOL, "/sim/traffic-manager/enabled", true, "", nullptr },
2011 {"disable-ai-traffic", ParamType::NONE, OptionType::OPT_BOOL, "/sim/traffic-manager/enabled", false, "", nullptr },
2012 {"enable-ai-traffic", ParamType::NONE, OptionType::OPT_BOOL, "/sim/traffic-manager/enabled", true, "", nullptr },
2013 {"allow-nasal-from-sockets", ParamType::VAL_BOOL, OptionType::OPT_BOOL, "", true, "", nullptr },
2014 {"disable-allow-nasal-from-sockets", ParamType::NONE, OptionType::OPT_BOOL, "", false, "", nullptr },
2015 {"enable-allow-nasal-from-sockets", ParamType::NONE, OptionType::OPT_BOOL, "", true, "", nullptr },
2016 {"anti-alias-hud", ParamType::VAL_BOOL, OptionType::OPT_BOOL, "/sim/hud/color/antialiased", true, "", nullptr },
2017 {"disable-anti-alias-hud", ParamType::NONE, OptionType::OPT_BOOL, "/sim/hud/color/antialiased", false, "", nullptr },
2018 {"enable-anti-alias-hud", ParamType::NONE, OptionType::OPT_BOOL, "/sim/hud/color/antialiased", true, "", nullptr },
2019 {"auto-coordination", ParamType::VAL_BOOL, OptionType::OPT_BOOL, "/controls/flight/auto-coordination", true, "", nullptr },
2020 {"disable-auto-coordination", ParamType::NONE, OptionType::OPT_BOOL, "/controls/flight/auto-coordination", false, "", nullptr },
2021 {"enable-auto-coordination", ParamType::NONE, OptionType::OPT_BOOL, "/controls/flight/auto-coordination", true, "", nullptr },
2022 {"clock-freeze", ParamType::VAL_BOOL, OptionType::OPT_BOOL, "/sim/freeze/clock", true, "", nullptr },
2023 {"disable-clock-freeze", ParamType::NONE, OptionType::OPT_BOOL, "/sim/freeze/clock", false, "", nullptr },
2024 {"enable-clock-freeze", ParamType::NONE, OptionType::OPT_BOOL, "/sim/freeze/clock", true, "", nullptr },
2025 {"clouds", ParamType::VAL_BOOL, OptionType::OPT_BOOL, "/environment/clouds/status", true, "", nullptr },
2026 {"disable-clouds", ParamType::NONE, OptionType::OPT_BOOL, "/environment/clouds/status", false, "", nullptr },
2027 {"enable-clouds", ParamType::NONE, OptionType::OPT_BOOL, "/environment/clouds/status", true, "", nullptr },
2028 {"clouds3d", ParamType::VAL_BOOL, OptionType::OPT_BOOL, "/sim/rendering/clouds3d-enable", true, "", nullptr },
2029 {"disable-clouds3d", ParamType::NONE, OptionType::OPT_BOOL, "/sim/rendering/clouds3d-enable", false, "", nullptr },
2030 {"enable-clouds3d", ParamType::NONE, OptionType::OPT_BOOL, "/sim/rendering/clouds3d-enable", true, "", nullptr },
2031 {"developer", ParamType::VAL_BOOL, OptionType::OPT_IGNORE | OptionType::OPT_BOOL, "", true, "", nullptr },
2032 {"disable-developer", ParamType::NONE, OptionType::OPT_IGNORE | OptionType::OPT_BOOL, "", false, "", nullptr },
2033 {"enable-developer", ParamType::NONE, OptionType::OPT_IGNORE | OptionType::OPT_BOOL, "", true, "", nullptr },
2034 {"distance-attenuation", ParamType::VAL_BOOL, OptionType::OPT_BOOL, "/sim/rendering/distance-attenuation", true, "", nullptr },
2035 {"disable-distance-attenuation", ParamType::NONE, OptionType::OPT_BOOL, "/sim/rendering/distance-attenuation", false, "", nullptr },
2036 {"enable-distance-attenuation", ParamType::NONE, OptionType::OPT_BOOL, "/sim/rendering/distance-attenuation", true, "", nullptr },
2037#ifdef ENABLE_IAX
2038 {"fgcom", ParamType::VAL_BOOL, OptionType::OPT_BOOL, "/sim/fgcom/enabled", true, "", nullptr },
2039 {"enable-fgcom", ParamType::NONE, OptionType::OPT_BOOL, "/sim/fgcom/enabled", true, "", nullptr },
2040 {"disable-fgcom", ParamType::NONE, OptionType::OPT_BOOL, "/sim/fgcom/enabled", false, "", nullptr },
2041#endif
2042 {"fpe", ParamType::VAL_BOOL, OptionType::OPT_IGNORE, "", true, "", nullptr },
2043 {"disable-fpe", ParamType::NONE, OptionType::OPT_IGNORE, "", false, "", nullptr },
2044 {"enable-fpe", ParamType::NONE, OptionType::OPT_IGNORE, "", true, "", nullptr },
2045 {"freeze", ParamType::VAL_BOOL, OptionType::OPT_FUNC, "", false, "true", fgOptFreeze },
2046 {"disable-freeze", ParamType::NONE, OptionType::OPT_FUNC, "", false, "false", fgOptFreeze },
2047 {"enable-freeze", ParamType::NONE, OptionType::OPT_FUNC, "", false, "true", fgOptFreeze },
2048 {"fuel-freeze", ParamType::VAL_BOOL, OptionType::OPT_BOOL, "/sim/freeze/fuel", true, "", nullptr },
2049 {"disable-fuel-freeze", ParamType::NONE, OptionType::OPT_BOOL, "/sim/freeze/fuel", false, "", nullptr },
2050 {"enable-fuel-freeze", ParamType::NONE, OptionType::OPT_BOOL, "/sim/freeze/fuel", true, "", nullptr },
2051 {"fullscreen", ParamType::VAL_BOOL, OptionType::OPT_BOOL, "/sim/startup/fullscreen", true, "", nullptr },
2052 {"disable-fullscreen", ParamType::NONE, OptionType::OPT_BOOL, "/sim/startup/fullscreen", false, "", nullptr },
2053 {"enable-fullscreen", ParamType::NONE, OptionType::OPT_BOOL, "/sim/startup/fullscreen", true, "", nullptr },
2054 {"gui", ParamType::VAL_BOOL, OptionType::OPT_FUNC, "", false, "true", fgOptGUI },
2055 {"disable-gui", ParamType::NONE, OptionType::OPT_FUNC, "", false, "false", fgOptGUI },
2056 {"enable-gui", ParamType::NONE, OptionType::OPT_FUNC, "", false, "true", fgOptGUI },
2057 {"hold-short", ParamType::VAL_BOOL, OptionType::OPT_FUNC, "", false, "true", fgOptHoldShort },
2058 {"disable-hold-short", ParamType::NONE, OptionType::OPT_FUNC, "", false, "false", fgOptHoldShort },
2059 {"enable-hold-short", ParamType::NONE, OptionType::OPT_FUNC, "", false, "true", fgOptHoldShort },
2060 {"hud", ParamType::VAL_BOOL, OptionType::OPT_BOOL, "/sim/hud/visibility[1]", true, "", nullptr },
2061 {"disable-hud", ParamType::NONE, OptionType::OPT_BOOL, "/sim/hud/visibility[1]", false, "", nullptr },
2062 {"enable-hud", ParamType::NONE, OptionType::OPT_BOOL, "/sim/hud/visibility[1]", true, "", nullptr },
2063 {"hud-3d", ParamType::VAL_BOOL, OptionType::OPT_BOOL, "/sim/hud/enable3d[1]", true, "", nullptr },
2064 {"disable-hud-3d", ParamType::NONE, OptionType::OPT_BOOL, "/sim/hud/enable3d[1]", false, "", nullptr },
2065 {"enable-hud-3d", ParamType::NONE, OptionType::OPT_BOOL, "/sim/hud/enable3d[1]", true, "", nullptr },
2066 {"horizon-effect", ParamType::VAL_BOOL, OptionType::OPT_BOOL, "/sim/rendering/horizon-effect", true, "", nullptr },
2067 {"disable-horizon-effect", ParamType::NONE, OptionType::OPT_BOOL, "/sim/rendering/horizon-effect", false, "", nullptr },
2068 {"enable-horizon-effect", ParamType::NONE, OptionType::OPT_BOOL, "/sim/rendering/horizon-effect", true, "", nullptr },
2069 {"ignore-autosave", ParamType::VAL_BOOL, OptionType::OPT_FUNC, "", false, "true", fgOptIgnoreAutosave },
2070 {"disable-ignore-autosave", ParamType::NONE, OptionType::OPT_FUNC, "", false, "false", fgOptIgnoreAutosave },
2071 {"enable-ignore-autosave", ParamType::NONE, OptionType::OPT_FUNC, "", false, "true", fgOptIgnoreAutosave },
2072 {"launcher", ParamType::VAL_BOOL, OptionType::OPT_IGNORE, "", true, "", nullptr },
2073 {"disable-launcher", ParamType::NONE, OptionType::OPT_IGNORE, "", false, "", nullptr },
2074 {"enable-launcher", ParamType::NONE, OptionType::OPT_IGNORE, "", true, "", nullptr },
2075 {"load-tape-create-video", ParamType::VAL_BOOL, OptionType::OPT_BOOL, "/sim/startup/load-tape/create-video", true, "", nullptr },
2076 {"disable-load-tape-create-video", ParamType::NONE, OptionType::OPT_BOOL, "/sim/startup/load-tape/create-video", false, "", nullptr },
2077 {"enable-load-tape-create-video", ParamType::NONE, OptionType::OPT_BOOL, "/sim/startup/load-tape/create-video", true, "", nullptr },
2078 {"mouse-pointer", ParamType::VAL_BOOL, OptionType::OPT_BOOL, "/sim/startup/mouse-pointer", true, "", nullptr },
2079 {"disable-mouse-pointer", ParamType::NONE, OptionType::OPT_BOOL, "/sim/startup/mouse-pointer", false, "", nullptr },
2080 {"enable-mouse-pointer", ParamType::NONE, OptionType::OPT_BOOL, "/sim/startup/mouse-pointer", true, "", nullptr },
2081 {"panel", ParamType::VAL_BOOL, OptionType::OPT_BOOL, "/sim/panel/visibility", true, "", nullptr },
2082 {"disable-panel", ParamType::NONE, OptionType::OPT_BOOL, "/sim/panel/visibility", false, "", nullptr },
2083 {"enable-panel", ParamType::NONE, OptionType::OPT_BOOL, "/sim/panel/visibility", true, "", nullptr },
2084 {"random-buildings", ParamType::VAL_BOOL, OptionType::OPT_BOOL, "/sim/rendering/random-buildings", true, "", nullptr },
2085 {"disable-random-buildings", ParamType::NONE, OptionType::OPT_BOOL, "/sim/rendering/random-buildings", false, "", nullptr },
2086 {"enable-random-buildings", ParamType::NONE, OptionType::OPT_BOOL, "/sim/rendering/random-buildings", true, "", nullptr },
2087 {"random-objects", ParamType::VAL_BOOL, OptionType::OPT_BOOL, "/sim/rendering/random-objects", true, "", nullptr },
2088 {"disable-random-objects", ParamType::NONE, OptionType::OPT_BOOL, "/sim/rendering/random-objects", false, "", nullptr },
2089 {"enable-random-objects", ParamType::NONE, OptionType::OPT_BOOL, "/sim/rendering/random-objects", true, "", nullptr },
2090 {"random-vegetation", ParamType::VAL_BOOL, OptionType::OPT_BOOL, "/sim/rendering/random-vegetation", true, "", nullptr },
2091 {"disable-random-vegetation", ParamType::NONE, OptionType::OPT_BOOL, "/sim/rendering/random-vegetation", false, "", nullptr },
2092 {"enable-random-vegetation", ParamType::NONE, OptionType::OPT_BOOL, "/sim/rendering/random-vegetation", true, "", nullptr },
2093 {"read-only", ParamType::VAL_BOOL, OptionType::OPT_BOOL, "/sim/fghome-readonly", true, "", nullptr },
2094 {"disable-read-only", ParamType::NONE, OptionType::OPT_BOOL, "/sim/fghome-readonly", false, "", nullptr },
2095 {"enable-read-only", ParamType::NONE, OptionType::OPT_BOOL, "/sim/fghome-readonly", true, "", nullptr },
2096 {"real-weather-fetch", ParamType::VAL_BOOL, OptionType::OPT_BOOL, "/environment/realwx/enabled", true, "", nullptr },
2097 {"disable-real-weather-fetch", ParamType::NONE, OptionType::OPT_BOOL, "/environment/realwx/enabled", false, "", nullptr },
2098 {"enable-real-weather-fetch", ParamType::NONE, OptionType::OPT_BOOL, "/environment/realwx/enabled", true, "", nullptr },
2099 {"restart-launcher", ParamType::VAL_BOOL, OptionType::OPT_BOOL, "/sim/restart-launcher-on-exit", true, "", nullptr },
2100 {"disable-restart-launcher", ParamType::NONE, OptionType::OPT_BOOL, "/sim/restart-launcher-on-exit", false, "", nullptr },
2101 {"enable-restart-launcher", ParamType::NONE, OptionType::OPT_BOOL, "/sim/restart-launcher-on-exit", true, "", nullptr },
2102 {"restore-defaults", ParamType::VAL_BOOL, OptionType::OPT_BOOL, "/sim/startup/restore-defaults", true, "", nullptr },
2103 {"disable-restore-defaults", ParamType::NONE, OptionType::OPT_BOOL, "/sim/startup/restore-defaults", false, "", nullptr },
2104 {"enable-restore-defaults", ParamType::NONE, OptionType::OPT_BOOL, "/sim/startup/restore-defaults", true, "", nullptr },
2105 {"save-on-exit", ParamType::VAL_BOOL, OptionType::OPT_BOOL, "/sim/startup/save-on-exit", true, "", nullptr },
2106 {"disable-save-on-exit", ParamType::NONE, OptionType::OPT_BOOL, "/sim/startup/save-on-exit", false, "", nullptr },
2107 {"enable-save-on-exit", ParamType::NONE, OptionType::OPT_BOOL, "/sim/startup/save-on-exit", true, "", nullptr },
2108 {"sentry", ParamType::VAL_BOOL, OptionType::OPT_BOOL, "/sim/startup/sentry-crash-reporting-enabled", true, "", nullptr },
2109 {"enable-sentry", ParamType::NONE, OptionType::OPT_BOOL, "/sim/startup/sentry-crash-reporting-enabled", true, "", nullptr },
2110 {"disable-sentry", ParamType::NONE, OptionType::OPT_BOOL, "/sim/startup/sentry-crash-reporting-enabled", false, "", nullptr },
2111 {"sound", ParamType::VAL_BOOL, OptionType::OPT_BOOL, "/sim/sound/working", true, "", nullptr },
2112 {"disable-sound", ParamType::NONE, OptionType::OPT_BOOL, "/sim/sound/working", false, "", nullptr },
2113 {"enable-sound", ParamType::NONE, OptionType::OPT_BOOL, "/sim/sound/working", true, "", nullptr },
2114 {"specular-highlight", ParamType::VAL_BOOL, OptionType::OPT_BOOL, "/sim/rendering/specular-highlight", true, "", nullptr },
2115 {"disable-specular-highlight", ParamType::NONE, OptionType::OPT_BOOL, "/sim/rendering/specular-highlight", false, "", nullptr },
2116 {"enable-specular-highlight", ParamType::NONE, OptionType::OPT_BOOL, "/sim/rendering/specular-highlight", true, "", nullptr },
2117 {"splash-screen", ParamType::VAL_BOOL, OptionType::OPT_BOOL, "/sim/startup/splash-screen", true, "", nullptr },
2118 {"disable-splash-screen", ParamType::NONE, OptionType::OPT_BOOL, "/sim/startup/splash-screen", false, "", nullptr },
2119 {"enable-splash-screen", ParamType::NONE, OptionType::OPT_BOOL, "/sim/startup/splash-screen", true, "", nullptr },
2120 {"terrasync", ParamType::VAL_BOOL, OptionType::OPT_BOOL, "/sim/terrasync/enabled", true, "", nullptr },
2121 {"disable-terrasync", ParamType::NONE, OptionType::OPT_BOOL, "/sim/terrasync/enabled", false, "", nullptr },
2122 {"enable-terrasync", ParamType::NONE, OptionType::OPT_BOOL, "/sim/terrasync/enabled", true, "", nullptr },
2123 {"texture-cache", ParamType::VAL_BOOL, OptionType::OPT_BOOL, "/sim/rendering/texture-cache/cache-enabled", true, "", nullptr },
2124 {"enable-texture-cache", ParamType::NONE, OptionType::OPT_BOOL, "/sim/rendering/texture-cache/cache-enabled", true, "", nullptr },
2125 {"disable-texture-cache", ParamType::NONE, OptionType::OPT_BOOL, "/sim/rendering/texture-cache/cache-enabled", false, "", nullptr },
2126#ifdef ENABLE_OSGXR
2127 {"vr", ParamType::VAL_BOOL, OptionType::OPT_BOOL, "/sim/vr/enabled", true, "", nullptr },
2128 {"disable-vr", ParamType::NONE, OptionType::OPT_BOOL, "/sim/vr/enabled", false, "", nullptr },
2129 {"enable-vr", ParamType::NONE, OptionType::OPT_BOOL, "/sim/vr/enabled", true, "", nullptr },
2130#endif
2131 {"wireframe", ParamType::VAL_BOOL, OptionType::OPT_BOOL, "/sim/rendering/wireframe", true, "", nullptr },
2132 {"disable-wireframe", ParamType::NONE, OptionType::OPT_BOOL, "/sim/rendering/wireframe", false, "", nullptr },
2133 {"enable-wireframe", ParamType::NONE, OptionType::OPT_BOOL, "/sim/rendering/wireframe", true, "", nullptr },
2134};
2135// clang-format on
2136
2137namespace flightgear
2138{
2139
2144{
2145public:
2146 OptionValue(const OptionDesc* d, const string& v) :
2147 desc(d), value(v)
2148 {;}
2149
2151 string value;
2152};
2153
2154typedef std::vector<OptionValue> OptionValueVec;
2155typedef std::map<string, const OptionDesc*> OptionDescDict;
2156
2158{
2159public:
2160
2161 OptionValueVec::const_iterator findValue(const string& key) const
2162 {
2163 OptionValueVec::const_iterator it = values.begin();
2164 for (; it != values.end(); ++it) {
2165 if (!it->desc) {
2166 continue; // ignore markers
2167 }
2168
2169 if (it->desc->option == key) {
2170 return it;
2171 }
2172 } // of set values iteration
2173
2174 return it; // not found
2175 }
2176
2177 OptionValueVec::iterator findValue(const string& key)
2178 {
2179 OptionValueVec::iterator it = values.begin();
2180 for (; it != values.end(); ++it) {
2181 if (!it->desc) {
2182 continue; // ignore markers
2183 }
2184
2185 if (it->desc->option == key) {
2186 return it;
2187 }
2188 } // of set values iteration
2189
2190 return it; // not found
2191 }
2192
2193 const OptionDesc* findOption(const string& key) const
2194 {
2195 OptionDescDict::const_iterator it = options.find(key);
2196 if (it == options.end()) {
2197 return NULL;
2198 }
2199
2200 return it->second;
2201 }
2202
2203 int processOption(const OptionDesc* desc, const string& arg_value)
2204 {
2205 if (!desc) {
2206 return FG_OPTIONS_OK; // tolerate marker options
2207 }
2208
2209 switch ( desc->type & 0xffff ) {
2211 if ( desc->param_type != ParamType::NONE && !arg_value.empty() ) {
2212 fgSetBool( desc->property, paramToBool(arg_value) );
2213 }
2214 else {
2215 fgSetBool( desc->property, desc->b_param );
2216 }
2217 break;
2219 if ( desc->param_type != ParamType::NONE && !arg_value.empty() ) {
2220 fgSetString( desc->property, arg_value.c_str() );
2221 } else if ( desc->param_type == ParamType::NONE && arg_value.empty() ) {
2222 fgSetString( desc->property, desc->s_param );
2223 } else if ( desc->param_type != ParamType::NONE ) {
2224 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << desc->option << "' needs a parameter" );
2225 return FG_OPTIONS_ERROR;
2226 } else {
2227 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << desc->option << "' does not have a parameter" );
2228 return FG_OPTIONS_ERROR;
2229 }
2230 break;
2232 if ( !arg_value.empty() ) {
2233 fgSetDouble( desc->property, atof( arg_value ) );
2234 } else {
2235 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << desc->option << "' needs a parameter" );
2236 return FG_OPTIONS_ERROR;
2237 }
2238 break;
2240 if ( !arg_value.empty() ) {
2241 fgSetInt( desc->property, atoi( arg_value ) );
2242 } else {
2243 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << desc->option << "' needs a parameter" );
2244 return FG_OPTIONS_ERROR;
2245 }
2246 break;
2248 // XXX return value of add_channel should be checked?
2249 if ( desc->param_type != ParamType::NONE && !arg_value.empty() ) {
2250 add_channel( desc->option, arg_value );
2251 } else if ( desc->param_type == ParamType::NONE && arg_value.empty() ) {
2252 add_channel( desc->option, desc->s_param );
2253 } else if ( desc->param_type != ParamType::NONE ) {
2254 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << desc->option << "' needs a parameter" );
2255 return FG_OPTIONS_ERROR;
2256 } else {
2257 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << desc->option << "' does not have a parameter" );
2258 return FG_OPTIONS_ERROR;
2259 }
2260 break;
2262 if ( desc->param_type != ParamType::NONE && !arg_value.empty() ) {
2263 return desc->func( arg_value.c_str() );
2264 } else if ( arg_value.empty() && strlen(desc->s_param) ) {
2265 // It doesn't matter if the option requires a parameter or not,
2266 // always as there is no parameter but s_param is set, then call the function with s_param.
2267 return desc->func( desc->s_param );
2268 } else if ( desc->param_type != ParamType::NONE ) {
2269 // The option requires a parameter, but arg_value and s_param are empty.
2270 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << desc->option << "' needs a parameter" );
2271 return FG_OPTIONS_ERROR;
2272 }
2273
2274 SG_LOG( SG_GENERAL, SG_ALERT, "Option '" << desc->option << "' does not have a parameter" );
2275 return FG_OPTIONS_ERROR;
2276
2278 break;
2279 }
2280
2281 return FG_OPTIONS_OK;
2282 }
2283
2290 {
2291 values.push_back(OptionValue(NULL, "-"));
2292 }
2293
2298 OptionValueVec::const_iterator rfindGroup(OptionValueVec::const_iterator pos) const
2299 {
2300 while (--pos != values.begin()) {
2301 if (pos->desc == NULL) {
2302 return pos; // found a marker, we're done
2303 }
2304 }
2305
2306 return pos;
2307 }
2308
2309 // Return a pointer to a new JSON array node
2310 // (["/foo/bar", "/other/path", ...]) created from the given PathList.
2312 {
2313 cJSON *resultNode = cJSON_CreateArray();
2314 cJSON *prevNode = nullptr;
2315 bool isFirst = true;
2316
2317 for (const SGPath& path : pl) {
2318 cJSON *pathNode = cJSON_CreateString(path.utf8Str().c_str());
2319
2320 if (isFirst) {
2321 isFirst = false;
2322 resultNode->child = pathNode;
2323 } else {
2324 prevNode->next = pathNode;
2325 pathNode->prev = prevNode;
2326 }
2327
2328 prevNode = pathNode;
2329 }
2330
2331 return resultNode;
2332 }
2333
2338
2341 simgear::PathList configFiles;
2342 simgear::PathList propertyFiles;
2343};
2344
2346{
2347 if (shared_instance == NULL) {
2348 shared_instance = new Options;
2349 }
2350
2351 return shared_instance;
2352}
2353
2355{
2356 if (shared_instance != nullptr) {
2357 delete shared_instance;
2358 shared_instance = nullptr;
2359 }
2360}
2361
2362Options::Options() :
2363 p(new OptionsPrivate())
2364{
2365 p->showHelp = false;
2366 p->verbose = false;
2367 p->showAircraft = false;
2368 p->shouldLoadDefaultConfig = true;
2369
2370// build option map
2371 for (auto it = fgOptionArray.begin(); it != fgOptionArray.end(); ++it) {
2372 // REVIEW: Memory Leak - 15,768 bytes in 219 blocks are still reachable
2373 p->options[ it->option ] = it;
2374 }
2375}
2376
2378{
2379}
2380
2381OptionResult Options::init(int argc, char** argv, const SGPath& appDataPath)
2382{
2383// first, process the command line
2384 bool inOptions = true;
2385 std::optional<std::string> value;
2386
2387 for (int i=1; i<argc; ++i) {
2388 // important : on first run after the Gatekeeper quarantine flag is
2389 // cleared, launchd passes us a null argument here. Avoid dying in
2390 // that case.
2391 if (!argv[i]) {
2392 continue;
2393 }
2394
2395 if (inOptions && (argv[i][0] == '-')) {
2396 if (strcmp(argv[i], "--") == 0) { // end of options delimiter
2397 inOptions = false;
2398 value = {};
2399 continue;
2400 }
2401
2402 const string currentOption(argv[i]);
2403 // Get the next string from the list if it's a value for current option
2404 if (currentOption.find("=") == string::npos) {
2405 value = getValueFromNextParam(i, argc, argv);
2406 }
2407 else { // we have the = sign so we have the value in one string
2408 value = {};
2409 }
2410
2411 int result = parseOption(currentOption, value, /* fromConfigFile */ false);
2412 processArgResult(result);
2413 } else if (value.has_value()) {
2414 // Skip the value for previous option
2415 value = {};
2416 } else {
2417 // XML properties file
2418 SGPath f = SGPath::fromUtf8(argv[i]);
2419 if (!f.exists()) {
2420 SG_LOG(SG_GENERAL, SG_ALERT, "config file not found:" << f);
2421 } else {
2422 p->propertyFiles.push_back(f);
2423 }
2424 }
2425 } // of arguments iteration
2426 p->insertGroupMarker(); // command line is one group
2427
2428 // establish log-level before anything else - otherwise it is not possible
2429 // to show extra (debug/info/warning) messages for the start-up phase.
2430 // Leave the simgear logstream default value of SG_ALERT if the argument is
2431 // not supplied.
2432 if (isOptionSet("log-level"))
2433 fgOptLogLevel(valueForOption("log-level").c_str());
2434
2435 simgear::PathList::const_iterator i;
2436 for (i = p->configFiles.begin(); i != p->configFiles.end(); ++i) {
2437 readConfig(*i);
2438 }
2439
2440 if (!p->shouldLoadDefaultConfig) {
2441 return setupRoot(argc, argv);
2442 }
2443
2444// then config files
2445 SGPath config;
2446
2447 if( !hostname.empty() ) {
2448 // Check for ~/.fgfsrc.hostname
2449 config = SGPath::home();
2450 config.append(".fgfsrc");
2451 config.concat( "." );
2452 config.concat( hostname );
2453 readConfig(config);
2454 }
2455
2456// Check for ~/.fgfsrc
2457 config = SGPath::home();
2458 config.append(".fgfsrc");
2459 readConfig(config);
2460
2461// check for a config file in app data
2462 SGPath appDataConfig(appDataPath);
2463 appDataConfig.append("fgfsrc");
2464 if (appDataConfig.exists()) {
2465 readConfig(appDataConfig);
2466 }
2467
2468// setup FG_ROOT
2469 auto res = setupRoot(argc, argv);
2470 if (res != FG_OPTIONS_OK) {
2471 return res;
2472 }
2473
2474// system.fgfsrc is disabled, as we no longer allow anything in fgdata to set
2475// fg-root/fg-home/fg-aircraft and hence control what files Nasal can access
2476 std::string nameForError = config.utf8Str();
2477 if( ! hostname.empty() ) {
2478 config = globals->get_fg_root();
2479 config.append( "system.fgfsrc" );
2480 config.concat( "." );
2481 config.concat( hostname );
2482 if (config.exists()) {
2484 "Unsupported configuration",
2485 "You have a '" + config.utf8Str() + "' file, which is no longer "
2486 "processed for security reasons.",
2487 "If you created this file intentionally, please move it to '" +
2488 nameForError + "'.");
2489 }
2490 }
2491
2492 config = globals->get_fg_root();
2493 config.append( "system.fgfsrc" );
2494 if (config.exists()) {
2496 "Unsupported configuration",
2497 "You have a '" + config.utf8Str() + "' file, which is no longer "
2498 "processed for security reasons.",
2499 "If you created this file intentionally, please move it to '" +
2500 nameForError + "'.");
2501 }
2502
2503 return FG_OPTIONS_OK;
2504}
2505
2506static int
2508{
2509 if (simgear::strutils::starts_with(option, "--prop:") ||
2510 simgear::strutils::starts_with(option, "prop:")
2511 ) {
2512 // The --prop option comes with the whole string with the property name,
2513 // we need to truncate it only to the option name.
2514 option = "prop";
2515 }
2516
2517 const bool withDashes = simgear::strutils::starts_with(option, "--");
2518 const string dashes("--");
2519
2520 const auto desc = std::find_if(fgOptionArray.begin(), fgOptionArray.end(), [&withDashes, &dashes, &option](const OptionDesc& opDesc) {
2521 return (withDashes && dashes + opDesc.option == option) || (!withDashes && opDesc.option == option);
2522 });
2523
2524 if (desc != fgOptionArray.end()) {
2525 return desc->param_type;
2526 }
2527
2528 return ParamType::NONE;
2529}
2530
2531std::optional<std::string> Options::getValueFromNextParam(int index, int argc, char** argv)
2532{
2533 if (index + 1 >= argc) {
2534 // No more arguments, return empty value
2535 return {};
2536 }
2537
2538 const string currentOption(argv[index]);
2539
2540 // Get param type of current option
2541 const int paramType = getOptionParamType(currentOption);
2542
2543 if (paramType == ParamType::NONE) {
2544 // We know that the option does not take parameters so return empty value
2545 return {};
2546 }
2547
2548 const string value(argv[index + 1]);
2549
2550 if (paramType == ParamType::VAL_BOOL && simgear::strutils::is_bool(value)) {
2551 // We know that the option takes a bool parameter and the value is of
2552 // type boolean, so assign a value to the option
2553 return value;
2554 }
2555
2556 if (simgear::strutils::starts_with(value, "-")) {
2557 // It's not a value but an option (including -c, -h, -v, -psn),
2558 // return empty value
2559 return {};
2560 }
2561
2562 if (paramType == ParamType::REGULAR) {
2563 return value;
2564 }
2565
2566 return {};
2567}
2568
2570{
2571 for (const string& pathOpt : valuesForOption("fg-aircraft")) {
2572 PathList paths = SGPath::pathsFromUtf8(pathOpt);
2573 globals->append_aircraft_paths(paths);
2574 }
2575
2576 const char* envp = ::getenv("FG_AIRCRAFT");
2577 if (envp) {
2578 globals->append_aircraft_paths(SGPath::pathsFromEnv("FG_AIRCRAFT"));
2579 }
2580
2581}
2582
2584{
2585 string aircraft;
2586 if (g_load_tape_aircraft != "") {
2587 // Use Continuous recording's aircraft if we are replaying on startup.
2588 aircraft = g_load_tape_aircraft;
2589 }
2590 else if (isOptionSet("aircraft")) {
2591 aircraft = valueForOption("aircraft");
2592 } else if (isOptionSet("vehicle")) {
2593 aircraft = valueForOption("vehicle");
2594 }
2595
2596 if (!aircraft.empty()) {
2597 fgSetString("/sim/aircraft-id", aircraft);
2598 const auto lastDotPos = aircraft.rfind('.');
2599 if (lastDotPos != string::npos) {
2600 // ensure /sim/aircraft is only the local ID, not the fully-qualified ID
2601 // otherwise some existing logic gets confused.
2602 fgSetString("/sim/aircraft", aircraft.substr(lastDotPos + 1));
2603 } else {
2604 fgSetString("/sim/aircraft", aircraft);
2605 }
2606
2607 SG_LOG(SG_INPUT, SG_INFO, "aircraft = " << aircraft );
2608 } else {
2609 SG_LOG(SG_INPUT, SG_INFO, "No user specified aircraft, using default" );
2610 // ensure aircraft-id is valid
2611 fgSetString("/sim/aircraft-id", fgGetString("/sim/aircraft").c_str());
2612 }
2613
2614 if (p->showAircraft) {
2615 PathList path_list;
2616
2617 fgOptLogLevel( "alert" );
2618
2619 // First place to check is the 'Aircraft' sub-directory in $FG_ROOT
2620
2621 SGPath rootAircraft = globals->get_fg_root();
2622 rootAircraft.append("Aircraft");
2623 path_list.push_back(rootAircraft);
2624
2625 // Additionally, aircraft may also be found in user-defined places
2626 // (via $FG_AIRCRAFT or with the '--fg-aircraft' option)
2627 PathList aircraft_paths = globals->get_aircraft_paths();
2628
2629 path_list.insert(path_list.end(), aircraft_paths.begin(),
2630 aircraft_paths.end());
2631
2632 fgShowAircraft(path_list);
2633 // this is to indicate that we did show it
2635 }
2636
2637 if (isOptionSet("aircraft-dir")) {
2638 SGPath aircraftDirPath = SGPath::fromUtf8(valueForOption("aircraft-dir"));
2639 SGPath realAircraftPath = aircraftDirPath.realpath();
2640 globals->append_read_allowed_paths(realAircraftPath);
2641
2642 // Set this now, so it's available in FindAndCacheAircraft. Use realpath()
2643 // as in FGGlobals::append_aircraft_path(), otherwise SGPath::validate()
2644 // will deny access to resources under this path if one of its components
2645 // is a symlink (which is not a problem, since it was given as is by the
2646 // user---this is very different from a symlink *under* the aircraft dir
2647 // or a scenery dir).
2648 fgSetString("/sim/aircraft-dir", realAircraftPath.utf8Str());
2649 }
2650
2651 if (isOptionSet("state")) {
2652 std::string stateName = valueForOption("state");
2653 // can't validate this until the -set.xml is parsed
2654 fgSetString("/sim/aircraft-state", stateName);
2655 }
2656
2657 return FG_OPTIONS_OK;
2658}
2659
2660void Options::processArgResult(int result)
2661{
2662 if ((result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR))
2663 p->showHelp = true;
2664 else if (result == FG_OPTIONS_VERBOSE_HELP)
2665 p->verbose = true;
2666 else if (result == FG_OPTIONS_SHOW_AIRCRAFT) {
2667 p->showAircraft = true;
2668 } else if (result == FG_OPTIONS_NO_DEFAULT_CONFIG) {
2669 p->shouldLoadDefaultConfig = false;
2670 } else if (result == FG_OPTIONS_SHOW_SOUND_DEVICES) {
2671 SGSoundMgr smgr;
2672
2673 smgr.init();
2674 string vendor = smgr.get_vendor();
2675 string renderer = smgr.get_renderer();
2676 cout << renderer << " provided by " << vendor << endl;
2677 cout << endl << "No. Device" << endl;
2678
2679 vector <std::string>devices = smgr.get_available_devices();
2680 for (vector <std::string>::size_type i=0; i<devices.size(); i++) {
2681 cout << i << ". \"" << devices[i] << "\"" << endl;
2682 }
2683 devices.clear();
2684 smgr.stop();
2685 fgExit(0);
2686 } else if (result == FG_OPTIONS_EXIT) {
2687 fgExit(0);
2688 }
2689}
2690
2691void Options::readConfig(const SGPath& path)
2692{
2693 using namespace simgear;
2694
2695 sg_gzifstream in(path);
2696 if (!in.is_open()) {
2697 return;
2698 }
2699
2700 SG_LOG( SG_GENERAL, SG_INFO, "Processing config file: " << path );
2701
2702 in >> skipcomment;
2703 while ( ! in.eof() ) {
2704 string line;
2705 getline( in, line, '\n' );
2706
2707 line = strutils::strip(line);
2708
2709 // avoid processing empty lines
2710 // https://sourceforge.net/p/flightgear/codetickets/2927/
2711 if (line.empty()) {
2712 in >> skipcomment;
2713 continue;
2714 }
2715
2716 std::optional<std::string> value;
2717 const size_t space = line.find(' ');
2718 const size_t equal = line.find('=');
2719 if (space != string::npos && space < equal) {
2720 // We assume that the value is separated by a space from the option name, like:
2721 // --metar XXXX 280900Z 28007KT 9999 20/16 Q1010 instead of
2722 // --metar=XXXX 280900Z 28007KT 9999 20/16 Q1010
2723 value = strutils::strip(line.substr(space + 1));
2724 line = line.substr(0, space);
2725 }
2726
2727 if ( parseOption(line, value, /* fromConfigFile */ true) == FG_OPTIONS_ERROR ) {
2728 cerr << endl << "Config file parse error: " << path << " '"
2729 << line << "'" << endl;
2730 p->showHelp = true;
2731 }
2732 in >> skipcomment;
2733 }
2734
2735 p->insertGroupMarker(); // each config file is a group
2736}
2737
2738bool Options::paramToBool(const std::string& param)
2739{
2740 if (simgear::strutils::is_bool(param)) {
2741 return simgear::strutils::to_bool(param);
2742 }
2743
2744 return true;
2745}
2746
2752int Options::parseOption(const string& s, const std::optional<std::string>& val, bool fromConfigFile)
2753{
2754 if ((s == "--help") || (s=="-h")) {
2755 return FG_OPTIONS_HELP;
2756 } else if ( (s == "--verbose") || (s == "-v") ) {
2757 // verbose help/usage request
2759 } else if (simgear::strutils::starts_with(s, "--console") || s == "-c") {
2760 return fgOptConsole(getValueForBooleanOption(s, "--console", val).c_str());
2761 } else if (simgear::strutils::starts_with(s, "-psn")) {
2762 // on Mac, when launched from the GUI, we are passed the ProcessSerialNumber
2763 // as an argument (and no others). Silently ignore the argument here.
2764 return FG_OPTIONS_OK;
2765 } else if (simgear::strutils::starts_with(s, "--show-aircraft")) {
2766 return paramToBool(getValueForBooleanOption(s, "--show-aircraft", val))
2768 : FG_OPTIONS_OK;
2769 } else if (simgear::strutils::starts_with(s, "--show-sound-devices")) {
2770 return paramToBool(getValueForBooleanOption(s, "--show-sound-devices", val))
2772 : FG_OPTIONS_OK;
2773 } else if (simgear::strutils::starts_with(s, "--no-default-config")) {
2774 return paramToBool(getValueForBooleanOption(s, "--no-default-config", val))
2776 : FG_OPTIONS_OK;
2777 } else if (simgear::strutils::starts_with(s, "--prop:")) {
2778 // property setting has a slightly different syntax, so fudge things
2779 const OptionDesc* desc = p->findOption("prop");
2780
2781 const size_t optLen = strlen("--prop:");
2782
2783 if (s.find('=', optLen) != string::npos) {
2784 p->values.push_back(OptionValue(desc, s.substr(optLen)));
2785 return FG_OPTIONS_OK;
2786 }
2787
2788 if (val.has_value()) {
2789 p->values.push_back(OptionValue(desc, s.substr(optLen) + "=" + val.value()));
2790 return FG_OPTIONS_OK;
2791 }
2792
2793 SG_LOG(SG_GENERAL, SG_ALERT, "malformed property option: " << s);
2794 return FG_OPTIONS_ERROR;
2795 } else if (simgear::strutils::starts_with(s, "--config=")) {
2796 return parseConfigOption(s.substr(9), fromConfigFile);
2797 } else if (simgear::strutils::starts_with(s, "--config") && val.has_value() ) {
2798 return parseConfigOption(val.value(), fromConfigFile);
2799 } else if (simgear::strutils::starts_with(s, "--")) {
2800 size_t eqPos = s.find( '=' );
2801 string key, value;
2802 if (eqPos == string::npos) {
2803 key = s.substr(2);
2804
2805 if (val.has_value()) {
2806 value = val.value();
2807 }
2808 } else {
2809 key = s.substr( 2, eqPos - 2 );
2810 value = s.substr( eqPos + 1);
2811 }
2812
2813 return addOption(key, value);
2814 } else if (s.empty()) {
2815 return FG_OPTIONS_OK;
2816 } else {
2817 flightgear::modalMessageBox("Unknown option", "Unknown command-line option: " + s);
2818 return FG_OPTIONS_ERROR;
2819 }
2820}
2821
2822string Options::getValueForBooleanOption(const string& str, const string& option, const std::optional<std::string>& value)
2823{
2824 if (simgear::strutils::starts_with(str, option + "=")) {
2825 // We have option with "=", get value after "=" sign
2826 return str.substr((option + "=").size());
2827 }
2828 else if (value.has_value()) {
2829 // Get value after " " sign
2830 return value.value();
2831 }
2832
2833 // The option has no value, return "true" as default
2834 return "true";
2835}
2836
2837int Options::parseConfigOption(const SGPath &path, bool fromConfigFile)
2838{
2839 if (path.extension() == "xml") {
2840 p->propertyFiles.push_back(path);
2841 }
2842 else if (fromConfigFile) {
2844 "FlightGear",
2845 "Invalid use of the --config option.",
2846 "Sorry, it is currently not supported to load a configuration file "
2847 "using --config from another configuration file.\n\n"
2848 "Note: this does not apply to loading of XML PropertyList files "
2849 "with --config."
2850 );
2851 }
2852 else { // the --config option comes from the command line
2853 p->configFiles.push_back(path);
2854 }
2855
2856 return FG_OPTIONS_OK;
2857}
2858
2859int Options::addOption(const string &key, const string &value)
2860{
2861 if (key == "config") {
2862 // occurs when the launcher adds --config options
2863 SGPath path(value);
2864 if (!path.exists()) {
2865 return FG_OPTIONS_ERROR;
2866 }
2867
2868 if (path.extension() == "xml") {
2869 p->propertyFiles.push_back(path);
2870 } else {
2871 p->insertGroupMarker(); // begin a group for the config file
2872 readConfig(path);
2873 }
2874
2875 return FG_OPTIONS_OK;
2876 }
2877
2878 const OptionDesc* desc = p->findOption(key);
2879 if (!desc) {
2880 flightgear::modalMessageBox("Unknown option", "Unknown command-line option: " + key);
2881 return FG_OPTIONS_ERROR;
2882 }
2883
2884 if (!(desc->type & OPTION_MULTI)) {
2885 OptionValueVec::const_iterator it = p->findValue(key);
2886 if (it != p->values.end()) {
2887 SG_LOG(SG_GENERAL, SG_WARN, "multiple values forbidden for option:" << key << ", ignoring:" << value);
2888 return FG_OPTIONS_OK;
2889 }
2890 }
2891
2892 p->values.push_back(OptionValue(desc, value));
2893 return FG_OPTIONS_OK;
2894}
2895
2896int Options::setOption(const string &key, const string &value)
2897{
2898 const OptionDesc* desc = p->findOption(key);
2899 if (!desc) {
2900 flightgear::modalMessageBox("Unknown option", "Unknown command-line option: " + key);
2901 return FG_OPTIONS_ERROR;
2902 }
2903
2904 if (!(desc->type & OPTION_MULTI)) {
2905 OptionValueVec::iterator it = p->findValue(key);
2906 if (it != p->values.end()) {
2907 // remove existing valye
2908 p->values.erase(it);
2909 }
2910 }
2911
2912 p->values.push_back(OptionValue(desc, value));
2913 return FG_OPTIONS_OK;
2914}
2915
2916void Options::clearOption(const std::string& key)
2917{
2918 OptionValueVec::iterator it = p->findValue(key);
2919 for (; it != p->values.end(); it = p->findValue(key)) {
2920 p->values.erase(it);
2921 }
2922}
2923
2924bool Options::isOptionSet(const string &key) const
2925{
2927 return isBoolOptionEnable(key);
2928 }
2929
2930 OptionValueVec::const_iterator it = p->findValue(key);
2931 return (it != p->values.end());
2932}
2933
2934string Options::valueForOption(const string& key, const string& defValue) const
2935{
2936 OptionValueVec::const_iterator it = p->findValue(key);
2937 if (it == p->values.end()) {
2938 return defValue;
2939 }
2940
2941 return it->value;
2942}
2943
2944string_list Options::valuesForOption(const std::string& key) const
2945{
2946 string_list result;
2947 OptionValueVec::const_iterator it = p->values.begin();
2948 for (; it != p->values.end(); ++it) {
2949 if (!it->desc) {
2950 continue; // ignore marker values
2951 }
2952
2953 if (it->desc->option == key) {
2954 result.push_back(it->value);
2955 }
2956 }
2957
2958 return result;
2959}
2960
2961std::optional<bool> Options::checkBoolOptionSet(const string& key) const
2962{
2963 if (isOptionSet("enable-" + key)) {
2964 return true; // explicitly enabled
2965 }
2966
2967 if (isOptionSet("disable-" + key)) {
2968 return false; // explicitly disabled
2969 }
2970
2971 OptionValueVec::const_iterator it = p->findValue(key);
2972 if (it == p->values.end()) {
2973 return {}; // option not found
2974 }
2975
2976 if (it->value.empty()) {
2977 // The user used a boolean option but without passing a value, such as e.g. `--fullscreen`.
2978 // Then return the enabled flag.
2979 return true; // enabled by default
2980 }
2981
2982 // The user used a boolean option with a passed value, such as `--fullscreen false`.
2983 // Convert the value to boolean.
2984 return paramToBool(it->value)
2985 ? true // explicitly enabled
2986 : false; // explicitly disabled
2987}
2988
2989bool Options::isBoolOptionEnable(const string &key) const
2990{
2991 const std::optional<bool> value = checkBoolOptionSet(key);
2992 return value.has_value() && value.value() == true;
2993}
2994
2995bool Options::isBoolOptionDisable(const string &key) const
2996{
2997 const std::optional<bool> value = checkBoolOptionSet(key);
2998 return value.has_value() && value.value() == false;
2999}
3000
3002{
3003#if defined(SG_WINDOWS)
3004 const SGPath p = SGPath::home() / "FlightGear" / "Downloads";
3005 return p;
3006#endif
3007 return globals->get_fg_home();
3008}
3009
3011{
3012 SGPath downloadDir = SGPath::fromUtf8(valueForOption("download-dir"));
3013 if (!downloadDir.isNull()) {
3014 return downloadDir;
3015 }
3016
3017 return defaultDownloadDir();
3018}
3019
3021{
3022 return Options::sharedInstance()->actualDownloadDir() / "TextureCache";
3023}
3024
3026{
3027 // establish locale before showing help (this selects the default locale,
3028 // when no explicit option was set)
3029 globals->get_locale()->selectLanguage(valueForOption("language").c_str());
3030
3031 // now FG_ROOT is setup, process various command line options that bail us
3032 // out quickly, but rely on aircraft / root settings
3033 if (p->showHelp) {
3034 showUsage();
3035 return FG_OPTIONS_EXIT;
3036 }
3037
3038 // processing order is complicated. We must process groups LIFO, but the
3039 // values *within* each group in FIFO order, to retain consistency with
3040 // older versions of FG, and existing user configs.
3041 // in practice this means system.fgfsrc must be *processed* before
3042 // .fgfsrc, which must be processed before the command line args, and so on.
3043 OptionValueVec::const_iterator groupEnd = p->values.end();
3044
3045 while (groupEnd != p->values.begin()) {
3046 OptionValueVec::const_iterator groupBegin = p->rfindGroup(groupEnd);
3047 // run over the group in FIFO order
3048 OptionValueVec::const_iterator it;
3049 for (it = groupBegin; it != groupEnd; ++it) {
3050 int result = p->processOption(it->desc, it->value);
3051 switch(result)
3052 {
3053 case FG_OPTIONS_ERROR:
3054 showUsage();
3055 return FG_OPTIONS_ERROR;
3056
3057 case FG_OPTIONS_EXIT:
3058 return FG_OPTIONS_EXIT;
3059
3060 default:
3061 break;
3062 }
3063 if (it->desc) {
3064 SG_LOG(SG_GENERAL, SG_INFO, "\toption:" << it->desc->option << " = " << it->value);
3065 }
3066 }
3067
3068 groupEnd = groupBegin;
3069 }
3070
3071 for (const SGPath& file : p->propertyFiles) {
3072 SG_LOG(SG_GENERAL, SG_INFO,
3073 "Reading command-line property file " << file);
3074 readProperties(file, globals->get_props());
3075 }
3076
3077// now options are process, do supplemental fixup
3078 const char *envp = ::getenv( "FG_SCENERY" );
3079 if (envp) {
3080 globals->append_fg_scenery(SGPath::pathsFromEnv("FG_SCENERY"));
3081 }
3082
3083 // Download dir fix-up
3084 SGPath downloadDir = SGPath::fromUtf8(valueForOption("download-dir"));
3085 if (downloadDir.isNull()) {
3086 downloadDir = defaultDownloadDir();
3087 SG_LOG(SG_GENERAL, SG_INFO,
3088 "Using default download dir: " << downloadDir);
3089 } else {
3090 SG_LOG(SG_GENERAL, SG_INFO,
3091 "Using explicit download dir: " << downloadDir);
3092 }
3093
3094 simgear::Dir d(downloadDir);
3095 if (!d.exists()) {
3096 SG_LOG(SG_GENERAL, SG_INFO,
3097 "Creating download dir: " << downloadDir);
3098 d.create(0755);
3099 }
3100
3101 // This is safe because the value of 'downloadDir' is trustworthy. In
3102 // particular, it can't be influenced by Nasal code, not even indirectly
3103 // via a Nasal-writable place such as the property tree.
3104 globals->set_download_dir(downloadDir);
3105
3106 // Texture Cache directory handling
3107 SGPath textureCacheDir = SGPath::fromUtf8(valueForOption("texture-cache-dir"));
3108 if (textureCacheDir.isNull()) {
3109 textureCacheDir = defaultTextureCacheDir();
3110 SG_LOG(SG_GENERAL, SG_INFO,
3111 "Using default texture cache directory: " << textureCacheDir);
3112 }
3113 else {
3114 SG_LOG(SG_GENERAL, SG_INFO,
3115 "Using explicit texture cache directory: " << textureCacheDir);
3116 }
3117
3118 simgear::Dir tcd(textureCacheDir);
3119 if (!tcd.exists()) {
3120 SG_LOG(SG_GENERAL, SG_INFO,
3121 "Creating texture cache directory: " << textureCacheDir);
3122 tcd.create(0755);
3123 }
3124
3125 globals->set_texture_cache_dir(textureCacheDir);
3126
3127
3128 // TerraSync directory fixup
3129 SGPath terrasyncDir = SGPath::fromUtf8(valueForOption("terrasync-dir"));
3130 if (terrasyncDir.isNull()) {
3131 terrasyncDir = downloadDir / "TerraSync";
3132 // No “default” qualifier here, because 'downloadDir' may be non-default
3133 SG_LOG(SG_GENERAL, SG_INFO,
3134 "Using TerraSync dir: " << terrasyncDir);
3135 } else {
3136 SG_LOG(SG_GENERAL, SG_INFO,
3137 "Using explicit TerraSync dir: " << terrasyncDir);
3138 }
3139
3140 d = simgear::Dir(terrasyncDir);
3141 if (!d.exists()) {
3142 SG_LOG(SG_GENERAL, SG_INFO,
3143 "Creating TerraSync dir: " << terrasyncDir);
3144 d.create(0755);
3145 }
3146
3147 // This is safe because the value of 'terrasyncDir' is trustworthy. In
3148 // particular, it can't be influenced by Nasal code, not even indirectly
3149 // via a Nasal-writable place such as the property tree.
3150 globals->set_terrasync_dir(terrasyncDir);
3151
3152 // check if we setup a scenery path so far
3153 bool addFGDataScenery = globals->get_fg_scenery().empty();
3154
3155 // always add the terrasync location, regardless of whether terrasync
3156 // is enabled or not. This allows us to toggle terrasync on/off at
3157 // runtime and have things work as expected
3158 const PathList& scenery_paths(globals->get_fg_scenery());
3159 if (std::find(scenery_paths.begin(), scenery_paths.end(), terrasyncDir) == scenery_paths.end()) {
3160 // terrasync dir is not in the scenery paths, add it
3161 globals->append_fg_scenery(terrasyncDir);
3162 }
3163
3164 if (addFGDataScenery) {
3165 // no scenery paths set at all, use the data in FG_ROOT
3166 // ensure this path is added last
3167 SGPath root(globals->get_fg_root());
3168 root.append("Scenery");
3169 globals->append_fg_scenery(root);
3170 }
3171
3172 if (!g_load_tape_aircraft.empty()) {
3173 // This might not be necessary, because we always end up calling
3174 // Options::initAircraft() later on, which also knows to use
3175 // g_load_tape_aircraft if it is not "".
3176 //
3177 SG_LOG(SG_GENERAL, SG_MANDATORY_INFO, "overriding aircraft from " << fgGetString("/sim/aircraft") << " to " << g_load_tape_aircraft);
3178 fgSetString("/sim/aircraft", g_load_tape_aircraft);
3179 }
3180 if (!g_load_tape_airport.empty()) {
3181 SG_LOG(SG_GENERAL, SG_MANDATORY_INFO, "overriding airport from " << fgGetString("/sim/presets/airport-id") << " to " << g_load_tape_airport);
3183 }
3184
3185 if (isOptionSet("json-report")) {
3186 printJSONReport();
3187 return FG_OPTIONS_EXIT;
3188 } else if (isOptionSet("version")) {
3189 showVersion();
3190 return FG_OPTIONS_EXIT;
3191 } else if (isOptionSet("info")) {
3192 showInfo();
3193 return FG_OPTIONS_EXIT;
3194 }
3195
3196 return FG_OPTIONS_OK;
3197}
3198
3199void Options::showUsage() const
3200{
3201 fgOptLogLevel( "alert" );
3202
3203 FGLocale *locale = globals->get_locale();
3204 SGPropertyNode options_root;
3205
3206 simgear::requestConsole(false); // ensure console is shown on Windows
3207 cout << endl;
3208
3209 try {
3210 fgLoadProps("options.xml", &options_root);
3211 } catch (const sg_exception &) {
3212 cout << "Unable to read the help file." << endl;
3213 cout << "Make sure the file options.xml is located in the FlightGear base directory," << endl;
3214 cout << "and the location of the base directory is specified by setting $FG_ROOT or" << endl;
3215 cout << "by adding --fg-root=path as a program argument." << endl;
3216
3217 exit(-1);
3218 }
3219
3220 SGPropertyNode *options = options_root.getNode("options");
3221 if (!options) {
3222 SG_LOG( SG_GENERAL, SG_ALERT,
3223 "Error reading options.xml: <options> element not found." );
3224 exit(-1);
3225 }
3226
3227 std::string usage = locale->getLocalizedString(options->getStringValue("usage"), "options");
3228 if (!usage.empty()) {
3229 cout << usage << endl;
3230 }
3231
3232 vector<SGPropertyNode_ptr>section = options->getChildren("section");
3233 for (unsigned int j = 0; j < section.size(); j++) {
3234 string msg = "";
3235
3236 vector<SGPropertyNode_ptr>option = section[j]->getChildren("option");
3237 for (unsigned int k = 0; k < option.size(); k++) {
3238
3239 SGPropertyNode *name = option[k]->getNode("name");
3240 SGPropertyNode *short_name = option[k]->getNode("short");
3241 SGPropertyNode *key = option[k]->getNode("key");
3242 SGPropertyNode *arg = option[k]->getNode("arg");
3243 SGPropertyNode *optionalArg = option[k]->getNode("optional-arg");
3244 bool brief = option[k]->getNode("brief") != 0;
3245
3246 if ((brief || p->verbose) && name) {
3247 string tmp = name->getStringValue();
3248
3249 if (key){
3250 tmp.append(":");
3251 tmp.append(key->getStringValue());
3252 }
3253 if (arg) {
3254 tmp.append("=");
3255 tmp.append(arg->getStringValue());
3256 } else if (optionalArg) {
3257 tmp.append("[=");
3258 tmp.append(optionalArg->getStringValue());
3259 tmp.append("]");
3260 }
3261
3262 if (short_name) {
3263 tmp.append(", -");
3264 tmp.append(short_name->getStringValue());
3265 }
3266
3267 if (tmp.size() <= 25) {
3268 msg+= " --";
3269 msg += tmp;
3270 msg.append( 27-tmp.size(), ' ');
3271 } else {
3272 msg += "\n --";
3273 msg += tmp + '\n';
3274 msg.append(32, ' ');
3275 }
3276 // There may be more than one <description> tag associated
3277 // with one option
3278
3279 vector<SGPropertyNode_ptr> desc;
3280 desc = option[k]->getChildren("description");
3281 if (! desc.empty()) {
3282 for ( unsigned int l = 0; l < desc.size(); l++) {
3283 string t = desc[l]->getStringValue();
3284
3285 // There may be more than one translation line.
3286 vector<string> transDesc = locale->getLocalizedStrings(t, "options");
3287 auto it = transDesc.begin();
3288
3289 for (int m = 0; it != transDesc.end(); it++, m++) {
3290 string t_str = *it; // translated string
3291
3292 if ((m > 0) || ((l > 0) && m == 0)) {
3293 msg.append( 32, ' ');
3294 }
3295
3296 // If the string is too large to fit on the screen,
3297 // then split it up in several pieces.
3298
3299 while ( t_str.size() > 47 ) {
3300 string::size_type m = t_str.rfind(' ', 47);
3301
3302 if (m == string::npos) {
3303 m = t_str.find(' '); // fallback: find the first space
3304 }
3305
3306 if (m == string::npos) {
3307 // No line wrapping at all. Maybe this is not the best for
3308 // some languages like Chinese, but at least this will
3309 // prevent FG from eating all memory.
3310 break;
3311 } else {
3312 msg += t_str.substr(0, m) + '\n';
3313 msg.append( 32, ' ');
3314 t_str.erase(t_str.begin(), t_str.begin() + m + 1);
3315 }
3316 }
3317 msg += t_str + '\n';
3318 }
3319 }
3320 }
3321 }
3322 }
3323
3324 std::string name = locale->getLocalizedString(section[j]->getStringValue("name"),"options");
3325 if (!msg.empty() && !name.empty()) {
3326 cout << endl << name << ":" << endl;
3327 cout << msg;
3328 msg.erase();
3329 }
3330 }
3331
3332 if ( !p->verbose ) {
3333 std::string verbose_help = locale->getLocalizedString(options->getStringValue("verbose-help"),"options");
3334 if (!verbose_help.empty())
3335 cout << endl << verbose_help << endl;
3336 }
3337#ifdef _MSC_VER
3338 std::cout << "Hit a key to continue..." << std::endl;
3339 std::cin.get();
3340#endif
3341}
3342
3343void Options::showVersion() const
3344{
3345 cout << "FlightGear version: " << FLIGHTGEAR_VERSION << endl;
3346 cout << "Revision: " << REVISION << endl;
3347 cout << "Build-Date: " << BUILD_DATE << endl;
3348 cout << "Build-Type: " << FG_BUILD_TYPE << endl;
3349 cout << "SimGear version: " << SG_STRINGIZE(SIMGEAR_VERSION) << endl;
3350 cout << "OSG version: " << osgGetVersion() << endl;
3351
3352 const auto fgRootPath = globals->get_fg_root();
3353 cout << "Base Package (FGData) at " << fgRootPath << " is version:" << fgBasePackageVersion(fgRootPath) << endl;
3354 const auto fgDataInfo = fgBasePackageInfo(fgRootPath);
3355 if (fgDataInfo) {
3356 cout << "\tbuilt on " << fgDataInfo.value().buildDate << endl;
3357 cout << "\tfrom FGData Git revision: " << fgDataInfo.value().gitRevision << endl;
3358 }
3359}
3360
3361void Options::showInfo() const
3362{
3363 cout << "FlightGear version: " << FLIGHTGEAR_VERSION << endl;
3364
3365 cout << "Sentry.io UUID: " << flightgear::sentryUserId() << endl;
3366
3367 // paths
3368 cout << "FG_ROOT=" << globals->get_fg_root() << endl;
3369 cout << "FG_HOME=" << globals->get_fg_home() << endl;
3370 cout << "FG_SCENERY=";
3372 cout << SGPath::join(scn, SGPath::pathListSep) << endl;
3373
3374 cout << "Download-directory: " << globals->get_download_dir() << endl;
3375 cout << "TerraSync-directory: " << globals->get_terrasync_dir() << endl;
3376}
3377
3378// Print a report using JSON syntax on the standard output, encoded in UTF-8.
3379//
3380// The report format is versioned, don't forget to update it when making
3381// changes (see below).
3382void Options::printJSONReport() const
3383{
3384 cJSON *rootNode = cJSON_CreateObject();
3385
3386 cJSON *metaNode = cJSON_CreateObject();
3387 cJSON_AddItemToObject(rootNode, "meta", metaNode);
3388 cJSON_AddStringToObject(metaNode, "type", "FlightGear JSON report");
3389 // When making compatible changes to the format (e.g., adding members to
3390 // JSON objects), only the minor version number should be increased.
3391 // Increase the major version number when a change is backward-incompatible
3392 // (such as the removal, renaming or semantic change of a member). Of
3393 // course, incompatible changes should only be considered as a last
3394 // recourse.
3395 cJSON_AddNumberToObject(metaNode, "formatMajorVersion", 2);
3396 cJSON_AddNumberToObject(metaNode, "formatMinorVersion", 0);
3397
3398 cJSON *generalNode = cJSON_CreateObject();
3399 cJSON_AddItemToObject(rootNode, "general", generalNode);
3400 cJSON_AddStringToObject(generalNode, "name", "FlightGear");
3401 cJSON_AddStringToObject(generalNode, "version", FLIGHTGEAR_VERSION);
3402 cJSON_AddStringToObject(generalNode, "buildDate", BUILD_DATE);
3403 cJSON_AddStringToObject(generalNode, "buildType", FG_BUILD_TYPE);
3404 cJSON_AddStringToObject(generalNode, "buildRevision", REVISION);
3405
3406 cJSON *configNode = cJSON_CreateObject();
3407 cJSON_AddItemToObject(rootNode, "config", configNode);
3408 cJSON_AddStringToObject(configNode, "fgRoot",
3409 globals->get_fg_root().utf8Str().c_str());
3410 cJSON_AddStringToObject(configNode, "fgHome",
3411 globals->get_fg_home().utf8Str().c_str());
3412
3413 cJSON *sceneryPathsNode = p->createJSONArrayFromPathList(globals->get_fg_scenery());
3414 cJSON_AddItemToObject(configNode, "sceneryPaths", sceneryPathsNode);
3415
3416 cJSON *aircraftPathsNode = p->createJSONArrayFromPathList(
3418 cJSON_AddItemToObject(configNode, "aircraftPaths", aircraftPathsNode);
3419
3420 cJSON_AddStringToObject(configNode, "terrasyncPath",
3421 globals->get_terrasync_dir().utf8Str().c_str());
3422
3423 cJSON_AddStringToObject(configNode, "downloadPath",
3424 globals->get_download_dir().utf8Str().c_str());
3425
3426 cJSON_AddStringToObject(configNode, "autosavePath",
3427 globals->autosaveFilePath().utf8Str().c_str());
3428
3429 const auto sentryUid = fgGetString("sim/crashreport/sentry-user-id");
3430 cJSON_AddStringToObject(configNode, "sentryUUID", sentryUid.c_str());
3431
3432 // Get the ordered lists of apt.dat, fix.dat and nav.dat files used by the
3433 // NavCache
3434 NavDataCache* cache = NavDataCache::instance();
3435 if (!cache) {
3437 }
3438
3439 cJSON *navDataNode = cJSON_CreateObject();
3440 cJSON_AddItemToObject(rootNode, "navData", navDataNode);
3441
3442 // Write each list to the JSON tree
3443 for (const auto& datType: {NavDataCache::DATFILETYPE_APT,
3446 // For this method, it doesn't matter if the cache is out-of-date
3447 const NavDataCache::DatFilesGroupInfo& datFilesInfo =
3448 cache->getDatFilesInfo(datType);
3449
3450 // Create a list of SGPath instances (for the .dat files) from the list of
3451 // NavDataCache::SceneryLocation structs that datFilesInfo.paths is.
3452 PathList datFiles(datFilesInfo.paths.size());
3453 const auto map = [](const auto& e) { return e.datPath; };
3454 std::transform(std::cbegin(datFilesInfo.paths),
3455 std::cend(datFilesInfo.paths), std::begin(datFiles), map);
3456
3457 cJSON *datPathsNode = p->createJSONArrayFromPathList(datFiles);
3458 string key = NavDataCache::datTypeStr[datType] + "DatPaths";
3459 cJSON_AddItemToObject(navDataNode, key.c_str(), datPathsNode);
3460 }
3461
3462
3463 // Print the JSON tree to the standard output
3464 char *report = cJSON_Print(rootNode);
3465 cout << report << endl;
3466 cJSON_Delete(rootNode);
3467}
3468
3469#if defined(__CYGWIN__)
3470SGPath Options::platformDefaultRoot() const
3471{
3472 return SGPath::fromUtf8("../data");
3473}
3474
3475#elif defined(SG_WINDOWS)
3476SGPath Options::platformDefaultRoot() const
3477{
3478 return SGPath::fromUtf8("..\\data");
3479}
3480#elif defined(SG_MAC)
3481// platformDefaultRoot defined in CocoaHelpers.mm
3482#else
3484{
3485 return SGPath::fromUtf8(PKGLIBDIR);
3486}
3487
3488#endif
3489
3491{
3492 string_list result;
3493 for (auto opt : p->values) {
3494 if (opt.desc == nullptr) {
3495 continue;
3496 }
3497
3498 if (!strcmp(opt.desc->option,"prop")) {
3499 result.push_back("prop:" + opt.value);
3500 } else if (opt.value.empty()) {
3501 result.push_back(opt.desc->option);
3502 } else {
3503 result.push_back(std::string(opt.desc->option) + "=" + opt.value);
3504 }
3505 }
3506
3507 return result;
3508}
3509
3510OptionResult Options::setupRoot(int argc, char** argv)
3511{
3512 SGPath root(globals->get_fg_root());
3513 bool usingDefaultRoot = false;
3514
3515 // root has already been set, so skip the fg_root setting and validation.
3516 if (!root.isNull()) {
3517 return FG_OPTIONS_OK;
3518 }
3519
3520 if (isOptionSet("fg-root")) {
3521 root = SGPath::fromUtf8(valueForOption("fg-root")); // easy!
3522 SG_LOG(SG_GENERAL, SG_INFO, "set from command-line argument: fg_root = " << root );
3523 } else {
3524 // Next check if fg-root is set as an env variable
3525 char *envp = ::getenv( "FG_ROOT" );
3526 if ( envp != nullptr ) {
3527 root = SGPath::fromEnv("FG_ROOT");
3528 SG_LOG(SG_GENERAL, SG_INFO, "set from FG_ROOT env var: fg_root = " << root );
3529 } else {
3530#if defined(HAVE_QT)
3531 auto restoreResult = restoreUserSelectedRoot(root);
3532 if (restoreResult == SetupRootResult::UserExit) {
3533 return FG_OPTIONS_EXIT;
3534 } else if (restoreResult == SetupRootResult::UseDefault) {
3535 root = SGPath{}; // clear any value, so we fall through in root.isNull() below
3536 }
3537#endif
3538
3539 if (root.isNull()) {
3540 usingDefaultRoot = true;
3541 root = platformDefaultRoot();
3542 SG_LOG(SG_GENERAL, SG_INFO, "platform default fg_root = " << root );
3543 } else {
3544 SG_LOG(SG_GENERAL, SG_INFO, "Qt launcher set fg_root = " << root );
3545 }
3546 }
3547 }
3548
3549 globals->set_fg_root(root);
3550 string base_version = fgBasePackageVersion(root);
3551
3552
3553#if defined(HAVE_QT)
3554 // only compare major and minor version, not the patch level.
3555 const int versionComp = simgear::strutils::compare_versions(FLIGHTGEAR_VERSION, base_version, 2);
3556
3557 // note we never end up here if restoring a user selected root via
3558 // the Qt GUI, since that code pre-validates the path. But if we're using
3559 // a command-line, env-var or default root this check can fail and
3560 // we still want to use the GUI in that case
3561 if (versionComp != 0) {
3562 flightgear::initApp(argc, argv);
3563 bool ok = flightgear::showSetupRootDialog(usingDefaultRoot);
3564 if (!ok) {
3565 return FG_OPTIONS_EXIT;
3566 }
3567 }
3568#else
3569 SG_UNUSED(usingDefaultRoot);
3570
3571 // validate it
3572 if (base_version.empty()) {
3574 "Base package not found",
3575 "Required data files not found, please check your installation.",
3576 "Looking for base-package files at: '" + root.str() + "'");
3577 }
3578
3579 // only compare major and minor version, not the patch level.
3580 const int versionComp = simgear::strutils::compare_versions(FLIGHTGEAR_VERSION, base_version, 2);
3581 if (versionComp != 0) {
3583 "Base package version mismatch",
3584 "Version check failed, please check your installation.",
3585 "Found data files for version '" + base_version + "' at '" +
3586 globals->get_fg_root().str() + "', version '" +
3587 std::string(FLIGHTGEAR_VERSION) + "' is required.");
3588 }
3589#endif
3590 return FG_OPTIONS_OK;
3591}
3592
3594{
3595 return p->shouldLoadDefaultConfig;
3596}
3597
3599{
3600 p->shouldLoadDefaultConfig = load;
3601}
3602
3603bool Options::checkForArg(int argc, char* argv[], const char* checkArg)
3604{
3605 for (int i = 0; i < argc; ++i) {
3606 char* arg = argv[i];
3607 if (arg == nullptr) {
3608 continue;
3609 }
3610
3611 if (*arg != '-') { // we only care about args with a leading hypen
3612 continue;
3613 }
3614
3615 arg++;
3616 if (*arg == '-') { // skip double hypens
3617 arg++;
3618 }
3619
3620 if (strcmp(arg, checkArg) == 0) {
3621 return true;
3622 }
3623 }
3624
3625 return false;
3626}
3627
3628std::optional<bool> Options::checkForBoolArg(int argc, char* argv[], const string& checkArg)
3629{
3630 for (int i = 0; i < argc; ++i) {
3631 char* arg = argv[i];
3632 if (arg == nullptr) {
3633 continue;
3634 }
3635
3636 if (*arg != '-') { // we only care about args with a leading hypen
3637 continue;
3638 }
3639
3640 arg++;
3641 if (*arg == '-') { // skip double hypens
3642 arg++;
3643 }
3644
3645 string option(arg);
3646
3647 if (option == "enable-" + checkArg) {
3648 return true; // explicitly enabled
3649 }
3650
3651 if (option == "disable-" + checkArg) {
3652 return false; // explicitly disabled
3653 }
3654
3655 std::optional<std::string> value;
3656 const size_t equal = option.find("=");
3657 if (equal == string::npos) {
3658 value = getValueFromNextParam(i, argc, argv);
3659 }
3660 else {
3661 value = option.substr(equal + 1);
3662 option = option.substr(0, equal);
3663 }
3664
3665 if (option != checkArg) {
3666 continue;
3667 }
3668
3669 if (!value.has_value()) {
3670 return true; // enabled by default
3671 }
3672
3673 return paramToBool(value.value())
3674 ? true // explicitly enabled
3675 : false; // explicitly disabled
3676 }
3677
3678 return {}; // option not found
3679}
3680
3681bool Options::checkForArgEnable(int argc, char* argv[], const string& checkArg)
3682{
3683 const std::optional<bool> value = checkForBoolArg(argc, argv, checkArg);
3684 return value.has_value() && value.value() == true;
3685}
3686
3687bool Options::checkForArgDisable(int argc, char* argv[], const string& checkArg)
3688{
3689 const std::optional<bool> value = checkForBoolArg(argc, argv, checkArg);
3690 return value.has_value() && value.value() == false;
3691}
3692
3693std::string Options::getArgValue(int argc, char* argv[], const char* checkArg)
3694{
3695 const auto len = strlen(checkArg);
3696 for (int i = 0; i < argc; ++i) {
3697 char* arg = argv[i];
3698 if (arg == nullptr) {
3699 continue;
3700 }
3701
3702 if (strncmp(arg, checkArg, len) == 0) {
3703 const auto alen = strlen(arg);
3704 if ((alen - len) < 2) {
3705 // no value after the =, or missing = entirely
3706 std::optional<std::string> value = getValueFromNextParam(i, argc, argv);
3707 return value.has_value() ? value.value() : "";
3708 }
3709
3710 return std::string(arg + len + 1);
3711 }
3712 } // of args iteration
3713
3714 return {};
3715}
3716
3717} // of namespace flightgear
#define p(x)
#define min(X, Y)
bool options(int, char **)
Definition JSBSim.cpp:568
#define i(x)
void fgExit(int status)
VisitResult visitDir(const simgear::Dir &d, unsigned int depth)
static SGPropertyNode_ptr registerScenarioFile(SGPropertyNode_ptr root, const SGPath &p)
PathList get_aircraft_paths() const
Definition globals.cxx:513
const SGPath & get_download_dir() const
Definition globals.hxx:216
const PathList & get_fg_scenery() const
Definition globals.hxx:234
const SGPath & get_fg_home() const
Definition globals.hxx:213
SGPath autosaveFilePath(SGPath userDataPath=SGPath()) const
Return an SGPath instance for the autosave file under 'userDataPath', which defaults to $FG_HOME.
Definition globals.cxx:739
const SGPath & get_fg_root() const
Definition globals.hxx:189
void set_fg_root(const SGPath &root)
Definition globals.cxx:265
const SGPath & get_terrasync_dir() const
Definition globals.hxx:226
static FGHTTPClient * getOrCreate()
std::vector< std::string > getLocalizedStrings(const std::string &id, const std::string &resource)
Obtain a list of translations that share the same tag name (id stem).
Definition locale.cxx:541
std::string getLocalizedString(const std::string &id, const std::string &resource, const std::string &defaultValue={})
Obtain a single string matching the given id, with fallback.
Definition locale.cxx:533
void show(const vector< SGPath > &path_list)
Definition options.cxx:273
const DatFilesGroupInfo & getDatFilesInfo(DatFileType datFileType) const
static NavDataCache * createInstance()
static const std::string datTypeStr[]
static NavDataCache * instance()
internal storage of a value->option binding
Definition options.cxx:2144
const OptionDesc * desc
Definition options.cxx:2150
OptionValue(const OptionDesc *d, const string &v)
Definition options.cxx:2146
OptionValueVec::const_iterator findValue(const string &key) const
Definition options.cxx:2161
cJSON * createJSONArrayFromPathList(const PathList &pl) const
Definition options.cxx:2311
const OptionDesc * findOption(const string &key) const
Definition options.cxx:2193
OptionValueVec::iterator findValue(const string &key)
Definition options.cxx:2177
OptionValueVec::const_iterator rfindGroup(OptionValueVec::const_iterator pos) const
given a current iterator into the values, find the preceding group marker, or return the beginning of...
Definition options.cxx:2298
int processOption(const OptionDesc *desc, const string &arg_value)
Definition options.cxx:2203
void insertGroupMarker()
insert a marker value into the values vector.
Definition options.cxx:2289
static std::optional< bool > checkForBoolArg(int argc, char *argv[], const std::string &checkArg)
Check if the user has specified a given boolean option.
Definition options.cxx:3628
void setShouldLoadDefaultConfig(bool load)
when using the built-in launcher, we disable the default config files.
Definition options.cxx:3598
int addOption(const std::string &key, const std::string &value)
set an option value, assuming it is not already set (or multiple values are permitted) This can be us...
Definition options.cxx:2859
static void reset()
Delete the entire options object.
Definition options.cxx:2354
OptionResult init(int argc, char *argv[], const SGPath &appDataPath)
pass command line arguments, read default config files
Definition options.cxx:2381
int setOption(const std::string &key, const std::string &value)
set an option, overwriting any existing value which might be set
Definition options.cxx:2896
SGPath platformDefaultRoot() const
Definition options.cxx:3483
OptionResult processOptions()
apply option values to the simulation state (set properties, etc).
Definition options.cxx:3025
string_list extractOptions() const
extractOptions - extract the currently set options as a string array.
Definition options.cxx:3490
static bool checkForArgEnable(int argc, char *argv[], const std::string &checkArg)
Return true when user explicitly enabled boolean option, otherwise false.
Definition options.cxx:3681
void initPaths()
process command line options relating to scenery / aircraft / data paths
Definition options.cxx:2569
string_list valuesForOption(const std::string &key) const
return all values for a multi-valued option
Definition options.cxx:2944
static std::string getArgValue(int argc, char *argv[], const char *checkArg)
getArgValue - get the value of an argument if it exists, or an empty string otherwise
Definition options.cxx:3693
bool isBoolOptionDisable(const std::string &key) const
An overlay on checkBoolOptionSet, to check whether user used the option with explicitly disable it.
Definition options.cxx:2995
void readConfig(const SGPath &path)
parse a config file (eg, .fgfsrc)
Definition options.cxx:2691
static bool paramToBool(const std::string &param)
Convert string to bool for boolean options.
Definition options.cxx:2738
bool isBoolOptionEnable(const std::string &key) const
An overlay on checkBoolOptionSet, except that when the user has not used the option at all then false...
Definition options.cxx:2989
static bool checkForArg(int argc, char *argv[], const char *arg)
Check if the arguments array contains a particular string (with a '–' or '-' prefix).
Definition options.cxx:3603
SGPath actualDownloadDir()
the actual download dir in use, which may be the default or a user-supplied value
Definition options.cxx:3010
OptionResult initAircraft()
init the aircraft options
Definition options.cxx:2583
std::string valueForOption(const std::string &key, const std::string &defValue=std::string()) const
read the value for an option, if it has been set
Definition options.cxx:2934
static bool checkForArgDisable(int argc, char *argv[], const std::string &checkArg)
Return true when user explicitly disabled boolean option by set false value.
Definition options.cxx:3687
bool shouldLoadDefaultConfig() const
should defualt configuration files be loaded and processed or not?
Definition options.cxx:3593
std::optional< bool > checkBoolOptionSet(const std::string &key) const
Check if the user has specified a given boolean option.
Definition options.cxx:2961
bool isOptionSet(const std::string &key) const
Check if a particular option has been set (so far).
Definition options.cxx:2924
static Options * sharedInstance()
Definition options.cxx:2345
void clearOption(const std::string &key)
Definition options.cxx:2916
static const std::unique_ptr< AddonManager > & instance()
const char * name
string fgBasePackageVersion(const SGPath &base_path)
Definition fg_init.cxx:156
std::optional< FGBasePackageInfo > fgBasePackageInfo(const SGPath &path)
Parse the base package info JSON.
Definition fg_init.cxx:174
void fgOSExit(int code)
long fgGetLong(const char *name, long defaultValue)
Get a long value for a property.
Definition fg_props.cxx:538
bool fgLoadProps(const std::string &path, SGPropertyNode *props, bool in_fg_root, int default_mode)
Load properties from a file.
Definition fg_props.cxx:469
void setLoggingPriority(const char *p)
Set the logging priority.
Definition fg_props.cxx:100
std::string fgGetString(const char *name, const char *defaultValue)
Get a string value for a property.
Definition fg_props.cxx:556
bool fgSetLong(const char *name, long val)
Set a long value for a property.
Definition fg_props.cxx:574
bool fgSetInt(const char *name, int val)
Set an int value for a property.
Definition fg_props.cxx:568
void setLoggingClasses(const char *c)
Set the logging classes.
Definition fg_props.cxx:65
void fgTie(const char *name, V(*getter)(), void(*setter)(V)=0, bool useDefault=true)
Tie a property to a pair of simple functions.
Definition fg_props.hxx:751
char * hostname
Definition fgjs.cxx:225
FGGlobals * globals
Definition globals.cxx:142
std::vector< SGPath > PathList
Definition globals.hxx:37
std::vector< std::string > string_list
Definition globals.hxx:36
FlightGear Localization Support.
const std::string & getStringValue(const char *spec)
const char * PROPERTY_ROOT
Definition httpd.cxx:49
FlightPlan.hxx - defines a full flight-plan object, including departure, cruise, arrival information ...
Definition Addon.cxx:53
MessageBoxResult modalMessageBox(const std::string &caption, const std::string &msg, const std::string &moreText)
MessageBoxResult fatalMessageBoxWithoutExit(const std::string &caption, const std::string &msg, const std::string &moreText, bool reportToSentry)
SGPath defaultDownloadDir()
return the default platform dependant download directory.
Definition options.cxx:3001
void initApp(int &argc, char **argv, bool doInitQSettings)
SGPath defaultTextureCacheDir()
Definition options.cxx:3020
std::map< string, const OptionDesc * > OptionDescDict
Definition options.cxx:2155
const char * name
std::string sentryUserId()
retrive the anonymous user ID (a UUID) for this installation.
void fatalMessageBoxThenExit(const std::string &caption, const std::string &msg, const std::string &moreText, int exitStatus, bool reportToSentry)
std::vector< OptionValue > OptionValueVec
Definition options.cxx:2154
bool showSetupRootDialog(bool usingDefaultRoot)
static int getOptionParamType(string option)
Definition options.cxx:2507
SetupRootResult restoreUserSelectedRoot(SGPath &path)
OptionResult
option processing can have various result values depending on what the user requested.
Definition options.hxx:52
@ FG_OPTIONS_VERBOSE_HELP
Definition options.hxx:57
@ FG_OPTIONS_SHOW_AIRCRAFT
Definition options.hxx:58
@ FG_OPTIONS_OK
Definition options.hxx:53
@ FG_OPTIONS_HELP
Definition options.hxx:54
@ FG_OPTIONS_SHOW_SOUND_DEVICES
Definition options.hxx:59
@ FG_OPTIONS_EXIT
Definition options.hxx:56
@ FG_OPTIONS_ERROR
Definition options.hxx:55
@ FG_OPTIONS_NO_DEFAULT_CONFIG
Definition options.hxx:61
const std::initializer_list< OptionDesc > fgOptionArray
Definition options.cxx:1828
static int fgOptLogClasses(const char *arg)
Definition options.cxx:1117
static int fgOptRoc(const char *arg)
Definition options.cxx:916
static int fgOptVNorth(const char *arg)
Definition options.cxx:862
const int OPTION_MULTI
Definition options.cxx:1816
static bool parse_colon(const string &s, double *val1, double *val2)
Definition options.cxx:1302
static int fgOptHttpd(const char *arg)
Definition options.cxx:1054
static int fgOptStartDateLat(const char *arg)
Definition options.cxx:1021
static int fgOptTurbulence(const char *arg)
Definition options.cxx:1266
static int fgOptADF(const char *arg)
Definition options.cxx:1358
static int fgOptCallSign(const char *arg)
Definition options.cxx:1468
static int fgOptADF2(const char *arg)
Definition options.cxx:1377
static int fgOptCeiling(const char *arg)
Definition options.cxx:1273
static double parse_fov(const string &arg)
Definition options.cxx:627
static int fgOptVDown(const char *arg)
Definition options.cxx:886
static int fgOptLogDir(const char *arg)
Definition options.cxx:1126
static int fgOptAirport(const char *arg)
Definition options.cxx:1452
static long int parse_time_offset(const string &time_str)
Definition options.cxx:608
static int fgOptNoTrim(const char *arg)
Definition options.cxx:1764
static int fgOptCarrierPos(const char *arg)
Definition options.cxx:765
static int fgOptHoldShort(const char *arg)
Definition options.cxx:1755
static int fgOptVisibilityMeters(const char *arg)
Definition options.cxx:1206
static int fgOptLoadTape(const char *arg)
Definition options.cxx:1601
static int fgOptTraceWrite(const char *arg)
Definition options.cxx:1170
static int fgOptAllowNasalRead(const char *arg)
Definition options.cxx:930
#define NEW_DEFAULT_MODEL_HZ
Definition options.cxx:102
static int fgOptAltitude(const char *arg)
Definition options.cxx:814
ParamType
Definition options.cxx:1814
@ VAL_BOOL
Definition options.cxx:1814
@ NONE
Definition options.cxx:1814
@ REGULAR
Definition options.cxx:1814
static void clearLocation()
Definition options.cxx:682
static int fgOptScenario(const char *arg)
Definition options.cxx:1423
static int fgOptParkpos(const char *arg)
Definition options.cxx:772
static int fgOptVisibilityMiles(const char *arg)
Definition options.cxx:1213
void fgSetDefaults()
Set a few fail-safe default property values.
Definition options.cxx:127
static int fgOptWind(const char *arg)
Definition options.cxx:1254
static double atof(const string &str)
Definition options.cxx:107
static int fgOptLivery(const char *arg)
Definition options.cxx:1414
static int fgOptRunway(const char *arg)
Definition options.cxx:1460
static int fgOptFailure(const char *arg)
Definition options.cxx:1317
static long int parse_date(const string &date, const char *timeType)
Definition options.cxx:536
static int fgOptCarrier(const char *arg)
Definition options.cxx:757
static int fgOptTimeOffset(const char *arg)
Definition options.cxx:1000
static int fgOptMach(const char *arg)
Definition options.cxx:908
static int fgOptFgScenery(const char *arg)
Definition options.cxx:923
static int fgOptADF1(const char *arg)
Definition options.cxx:1367
static double parse_degree(const string &degree_str)
Definition options.cxx:597
static int fgOptUBody(const char *arg)
Definition options.cxx:826
static int fgOptAdditionalDataDir(const char *arg)
Definition options.cxx:726
static std::string urlToLocalPath(const char *url)
Definition options.cxx:1557
static int fgOptAddon(const char *arg)
Definition options.cxx:708
static int fgOptStartDateGmt(const char *arg)
Definition options.cxx:1033
static int fgOptWp(const char *arg)
Definition options.cxx:1290
static int fgOptTACAN(const char *arg)
Definition options.cxx:806
static int fgOptGUI(const char *arg)
Definition options.cxx:1746
OptionType
Definition options.cxx:1815
@ OPT_CHANNEL
Definition options.cxx:1815
@ OPT_INT
Definition options.cxx:1815
@ OPT_BOOL
Definition options.cxx:1815
@ OPT_IGNORE
Definition options.cxx:1815
@ OPT_DOUBLE
Definition options.cxx:1815
@ OPT_FUNC
Definition options.cxx:1815
@ OPT_STRING
Definition options.cxx:1815
static int fgOptNAV2(const char *arg)
Definition options.cxx:1348
static int fgOptViewOffset(const char *arg)
Definition options.cxx:1180
static int fgOptLon(const char *arg)
Definition options.cxx:788
static int fgOptWBody(const char *arg)
Definition options.cxx:850
static int fgOptVc(const char *arg)
Definition options.cxx:898
static int fgSetupProxy(const char *arg)
Definition options.cxx:1066
static int fgOptGeometry(const char *arg)
Definition options.cxx:950
static int atoi(const string &str)
Definition options.cxx:113
static flightgear::Options * shared_instance
Definition options.cxx:104
static int fgOptFreeze(const char *arg)
Definition options.cxx:1500
static int fgOptNDB(const char *arg)
Definition options.cxx:749
static std::string g_load_tape_aircraft
Definition options.cxx:1597
static int fgOptFIX(const char *arg)
Definition options.cxx:780
static int fgOptLat(const char *arg)
Definition options.cxx:797
static int fgOptNAV1(const char *arg)
Definition options.cxx:1338
static int fgOptBpp(const char *arg)
Definition options.cxx:984
static int fgOptVBody(const char *arg)
Definition options.cxx:838
static int fgOptJpgHttpd(const char *arg)
Definition options.cxx:1045
static int fgOptLogLevel(const char *arg)
Definition options.cxx:1108
static bool parse_wind(const string &wind, double *min_hdg, double *max_hdg, double *speed, double *gust)
Definition options.cxx:378
static int fgOptStartDateSys(const char *arg)
Definition options.cxx:1009
static int fgOptVEast(const char *arg)
Definition options.cxx:874
static int fgOptVOR(const char *arg)
Definition options.cxx:741
static int fgOptInAir(const char *arg)
Definition options.cxx:1773
static int fgOptDME(const char *arg)
Definition options.cxx:1387
static int fgOptIgnoreAutosave(const char *arg)
Definition options.cxx:1489
static int fgOptRandomWind(const char *arg)
Definition options.cxx:1243
static int fgOptConsole(const char *arg)
Definition options.cxx:1231
static std::string g_load_tape_airport
Definition options.cxx:1598
static bool parseIntValue(char **ppParserPos, int *pValue, int min, int max, const char *field, const char *argument)
Definition options.cxx:404
static int fgOptFov(const char *arg)
Definition options.cxx:943
static bool add_channel(const string &type, const string &channel_str)
Definition options.cxx:667
static double parse_time(const string &time_in)
Definition options.cxx:455
void fgShowAircraft(const vector< SGPath > &path_list)
Definition options.cxx:365
static int fgOptSetProperty(const char *raw)
Definition options.cxx:1513
static int fgOptMetar(const char *arg)
Definition options.cxx:1220
static int fgOptTraceRead(const char *arg)
Definition options.cxx:1098
bool fgSetDouble(const char *name, double defaultValue)
Set a double value for a property.
Definition proptest.cpp:31
bool fgGetBool(char const *name, bool def)
Get a bool value for a property.
Definition proptest.cpp:25
bool fgSetBool(char const *name, bool val)
Set a bool value for a property.
Definition proptest.cpp:24
double fgGetDouble(const char *name, double defaultValue)
Get a double value for a property.
Definition proptest.cpp:30
bool fgSetString(char const *name, char const *str)
Set a string value for a property.
Definition proptest.cpp:26
SGPropertyNode * fgGetNode(const char *path, bool create)
Get a property node.
Definition proptest.cpp:27
bool replay(FGReplayInternal &self, double time)
Replay a saved frame based on time, interpolate from the two nearest saved frames.
static std::string makeTapePath(const std::string &tape_name)
Definition replay.cxx:103
static int loadContinuousHeader(const std::string &path, std::istream *in, SGPropertyNode *properties)
Definition replay.cxx:108
int(* func)(const char *)
Definition options.cxx:1825
const char * option
Definition options.cxx:1819
const char * property
Definition options.cxx:1822
const char * s_param
Definition options.cxx:1824
#define FG_FOV_MIN
Definition view.hxx:39
#define FG_FOV_MAX
Definition view.hxx:40
void report(Airplane *a)
int usage()