9 #include "create_wrapper.hpp"
10 #include "create_docu.hpp"
15 CompilationUnit* unit = 0;
16 std::istream* input = 0;
17 std::string inputfile;
18 std::string selected_namespace;
19 std::string modulename = "wrapper";
23 std::cout << "Usage: miniswig --input FILE --output-cpp FILE --output-hpp FILE [--module NAME] [--select-namespace NAME]\n";
27 int main(int argc, char** argv)
29 std::string outputcpp;
30 std::string outputhpp;
31 std::string output_doc;
32 for(int i = 0; i < argc; ++i) {
33 if(strcmp(argv[i], "--module") == 0) {
35 std::cerr << "Need to specify a module name.\n";
39 modulename = argv[++i];
40 } else if(strcmp(argv[i], "--input") == 0) {
42 std::cerr << "Need to specify input file name.\n";
46 inputfile = argv[++i];
47 } else if(strcmp(argv[i], "--output-cpp") == 0) {
49 std::cerr << "Need to specifiy output cpp name.\n";
53 outputcpp = argv[++i];
54 } else if(strcmp(argv[i], "--output-hpp") == 0) {
56 std::cerr << "Need to specify output hpp name.\n";
60 outputhpp = argv[++i];
61 } else if(strcmp(argv[i], "--select-namespace") == 0) {
63 std::cerr << "Need to specify a namespace.\n";
67 selected_namespace = argv[++i];
68 } else if(strcmp(argv[i], "--output-doc") == 0) {
70 std::cerr << "Need to specify document xml file.\n";
74 output_doc = argv[++i];
75 } else if(argv[i][0] == '-') {
76 std::cerr << "Unknown option '" << argv[i] << "'.\n";
82 if( inputfile == "" || (
83 (outputcpp == "" || outputhpp == "") && output_doc == "")) {
84 std::cerr << "Not all options specified.\n";
90 input = new std::ifstream(inputfile.c_str());
92 std::cerr << "Couldn't open file '" << input << "' for reading.\n";
95 current_file = inputfile;
96 unit = new CompilationUnit();
97 Namespace* std_namespace = new Namespace();
98 std_namespace->name = "std";
99 std_namespace->types.push_back(new StringType());
100 unit->namespaces.push_back(std_namespace);
101 unit->types.push_back(new HSQUIRRELVMType());
102 unit->types.push_back(new SQIntegerType());
106 Namespace* ns = unit;
107 if(selected_namespace != "") {
108 ns = ns->findNamespace(selected_namespace);
111 if(outputcpp != "") {
112 std::ofstream cppout(outputcpp.c_str());
114 std::cerr << "Couldn't open file '"
115 << outputcpp << "' for writing.\n";
118 std::ofstream hppout(outputhpp.c_str());
120 std::cerr << "Couldn't open file '" << outputhpp
121 << "' for writing.\n";
125 WrapperCreator creator(cppout, hppout);
126 creator.create_wrapper(ns);
129 if(output_doc != "") {
130 std::ofstream dout(output_doc.c_str());
132 std::cerr << "Couldn't open file '"
133 << output_doc << "' for writing.\n";
136 DocuCreator creator(dout);
137 creator.create_docu(ns);
139 } catch(std::exception& e) {
140 std::cerr << "Exception: " << e.what() << "\n";