-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerator.cpp
99 lines (84 loc) · 2.24 KB
/
generator.cpp
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
#include<iostream>
#include<fstream>
#include<ctime>
#include<string>
using namespace std;
const string OUT_DIR = "outputs";
const string INP_DIR = "codes";
const string MAPPER_FILE_NAME = "mapper.txt";
ofstream outFile;
long fileNumber=0,dirNumber=0,errorNumber=0;
string get_file_name(){
return "CODES_LIST.cpp";
}
void dumpFileContents(string dirName, string fileName){
if(fileName.length()<0){
return ;
}
string filePath;
if(dirName.length()>0){
filePath=dirName + "\\" + fileName;
}
else{
filePath= ".\\" + fileName;
}
cout<<"\tDUMPING FILE("<<(++fileNumber)<<"): "<<filePath<<endl;
ifstream codeFile;
codeFile.open(filePath);
if(codeFile != NULL){
outFile<<"// __________________________"<<endl<<endl;
outFile<<"// "<<filePath<<endl;
string contents;
while(!codeFile.eof()){
getline(codeFile,contents);
outFile<<contents<<endl;
}
outFile<<"// __________________________"<<endl<<endl<<endl<<endl;
}
else{
errorNumber++;
cout<<"ERROR: opening file : "<<filePath<<endl;
}
}
void recurseProcessDirectory(string dirName){
if(dirName.length()>0){
ifstream dirMapper;
dirMapper.open(dirName + "\\" + MAPPER_FILE_NAME);
if(dirMapper==NULL){
errorNumber++;
cout<<"ERROR: failed to find mapper file at : "+dirName<<endl;
}
else{
cout<<"Processing directory("<<(++dirNumber)<<"): "<<dirName<<endl;
string entityName;
while(!dirMapper.eof()){
getline(dirMapper,entityName);
if(entityName.length()<=0) continue;
if(entityName.find(".")>=0 && entityName.find(".")<entityName.length()){
dumpFileContents(dirName,entityName);
}
else{
recurseProcessDirectory(dirName + "\\" + entityName);
}
}
dirMapper.close();
}
}
}
int main(){
string filename=get_file_name();
cout<<"output at file : "<<filename<<endl;
string outputPath=".\\" + OUT_DIR + "\\" + filename;
outFile.open(outputPath);
if(outFile != NULL){
recurseProcessDirectory(".\\" + INP_DIR);
outFile.close();
cout<<endl<<"Writing Completed !"<<endl;
}
else{
cout<<"Error opening file : "<<outputPath<<endl;
cout<<endl<<"Program failed!"<<endl;
}
cout<<errorNumber<<" errors ."<<endl<<dirNumber<<" directorie(s) and "<<fileNumber<<" file(s) processed."<<endl;
return 0;
}