Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

cdmlc.cc

00001 /*
00002 *  Name:      cdmlc.cc
00003 *  Author:    Rafael Jesus Alcantara Perez
00004 *  Summary:   CDML compiler
00005 *  Date:      $Date: 2003/10/06 12:45:11 $
00006 *  Revision:  $Revision: 1.2 $
00007 *
00008 *  Copyright (C) 1994-2002  Rafael Jesus Alcantara Perez <rafa@dedalo-ing.com>
00009 *
00010 *  This program is free software; you can redistribute it and/or modify
00011 *  it under the terms of the GNU General Public License as published by
00012 *  the Free Software Foundation; either version 2 of the License, or
00013 *  (at your option) any later version.
00014 *
00015 *  This program is distributed in the hope that it will be useful,
00016 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 *  GNU General Public License for more details.
00019 *
00020 *  You should have received a copy of the GNU General Public License
00021 *  along with this program; if not, write to the Free Software
00022 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00023 *  MA 02111-1307, USA.
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 //  L O C A L   V A R I A B L E S
00034 //
00035 
00037 static const char*   _pkcVersion = "0.0.5";
00038 
00039 
00040 //
00041 //  L O C A L   F U N C T I O N S
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   //  Create options with their default values.
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       //  Reads CDML, and then removes all superfluous information.
00092       //
00093       tCompilerPbcg.setCdmlPath (tConfigProcessor ["cdml-path"].getValue());
00094       tCompilerPbcg.loadFrom (tConfigProcessor.argumentValue (0));
00095       tCompilerPbcg.compile();
00096 
00097       //
00098       //  Removes description to accelerate read stage.
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 }  // main()

Generated on Mon Oct 13 02:35:22 2003 for MPCL by doxygen1.2.18