From 44479895f325cbbc283553dcb10b29a0af3b480b Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 4 May 2024 14:43:48 +0200 Subject: Added yscan --- yscan.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 yscan.cpp (limited to 'yscan.cpp') diff --git a/yscan.cpp b/yscan.cpp new file mode 100644 index 0000000..8dad6bf --- /dev/null +++ b/yscan.cpp @@ -0,0 +1,55 @@ +#include "yscan.h" + +#include "file.h" + +#include +#include +#include + +#include + +#include + +namespace fs = std::filesystem; +using namespace std::string_literals; + +int yscan(int argc, char* argv[]) +{ + try { + std::string name {fs::current_path().stem().string()}; + + std::string sources; + std::string test_sources; + for (const auto& i: fs::directory_iterator(".")) { + fs::path p{i.path().filename()}; + if (is_compile_unit_source_by_extension(p)) { + if (p.string().substr(0, 4) == "test") { + test_sources += " " + p.string() + "\n"; + } else { + sources += " " + p.string() + "\n"; + } + } + } + + if (!test_sources.empty()) { + test_sources = fmt::format(R"( + {} +{} +)", "test-"s + name, test_sources); + } + + std::string contents {R"( + + {} +{} +{} +)"}; + contents = fmt::format(contents, name, sources, test_sources); + std::cout << contents << std::endl; + } catch (const std::exception& ex) { + std::cerr << "yscan: " << ex.what() << std::endl; + return 1; + } + return 0; +} + -- cgit v1.2.3