10 #include "create_wrapper.hpp"
11 #include "create_docu.hpp"
16 CompilationUnit* unit = 0;
17 std::istream* input = 0;
18 std::string inputfile;
19 std::string selected_namespace;
20 std::string modulename = "wrapper";
24 std::cout << "Usage: miniswig --input FILE --output-cpp FILE --output-hpp FILE [--module NAME] [--select-namespace NAME]\n";
28 int main(int argc, char** argv)
30 std::string outputcpp;
31 std::string outputhpp;
32 std::string output_doc;
33 for(int i = 0; i < argc; ++i) {
34 if(strcmp(argv[i], "--module") == 0) {
36 std::cerr << "Need to specify a module name.\n";
40 modulename = argv[++i];
41 } else if(strcmp(argv[i], "--input") == 0) {
43 std::cerr << "Need to specify input file name.\n";
47 inputfile = argv[++i];
48 } else if(strcmp(argv[i], "--output-cpp") == 0) {
50 std::cerr << "Need to specifiy output cpp name.\n";
54 outputcpp = argv[++i];
55 } else if(strcmp(argv[i], "--output-hpp") == 0) {
57 std::cerr << "Need to specify output hpp name.\n";
61 outputhpp = argv[++i];
62 } else if(strcmp(argv[i], "--select-namespace") == 0) {
64 std::cerr << "Need to specify a namespace.\n";
68 selected_namespace = argv[++i];
69 } else if(strcmp(argv[i], "--output-doc") == 0) {
71 std::cerr << "Need to specify document xml file.\n";
75 output_doc = argv[++i];
76 } else if(argv[i][0] == '-') {
77 std::cerr << "Unknown option '" << argv[i] << "'.\n";
83 if( inputfile == "" || (
84 (outputcpp == "" || outputhpp == "") && output_doc == "")) {
85 std::cerr << "Not all options specified.\n";
91 input = new std::ifstream(inputfile.c_str());
93 std::cerr << "Couldn't open file '" << input << "' for reading.\n";
96 current_file = inputfile;
97 unit = new CompilationUnit();
98 Namespace* std_namespace = new Namespace();
99 std_namespace->name = "std";
100 std_namespace->types.push_back(new StringType());
101 unit->namespaces.push_back(std_namespace);
102 unit->types.push_back(new HSQUIRRELVMType());
103 unit->types.push_back(new SQIntegerType());
107 Namespace* ns = unit;
108 if(selected_namespace != "") {
109 ns = ns->findNamespace(selected_namespace);
112 if(outputcpp != "") {
113 std::ofstream cppout(outputcpp.c_str());
115 std::cerr << "Couldn't open file '"
116 << outputcpp << "' for writing.\n";
119 std::ofstream hppout(outputhpp.c_str());
121 std::cerr << "Couldn't open file '" << outputhpp
122 << "' for writing.\n";
126 WrapperCreator creator(cppout, hppout);
127 creator.create_wrapper(ns);
130 if(output_doc != "") {
131 std::ofstream dout(output_doc.c_str());
133 std::cerr << "Couldn't open file '"
134 << output_doc << "' for writing.\n";
137 DocuCreator creator(dout);
138 creator.create_docu(ns);
140 } catch(std::exception& e) {
141 std::cerr << "Exception: " << e.what() << "\n";