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
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 #include "../config.h"
00055 #include "cmdline_parser.hh"
00056 #include "prop_registry.hh"
00057 #include "parse_util.hh"
00058 #include "cppcc_driver.hh"
00059
00060 void printVersion ()
00061 {
00062 cerr << "C++ Compiler Compiler Ver. " << VERSION << endl
00063 << "Copyright (C) 2002 Alec Panovici (alecu@email.com)" << endl
00064 << "This program is free software; you may redistribute it under the terms of" << endl
00065 << "the GNU General Public License." << endl
00066 << endl;
00067 }
00068
00069 int main (int argc, char *argv[]) throw (exception)
00070 {
00071 PropRegistry registry;
00072 CmdLineParser clp("cppcc", registry);
00073 int fileArgc;
00074
00075
00076
00077 registry["print_usage"] = false;
00078 registry["print_version"] = false;
00079 registry["be_verbose"] = false;
00080 registry["debug"] = "";
00081 registry["target_dir"] = "";
00082
00083
00084 clp
00085 .add("b", false, true, "h", "help", "print_usage", "Prints this help message.")
00086 .add("b", false, true, "V", "version", "print_version", "Output version and copyright information.")
00087 .add("b", false, true, "v", "verbose", "be_verbose", "Makes CppCC be verbose about what it's doing.")
00088 .add("s", false, true, "d", "dir", "target_dir", "Put the ouput files ino the specified dir.")
00089 #ifdef DEBUG
00090 .add("s", false, true, "g", "debug", "debug", "Enables debug switches; each letter in the string argument enables a certain feature: \'s\' - enables scanner's debug features, \'p\' - enables parser's debug features, \'o\' - enables the option parser debug features, \'d\' - causes a parse tree dump \'f\' - dumps DFA intermediate data.");
00091 #endif
00092 ;
00093
00094
00095 try {
00096 fileArgc = clp.parse(--argc, ++argv);
00097 } catch (CmdLineParseException &pex)
00098 {
00099 die(formatError((string) ("Bad command line syntax "
00100 "(run cppcc --help for usage help) :")
00101 + pex.what()));
00102 }
00103
00104 if (((string) registry["target_dir"]) != "")
00105 registry["target_dir"] = (string) registry["target_dir"] + '/';
00106
00107 if (registry["print_usage"]) {
00108 printVersion();
00109 clp.printUsage(cout);
00110 return 0;
00111 }
00112
00113 if (registry["print_version"]) { printVersion(); }
00114
00115 if (fileArgc == argc)
00116 die(formatError("No input files given."));
00117
00118 registry["input_file"] = argv[fileArgc];
00119
00120
00121 bool ok = CppCcDriver().run(registry);
00122
00123 if (registry["be_verbose"])
00124 cerr << "CppCC finished " << (ok ? "" : "un" ) << "successfully." << endl;
00125
00126 return !ok;
00127 }