summaryrefslogtreecommitdiffstats
path: root/ue1/imgsynth/imgsynth.cpp
diff options
context:
space:
mode:
authormanuel <manuel@nc8430.lan>2009-04-27 00:24:16 +0200
committermanuel <manuel@nc8430.lan>2009-04-27 00:24:16 +0200
commit384539f7cc9feaa7ef7cee385cce472c6966c843 (patch)
tree42d3cbc96d44087c0b6bbe8d41710e5c5f1efced /ue1/imgsynth/imgsynth.cpp
downloadooprog-384539f7cc9feaa7ef7cee385cce472c6966c843.tar.gz
ooprog-384539f7cc9feaa7ef7cee385cce472c6966c843.tar.bz2
ooprog-384539f7cc9feaa7ef7cee385cce472c6966c843.zip
Adding ue1
Diffstat (limited to 'ue1/imgsynth/imgsynth.cpp')
-rw-r--r--ue1/imgsynth/imgsynth.cpp84
1 files changed, 84 insertions, 0 deletions
diff --git a/ue1/imgsynth/imgsynth.cpp b/ue1/imgsynth/imgsynth.cpp
new file mode 100644
index 0000000..a172c76
--- /dev/null
+++ b/ue1/imgsynth/imgsynth.cpp
@@ -0,0 +1,84 @@
1/**
2 * @module imgsynth
3 * @author Manuel Mausz, 0728348
4 * @brief imgsynth reads a scriptfile given as commandline option
5 * and executes all known function inside.
6 * On error (e.g. unknown function) the program will terminate
7 * @date 17.04.2009
8 * @par Exercise
9 * 1
10 */
11
12#include <iostream>
13#include <boost/program_options.hpp>
14#include "cscriptparser.h"
15
16using namespace std;
17namespace po = boost::program_options;
18
19/**
20 * @func main
21 * @brief program entry point
22 * @param argc standard parameter of main
23 * @param argv standard parameter of main
24 * @return 0 on success, not 0 otherwise
25 * @globalvars none
26 * @exception none
27 * @conditions none
28 *
29 * setup commandline options, parse them and pass scriptfile to scriptparser
30 * instance. On error print error message to stderr.
31 * Unknown commandline options will print a usage message.
32 */
33int main(int argc, char* argv[])
34{
35 string me(argv[0]);
36
37 /* define commandline options */
38 po::options_description desc("Allowed options");
39 desc.add_options()
40 ("help,h", "this help message")
41 ("input,i", po::value<string>(), "input scriptfile");
42
43 /* parse commandline options */
44 po::variables_map vm;
45 try
46 {
47 po::store(po::parse_command_line(argc, argv, desc), vm);
48 po::notify(vm);
49 }
50 catch(po::error& ex)
51 {
52 cerr << "Error: " << ex.what() << endl;
53 }
54
55 /* print usage upon request or missing params */
56 if (vm.count("help") || !vm.count("input"))
57 {
58 cout << "Usage: " << me << " -i <scriptfile>" << endl;
59 cout << desc << endl;
60 return 0;
61 }
62
63 CScriptparser parser(vm["input"].as<string>());
64 try
65 {
66 parser.parse();
67 }
68 catch(CScriptparser::ParserError& ex)
69 {
70 cerr << me << ": Error while processing scriptfile: " << ex.what() << endl;
71 if (!ex.getLine().empty())
72 cerr << "Scriptline: '" << ex.getLine() << "'" << endl;
73 return 1;
74 }
75 catch(exception& ex)
76 {
77 cerr << me << ": Unexpected exception: " << ex.what() << endl;
78 return 1;
79 }
80
81 return 0;
82}
83
84/* vim: set et sw=2 ts=2: */