#include #include #include #include #include #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" namespace { /** * Jpp top-level directory. */ static const std::string JPP_DIR = getenv("JPP_DIR"); /** * Look for specified target in given file name. * * \param file_name file name * \param target target * \param path path */ inline void include(const std::string& file_name, const std::string& target, const std::string& path = "") { using namespace std; ifstream in(file_name.c_str()); if (!in) { //cerr << "Error opening: " << file_name << endl; } for (string buffer; getline(in, buffer); ) { const string::size_type ipos = buffer.find("\""); if (buffer.find("#include") == 0 && ipos != string::npos) { const string source = buffer.substr(ipos + 1, buffer.length() - ipos - 2); if (source.find(target) != string::npos) { cout << ((path.empty() ? file_name : path) + " -> " + source) << endl; break; } include(JPP_DIR + "/software/" + source, target, ((path.empty() ? file_name : path) + " -> " + source)); } } in.close(); } } /** * \file * Auxiliary program to check for include file within Jpp repository. * \author mdejong */ int main(int argc, char **argv) { using namespace std; string source; string target; int debug; try { JParser<> zap("Auxiliary program to recursively check for include file in Jpp repository."); zap['f'] = make_field(source, "name of source file to be inspected"); zap['i'] = make_field(target, "name of include file to be searched"); zap['d'] = make_field(debug) = 1; if (zap.read(argc, argv) != 0) return 1; } catch(const exception& error) { FATAL(error.what() << endl); } DEBUG("JPP_DIR" << ' ' << JPP_DIR << endl); include(source, target); }