Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
include.cc
Go to the documentation of this file.
1
2#include <string>
3#include <iostream>
4#include <iomanip>
5#include <fstream>
6#include <cstdlib>
7
8#include "Jeep/JParser.hh"
9#include "Jeep/JMessage.hh"
10
11namespace {
12
13 /**
14 * Jpp top-level directory.
15 */
16 static const std::string JPP_DIR = getenv("JPP_DIR");
17
18
19 /**
20 * Look for specified target in given file name.
21 *
22 * \param file_name file name
23 * \param target target
24 * \param path path
25 */
26 inline void include(const std::string& file_name, const std::string& target, const std::string& path = "")
27 {
28 using namespace std;
29
30 ifstream in(file_name.c_str());
31
32 if (!in) {
33 //cerr << "Error opening: " << file_name << endl;
34 }
35
36 for (string buffer; getline(in, buffer); ) {
37
38 const string::size_type ipos = buffer.find("\"");
39
40 if (buffer.find("#include") == 0 && ipos != string::npos) {
41
42 const string source = buffer.substr(ipos + 1, buffer.length() - ipos - 2);
43
44 if (source.find(target) != string::npos) {
45 cout << ((path.empty() ? file_name : path) + " -> " + source) << endl;
46 break;
47 }
48
49 include(JPP_DIR + "/software/" + source, target, ((path.empty() ? file_name : path) + " -> " + source));
50 }
51 }
52
53 in.close();
54 }
55}
56
57
58/**
59 * \file
60 * Auxiliary program to check for include file within Jpp repository.
61 * \author mdejong
62 */
63int main(int argc, char **argv)
64{
65 using namespace std;
66
67 string source;
68 string target;
69 int debug;
70
71 try {
72
73 JParser<> zap("Auxiliary program to recursively check for include file in Jpp repository.");
74
75 zap['f'] = make_field(source, "name of source file to be inspected");
76 zap['i'] = make_field(target, "name of include file to be searched");
77 zap['d'] = make_field(debug) = 1;
78
79 if (zap.read(argc, argv) != 0)
80 return 1;
81 }
82 catch(const exception& error) {
83 FATAL(error.what() << endl);
84 }
85
86 DEBUG("JPP_DIR" << ' ' << JPP_DIR << endl);
87
88 include(source, target);
89}
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Utility class to parse command line options.
Definition JParser.hh:1698
int read(const int argc, const char *const argv[])
Parse the program's command line options.
Definition JParser.hh:1992
int main(int argc, char **argv)
Definition include.cc:63
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition JString.hh:478