7 #include "create_wrapper.h"
12 CompilationUnit* unit = 0;
13 std::istream* input = 0;
14 std::string inputfile;
15 std::string selected_namespace;
16 std::string modulename = "wrapper";
20 std::cout << "Usage: miniswig --input FILE --output-cpp FILE --output-hpp FILE [--module NAME] [--select-namespace NAME]\n";
24 int main(int argc, char** argv)
26 std::string outputcpp;
27 std::string outputhpp;
28 for(int i = 0; i < argc; ++i) {
29 if(strcmp(argv[i], "--module") == 0) {
31 std::cerr << "Need to specify a module name.\n";
35 modulename = argv[++i];
36 } else if(strcmp(argv[i], "--input") == 0) {
38 std::cerr << "Need to specify input file name.\n";
42 inputfile = argv[++i];
43 } else if(strcmp(argv[i], "--output-cpp") == 0) {
45 std::cerr << "Need to specifiy output cpp name.\n";
49 outputcpp = argv[++i];
50 } else if(strcmp(argv[i], "--output-hpp") == 0) {
52 std::cerr << "Need to specify output hpp name.\n";
56 outputhpp = argv[++i];
57 } else if(strcmp(argv[i], "--select-namespace") == 0) {
59 std::cerr << "Need to specify a namespace.\n";
63 selected_namespace = argv[++i];
64 } else if(argv[i][0] == '-') {
65 std::cerr << "Unknown option '" << argv[i] << "'.\n";
71 if(inputfile == "" || outputcpp == "" || outputhpp == "") {
72 std::cerr << "Not all options specified.\n";
78 input = new std::ifstream(inputfile.c_str());
80 std::cerr << "Couldn't open file '" << input << "' for reading.\n";
83 unit = new CompilationUnit();
84 Namespace* std_namespace = new Namespace();
85 std_namespace->name = "std";
86 std_namespace->types.push_back(new StringType());
87 unit->namespaces.push_back(std_namespace);
88 unit->types.push_back(new HSQUIRRELVMType());
92 std::ofstream cppout(outputcpp.c_str());
94 std::cerr << "Couldn't open file '" << outputcpp << "' for writing.\n";
97 std::ofstream hppout(outputhpp.c_str());
99 std::cerr << "Couldn't open file '" << outputhpp << "' for writing.\n";
103 Namespace* ns = unit;
104 if(selected_namespace != "") {
105 ns = ns->findNamespace(selected_namespace);
108 WrapperCreator creator(cppout, hppout);
109 creator.create_wrapper(ns);
110 } catch(std::exception& e) {
111 std::cerr << e.what() << "\n";