From: Jens Thiele Date: Tue, 21 Nov 2006 14:35:21 +0000 (+0000) Subject: copy includes from input file to common_hpp file X-Git-Tag: v0.2~103 X-Git-Url: http://developer.intra2net.com/git/?p=libt2n;a=commitdiff_plain;h=d5b431f83d0e215a590b3ec4df8ef5f212004960 copy includes from input file to common_hpp file --- diff --git a/codegen/codegen-stubhead.hxx b/codegen/codegen-stubhead.hxx index 5c330f3..fa9947f 100644 --- a/codegen/codegen-stubhead.hxx +++ b/codegen/codegen-stubhead.hxx @@ -6,8 +6,6 @@ #include #include #include -#include -#include #include #include diff --git a/codegen/main.cpp b/codegen/main.cpp index a023eaf..f8a2e23 100644 --- a/codegen/main.cpp +++ b/codegen/main.cpp @@ -295,7 +295,6 @@ used_groups(const std::list &funcs) { void output_common_hpp(std::ostream &o, const std::list &procs) { std::set groups(used_groups(procs)); - o << "#include \"codegen-stubhead.hxx\"\n"; for (std::set::iterator it=groups.begin();it!=groups.end();++it) { o << "class cmd_group_" << *it << " : public libt2n::command\n" << "{\n" @@ -476,17 +475,57 @@ struct cpp_file : public std::ofstream } }; +std::list +get_includes(const std::string &fname) +{ + // grep "#include" fname + std::ifstream in(fname.c_str()); + std::string line; + std::list ret; + while (std::getline(in,line)) { + if (line.find("#include")!=std::string::npos) + ret.push_back(line); + } + return ret; +} + +void +paste_includes(std::ostream &o, std::list &i) +{ + o << std::endl + << "// copied includes begin" << std::endl; + for (std::list::const_iterator it=i.begin(); it!=i.end(); ++it) + o << *it << std::endl; + o << "// copied includes end" << std::endl + << std::endl; +} + +struct RemoveGenerated +{ + RemoveGenerated(const std::string &_prefix) : prefix(_prefix) {} + bool operator()(const std::string &s) const { + return (s.find(prefix+"common.hxx")!=std::string::npos); + } + const std::string &prefix; +}; + int main(int argc, char* argv[]) { - if (argc != 3) { - std::cerr << "Usage: " << argv[0] << " gccxml-file outputprefix" << std::endl; + if (argc != 4) { + std::cerr << "Usage: " << argv[0] << " header-file gccxml-file outputprefix" << std::endl; return 1; } - std::string filepath(argv[1]); - std::string prefix(argv[2]); + std::string headerfile(argv[1]); + std::string xmlfile(argv[2]); + std::string prefix(argv[3]); + std::list includes(get_includes(headerfile)); + remove_if(includes.begin(), includes.end(), RemoveGenerated(prefix)); + includes.erase(remove_if(includes.begin(), includes.end(), RemoveGenerated(prefix)), includes.end()); + + paste_includes(std::cerr, includes); - Parser parser(filepath); + Parser parser(xmlfile); std::list procedures(parser.get_procedures()); std::cerr << "Procedures:" << std::endl; @@ -505,12 +544,18 @@ main(int argc, char* argv[]) std::string server_cpp_fname(prefix+"server.cpp"); header_file common_hpp(common_hpp_fname.c_str()); + common_hpp << "#include \"codegen-stubhead.hxx\"\n"; + paste_includes(common_hpp, includes); + output_common_hpp(common_hpp, procedures); cpp_file common_cpp(common_cpp_fname.c_str()); output_common_cpp(common_cpp, procedures, common_hpp_fname); header_file client_hpp(client_hpp_fname.c_str()); + // we can't paste the includes before codegen-stubhead.hxx was included + // but we also do not want to include codegen-stubhead.hxx in this file + // paste_includes(client_hpp, includes); output_client_hpp(client_hpp, procedures); cpp_file client_cpp(client_cpp_fname.c_str());