]> git.mxchange.org Git - flightgear.git/blob - src/Main/fg_commands.cxx
Simplify fgValidatePath + minor fix (requires simgear update)
[flightgear.git] / src / Main / fg_commands.cxx
1 // fg_commands.cxx - internal FGFS commands.
2
3 #ifdef HAVE_CONFIG_H
4 #  include "config.h"
5 #endif
6
7 #include <string.h>             // strcmp()
8
9 #include <simgear/compiler.h>
10
11 #include <string>
12 #include <fstream>
13
14 #include <simgear/sg_inlines.h>
15 #include <simgear/debug/logstream.hxx>
16 #include <simgear/math/sg_random.h>
17 #include <simgear/scene/material/mat.hxx>
18 #include <simgear/scene/material/matlib.hxx>
19 #include <simgear/structure/exception.hxx>
20 #include <simgear/structure/commands.hxx>
21 #include <simgear/props/props.hxx>
22 #include <simgear/props/props_io.hxx>
23 #include <simgear/structure/event_mgr.hxx>
24 #include <simgear/sound/soundmgr_openal.hxx>
25 #include <simgear/timing/sg_time.hxx>
26 #include <Network/RemoteXMLRequest.hxx>
27
28 #include <FDM/flight.hxx>
29 #include <GUI/gui.h>
30 #include <GUI/new_gui.hxx>
31 #include <GUI/dialog.hxx>
32 #include <Aircraft/replay.hxx>
33 #include <Scenery/scenery.hxx>
34 #include <Scenery/tilemgr.hxx>
35 #include <Scripting/NasalSys.hxx>
36 #include <Sound/sample_queue.hxx>
37 #include <Airports/xmlloader.hxx>
38 #include <Network/HTTPClient.hxx>
39 #include <Viewer/viewmgr.hxx>
40 #include <Viewer/viewer.hxx>
41 #include <Environment/presets.hxx>
42 #include <Navaids/NavDataCache.hxx>
43
44 #include "fg_init.hxx"
45 #include "fg_io.hxx"
46 #include "fg_os.hxx"
47 #include "fg_commands.hxx"
48 #include "fg_props.hxx"
49 #include "globals.hxx"
50 #include "logger.hxx"
51 #include "util.hxx"
52 #include "main.hxx"
53 #include "positioninit.hxx"
54
55 #include <boost/scoped_array.hpp>
56
57 #if FG_HAVE_GPERFTOOLS
58 # include <google/profiler.h>
59 #endif
60
61 using std::string;
62 using std::ifstream;
63 using std::ofstream;
64
65
66 ////////////////////////////////////////////////////////////////////////
67 // Static helper functions.
68 ////////////////////////////////////////////////////////////////////////
69
70
71 static inline SGPropertyNode *
72 get_prop (const SGPropertyNode * arg)
73 {
74     return fgGetNode(arg->getStringValue("property[0]", "/null"), true);
75 }
76
77 static inline SGPropertyNode *
78 get_prop2 (const SGPropertyNode * arg)
79 {
80     return fgGetNode(arg->getStringValue("property[1]", "/null"), true);
81 }
82
83
84 /**
85  * Get a double value and split it as required.
86  */
87 static void
88 split_value (double full_value, const char * mask,
89              double * unmodifiable, double * modifiable)
90 {
91     if (!strcmp("integer", mask)) {
92         *modifiable = (full_value < 0 ? ceil(full_value) : floor (full_value));
93         *unmodifiable = full_value - *modifiable;
94     } else if (!strcmp("decimal", mask)) {
95         *unmodifiable = (full_value < 0 ? ceil(full_value) : floor(full_value));
96         *modifiable = full_value - *unmodifiable;
97     } else {
98         if (strcmp("all", mask))
99             SG_LOG(SG_GENERAL, SG_ALERT, "Bad value " << mask << " for mask;"
100                    << " assuming 'all'");
101         *unmodifiable = 0;
102         *modifiable = full_value;
103     }
104 }
105
106
107 /**
108  * Clamp or wrap a value as specified.
109  */
110 static void
111 limit_value (double * value, const SGPropertyNode * arg)
112 {
113     const SGPropertyNode * min_node = arg->getChild("min");
114     const SGPropertyNode * max_node = arg->getChild("max");
115
116     bool wrap = arg->getBoolValue("wrap");
117
118     if (min_node == 0 || max_node == 0)
119         wrap = false;
120   
121     if (wrap) {                 // wrap such that min <= x < max
122         double min_val = min_node->getDoubleValue();
123         double max_val = max_node->getDoubleValue();
124         double resolution = arg->getDoubleValue("resolution");
125         if (resolution > 0.0) {
126             // snap to (min + N*resolution), taking special care to handle imprecision
127             int n = (int)floor((*value - min_val) / resolution + 0.5);
128             int steps = (int)floor((max_val - min_val) / resolution + 0.5);
129             SG_NORMALIZE_RANGE(n, 0, steps);
130             *value = min_val + resolution * n;
131         } else {
132             // plain circular wrapping
133             SG_NORMALIZE_RANGE(*value, min_val, max_val);
134         }
135     } else {                    // clamp such that min <= x <= max
136         if ((min_node != 0) && (*value < min_node->getDoubleValue()))
137             *value = min_node->getDoubleValue();
138         else if ((max_node != 0) && (*value > max_node->getDoubleValue()))
139             *value = max_node->getDoubleValue();
140     }
141 }
142
143 static bool
144 compare_values (SGPropertyNode * value1, SGPropertyNode * value2)
145 {
146     switch (value1->getType()) {
147     case simgear::props::BOOL:
148         return (value1->getBoolValue() == value2->getBoolValue());
149     case simgear::props::INT:
150         return (value1->getIntValue() == value2->getIntValue());
151     case simgear::props::LONG:
152         return (value1->getLongValue() == value2->getLongValue());
153     case simgear::props::FLOAT:
154         return (value1->getFloatValue() == value2->getFloatValue());
155     case simgear::props::DOUBLE:
156         return (value1->getDoubleValue() == value2->getDoubleValue());
157     default:
158         return !strcmp(value1->getStringValue(), value2->getStringValue());
159     }
160 }
161
162
163
164 ////////////////////////////////////////////////////////////////////////
165 // Command implementations.
166 ////////////////////////////////////////////////////////////////////////
167
168
169 /**
170  * Built-in command: do nothing.
171  */
172 static bool
173 do_null (const SGPropertyNode * arg)
174 {
175   return true;
176 }
177
178 /**
179  * Built-in command: run a Nasal script.
180  */
181 static bool
182 do_nasal (const SGPropertyNode * arg)
183 {
184     return ((FGNasalSys*)globals->get_subsystem("nasal"))->handleCommand(arg);
185 }
186
187 /**
188  * Built-in command: exit FlightGear.
189  *
190  * status: the exit status to return to the operating system (defaults to 0)
191  */
192 static bool
193 do_exit (const SGPropertyNode * arg)
194 {
195     SG_LOG(SG_INPUT, SG_INFO, "Program exit requested.");
196     fgSetBool("/sim/signals/exit", true);
197     globals->saveUserSettings();
198     fgOSExit(arg->getIntValue("status", 0));
199     return true;
200 }
201
202
203 /**
204  * Reset FlightGear (Shift-Escape or Menu->File->Reset)
205  */
206 static bool
207 do_reset (const SGPropertyNode * arg)
208 {
209     fgResetIdleState();
210     return true;
211 }
212
213
214 /**
215  * Change aircraft
216  */
217 static bool
218 do_switch_aircraft (const SGPropertyNode * arg)
219 {
220     fgSetString("/sim/aircraft", arg->getStringValue("aircraft"));
221     // start a reset
222     fgResetIdleState();
223     return true;
224 }
225
226 /**
227  */
228 static bool
229 do_reposition (const SGPropertyNode * arg)
230 {
231   fgStartReposition();
232   return true;
233 }
234
235 /**
236  * Built-in command: replay the FDR buffer
237  */
238 static bool
239 do_replay (const SGPropertyNode * arg)
240 {
241     FGReplay *r = (FGReplay *)(globals->get_subsystem( "replay" ));
242     return r->start();
243 }
244
245 /**
246  * Built-in command: pause/unpause the sim
247  */
248 static bool
249 do_pause (const SGPropertyNode * arg)
250 {
251     bool forcePause = arg->getBoolValue("force-pause", false );
252     bool forcePlay = arg->getBoolValue("force-play", false );
253
254     bool paused = fgGetBool("/sim/freeze/master",true) || fgGetBool("/sim/freeze/clock",true);
255
256     if(forcePause) paused = false;
257     if(forcePlay) paused = true;
258
259     if (paused && (fgGetInt("/sim/freeze/replay-state",0)>0))
260     {
261         do_replay(NULL);
262     }
263     else
264     {
265         fgSetBool("/sim/freeze/master",!paused);
266         fgSetBool("/sim/freeze/clock",!paused);
267     }
268   
269     SGPropertyNode_ptr args(new SGPropertyNode);
270     args->setStringValue("id", "sim-pause");
271     if (!paused && fgGetBool("/sim/view-name-popup")) {
272       args->setStringValue("label", "Simulation is paused");
273       globals->get_commands()->execute("show-message", args);
274     } else {
275       globals->get_commands()->execute("clear-message", args);
276     }
277   
278     return true;
279 }
280
281 /**
282  * Built-in command: load flight.
283  *
284  * file (optional): the name of the file to load (relative to current
285  *   directory).  Defaults to "fgfs.sav"
286  */
287 static bool
288 do_load (const SGPropertyNode * arg)
289 {
290     SGPath file(arg->getStringValue("file", "fgfs.sav"));
291
292     if (file.extension() != "sav")
293         file.concat(".sav");
294
295     std::string validated_path = fgValidatePath(file, false);
296     if (validated_path.empty()) {
297         SG_LOG(SG_IO, SG_ALERT, "load: reading '" << file << "' denied "
298                 "(unauthorized access)");
299         return false;
300     }
301
302     ifstream input(validated_path.c_str());
303     if (input.good() && fgLoadFlight(input)) {
304         input.close();
305         SG_LOG(SG_INPUT, SG_INFO, "Restored flight from " << file);
306         return true;
307     } else {
308         SG_LOG(SG_INPUT, SG_WARN, "Cannot load flight from " << file);
309         return false;
310     }
311 }
312
313
314 /**
315  * Built-in command: save flight.
316  *
317  * file (optional): the name of the file to save (relative to the
318  * current directory).  Defaults to "fgfs.sav".
319  */
320 static bool
321 do_save (const SGPropertyNode * arg)
322 {
323     SGPath file(arg->getStringValue("file", "fgfs.sav"));
324
325     if (file.extension() != "sav")
326         file.concat(".sav");
327
328     std::string validated_path = fgValidatePath(file, true);
329     if (validated_path.empty()) {
330         SG_LOG(SG_IO, SG_ALERT, "save: writing '" << file << "' denied "
331                 "(unauthorized access)");
332         return false;
333     }
334
335     bool write_all = arg->getBoolValue("write-all", false);
336     SG_LOG(SG_INPUT, SG_INFO, "Saving flight");
337     ofstream output(validated_path.c_str());
338     if (output.good() && fgSaveFlight(output, write_all)) {
339         output.close();
340         SG_LOG(SG_INPUT, SG_INFO, "Saved flight to " << file);
341         return true;
342     } else {
343         SG_LOG(SG_INPUT, SG_ALERT, "Cannot save flight to " << file);
344         return false;
345     }
346 }
347
348 /**
349  * Built-in command: save flight recorder tape.
350  *
351  */
352 static bool
353 do_save_tape (const SGPropertyNode * arg)
354 {
355     FGReplay* replay = (FGReplay*) globals->get_subsystem("replay");
356     replay->saveTape(arg);
357
358     return true;
359 }
360 /**
361  * Built-in command: load flight recorder tape.
362  *
363  */
364 static bool
365 do_load_tape (const SGPropertyNode * arg)
366 {
367     FGReplay* replay = (FGReplay*) globals->get_subsystem("replay");
368     replay->loadTape(arg);
369
370     return true;
371 }
372
373 /**
374  * Built-in command: (re)load the panel.
375  *
376  * path (optional): the file name to load the panel from 
377  * (relative to FG_ROOT).  Defaults to the value of /sim/panel/path,
378  * and if that's unspecified, to "Panels/Default/default.xml".
379  */
380 static bool
381 do_panel_load (const SGPropertyNode * arg)
382 {
383   string panel_path = arg->getStringValue("path");
384   if (!panel_path.empty()) {
385     // write to the standard property, which will force a load
386     fgSetString("/sim/panel/path", panel_path.c_str());
387   }
388   
389   return true;
390 }
391
392 /**
393  * Built-in command: (re)load preferences.
394  *
395  * path (optional): the file name to load the panel from (relative
396  * to FG_ROOT). Defaults to "preferences.xml".
397  */
398 static bool
399 do_preferences_load (const SGPropertyNode * arg)
400 {
401   try {
402     fgLoadProps(arg->getStringValue("path", "preferences.xml"),
403                 globals->get_props());
404   } catch (const sg_exception &e) {
405     guiErrorMessage("Error reading global preferences: ", e);
406     return false;
407   }
408   SG_LOG(SG_INPUT, SG_INFO, "Successfully read global preferences.");
409   return true;
410 }
411
412 static void
413 do_view_next(bool do_it)
414 {
415   // Only switch view if really requested to do so (and not for example while
416   // reset/reposition where /command/view/next is set to false)
417   if( do_it )
418   {
419     globals->get_current_view()->setHeadingOffset_deg(0.0);
420     globals->get_viewmgr()->next_view();
421   }
422 }
423
424 static void
425 do_view_prev(bool do_it)
426 {
427   if( do_it )
428   {
429     globals->get_current_view()->setHeadingOffset_deg(0.0);
430     globals->get_viewmgr()->prev_view();
431   }
432 }
433
434 /**
435  * An fgcommand to toggle fullscreen mode.
436  * No parameters.
437  */
438 static bool
439 do_toggle_fullscreen(const SGPropertyNode *arg)
440 {
441     fgOSFullScreen();
442     return true;
443 }
444
445 /**
446  * Built-in command: cycle view.
447  */
448 static bool
449 do_view_cycle (const SGPropertyNode * arg)
450 {
451   globals->get_current_view()->setHeadingOffset_deg(0.0);
452   globals->get_viewmgr()->next_view();
453   return true;
454 }
455
456 /**
457  * Built-in command: capture screen.
458  */
459 static bool
460 do_screen_capture (const SGPropertyNode * arg)
461 {
462   return fgDumpSnapShot();
463 }
464
465 static bool
466 do_reload_shaders (const SGPropertyNode*)
467 {
468     simgear::reload_shaders();
469     return true;
470 }
471
472 static bool
473 do_dump_scene_graph (const SGPropertyNode*)
474 {
475     fgDumpSceneGraph();
476     return true;
477 }
478
479 static bool
480 do_dump_terrain_branch (const SGPropertyNode*)
481 {
482     fgDumpTerrainBranch();
483
484     double lon_deg = fgGetDouble("/position/longitude-deg");
485     double lat_deg = fgGetDouble("/position/latitude-deg");
486     SGGeod geodPos = SGGeod::fromDegFt(lon_deg, lat_deg, 0.0);
487     SGVec3d zero = SGVec3d::fromGeod(geodPos);
488
489     SG_LOG(SG_INPUT, SG_INFO, "Model parameters:");
490     SG_LOG(SG_INPUT, SG_INFO, "Center: " << zero.x() << ", " << zero.y() << ", " << zero.z() );
491     SG_LOG(SG_INPUT, SG_INFO, "Rotation: " << lat_deg << ", " << lon_deg );
492
493     return true;
494 }
495
496 static bool
497 do_print_visible_scene_info(const SGPropertyNode*)
498 {
499     fgPrintVisibleSceneInfoCommand();
500     return true;
501 }
502
503 /**
504  * Built-in command: hires capture screen.
505  */
506 static bool
507 do_hires_screen_capture (const SGPropertyNode * arg)
508 {
509   fgHiResDump();
510   return true;
511 }
512
513
514 /**
515  * Reload the tile cache.
516  */
517 static bool
518 do_tile_cache_reload (const SGPropertyNode * arg)
519 {
520     SGPropertyNode *master_freeze = fgGetNode("/sim/freeze/master");
521     bool freeze = master_freeze->getBoolValue();
522     SG_LOG(SG_INPUT, SG_INFO, "ReIniting TileCache");
523     if ( !freeze ) {
524         master_freeze->setBoolValue(true);
525     }
526
527     globals->get_subsystem("tile-manager")->reinit();
528
529     if ( !freeze ) {
530         master_freeze->setBoolValue(false);
531     }
532     return true;
533 }
534
535 /**
536  * Reload the materials definition
537  */
538 static bool
539 do_materials_reload (const SGPropertyNode * arg)
540 {
541     SG_LOG(SG_INPUT, SG_INFO, "Reloading Materials");
542     SGMaterialLib* new_matlib =  new SGMaterialLib;
543     SGPath mpath( globals->get_fg_root() );
544     mpath.append( fgGetString("/sim/rendering/materials-file") );
545     bool loaded = new_matlib->load(globals->get_fg_root(), 
546                                   mpath.str(), 
547                                   globals->get_props());
548
549     if ( ! loaded ) {
550        SG_LOG( SG_GENERAL, SG_ALERT,
551                "Error loading materials file " << mpath.str() );
552        return false;
553     }  
554
555     globals->set_matlib(new_matlib);    
556     FGTileMgr* tileManager = static_cast<FGTileMgr*>(globals->get_subsystem("tile-manager"));
557     tileManager->materialLibChanged();
558     
559     return true;
560 }
561
562 /**
563  * Built-in command: toggle a bool property value.
564  *
565  * property: The name of the property to toggle.
566  */
567 static bool
568 do_property_toggle (const SGPropertyNode * arg)
569 {
570   SGPropertyNode * prop = get_prop(arg);
571   return prop->setBoolValue(!prop->getBoolValue());
572 }
573
574
575 /**
576  * Built-in command: assign a value to a property.
577  *
578  * property: the name of the property to assign.
579  * value: the value to assign; or
580  * property[1]: the property to copy from.
581  */
582 static bool
583 do_property_assign (const SGPropertyNode * arg)
584 {
585   SGPropertyNode * prop = get_prop(arg);
586   const SGPropertyNode * value = arg->getNode("value");
587
588   if (value != 0)
589       return prop->setUnspecifiedValue(value->getStringValue());
590   else
591   {
592       const SGPropertyNode * prop2 = get_prop2(arg);
593       if (prop2)
594           return prop->setUnspecifiedValue(prop2->getStringValue());
595       else
596           return false;
597   }
598 }
599
600
601 /**
602  * Built-in command: increment or decrement a property value.
603  *
604  * If the 'step' argument is present, it will be used; otherwise,
605  * the command uses 'offset' and 'factor', usually from the mouse.
606  *
607  * property: the name of the property to increment or decrement.
608  * step: the amount of the increment or decrement (default: 0).
609  * offset: offset from the current setting (used for the mouse; multiplied 
610  *         by factor)
611  * factor: scaling amount for the offset (defaults to 1).
612  * min: the minimum allowed value (default: no minimum).
613  * max: the maximum allowed value (default: no maximum).
614  * mask: 'integer' to apply only to the left of the decimal point, 
615  *       'decimal' to apply only to the right of the decimal point,
616  *       or 'all' to apply to the whole number (the default).
617  * wrap: true if the value should be wrapped when it passes min or max;
618  *       both min and max must be present for this to work (default:
619  *       false).
620  */
621 static bool
622 do_property_adjust (const SGPropertyNode * arg)
623 {
624   SGPropertyNode * prop = get_prop(arg);
625
626   double amount = 0;
627   if (arg->hasValue("step"))
628       amount = arg->getDoubleValue("step");
629   else
630       amount = (arg->getDoubleValue("factor", 1)
631                 * arg->getDoubleValue("offset"));
632           
633   double unmodifiable, modifiable;
634   split_value(prop->getDoubleValue(), arg->getStringValue("mask", "all"),
635               &unmodifiable, &modifiable);
636   modifiable += amount;
637   limit_value(&modifiable, arg);
638
639   prop->setDoubleValue(unmodifiable + modifiable);
640
641   return true;
642 }
643
644
645 /**
646  * Built-in command: multiply a property value.
647  *
648  * property: the name of the property to multiply.
649  * factor: the amount by which to multiply.
650  * min: the minimum allowed value (default: no minimum).
651  * max: the maximum allowed value (default: no maximum).
652  * mask: 'integer' to apply only to the left of the decimal point, 
653  *       'decimal' to apply only to the right of the decimal point,
654  *       or 'all' to apply to the whole number (the default).
655  * wrap: true if the value should be wrapped when it passes min or max;
656  *       both min and max must be present for this to work (default:
657  *       false).
658  */
659 static bool
660 do_property_multiply (const SGPropertyNode * arg)
661 {
662   SGPropertyNode * prop = get_prop(arg);
663   double factor = arg->getDoubleValue("factor", 1);
664
665   double unmodifiable, modifiable;
666   split_value(prop->getDoubleValue(), arg->getStringValue("mask", "all"),
667               &unmodifiable, &modifiable);
668   modifiable *= factor;
669   limit_value(&modifiable, arg);
670
671   prop->setDoubleValue(unmodifiable + modifiable);
672
673   return true;
674 }
675
676
677 /**
678  * Built-in command: swap two property values.
679  *
680  * property[0]: the name of the first property.
681  * property[1]: the name of the second property.
682  */
683 static bool
684 do_property_swap (const SGPropertyNode * arg)
685 {
686   SGPropertyNode * prop1 = get_prop(arg);
687   SGPropertyNode * prop2 = get_prop2(arg);
688
689                                 // FIXME: inefficient
690   const string & tmp = prop1->getStringValue();
691   return (prop1->setUnspecifiedValue(prop2->getStringValue()) &&
692           prop2->setUnspecifiedValue(tmp.c_str()));
693 }
694
695
696 /**
697  * Built-in command: Set a property to an axis or other moving input.
698  *
699  * property: the name of the property to set.
700  * setting: the current input setting, usually between -1.0 and 1.0.
701  * offset: the offset to shift by, before applying the factor.
702  * factor: the factor to multiply by (use negative to reverse).
703  */
704 static bool
705 do_property_scale (const SGPropertyNode * arg)
706 {
707   SGPropertyNode * prop = get_prop(arg);
708   double setting = arg->getDoubleValue("setting");
709   double offset = arg->getDoubleValue("offset", 0.0);
710   double factor = arg->getDoubleValue("factor", 1.0);
711   bool squared = arg->getBoolValue("squared", false);
712   int power = arg->getIntValue("power", (squared ? 2 : 1));
713
714   int sign = (setting < 0 ? -1 : 1);
715
716   switch (power) {
717   case 1:
718       break;
719   case 2:
720       setting = setting * setting * sign;
721       break;
722   case 3:
723       setting = setting * setting * setting;
724       break;
725   case 4:
726       setting = setting * setting * setting * setting * sign;
727       break;
728   default:
729       setting =  pow(setting, power);
730       if ((power % 2) == 0)
731           setting *= sign;
732       break;
733   }
734
735   return prop->setDoubleValue((setting + offset) * factor);
736 }
737
738
739 /**
740  * Built-in command: cycle a property through a set of values.
741  *
742  * If the current value isn't in the list, the cycle will
743  * (re)start from the beginning.
744  *
745  * property: the name of the property to cycle.
746  * value[*]: the list of values to cycle through.
747  */
748 static bool
749 do_property_cycle (const SGPropertyNode * arg)
750 {
751     SGPropertyNode * prop = get_prop(arg);
752     std::vector<SGPropertyNode_ptr> values = arg->getChildren("value");
753     
754     bool wrap = arg->getBoolValue("wrap", true);
755     // compatible with knob/pick animations
756     int offset = arg->getIntValue("offset", 1);
757     
758     int selection = -1;
759     int nSelections = values.size();
760
761     if (nSelections < 1) {
762         SG_LOG(SG_GENERAL, SG_ALERT, "No values for property-cycle");
763         return false;
764     }
765
766                                 // Try to find the current selection
767     for (int i = 0; i < nSelections; i++) {
768         if (compare_values(prop, values[i])) {
769             selection = i;
770             break;
771         }
772     }
773
774     if (selection < 0) { // default to first selection
775         selection = 0;
776     } else {
777         selection += offset;
778         if (wrap) {
779             selection = (selection + nSelections) % nSelections;
780         } else {
781             SG_CLAMP_RANGE(selection, 0, nSelections - 1);
782         }
783     }
784     
785     prop->setUnspecifiedValue(values[selection]->getStringValue());
786     return true;
787 }
788
789
790 /**
791  * Built-in command: randomize a numeric property value.
792  *
793  * property: the name of the property value to randomize.
794  * min: the minimum allowed value.
795  * max: the maximum allowed value.
796  */
797 static bool
798 do_property_randomize (const SGPropertyNode * arg)
799 {
800     SGPropertyNode * prop = get_prop(arg);
801     double min = arg->getDoubleValue("min", DBL_MIN);
802     double max = arg->getDoubleValue("max", DBL_MAX);
803     prop->setDoubleValue(sg_random() * (max - min) + min);
804     return true;
805 }
806
807 /**
808  * Built-in command: interpolate a property value over time
809  *
810  * property:        the name of the property value to interpolate.
811  * type:            the interpolation type ("numeric", "color", etc.)
812  * easing:          name of easing function (see http://easings.net/)
813  * value[0..n]      any number of constant values to interpolate
814  * time/rate[0..n]  time between each value, number of time elements must
815  *                  match those of value elements. Instead of time also rate can
816  *                  be used which automatically calculates the time to change
817  *                  the property value at the given speed.
818  * -or-
819  * property[1..n+1] any number of target values taken from named properties
820  * time/rate[0..n]  time between each value, number of time elements must
821  *                  match those of value elements. Instead of time also rate can
822  *                  be used which automatically calculates the time to change
823  *                  the property value at the given speed.
824  */
825 static bool
826 do_property_interpolate (const SGPropertyNode * arg)
827 {
828   SGPropertyNode * prop = get_prop(arg);
829   if( !prop )
830     return false;
831
832   simgear::PropertyList time_nodes = arg->getChildren("time");
833   simgear::PropertyList rate_nodes = arg->getChildren("rate");
834
835   if( !time_nodes.empty() && !rate_nodes.empty() )
836     // mustn't specify time and rate
837     return false;
838
839   simgear::PropertyList::size_type num_times = time_nodes.empty()
840                                              ? rate_nodes.size()
841                                              : time_nodes.size();
842
843   simgear::PropertyList value_nodes = arg->getChildren("value");
844   if( value_nodes.empty() )
845   {
846     simgear::PropertyList prop_nodes = arg->getChildren("property");
847
848     // must have one more property node
849     if( prop_nodes.size() != num_times + 1 )
850       return false;
851
852     value_nodes.reserve(num_times);
853     for( size_t i = 1; i < prop_nodes.size(); ++i )
854       value_nodes.push_back( fgGetNode(prop_nodes[i]->getStringValue()) );
855   }
856
857   // must match
858   if( value_nodes.size() != num_times )
859     return false;
860
861   double_list deltas;
862   deltas.reserve(num_times);
863
864   if( !time_nodes.empty() )
865   {
866     for( size_t i = 0; i < num_times; ++i )
867       deltas.push_back( time_nodes[i]->getDoubleValue() );
868   }
869   else
870   {
871     for( size_t i = 0; i < num_times; ++i )
872     {
873       // TODO calculate delta based on property type
874       double delta = value_nodes[i]->getDoubleValue()
875                    - ( i > 0
876                      ? value_nodes[i - 1]->getDoubleValue()
877                      : prop->getDoubleValue()
878                      );
879       deltas.push_back( fabs(delta / rate_nodes[i]->getDoubleValue()) );
880     }
881   }
882
883   return prop->interpolate
884   (
885     arg->getStringValue("type", "numeric"),
886     value_nodes,
887     deltas,
888     arg->getStringValue("easing", "linear")
889   );
890 }
891
892 /**
893  * Built-in command: reinit the data logging system based on the
894  * current contents of the /logger tree.
895  */
896 static bool
897 do_data_logging_commit (const SGPropertyNode * arg)
898 {
899     FGLogger *log = (FGLogger *)globals->get_subsystem("logger");
900     log->reinit();
901     return true;
902 }
903
904 /**
905  * Built-in command: Add a dialog to the GUI system.  Does *not*
906  * display the dialog.  The property node should have the same format
907  * as a dialog XML configuration.  It must include:
908  *
909  * name: the name of the GUI dialog for future reference.
910  */
911 static bool
912 do_dialog_new (const SGPropertyNode * arg)
913 {
914     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
915     if (!gui) {
916       return false;
917     }
918   
919     // Note the casting away of const: this is *real*.  Doing a
920     // "dialog-apply" command later on will mutate this property node.
921     // I'm not convinced that this isn't the Right Thing though; it
922     // allows client to create a node, pass it to dialog-new, and get
923     // the values back from the dialog by reading the same node.
924     // Perhaps command arguments are not as "const" as they would
925     // seem?
926     gui->newDialog((SGPropertyNode*)arg);
927     return true;
928 }
929
930 /**
931  * Built-in command: Show an XML-configured dialog.
932  *
933  * dialog-name: the name of the GUI dialog to display.
934  */
935 static bool
936 do_dialog_show (const SGPropertyNode * arg)
937 {
938     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
939     gui->showDialog(arg->getStringValue("dialog-name"));
940     return true;
941 }
942
943
944 /**
945  * Built-in Command: Hide the active XML-configured dialog.
946  */
947 static bool
948 do_dialog_close (const SGPropertyNode * arg)
949 {
950     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
951     if(arg->hasValue("dialog-name"))
952         return gui->closeDialog(arg->getStringValue("dialog-name"));
953     return gui->closeActiveDialog();
954 }
955
956
957 /**
958  * Update a value in the active XML-configured dialog.
959  *
960  * object-name: The name of the GUI object(s) (all GUI objects if omitted).
961  */
962 static bool
963 do_dialog_update (const SGPropertyNode * arg)
964 {
965     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
966     FGDialog * dialog;
967     if (arg->hasValue("dialog-name"))
968         dialog = gui->getDialog(arg->getStringValue("dialog-name"));
969     else
970         dialog = gui->getActiveDialog();
971
972     if (dialog != 0) {
973         dialog->updateValues(arg->getStringValue("object-name"));
974         return true;
975     } else {
976         return false;
977     }
978 }
979
980 static bool
981 do_open_browser (const SGPropertyNode * arg)
982 {
983     string path;
984     if (arg->hasValue("path"))
985         path = arg->getStringValue("path");
986     else
987     if (arg->hasValue("url"))
988         path = arg->getStringValue("url");
989     else
990         return false;
991
992     return openBrowser(path);
993 }
994
995 /**
996  * Apply a value in the active XML-configured dialog.
997  *
998  * object-name: The name of the GUI object(s) (all GUI objects if omitted).
999  */
1000 static bool
1001 do_dialog_apply (const SGPropertyNode * arg)
1002 {
1003     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1004     FGDialog * dialog;
1005     if (arg->hasValue("dialog-name"))
1006         dialog = gui->getDialog(arg->getStringValue("dialog-name"));
1007     else
1008         dialog = gui->getActiveDialog();
1009
1010     if (dialog != 0) {
1011         dialog->applyValues(arg->getStringValue("object-name"));
1012         return true;
1013     } else {
1014         return false;
1015     }
1016 }
1017
1018
1019 /**
1020  * Redraw GUI (applying new widget colors). Doesn't reload the dialogs,
1021  * unlike reinit().
1022  */
1023 static bool
1024 do_gui_redraw (const SGPropertyNode * arg)
1025 {
1026     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1027     gui->redraw();
1028     return true;
1029 }
1030
1031
1032 /**
1033  * Adds model to the scenery. The path to the added branch (/models/model[*])
1034  * is returned in property "property".
1035  */
1036 static bool
1037 do_add_model (const SGPropertyNode * arg)
1038 {
1039     SGPropertyNode * model = fgGetNode("models", true);
1040     int i;
1041     for (i = 0; model->hasChild("model",i); i++);
1042     model = model->getChild("model", i, true);
1043     copyProperties(arg, model);
1044     if (model->hasValue("elevation-m"))
1045         model->setDoubleValue("elevation-ft", model->getDoubleValue("elevation-m")
1046                 * SG_METER_TO_FEET);
1047     model->getNode("load", true);
1048     model->removeChildren("load");
1049     const_cast<SGPropertyNode *>(arg)->setStringValue("property", model->getPath());
1050     return true;
1051 }
1052
1053 /**
1054  * Built-in command: play an audio message (i.e. a wav file) This is
1055  * fire and forget.  Call this once per message and it will get dumped
1056  * into a queue.  Messages are played sequentially so they do not
1057  * overlap.
1058  */
1059 static bool
1060 do_play_audio_sample (const SGPropertyNode * arg)
1061 {
1062     SGSoundMgr *smgr = globals->get_soundmgr();
1063     if (!smgr) {
1064         SG_LOG(SG_GENERAL, SG_WARN, "play-audio-sample: sound-manager not running");
1065         return false;
1066     }
1067   
1068     string path = arg->getStringValue("path");
1069     string file = arg->getStringValue("file");
1070     float volume = arg->getFloatValue("volume");
1071     // cout << "playing " << path << " / " << file << endl;
1072     try {
1073         FGSampleQueue *queue = globals->get_chatter_queue();
1074         if ( !queue ) {
1075             queue = new FGSampleQueue(smgr, "chatter");
1076             queue->tie_to_listener();
1077             globals->set_chatter_queue(queue);
1078         }
1079
1080         SGSoundSample *msg = new SGSoundSample(file.c_str(), path);
1081         msg->set_volume( volume );
1082         queue->add( msg );
1083
1084         return true;
1085
1086     } catch (const sg_io_exception&) {
1087         SG_LOG(SG_GENERAL, SG_ALERT, "play-audio-sample: "
1088                 "failed to load" << path << '/' << file);
1089         return false;
1090     }
1091 }
1092
1093 /**
1094  * Built-in command: commit presets (read from in /sim/presets/)
1095  */
1096 static bool
1097 do_presets_commit (const SGPropertyNode * arg)
1098 {
1099     if (fgGetBool("/sim/initialized", false)) {
1100       fgResetIdleState();
1101     } else {
1102       // Nasal can trigger this during initial init, which confuses
1103       // the logic in ReInitSubsystems, since initial state has not been
1104       // saved at that time. Short-circuit everything here.
1105       flightgear::initPosition();
1106     }
1107     
1108     return true;
1109 }
1110
1111 /**
1112  * Built-in command: set log level (0 ... 7)
1113  */
1114 static bool
1115 do_log_level (const SGPropertyNode * arg)
1116 {
1117    sglog().setLogLevels( SG_ALL, (sgDebugPriority)arg->getIntValue() );
1118
1119    return true;
1120 }
1121
1122 /*
1123 static bool
1124 do_decrease_visibility (const SGPropertyNode * arg)
1125 {
1126     Environment::Presets::VisibilitySingleton::instance()->adjust( 0.9 );
1127     return true;
1128 }
1129  
1130 static bool
1131 do_increase_visibility (const SGPropertyNode * arg)
1132 {
1133     Environment::Presets::VisibilitySingleton::instance()->adjust( 1.1 );
1134     return true;
1135 }
1136 */
1137 /**
1138  * An fgcommand to allow loading of xml files via nasal,
1139  * the xml file's structure will be made available within
1140  * a property tree node defined under argument "targetnode",
1141  * or in the given argument tree under "data" otherwise.
1142  *
1143  * @param filename a string to hold the complete path & filename of an XML file
1144  * @param targetnode a string pointing to a location within the property tree
1145  * where to store the parsed XML file. If <targetnode> is undefined, then the
1146  * file contents are stored under a node <data> in the argument tree.
1147  */
1148
1149 static bool
1150 do_load_xml_to_proptree(const SGPropertyNode * arg)
1151 {
1152     SGPath file(arg->getStringValue("filename"));
1153     if (file.str().empty())
1154         return false;
1155
1156     if (file.extension() != "xml")
1157         file.concat(".xml");
1158     
1159     std::string icao = arg->getStringValue("icao");
1160     if (icao.empty()) {
1161         if (file.isRelative()) {
1162           SGPath absPath = globals->resolve_maybe_aircraft_path(file.str());
1163           if (!absPath.isNull())
1164               file = absPath;
1165           else
1166           {
1167               SG_LOG(SG_IO, SG_ALERT, "loadxml: Cannot find XML property file '"  
1168                           << file.str() << "'.");
1169               return false;
1170           }
1171         }
1172     } else {
1173         if (!XMLLoader::findAirportData(icao, file.str(), file)) {
1174           SG_LOG(SG_IO, SG_INFO, "loadxml: failed to find airport data for "
1175             << file.str() << " at ICAO:" << icao);
1176           return false;
1177         }
1178     }
1179     
1180     std::string validated_path = fgValidatePath(file, false);
1181     if (validated_path.empty()) {
1182         SG_LOG(SG_IO, SG_ALERT, "loadxml: reading '" << file.str() << "' denied "
1183                 "(unauthorized directory - authorization no longer follows symlinks; to authorize reading additional directories, add them to --fg-aircraft)");
1184         return false;
1185     }
1186
1187     SGPropertyNode *targetnode;
1188     if (arg->hasValue("targetnode"))
1189         targetnode = fgGetNode(arg->getStringValue("targetnode"), true);
1190     else
1191         targetnode = const_cast<SGPropertyNode *>(arg)->getNode("data", true);
1192
1193     try {
1194         readProperties(validated_path.c_str(), targetnode, true);
1195     } catch (const sg_exception &e) {
1196         SG_LOG(SG_IO, SG_WARN, "loadxml: " << e.getFormattedMessage());
1197         return false;
1198     }
1199
1200     return true;
1201 }
1202
1203 static bool
1204 do_load_xml_from_url(const SGPropertyNode * arg)
1205 {
1206     FGHTTPClient* http = static_cast<FGHTTPClient*>(globals->get_subsystem("http"));
1207     if (!http) {
1208         SG_LOG(SG_IO, SG_ALERT, "xmlhttprequest: HTTP client not running");
1209         return false;
1210     }
1211   
1212     std::string url(arg->getStringValue("url"));
1213     if (url.empty())
1214         return false;
1215         
1216     SGPropertyNode *targetnode;
1217     if (arg->hasValue("targetnode"))
1218         targetnode = fgGetNode(arg->getStringValue("targetnode"), true);
1219     else
1220         targetnode = const_cast<SGPropertyNode *>(arg)->getNode("data", true);
1221     
1222     RemoteXMLRequest* req = new RemoteXMLRequest(url, targetnode);
1223     
1224     if (arg->hasChild("body"))
1225         req->setBodyData(arg->getChild("body"));
1226     
1227 // connect up optional reporting properties
1228     if (arg->hasValue("complete")) 
1229         req->setCompletionProp(fgGetNode(arg->getStringValue("complete"), true));
1230     if (arg->hasValue("failure")) 
1231         req->setFailedProp(fgGetNode(arg->getStringValue("failure"), true));
1232     if (arg->hasValue("status")) 
1233         req->setStatusProp(fgGetNode(arg->getStringValue("status"), true));
1234         
1235     http->makeRequest(req);
1236     return true;
1237 }
1238
1239
1240 /**
1241  * An fgcommand to allow saving of xml files via nasal,
1242  * the file's structure will be determined based on what's
1243  * encountered in the passed (source) property tree node
1244  *
1245  * @param filename a string to hold the complete path & filename of the (new)
1246  * XML file
1247  * @param sourcenode a string pointing to a location within the property tree
1248  * where to find the nodes that should be written recursively into an XML file
1249  * @param data if no sourcenode is given, then the file contents are taken from
1250  * the argument tree's "data" node.
1251  */
1252
1253 static bool
1254 do_save_xml_from_proptree(const SGPropertyNode * arg)
1255 {
1256     SGPath file(arg->getStringValue("filename"));
1257     if (file.str().empty())
1258         return false;
1259
1260     if (file.extension() != "xml")
1261         file.concat(".xml");
1262
1263     std::string validated_path = fgValidatePath(file, true);
1264     if (validated_path.empty()) {
1265         SG_LOG(SG_IO, SG_ALERT, "savexml: writing to '" << file.str() << "' denied "
1266                 "(unauthorized directory - authorization no longer follows symlinks)");
1267         return false;
1268     }
1269
1270     SGPropertyNode *sourcenode;
1271     if (arg->hasValue("sourcenode"))
1272         sourcenode = fgGetNode(arg->getStringValue("sourcenode"), true);
1273     else if (arg->getNode("data", false))
1274         sourcenode = const_cast<SGPropertyNode *>(arg)->getNode("data");
1275     else
1276         return false;
1277
1278     try {
1279         writeProperties (validated_path.c_str(), sourcenode, true);
1280     } catch (const sg_exception &e) {
1281         SG_LOG(SG_IO, SG_WARN, "savexml: " << e.getFormattedMessage());
1282         return false;
1283     }
1284
1285     return true;
1286 }
1287
1288 static bool
1289 do_press_cockpit_button (const SGPropertyNode *arg)
1290 {
1291   const char *prefix = arg->getStringValue("prefix");
1292
1293   if (arg->getBoolValue("guarded") && fgGetDouble((string(prefix) + "-guard").c_str()) < 1)
1294     return true;
1295
1296   string prop = string(prefix) + "-button";
1297   double value;
1298
1299   if (arg->getBoolValue("latching"))
1300     value = fgGetDouble(prop.c_str()) > 0 ? 0 : 1;
1301   else
1302     value = 1;
1303
1304   fgSetDouble(prop.c_str(), value);
1305   fgSetBool(arg->getStringValue("discrete"), value > 0);
1306
1307   return true;
1308 }
1309
1310 static bool
1311 do_release_cockpit_button (const SGPropertyNode *arg)
1312 {
1313   const char *prefix = arg->getStringValue("prefix");
1314
1315   if (arg->getBoolValue("guarded")) {
1316     string prop = string(prefix) + "-guard";
1317     if (fgGetDouble(prop.c_str()) < 1) {
1318       fgSetDouble(prop.c_str(), 1);
1319       return true;
1320     }
1321   }
1322
1323   if (! arg->getBoolValue("latching")) {
1324     fgSetDouble((string(prefix) + "-button").c_str(), 0);
1325     fgSetBool(arg->getStringValue("discrete"), false);
1326   }
1327
1328   return true;
1329 }
1330
1331 // Optional profiling commands using gperftools:
1332 // http://code.google.com/p/gperftools/
1333
1334 #if !FG_HAVE_GPERFTOOLS
1335 static void
1336 no_profiling_support()
1337 {
1338   SG_LOG
1339   (
1340     SG_GENERAL,
1341     SG_WARN,
1342     "No profiling support! Install gperftools and reconfigure/rebuild fgfs."
1343   );
1344 }
1345 #endif
1346
1347 static bool
1348 do_profiler_start(const SGPropertyNode *arg)
1349 {
1350 #if FG_HAVE_GPERFTOOLS
1351   const char *filename = arg->getStringValue("filename", "fgfs.profile");
1352   ProfilerStart(filename);
1353   return true;
1354 #else
1355   no_profiling_support();
1356   return false;
1357 #endif
1358 }
1359
1360 static bool
1361 do_profiler_stop(const SGPropertyNode *arg)
1362 {
1363 #if FG_HAVE_GPERFTOOLS
1364   ProfilerStop();
1365   return true;
1366 #else
1367   no_profiling_support();
1368   return false;
1369 #endif
1370 }
1371
1372
1373 static bool
1374 do_set_scenery_paths(const SGPropertyNode* arg)
1375 {
1376   SGPropertyNode* sim = fgGetNode("/sim", true);
1377   sim->removeChildren("fg-scenery");
1378   
1379   globals->clear_fg_scenery();
1380   
1381   std::string terrasyncPath(fgGetString("/sim/terrasync/scenery-dir"));
1382   bool seenTerrasyncPath = false;
1383   
1384   simgear::PropertyList paths = arg->getChildren("path");
1385   for (size_t i = 0; i < paths.size(); ++i) {
1386     std::string s = paths[i]->getStringValue();
1387     if (s == terrasyncPath) {
1388       seenTerrasyncPath = true;
1389     }
1390     
1391     globals->append_fg_scenery(s);
1392   }
1393   
1394   if (fgGetBool("/sim/terrasync/enabled") && !seenTerrasyncPath) {
1395     globals->append_fg_scenery(terrasyncPath);
1396   }
1397   
1398   if (paths.empty()) {
1399     // no scenery paths set *at all*, use the data in FG_ROOT
1400     SGPath root(globals->get_fg_root());
1401     root.append("Scenery");
1402     globals->append_fg_scenery(root.str());
1403   }
1404
1405     // might need to drop ground-nets from the DB. Also need to drop
1406     // them from memory, but this is tricky since FGAirportDynamics holds
1407     // an instance directly, and AI code may have pointers to ground-net
1408     // nodes. For now we'll leave-in memory versions untouched.
1409     flightgear::NavDataCache::instance()->dropGroundnetsIfRequired();
1410   
1411   return true;
1412 }
1413
1414 ////////////////////////////////////////////////////////////////////////
1415 // Command setup.
1416 ////////////////////////////////////////////////////////////////////////
1417
1418
1419 /**
1420  * Table of built-in commands.
1421  *
1422  * New commands do not have to be added here; any module in the application
1423  * can add a new command using globals->get_commands()->addCommand(...).
1424  */
1425 static struct {
1426   const char * name;
1427   SGCommandMgr::command_t command;
1428 } built_ins [] = {
1429     { "null", do_null },
1430     { "nasal", do_nasal },
1431     { "exit", do_exit },
1432     { "reset", do_reset },
1433     { "reposition", do_reposition },
1434     { "switch-aircraft", do_switch_aircraft },
1435     { "pause", do_pause },
1436     { "load", do_load },
1437     { "save", do_save },
1438     { "save-tape", do_save_tape },
1439     { "load-tape", do_load_tape },
1440     { "panel-load", do_panel_load },
1441     { "preferences-load", do_preferences_load },
1442     { "toggle-fullscreen", do_toggle_fullscreen },
1443     { "view-cycle", do_view_cycle },
1444     { "screen-capture", do_screen_capture },
1445     { "hires-screen-capture", do_hires_screen_capture },
1446     { "tile-cache-reload", do_tile_cache_reload },
1447     /*
1448     { "set-sea-level-air-temp-degc", do_set_sea_level_degc },
1449     { "set-outside-air-temp-degc", do_set_oat_degc },
1450     { "set-dewpoint-sea-level-air-temp-degc", do_set_dewpoint_sea_level_degc },
1451     { "set-dewpoint-temp-degc", do_set_dewpoint_degc },
1452     */
1453     { "property-toggle", do_property_toggle },
1454     { "property-assign", do_property_assign },
1455     { "property-adjust", do_property_adjust },
1456     { "property-multiply", do_property_multiply },
1457     { "property-swap", do_property_swap },
1458     { "property-scale", do_property_scale },
1459     { "property-cycle", do_property_cycle },
1460     { "property-randomize", do_property_randomize },
1461     { "property-interpolate", do_property_interpolate },
1462     { "data-logging-commit", do_data_logging_commit },
1463     { "dialog-new", do_dialog_new },
1464     { "dialog-show", do_dialog_show },
1465     { "dialog-close", do_dialog_close },
1466     { "dialog-update", do_dialog_update },
1467     { "dialog-apply", do_dialog_apply },
1468     { "open-browser", do_open_browser },
1469     { "gui-redraw", do_gui_redraw },
1470     { "add-model", do_add_model },
1471     { "play-audio-sample", do_play_audio_sample },
1472     { "presets-commit", do_presets_commit },
1473     { "log-level", do_log_level },
1474     { "replay", do_replay },
1475     /*
1476     { "decrease-visibility", do_decrease_visibility },
1477     { "increase-visibility", do_increase_visibility },
1478     */
1479     { "loadxml", do_load_xml_to_proptree},
1480     { "savexml", do_save_xml_from_proptree },
1481     { "xmlhttprequest", do_load_xml_from_url },
1482     { "press-cockpit-button", do_press_cockpit_button },
1483     { "release-cockpit-button", do_release_cockpit_button },
1484     { "dump-scenegraph", do_dump_scene_graph },
1485     { "dump-terrainbranch", do_dump_terrain_branch },
1486     { "print-visible-scene", do_print_visible_scene_info },
1487     { "reload-shaders", do_reload_shaders },
1488     { "reload-materials", do_materials_reload },
1489     { "set-scenery-paths", do_set_scenery_paths },
1490   
1491     { "profiler-start", do_profiler_start },
1492     { "profiler-stop",  do_profiler_stop },
1493
1494     { 0, 0 }                    // zero-terminated
1495 };
1496
1497
1498 /**
1499  * Initialize the default built-in commands.
1500  *
1501  * Other commands may be added by other parts of the application.
1502  */
1503 void
1504 fgInitCommands ()
1505 {
1506   SG_LOG(SG_GENERAL, SG_BULK, "Initializing basic built-in commands:");
1507   for (int i = 0; built_ins[i].name != 0; i++) {
1508     SG_LOG(SG_GENERAL, SG_BULK, "  " << built_ins[i].name);
1509     globals->get_commands()->addCommand(built_ins[i].name,
1510                                         built_ins[i].command);
1511   }
1512
1513   typedef bool (*dummy)();
1514   fgTie( "/command/view/next", dummy(0), do_view_next );
1515   fgTie( "/command/view/prev", dummy(0), do_view_prev );
1516
1517   globals->get_props()->setValueReadOnly( "/sim/debug/profiler-available",
1518                                           bool(FG_HAVE_GPERFTOOLS) );
1519 }
1520
1521 // end of fg_commands.cxx