|
|
@@ -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;
|
|
|
};
|
|
|
}
|
|
|
|