From d1729690f5910314a143770ba325101bb651041d Mon Sep 17 00:00:00 2001 From: foryoung365 Date: Fri, 25 Oct 2024 16:16:44 +0800 Subject: [PATCH 1/2] fix header search issue --- simplecpp.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/simplecpp.cpp b/simplecpp.cpp index 67e59abb..cfa7eb65 100755 --- a/simplecpp.cpp +++ b/simplecpp.cpp @@ -3123,6 +3123,24 @@ static std::string openHeader(std::ifstream &f, const simplecpp::DUI &dui, const return ret; } +static bool IsFileExists(const std::string& simplePath) +{ + if (simplePath.empty()) + { + return false; + } + + // This is a workaround to properly check if a file exists, + // since std::ifstream::good() incorrectly returns true for directories + std::fstream fs(simplePath, std::ios::app); + if (fs.good()) + { + return true; + } + + return false; +} + static std::string getFileName(const std::map &filedata, const std::string &sourcefile, const std::string &header, const simplecpp::DUI &dui, bool systemheader) { if (filedata.empty()) { @@ -3136,6 +3154,13 @@ static std::string getFileName(const std::map::const_iterator it = dui.includePaths.begin(); it != dui.includePaths.end(); ++it) { From c14e2b16882118d415815b5fda046c579a3f74ff Mon Sep 17 00:00:00 2001 From: foryoung365 Date: Mon, 28 Oct 2024 15:29:53 +0800 Subject: [PATCH 2/2] use ios::in | ios::out instead --- simplecpp.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/simplecpp.cpp b/simplecpp.cpp index cfa7eb65..f78200e9 100755 --- a/simplecpp.cpp +++ b/simplecpp.cpp @@ -3125,20 +3125,20 @@ static std::string openHeader(std::ifstream &f, const simplecpp::DUI &dui, const static bool IsFileExists(const std::string& simplePath) { - if (simplePath.empty()) - { - return false; - } + if (simplePath.empty()) + { + return false; + } - // This is a workaround to properly check if a file exists, + // This is a workaround to properly check if a file exists, // since std::ifstream::good() incorrectly returns true for directories - std::fstream fs(simplePath, std::ios::app); - if (fs.good()) - { - return true; - } + std::fstream fs(simplePath, std::ios::in | std::ios::out); + if (fs.good()) + { + return true; + } - return false; + return false; } static std::string getFileName(const std::map &filedata, const std::string &sourcefile, const std::string &header, const simplecpp::DUI &dui, bool systemheader)