-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstrip.cpp
More file actions
39 lines (31 loc) · 1.04 KB
/
strip.cpp
File metadata and controls
39 lines (31 loc) · 1.04 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
#include <cstdio>
#include <filesystem>
#include <string>
#include <cstring>
int main() {
// In generated code, one line should not exceed 1023 chars.
char line[1024];
for (const auto& f : std::filesystem::recursive_directory_iterator("output")) {
if (f.is_directory())
continue;
auto fileName = f.path().string();
FILE* fIn = std::fopen(fileName.c_str(), "rb");
if (!fIn) {
std::printf("Cannot open to read: %s\n", fileName.c_str());
continue;
}
std::string content;
for (; std::fscanf(fIn, "%[^\n]", line) > 0; std::fscanf(fIn, "%[\n]", line)) {
if (std::strstr(line, "this file cannot be executed directly") || std::strlen(line) == 0)
continue;
content += line;
content.push_back('\n');
}
std::fclose(fIn);
FILE* fOut = std::fopen(fileName.c_str(), "wb");
auto written = std::fwrite((const void*)(content.c_str()), sizeof(char), content.length(), fOut);
std::printf("%s expected to write %zd bytes, %zd bytes written\n", fileName.c_str(), content.length(), written);
std::fclose(fOut);
}
return 0;
}