7 #include "create_wrapper.hpp"
8 #include "create_docu.hpp"
13 CompilationUnit* unit = 0;
14 std::istream* input = 0;
15 std::string inputfile;
16 std::string selected_namespace;
17 std::string modulename = "wrapper";
21 std::cout << "Usage: miniswig --input FILE --output-cpp FILE --output-hpp FILE [--module NAME] [--select-namespace NAME]\n";
25 int main(int argc, char** argv)
27 std::string outputcpp;
28 std::string outputhpp;
29 std::string output_doc;
30 for(int i = 0; i < argc; ++i) {
31 if(strcmp(argv[i], "--module") == 0) {
33 std::cerr << "Need to specify a module name.\n";
37 modulename = argv[++i];
38 } else if(strcmp(argv[i], "--input") == 0) {
40 std::cerr << "Need to specify input file name.\n";
44 inputfile = argv[++i];
45 } else if(strcmp(argv[i], "--output-cpp") == 0) {
47 std::cerr << "Need to specifiy output cpp name.\n";
51 outputcpp = argv[++i];
52 } else if(strcmp(argv[i], "--output-hpp") == 0) {
54 std::cerr << "Need to specify output hpp name.\n";
58 outputhpp = argv[++i];
59 } else if(strcmp(argv[i], "--select-namespace") == 0) {
61 std::cerr << "Need to specify a namespace.\n";
65 selected_namespace = argv[++i];
66 } else if(strcmp(argv[i], "--output-doc") == 0) {
68 std::cerr << "Need to specify document xml file.\n";
72 output_doc = argv[++i];
73 } else if(argv[i][0] == '-') {
74 std::cerr << "Unknown option '" << argv[i] << "'.\n";
80 if( inputfile == "" || (
81 (outputcpp == "" || outputhpp == "") && output_doc == "")) {
82 std::cerr << "Not all options specified.\n";
88 input = new std::ifstream(inputfile.c_str());
90 std::cerr << "Couldn't open file '" << input << "' for reading.\n";
93 current_file = inputfile;
94 unit = new CompilationUnit();
95 Namespace* std_namespace = new Namespace();
96 std_namespace->name = "std";
97 std_namespace->types.push_back(new StringType());
98 unit->namespaces.push_back(std_namespace);
99 unit->types.push_back(new HSQUIRRELVMType());
103 Namespace* ns = unit;
104 if(selected_namespace != "") {
105 ns = ns->findNamespace(selected_namespace);
108 if(outputcpp != "") {
109 std::ofstream cppout(outputcpp.c_str());
111 std::cerr << "Couldn't open file '"
112 << outputcpp << "' for writing.\n";
115 std::ofstream hppout(outputhpp.c_str());
117 std::cerr << "Couldn't open file '" << outputhpp
118 << "' for writing.\n";
122 WrapperCreator creator(cppout, hppout);
123 creator.create_wrapper(ns);
126 if(output_doc != "") {
127 std::ofstream dout(output_doc.c_str());
129 std::cerr << "Couldn't open file '"
130 << dout << "' for writing.\n";
133 DocuCreator creator(dout);
134 creator.create_docu(ns);
136 } catch(std::exception& e) {
137 std::cerr << e.what() << "\n";