aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--td/generate/remove_documentation.cpp2
-rw-r--r--tdtl/td/tl/tl_file_utils.cpp13
-rw-r--r--tdtl/td/tl/tl_file_utils.h2
-rw-r--r--tdtl/td/tl/tl_generate.cpp13
4 files changed, 15 insertions, 15 deletions
diff --git a/td/generate/remove_documentation.cpp b/td/generate/remove_documentation.cpp
index 7e4651414..f6cb017e6 100644
--- a/td/generate/remove_documentation.cpp
+++ b/td/generate/remove_documentation.cpp
@@ -15,7 +15,7 @@ int main(int argc, char *argv[]) {
std::string file_name = argv[i];
std::string old_contents = td::tl::get_file_contents(file_name);
std::string new_contents = td::tl::remove_documentation(old_contents);
- if (new_contents != old_contents && !td::tl::put_file_contents(file_name, new_contents)) {
+ if (!td::tl::put_file_contents(file_name, new_contents, true)) {
std::fprintf(stderr, "Can't write file %s\n", file_name.c_str());
std::abort();
}
diff --git a/tdtl/td/tl/tl_file_utils.cpp b/tdtl/td/tl/tl_file_utils.cpp
index 91c859d03..a78f8d29f 100644
--- a/tdtl/td/tl/tl_file_utils.cpp
+++ b/tdtl/td/tl/tl_file_utils.cpp
@@ -44,7 +44,18 @@ std::string get_file_contents(const std::string &file_name) {
return result;
}
-bool put_file_contents(const std::string &file_name, const std::string &contents) {
+bool put_file_contents(const std::string &file_name, const std::string &contents, bool compare_documentation) {
+ std::string old_file_contents = get_file_contents(file_name);
+ if (!compare_documentation) {
+ old_file_contents = remove_documentation(old_file_contents);
+ }
+
+ if (old_file_contents == contents) {
+ return true;
+ }
+
+ std::fprintf(stderr, "Write file %s\n", file_name.c_str());
+
FILE *f = std::fopen(file_name.c_str(), "wb");
if (f == NULL) {
std::fprintf(stderr, "Can't open file \"%s\"\n", file_name.c_str());
diff --git a/tdtl/td/tl/tl_file_utils.h b/tdtl/td/tl/tl_file_utils.h
index 6d4cc7132..420d26948 100644
--- a/tdtl/td/tl/tl_file_utils.h
+++ b/tdtl/td/tl/tl_file_utils.h
@@ -13,7 +13,7 @@ namespace tl {
std::string get_file_contents(const std::string &file_name);
-bool put_file_contents(const std::string &file_name, const std::string &contents);
+bool put_file_contents(const std::string &file_name, const std::string &contents, bool compare_documentation);
std::string remove_documentation(const std::string &str);
diff --git a/tdtl/td/tl/tl_generate.cpp b/tdtl/td/tl/tl_generate.cpp
index 62345df79..5222dd318 100644
--- a/tdtl/td/tl/tl_generate.cpp
+++ b/tdtl/td/tl/tl_generate.cpp
@@ -883,18 +883,7 @@ tl_config read_tl_config_from_file(const std::string &file_name) {
bool write_tl_to_file(const tl_config &config, const std::string &file_name, const TL_writer &w) {
tl_string_outputer out;
write_tl(config, out, w);
-
- std::string old_file_contents = get_file_contents(file_name);
- if (!w.is_documentation_generated()) {
- old_file_contents = remove_documentation(old_file_contents);
- }
-
- if (old_file_contents != out.get_result()) {
- std::fprintf(stderr, "Write tl to file %s\n", file_name.c_str());
- return put_file_contents(file_name, out.get_result());
- }
-
- return true;
+ return put_file_contents(file_name, out.get_result(), w.is_documentation_generated());
}
} // namespace tl