]> git.mxchange.org Git - flightgear.git/blobdiff - src/Input/fgjs.cxx
Use the short xml name for properties in JSON
[flightgear.git] / src / Input / fgjs.cxx
index e73266a63c18b0fc7b572d65958b87c21c66f67e..59effd534ddf7cd080160ef3fe41eb7fd79f3b94 100644 (file)
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
 #include <simgear/compiler.h>
 
+#ifdef _WIN32
+#  include <winsock2.h>
+#endif
+
 #include <math.h>
 
-#include STL_IOSTREAM
-#include STL_FSTREAM
-#include STL_STRING
+#include <iostream>
+#include <fstream>
+#include <string>
 
-SG_USING_STD(fstream);
-SG_USING_STD(cout);
-SG_USING_STD(cin);
-SG_USING_STD(endl);
-SG_USING_STD(ios);
-SG_USING_STD(string);
+using std::fstream;
+using std::cout;
+using std::cin;
+using std::endl;
+using std::ios;
+using std::string;
 
 #include <simgear/constants.h>
 #include <simgear/debug/logstream.hxx>
 #include <simgear/misc/sg_path.hxx>
 #include <simgear/misc/sgstream.hxx>
 #include <simgear/structure/exception.hxx>
+#include <simgear/props/props_io.hxx>
 
 #include <Main/fg_io.hxx>
 #include <Main/fg_props.hxx>
@@ -49,6 +58,11 @@ SG_USING_STD(string);
 
 #include "jsinput.h"
 
+#ifdef __APPLE__
+#  include <CoreFoundation/CoreFoundation.h>
+#endif
+
+using simgear::PropertyList;
 
 bool confirmAnswer() {
     char answer;
@@ -72,6 +86,8 @@ int main( int argc, char *argv[] ) {
             cout << "Usage:" << endl;
             cout << "  --help\t\t\tShow this help" << endl;
             exit(0);
+       } else if (strncmp("--fg-root=", argv[i], 10) == 0) {
+           // used later
         } else {
             cout << "Unknown option \"" << argv[i] << "\"" << endl;
             exit(0);
@@ -121,12 +137,12 @@ int main( int argc, char *argv[] ) {
     SGPropertyNode *templatetree = new SGPropertyNode();
     try {
         readProperties(templatefile.str().c_str(), templatetree);
-    } catch (sg_io_exception e) {
+    } catch (sg_io_exception e) {
         cout << e.getFormattedMessage ();
     }
 
-    vector<SGPropertyNode_ptr> axes = templatetree->getChildren("axis");
-    for(vector<SGPropertyNode_ptr>::iterator iter = axes.begin(); iter != axes.end(); iter++) {
+    PropertyList axes = templatetree->getChildren("axis");
+    for(PropertyList::iterator iter = axes.begin(); iter != axes.end(); ++iter) {
         cout << "Move the control you wish to use for " << (*iter)->getStringValue("desc")
              << " " << (*iter)->getStringValue("direction") << endl;
         cout << "Pressing a button skips this axis" << endl;
@@ -143,18 +159,18 @@ int main( int argc, char *argv[] ) {
                         ->getDeadBand(jsi->getInputAxis()));
                 axis->setDoubleValue("binding/factor", jsi->getInputAxisPositive() ? 1.0 : -1.0);
             } else {
-                iter--;
+                --iter;
             }
         } else {
             cout << "Skipping control" << endl;
             if ( ! confirmAnswer() )
-                iter--;
+                --iter;
         }
         cout << endl;
     }
 
-    vector<SGPropertyNode_ptr> buttons = templatetree->getChildren("button");
-    for(vector<SGPropertyNode_ptr>::iterator iter = buttons.begin(); iter != buttons.end(); iter++) {
+    PropertyList buttons = templatetree->getChildren("button");
+    for(PropertyList::iterator iter = buttons.begin(); iter != buttons.end(); ++iter) {
         cout << "Press the button you wish to use for " << (*iter)->getStringValue("desc") << endl;
         cout << "Moving a joystick axis skips this button" << endl;
         fflush( stdout );
@@ -167,12 +183,12 @@ int main( int argc, char *argv[] ) {
                 SGPropertyNode *button = jstree[ jsi->getInputJoystick() ]->getChild("button", jsi->getInputButton(), true);
                 copyProperties(*iter, button);
             } else {
-                iter--;
+                --iter;
             }
         } else {
             cout << "Skipping control" << endl;
             if (! confirmAnswer())
-                iter--;
+                --iter;
         }
         cout << endl;
     }
@@ -188,7 +204,7 @@ int main( int argc, char *argv[] ) {
 
             jstree[i]->setStringValue("name", jss->getJoystick(i)->getName());
             writeProperties(xfs[i], jstree[i], true);
-        } catch (sg_io_exception e) {
+        } catch (sg_io_exception e) {
             cout << e.getFormattedMessage ();
         }
         xfs[i].close();
@@ -200,6 +216,7 @@ int main( int argc, char *argv[] ) {
     delete jsi;
     delete[] xfs;
     delete jss;
+    delete[] jstree;
 
     return 1;
 }
@@ -221,12 +238,12 @@ static string fgScanForOption( const string& option, int argc, char **argv ) {
         free_hostname = true;
     }
 
-    SG_LOG(SG_GENERAL, SG_INFO, "Scanning command line for: " << option );
+    SG_LOG(SG_INPUT, SG_INFO, "Scanning command line for: " << option );
 
     int len = option.length();
 
     while ( i < argc ) {
-        SG_LOG( SG_GENERAL, SG_DEBUG, "argv[" << i << "] = " << argv[i] );
+        SG_LOG( SG_INPUT, SG_DEBUG, "argv[" << i << "] = " << argv[i] );
 
         string arg = argv[i];
         if ( arg.find( option ) == 0 ) {
@@ -247,25 +264,14 @@ static string fgScanForOption( const string& option, const string& path ) {
         return "";
     }
 
-    SG_LOG( SG_GENERAL, SG_INFO, "Scanning " << path << " for: " << option );
+    SG_LOG( SG_INPUT, SG_INFO, "Scanning " << path << " for: " << option );
 
     int len = option.length();
 
     in >> skipcomment;
-#ifndef __MWERKS__
     while ( ! in.eof() ) {
-#else
-    char c = '\0';
-    while ( in.get(c) && c != '\0' ) {
-        in.putback(c);
-#endif
         string line;
-
-#if defined( macintosh )
-        getline( in, line, '\r' );
-#else
         getline( in, line, '\n' );
-#endif
 
         // catch extraneous (DOS) line ending character
         if ( line[line.length() - 1] < 32 ) {
@@ -337,28 +343,26 @@ string getFGRoot ( int argc, char **argv ) {
     // find fg-root any other way.
     if ( root.empty() ) {
 #if defined( __CYGWIN__ )
-        root = "/FlightGear";
-#elif defined( WIN32 )
-        root = "\\FlightGear";
-#elif defined(OSX_BUNDLE)
-        /* the following code looks for the base package directly inside
-            the application bundle. This can be changed fairly easily by
-            fiddling with the code below. And yes, I know it's ugly and verbose.
+        root = "../data";
+#elif defined( _WIN32 )
+        root = "..\\data";
+#elif defined(__APPLE__) 
+        /*
+        The following code looks for the base package inside the application 
+        bundle, in the standard Contents/Resources location. 
         */
-        CFBundleRef appBundle = CFBundleGetMainBundle();
-        CFURLRef appUrl = CFBundleCopyBundleURL(appBundle);
-        CFRelease(appBundle);
 
-        // look for a 'data' subdir directly inside the bundle : is there
-        // a better place? maybe in Resources? I don't know ...
-        CFURLRef dataDir = CFURLCreateCopyAppendingPathComponent(NULL, appUrl, CFSTR("data"), true);
+        CFURLRef resourcesUrl = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
+
+        // look for a 'data' subdir
+        CFURLRef dataDir = CFURLCreateCopyAppendingPathComponent(NULL, resourcesUrl, CFSTR("data"), true);
 
         // now convert down to a path, and the a c-string
         CFStringRef path = CFURLCopyFileSystemPath(dataDir, kCFURLPOSIXPathStyle);
         root = CFStringGetCStringPtr(path, CFStringGetSystemEncoding());
 
         // tidy up.
-        CFRelease(appBundle);
+        CFRelease(resourcesUrl);
         CFRelease(dataDir);
         CFRelease(path);
 #else