2 次代码提交 45b7b8f5a4 ... 8c5fccc828

作者 SHA1 备注 提交日期
  irdvo 8c5fccc828 Strict matching the path 3 年之前
  irdvo 8e3979df84 gpxpath fetch added 3 年之前
共有 2 个文件被更改,包括 33 次插入21 次删除
  1. 2 2
      README.md
  2. 31 19
      gpxpath.cpp

+ 2 - 2
README.md

@@ -326,7 +326,7 @@ Geo tag the photo files with the GPX-files.
 Geo tag the photos with the GPX-files, based on the time of the photos and the geopositions in the GPX-files.
 
 Note: the tool expects the gpx extension for the GPX-files and the jpeg or jpg extension for the photo files.
-      Other extensions are ignored.
+      Files with other extensions are ignored.
 ```
 
 Examples:
@@ -358,7 +358,7 @@ Fetch a waypoint, track or route from a GPX-file.
    -t, --track=NAME      fetch the track with NAME
    -r, --route=NAME      fetch the route with NAME
 
-Fetch a waypoint, track or route from a GPX-file and display the GPX-file with this waypoint, track or route on standard output.
+Fetch a waypoint, track or route from a GPX-file and display the resulting GPX-file with this waypoint, track or route on standard output.
 ```
 
 Note: Use gpxls to find the waypoint, track or route name.

+ 31 - 19
gpxpath.cpp

@@ -5,7 +5,6 @@
 #include "XMLRawParser.h"
 #include "Arguments.h"
 
-const std::string version= "0.1.0";
 // ----------------------------------------------------------------------------
 
 namespace gpxtools
@@ -17,7 +16,8 @@ namespace gpxtools
     GPXPath() :
       _arguments("gpxrm [OPTION].. PATH [FILE]\nRead or set a path in a GPX-file.\n", "gpxpath v0.1", "Read or set a path in a GPX-file and display the result on standard output."),
       _value(_arguments, true,  'v', "value",       "VALUE", "set path to a value", ""),
-      _xmlParser(this)
+      _xmlParser(this),
+      _found(false)
     {
     }
 
@@ -33,22 +33,20 @@ namespace gpxtools
     {
       std::vector<std::string> filenames;
 
-      if (!_arguments.parse(argc,argv, filenames))
-      {
-        return false;
-      }
-      else if (!checkArguments(filenames))
-      {
-        return false;
-      }
-      else if (filenames.empty())
+      if (!_arguments.parse(argc,argv, filenames)) return false;
+
+      if (!checkArguments(filenames)) return false;
+
+      if (filenames.empty())
       {
-        return _xmlParser.parse(std::cin);
+        if (!_xmlParser.parse(std::cin)) return false;
       }
       else
       {
-        return parseFile(filenames.front());
+        if (!parseFile(filenames.front())) return false;
       }
+
+      return _found;
     }
 
     // -- Check arguments ---------------------------------------------------------
@@ -107,28 +105,42 @@ namespace gpxtools
 
     virtual void startElement(const std::string &path, const std::string &text, const std::string &, const Attributes &)
     {
-      if (std::equal(_path.begin(), _path.end(), path.begin()))
+      if (_value.value().empty() && (_path == path))
       {
-        std::cerr << "Found:" << path << std::endl;
+        _text.clear();
+        _found = true;
       }
     }
 
     virtual void text(const std::string &path, const std::string &text)
     {
+      if (_value.value().empty())
+      {
+        if (_path == path) _text += text;
+      }
     }
 
     virtual void endElement(const std::string &path, const std::string &text, const std::string &)
     {
+      if (_value.value().empty() && (_path == path))
+      {
+        XMLRawParser::trim(_text);
+
+        std::cout << _text << std::endl;
+      }
     }
 
   private:
     // Members
-    arg::Arguments  _arguments;
-    arg::Argument   _value;
+    arg::Arguments _arguments;
+    arg::Argument _value;
+
+    XMLRawParser _xmlParser;
 
-    XMLRawParser    _xmlParser;
+    std::string _path;
+    std::string _text;
 
-    std::string     _path;
+    bool _found;
   };
 }