Remove explicit mode parameter from tl_file_utils.
This commit is contained in:
parent
29ca948f09
commit
6ce85fdc4f
@ -13,9 +13,9 @@
|
||||
int main(int argc, char *argv[]) {
|
||||
for (int i = 1; i < argc; i++) {
|
||||
std::string file_name = argv[i];
|
||||
std::string old_contents = td::tl::get_file_contents(file_name, "rb");
|
||||
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, "wb", new_contents)) {
|
||||
if (new_contents != old_contents && !td::tl::put_file_contents(file_name, new_contents)) {
|
||||
std::fprintf(stderr, "Can't write file %s\n", file_name.c_str());
|
||||
std::abort();
|
||||
}
|
||||
|
@ -12,8 +12,8 @@
|
||||
namespace td {
|
||||
namespace tl {
|
||||
|
||||
std::string get_file_contents(const std::string &file_name, const std::string &mode) {
|
||||
FILE *f = std::fopen(file_name.c_str(), mode.c_str());
|
||||
std::string get_file_contents(const std::string &file_name) {
|
||||
FILE *f = std::fopen(file_name.c_str(), "rb");
|
||||
if (f == NULL) {
|
||||
return std::string();
|
||||
}
|
||||
@ -44,8 +44,8 @@ std::string get_file_contents(const std::string &file_name, const std::string &m
|
||||
return result;
|
||||
}
|
||||
|
||||
bool put_file_contents(const std::string &file_name, const std::string &mode, const std::string &contents) {
|
||||
FILE *f = std::fopen(file_name.c_str(), mode.c_str());
|
||||
bool put_file_contents(const std::string &file_name, const std::string &contents) {
|
||||
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());
|
||||
return false;
|
||||
|
@ -11,9 +11,9 @@
|
||||
namespace td {
|
||||
namespace tl {
|
||||
|
||||
std::string get_file_contents(const std::string &file_name, const std::string &mode);
|
||||
std::string get_file_contents(const std::string &file_name);
|
||||
|
||||
bool put_file_contents(const std::string &file_name, const std::string &mode, const std::string &contents);
|
||||
bool put_file_contents(const std::string &file_name, const std::string &contents);
|
||||
|
||||
std::string remove_documentation(const std::string &str);
|
||||
|
||||
|
@ -837,7 +837,7 @@ void write_tl(const tl_config &config, tl_outputer &out, const TL_writer &w) {
|
||||
}
|
||||
|
||||
tl_config read_tl_config_from_file(const std::string &file_name) {
|
||||
std::string config = get_file_contents(file_name, "rb");
|
||||
std::string config = get_file_contents(file_name);
|
||||
if (config.empty()) {
|
||||
std::fprintf(stderr, "Config file %s is empty\n", file_name.c_str());
|
||||
std::abort();
|
||||
@ -856,14 +856,14 @@ bool write_tl_to_file(const tl_config &config, const std::string &file_name, con
|
||||
tl_string_outputer out;
|
||||
write_tl(config, out, w);
|
||||
|
||||
std::string old_file_contents = get_file_contents(file_name, "rb");
|
||||
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, "wb", out.get_result());
|
||||
return put_file_contents(file_name, out.get_result());
|
||||
}
|
||||
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user