From 34399b9b93d8f4864381fa554e25ff55bea916fd Mon Sep 17 00:00:00 2001 From: Phuntsok Drak-pa Date: Wed, 23 May 2018 16:27:54 +0200 Subject: [PATCH] some style improvement --- src/common.cc | 5 +++-- src/compress.cc | 7 ++++--- src/main.cc | 6 +++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/common.cc b/src/common.cc index 222d42b..8c7a98d 100644 --- a/src/common.cc +++ b/src/common.cc @@ -30,10 +30,11 @@ using dic_t = std::map, uint32_t>; const std::pair dico(std::map, uint32_t> &t_dictionary, uint32_t t_nr_chaine, uint8_t t_c) { - if (t_nr_chaine == 0xFFFF) + if (t_nr_chaine == 0xFFFF) { return std::make_pair(true, t_c); + } auto &e = t_dictionary[std::make_pair(t_nr_chaine, t_c)]; - return (e) ? std::make_pair(true, e) + return (e != 0) ? std::make_pair(true, e) : std::make_pair( false, (e = static_cast< diff --git a/src/compress.cc b/src/compress.cc index 87e3f63..a477beb 100644 --- a/src/compress.cc +++ b/src/compress.cc @@ -92,8 +92,8 @@ void compress(const std::string &t_in_file, const char *t_out_file) { // Fichier de sortie FILE *out = - (t_out_file) ? fopen(t_out_file, "wb") : fopen("output.lzw", "wb"); - if (!out) { + (t_out_file != nullptr) ? fopen(t_out_file, "wb") : fopen("output.lzw", "wb"); + if (out == nullptr) { std::cerr << "Error at " << __FILE__ << ":" << __LINE__ - 4 << ": could not open output file. Aborting...\n"; input_file.close(); @@ -132,8 +132,9 @@ void compress(const std::string &t_in_file, const char *t_out_file) { chunk.reserve(static_cast(input_file.tellg() - prev_pos)); input_file.seekg(prev_pos, std::ios::beg); std::istreambuf_iterator itr(input_file); - for (std::streamoff i = 0; i < prev_pos; ++i, ++itr) + for (std::streamoff i = 0; i < prev_pos; ++i, ++itr){ ; + } chunk.assign((itr), std::istreambuf_iterator()); } uvec ret{}; diff --git a/src/main.cc b/src/main.cc index 9afc659..9deab8e 100644 --- a/src/main.cc +++ b/src/main.cc @@ -54,7 +54,6 @@ void help() { } int main(int argc, char *argv[]) { - if constexpr (debug_mode) { for (int i = 0; i < argc; ++i) printf("argv[%d] = %s\n", i, argv[i]); @@ -151,7 +150,7 @@ int main(int argc, char *argv[]) { if constexpr (debug_mode) { puts("Beginning compression"); } - if(output_path.empty()) { + if (output_path.empty()) { compress(input_path, nullptr); } else { compress(input_path, output_path.c_str()); @@ -160,7 +159,8 @@ int main(int argc, char *argv[]) { } else { puts("Not yet implemented :("); /* - Inversion des types du dictionnaire pour retrouver les chaînes plus aisément + Inversion des types du dictionnaire pour retrouver les chaînes plus + aisément */ }