-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcpFile.cpp
More file actions
142 lines (115 loc) · 3.41 KB
/
cpFile.cpp
File metadata and controls
142 lines (115 loc) · 3.41 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# include <iostream>
# include <string>
# include <fstream>
# include <cstring>
# include <set>
using namespace std;
std::string saveFileName="allFileName.txt";
char notUsedFile[]="plugHead.h";
set<string> st;
int Copy(const string a, const string b);
void CopyFile(const string &file, const string &filePath){
std::string fileName;
char fileBuffer[81];
ofstream osfn;
ofstream outputFile;
ifstream inputHeadFile;
// int count = 1;
// int fileSize = file.size();
/*while(count <= (fileSize - 2)){
fileName = fileName + file[count];
count++;
}*/
fileName = file;
if(strcmp(fileName.c_str(),"") != 0){
inputHeadFile.open(fileName.c_str(), ios::in);
if(inputHeadFile.fail()){
cout << " headFile: " << fileName << " Open fail" << endl;
return ;
}
}
osfn.open(saveFileName.c_str(), ios::app);
if(osfn.fail()){
cout << saveFileName << "Open fail" << endl;
return ;
}
cout << " headFile:" << fileName << " Open success" << endl;
if(!st.count(fileName)){
if(strcmp(fileName.c_str(),notUsedFile) != 0){
st.insert(fileName);
osfn << fileName << endl;
cout<<"osfn:"<<fileName<<endl;
fileName = filePath + fileName;
outputFile.open(fileName.c_str(), ios::out);
if(outputFile.fail()){
cout << fileName << "Open fail" << endl;
return ;
}
//inputHeadFile.getline(fileBuffer,81);
std::string fb;
while(std::getline(inputHeadFile,fb)){
outputFile<<fb<<endl;
}
/*while(!inputHeadFile.eof()){
outputFile << fileBuffer << "\n";
inputHeadFile.getline(fileBuffer,81);
}
outputFile << fileBuffer << "\n";
*/
inputHeadFile.close();
outputFile.close();
osfn.close();
cout << fileName << " " << filePath << endl;
Copy(fileName, filePath);
}
}else{
inputHeadFile.close();
outputFile.close();
osfn.close();
}
}
int Copy(const string copiedFileName, const string filePath){
ifstream inputFile;
string fileBuffer;
inputFile.open(copiedFileName.c_str(), ios::in);
if(inputFile.fail()){
cout << copiedFileName << " open fail" << endl;
return 0;
}
while(getline(inputFile,fileBuffer)){
if(fileBuffer.find("#include") != string::npos ||
(fileBuffer.find("#") != string::npos && fileBuffer.find("include") != string::npos) ){
size_t ext = fileBuffer.find("\"");
char strFb[128];
char buf[128];
memset(strFb,0,sizeof(strFb));
if(ext != string::npos){
cout<<"find:ext="<<ext<<" "<<fileBuffer.c_str()+ext<<endl;
sscanf(fileBuffer.c_str()+ext,"%s",strFb);
strFb[strlen(strFb)-1] = '\0';
cout<<"strFb:"<<strFb<<endl;
std::string fb = strFb+1;
CopyFile(fb, filePath);
}
}
}
inputFile.close();
return 0;
}
int main(int argv,char **argc){
if(argv != 2){
cout << "Usage:./cpFile <mainfileName>.c"<<endl;
return -1;
}
string filePath;
ofstream osfn;
osfn.open(saveFileName.c_str(),ios::out);
if(osfn.fail()){
cout << saveFileName << "Open fail" << endl;
return -1;
}
osfn.close();
filePath = "./CopyHeadFile/";
Copy(argc[1], filePath);
return 0;
}