-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
80 lines (60 loc) · 2.39 KB
/
main.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
#include "fileutil.hpp"
// https://github.com/Nettention/ChangeIncludeHeaderBackslashToSlash
int main(int argc, char *argv[]) {
if (argc != 3) {
std::cout << R"(Changes #include "..\aa.h" to #include "../aa.h".)"
<< std::endl
<< R"(Args example: msfa work/MySourceFolder cpp,h,inl)"
<< std::endl;
} else {
try {
std::vector<std::string> fileExts = collectFileExts(argv[2]);
// Find all cpp, h file in the specified folder.
std::vector<std::string> sourceFiles = collectFiles(argv[1], fileExts);
std::vector<std::string> changedFiles;
std::vector<std::string> unchangedFiles;
std::vector<std::string> erroredFiles;
std::string includeLine = "#include";
for (auto const& sourceFile : sourceFiles) {
// if an individual file fail just go to the next file
try {
std::ifstream infile{sourceFile};
std::stringstream sourceLines({ist{infile}, ist{}});
bool changed = false;
std::string line;
// std::cout << sourceLines.str() << endl;
std::stringstream newSourceLines;
while (std::getline(sourceLines, line)) {
// std::istringstream iss(line);
line = getChangedOrNotSourceLine(line, changed);
newSourceLines << line << std::endl;
// std::cout << line << endl;
}
infile.close();
if (changed) {
std::ofstream outfile;
outfile.open(sourceFile);
// std::cout << newSourceLines.str() << endl;
// outfile << newSourceLines.rdbuf();
outfile << newSourceLines.str();
outfile.close();
changedFiles.push_back(sourceFile);
} else {
unchangedFiles.push_back(sourceFile);
}
} catch (const std::exception &e) {
std::cout << " a standard exception was caught, with message '"
<< e.what() << "'\n";
erroredFiles.push_back(sourceFile);
}
}
std::cout << unchangedFiles.size() << " files are skipped. "
<< changedFiles.size() << " files are updated. "
<< erroredFiles.size() << " files are in error.\n";
} catch (const std::exception &e) {
std::cout << " a standard exception was caught, with message '"
<< e.what() << "'\n";
}
}
return 0;
}