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 current_file = inputfile;
84 unit = new CompilationUnit();
85 Namespace* std_namespace = new Namespace();
86 std_namespace->name = "std";
87 std_namespace->types.push_back(new StringType());
88 unit->namespaces.push_back(std_namespace);
89 unit->types.push_back(new HSQUIRRELVMType());
93 std::ofstream cppout(outputcpp.c_str());
95 std::cerr << "Couldn't open file '" << outputcpp << "' for writing.\n";
98 std::ofstream hppout(outputhpp.c_str());
100 std::cerr << "Couldn't open file '" << outputhpp << "' for writing.\n";
104 Namespace* ns = unit;
105 if(selected_namespace != "") {
106 ns = ns->findNamespace(selected_namespace);
109 WrapperCreator creator(cppout, hppout);
110 creator.create_wrapper(ns);
111 } catch(std::exception& e) {
112 std::cerr << e.what() << "\n";