00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <exception>
00027 #include <iostream>
00028 #include <mpcl/text/codegen/pattern_based_code_generator.hh>
00029 #include <mpcl/util/prefs/config_processor.hh>
00030
00031
00032
00033
00034
00035
00037 static const char* _pkcVersion = "0.0.5";
00038
00039
00040
00041
00042
00043
00045 int main (int argc, const char** argv)
00046 {
00047
00048 using mpcl::text::codegen::TPatternBasedCodeGenerator;
00049 using mpcl::text::TString;
00050 using mpcl::util::prefs::TConfigProcessor;
00051 using std::cerr;
00052 using std::cout;
00053 using std::endl;
00054
00055 TPatternBasedCodeGenerator tCompilerPbcg;
00056 TConfigProcessor tConfigProcessor (argc, argv);
00057 int iExitCode = 0;
00058
00059
00060
00061
00062 tConfigProcessor.addOption ("cdml-path", "m", ".");
00063 tConfigProcessor.addOption ("help", "h");
00064 tConfigProcessor.addOption ("version", "V");
00065 tConfigProcessor.setUsageStringHeader ("Usage: cdmlc [OPTION]... FILE\n\nOptions:");
00066 tConfigProcessor ["cdml-path"].setUsageString ("Path for searching CDML documents");
00067 tConfigProcessor ["help"].setUsageString ("Print usage information");
00068 tConfigProcessor ["version"].setUsageString ("Print version information");
00069 tConfigProcessor.processOptions();
00070
00071 if ( tConfigProcessor ["help"].isAtCmdLine() )
00072 {
00073 TString yUsageString (tConfigProcessor.formatUsageString());
00074
00075 cout << yUsageString;
00076 }
00077 else if ( tConfigProcessor ["version"].isAtCmdLine() )
00078 {
00079 cout << _pkcVersion << endl;
00080 }
00081 else if ( !tConfigProcessor.hasArguments() )
00082 {
00083 cerr << "cdmlc: there is no input file\n";
00084 iExitCode = 1;
00085 }
00086 else
00087 {
00088 try
00089 {
00090
00091
00092
00093 tCompilerPbcg.setCdmlPath (tConfigProcessor ["cdml-path"].getValue());
00094 tCompilerPbcg.loadFrom (tConfigProcessor.argumentValue (0));
00095 tCompilerPbcg.compile();
00096
00097
00098
00099
00100 tCompilerPbcg.setDescription ("");
00101 cout << tCompilerPbcg;
00102 }
00103 catch (const mpcl::TException& rktEXCEPTION)
00104 {
00105 iExitCode = 3;
00106 cerr << rktEXCEPTION;
00107 }
00108 catch (const std::exception& rktEXCEPTION)
00109 {
00110 iExitCode = 2;
00111 cerr << rktEXCEPTION.what() << endl;
00112 }
00113 catch (...)
00114 {
00115 iExitCode = 1;
00116 cerr << mpcl::TException ("unhandled exception", NULL, __FILE__, __LINE__);
00117 }
00118 }
00119 return iExitCode;
00120
00121 }