From b793919567fb834a38b5672b7c5554464b4b3605 Mon Sep 17 00:00:00 2001 From: firewave Date: Wed, 11 Jun 2025 12:40:46 +0200 Subject: [PATCH 1/2] main.cpp: replaced `std::exit()` with `return` --- main.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/main.cpp b/main.cpp index f05cf793..1f6b0419 100644 --- a/main.cpp +++ b/main.cpp @@ -77,18 +77,18 @@ int main(int argc, char **argv) } } else if (filename) { std::cout << "error: multiple filenames specified" << std::endl; - std::exit(1); + return 1; } else { filename = arg; } } if (error) - std::exit(1); + return 1; if (quiet && error_only) { std::cout << "error: -e cannot be used in conjunction with -q" << std::endl; - std::exit(1); + return 1; } if (!filename) { @@ -102,7 +102,7 @@ int main(int argc, char **argv) std::cout << " -q Quiet mode (no output)." << std::endl; std::cout << " -is Use std::istream interface." << std::endl; std::cout << " -e Output errors only." << std::endl; - std::exit(0); + return 0; } dui.removeComments = true; @@ -115,7 +115,7 @@ int main(int argc, char **argv) std::ifstream f(filename); if (!f.is_open()) { std::cout << "error: could not open file '" << filename << "'" << std::endl; - std::exit(1); + return 1; } rawtokens = new simplecpp::TokenList(f, files,filename,&outputList); } else { From 16665fda3e98681e9786c76e4dd2e62bb159fd0f Mon Sep 17 00:00:00 2001 From: firewave Date: Wed, 11 Jun 2025 12:42:01 +0200 Subject: [PATCH 2/2] main.cpp: error out when file/path provided by `-I` or `-include=` do not exist --- main.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/main.cpp b/main.cpp index 1f6b0419..3e664272 100644 --- a/main.cpp +++ b/main.cpp @@ -91,6 +91,33 @@ int main(int argc, char **argv) return 1; } + // TODO: move this logic into simplecpp? + { + bool inc_missing = false; + for (const std::string& inc : dui.includes) { + std::ifstream f(inc); + if (!f.is_open()) { + inc_missing = true; + std::cout << "error: could not open include '" << inc << "'" << std::endl; + } + } + if (inc_missing) + return 1; + } + { + bool inc_missing = false; + for (const std::string& inc : dui.includePaths) { + // TODO: check if this is a directory + std::ifstream f(inc); + if (!f.is_open()) { + inc_missing = true; + std::cout << "error: could not find include path '" << inc << "'" << std::endl; + } + } + if (inc_missing) + return 1; + } + if (!filename) { std::cout << "Syntax:" << std::endl; std::cout << "simplecpp [options] filename" << std::endl;