void output_common_hpp(std::ostream &o, const std::list<t2n_procedure> &procs) {
std::set<std::string> groups(used_groups(procs));
- o << "#include \"codegen-stubhead.hxx\"\n";
for (std::set<std::string>::iterator it=groups.begin();it!=groups.end();++it) {
o << "class cmd_group_" << *it << " : public libt2n::command\n"
<< "{\n"
}
};
+std::list<std::string>
+get_includes(const std::string &fname)
+{
+ // grep "#include" fname
+ std::ifstream in(fname.c_str());
+ std::string line;
+ std::list<std::string> 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<std::string> &i)
+{
+ o << std::endl
+ << "// copied includes begin" << std::endl;
+ for (std::list<std::string>::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<std::string> 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<t2n_procedure> procedures(parser.get_procedures());
std::cerr << "Procedures:" << std::endl;
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());