-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
70 lines (63 loc) · 1.56 KB
/
main.cpp
File metadata and controls
70 lines (63 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <iostream>
#include <fstream>
#include <map>
#include <string>
using namespace std;
map<string,string> dict;
string deal(string inp){
while (inp.find("$(") != string::npos){
int i = inp.find("$(") + 2;
int j = inp.find(')') - 1;
string ident = inp.substr(i, j-i+1);
if (dict.find(ident) != dict.end())
inp.replace(i-2, ident.length() + 3, dict[ident]);
else return "";
}
return inp;
}
void print(int depth){
for (int i=0;i<depth;i++)
cout<<" ";
cout<<"|-";
}
void dfs(string cur, int depth){
ifstream ff;
ff.open(cur.c_str());
if (!ff){
print(depth);
cout<<"Not found: "<<cur<<endl;
return;
}
map<string,int> flag;
char st[1024];
while (ff.getline(st,1024)){
string str(st);
if (str.substr(0,7) == "include"){
string next = deal(str.substr(8));
if (flag.find(str) == flag.end()){
print(depth);
flag[str] = 1;
if (next.length() > 0){
cout<<next<<endl;
dfs(deal(next),depth+1);
}else
cout<<"Not Found: "<<str<<endl;
}
}
}
ff.close();
}
int main(int argc, char **argv, char** envp){
char** env;
for (env=envp;*env!=0;env++){
char* thisEnv = *env;
string str(thisEnv);
int i = str.find('=');
if (i != string::npos)
dict[str.substr(0,i)] = str.substr(i+1);
}
dict["TOPDIR"] = "";
dict["BUILD_SYSTEM"] = "build/core";
cout<<"|-Makefile"<<endl;
dfs("Makefile",1);
}