summaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp36
1 files changed, 30 insertions, 6 deletions
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;
}