Download | Plain Text | No Line Numbers


  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.  
  16. using namespace std;
  17. namespace 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.  */
  33. int 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: */
  85.