From 8f18f9ef8f9e9431135fc4706c9abffc15be0333 Mon Sep 17 00:00:00 2001 From: erius Date: Sun, 27 Oct 2024 16:17:16 +0300 Subject: [PATCH] Made source files explicitly specified instead of globbing in cmake files Moved ftsort sources to bin/ftsort Moved tape_config.h into bin/ftsort Implemented command line parsing for ftsort in tape_config.cpp ftsort binary is in working state --- bin/CMakeLists.txt | 8 +++- bin/ftsort.cpp | 6 --- bin/ftsort/ftsort.cpp | 26 ++++++++++ bin/ftsort/tape_config.cpp | 89 +++++++++++++++++++++++++++++++++++ bin/ftsort/tape_config.h | 56 ++++++++++++++++++++++ include/tapelib/tape_config.h | 12 ----- src/CMakeLists.txt | 7 +-- src/tape_config.cpp | 16 ------- tests/CMakeLists.txt | 4 +- 9 files changed, 184 insertions(+), 40 deletions(-) delete mode 100644 bin/ftsort.cpp create mode 100644 bin/ftsort/ftsort.cpp create mode 100644 bin/ftsort/tape_config.cpp create mode 100644 bin/ftsort/tape_config.h delete mode 100644 include/tapelib/tape_config.h delete mode 100644 src/tape_config.cpp diff --git a/bin/CMakeLists.txt b/bin/CMakeLists.txt index 5a59aed..12e4339 100644 --- a/bin/CMakeLists.txt +++ b/bin/CMakeLists.txt @@ -1,2 +1,8 @@ -add_executable(ftsort ${PROJECT_SOURCE_DIR}/bin/ftsort.cpp) +add_compile_definitions(VERSION=${PROJECT_VERSION}) + +add_executable(ftsort) +target_sources(ftsort PRIVATE ftsort/ftsort.cpp + ftsort/tape_config.cpp + ftsort/tape_config.h +) target_link_libraries(ftsort PRIVATE tapelib) diff --git a/bin/ftsort.cpp b/bin/ftsort.cpp deleted file mode 100644 index f8dde37..0000000 --- a/bin/ftsort.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int main(int argc, char *argv[]) { - std::cout << "Hello, World!" << std::endl; - return 0; -} diff --git a/bin/ftsort/ftsort.cpp b/bin/ftsort/ftsort.cpp new file mode 100644 index 0000000..21dd251 --- /dev/null +++ b/bin/ftsort/ftsort.cpp @@ -0,0 +1,26 @@ +#include "filetape.h" +#include "tape_config.h" +#include "tape_util.h" +#include + +int main(int argc, char *argv[]) { + CmdArgs cmd = parse_command_line(argc, argv); + if (cmd.version) { + std::cout << VERSION_MSG << std::endl; + return 0; + } + if (cmd.help) { + std::cerr << HELP_MSG << std::endl; + return 0; + } + tape::FileTape input(cmd.input_file_name, cmd.settings); + tape::FileTape output(input, cmd.output_file_name, cmd.settings); + // tmp tape factory that captures cmd.settings from local scope + tape::TempTapeFactory factory = + [&](size_t cells) -> std::unique_ptr { + return std::make_unique( + tape::FileTape(cells, cmd.settings)); + }; + tape::external_sort(input, output, factory, cmd.memory_limit); + return 0; +} diff --git a/bin/ftsort/tape_config.cpp b/bin/ftsort/tape_config.cpp new file mode 100644 index 0000000..983c5d2 --- /dev/null +++ b/bin/ftsort/tape_config.cpp @@ -0,0 +1,89 @@ +#include "tape_config.h" +#include +#include + +const static struct std::vector