summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrégoire Duchêne <gduchene@fastmail.net>2011-02-19 19:42:14 +0100
committerGrégoire Duchêne <gduchene@fastmail.net>2011-02-19 19:42:14 +0100
commit7fa9597789edf8babd19e46d622c5d23d948ca2f (patch)
tree8f296bda1f71aed9c1578373594a1cdabcc6957c
parentdc3280e9748f754be468af6389135e2855f79eb4 (diff)
Options are now handled by Boost.Program_options.
Additionally, messages are displayed in a more conventional way.
-rw-r--r--Jamroot2
-rw-r--r--src/main.cpp36
2 files changed, 31 insertions, 7 deletions
diff --git a/Jamroot b/Jamroot
index f451ada..9c0a0a1 100644
--- a/Jamroot
+++ b/Jamroot
@@ -1 +1 @@
-exe mppdown : [ glob-tree *.cpp ] ;
+exe mppdown : [ glob-tree *.cpp ] : <linkflags>-lboost_program_options ;
diff --git a/src/main.cpp b/src/main.cpp
index f4fcc70..08d520a 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -13,6 +13,7 @@ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include <boost/program_options.hpp>
#include <boost/spirit/include/karma.hpp>
#include <boost/spirit/include/qi.hpp>
#include <fstream>
@@ -23,18 +24,41 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "parser/document_p.h"
namespace ka = boost::spirit::karma;
+namespace po = boost::program_options;
namespace qi = boost::spirit::qi;
int main(int argc, char** argv) {
using namespace std;
- if (argc != 2)
+ po::options_description general("Allowed options");
+ po::positional_options_description pgeneral;
+ po::variables_map variables;
+
+ general.add_options()
+ ("help,h", "produce this message")
+ ("input,i", "set the input file");
+
+ pgeneral.add("input", -1);
+
+ po::store(po::command_line_parser(argc,argv).
+ options(general).positional(pgeneral).run(), variables);
+
+ po::notify(variables);
+
+ if (variables.count("help")) {
+ cout << general << endl;
+ return 0;
+ }
+
+ if (!variables.count("input")) {
+ cerr << "mppdown: you must specify an input file" << endl;
return 1;
+ }
- wifstream ifile(argv[1]);
-
+ wifstream ifile(variables["input"].as<string>().c_str());
+
if (ifile.fail()) {
- cerr << "Error while reading the file." << endl;
+ cerr << "mppdown: error while reading the file" << endl;
return 1;
}
@@ -52,7 +76,7 @@ int main(int argc, char** argv) {
document_t ast;
if (!qi::parse(begin, end, parser, ast) || begin != end) {
- cerr << "Error while parsing the file." << endl;
+ cerr << "mppdown: error while parsing the file" << endl;
return 1;
}
@@ -61,7 +85,7 @@ int main(int argc, char** argv) {
oiterator sink(output);
if (!ka::generate(sink, generator, ast)) {
- cerr << "Error while generating the output." << endl;
+ cerr << "mppdown: error while generating the output" << endl;
return 1;
}