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