From d7bcbbfd0861a424c0cad4cd1f4cfa8517d5b9e0 Mon Sep 17 00:00:00 2001 From: erius Date: Sun, 27 Oct 2024 18:53:34 +0300 Subject: [PATCH] Renamed CmdArgs to AppSettings --- bin/ftsort/ftsort.cpp | 16 ++++++++-------- bin/ftsort/tape_config.cpp | 32 ++++++++++++++++---------------- bin/ftsort/tape_config.h | 8 +++++--- 3 files changed, 29 insertions(+), 27 deletions(-) diff --git a/bin/ftsort/ftsort.cpp b/bin/ftsort/ftsort.cpp index 21dd251..d6c8b94 100644 --- a/bin/ftsort/ftsort.cpp +++ b/bin/ftsort/ftsort.cpp @@ -1,26 +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) { + AppSettings settings = parse_command_line(argc, argv); + if (settings.version) { std::cout << VERSION_MSG << std::endl; return 0; } - if (cmd.help) { + if (settings.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); + tape::FileTape input(settings.input_file_name, settings.ft_settings); + tape::FileTape output(input, settings.output_file_name, + settings.ft_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::FileTape(cells, settings.ft_settings)); }; - tape::external_sort(input, output, factory, cmd.memory_limit); + tape::external_sort(input, output, factory, settings.memory_limit); return 0; } diff --git a/bin/ftsort/tape_config.cpp b/bin/ftsort/tape_config.cpp index 983c5d2..d8870d2 100644 --- a/bin/ftsort/tape_config.cpp +++ b/bin/ftsort/tape_config.cpp @@ -33,15 +33,15 @@ std::chrono::milliseconds parse_delay(const std::string &input) { return std::chrono::milliseconds(delay_ms); } -CmdArgs parse_command_line(int argc, char **argv) { - CmdArgs cmd{ +AppSettings parse_command_line(int argc, char **argv) { + AppSettings settings{ .config_file_path = "", .input_file_name = "", .output_file_name = "", .memory_limit = SIZE_MAX, .version = false, .help = false, - .settings = tape::FT_DEFAULT_SETTINGS, + .ft_settings = tape::FT_DEFAULT_SETTINGS, }; int opt_index = 0; int opt = 0; @@ -50,40 +50,40 @@ CmdArgs parse_command_line(int argc, char **argv) { &opt_index)) != -1) { switch (opt) { case 'r': - cmd.settings.read_delay = parse_delay(optarg); + settings.ft_settings.read_delay = parse_delay(optarg); break; case 'w': - cmd.settings.write_delay = parse_delay(optarg); + settings.ft_settings.write_delay = parse_delay(optarg); break; case 'f': - cmd.settings.seek_forward_delay = parse_delay(optarg); + settings.ft_settings.seek_forward_delay = parse_delay(optarg); break; case 'b': - cmd.settings.seek_backwards_delay = parse_delay(optarg); + settings.ft_settings.seek_backwards_delay = parse_delay(optarg); break; case 'm': - cmd.memory_limit = std::stoi(optarg); + settings.memory_limit = std::stoi(optarg); break; case 'c': - cmd.config_file_path = optarg; + settings.config_file_path = optarg; break; case 'v': - cmd.version = true; + settings.version = true; break; case 'h': case '?': default: - cmd.help = true; + settings.help = true; break; } } // parse positional args INPUT_FILE OUTPUT_FILE if (argc - optind < 2) { - cmd.help = true; - return cmd; + settings.help = true; + return settings; } // no linting to disable pointer arithmetic warning - cmd.input_file_name = argv[optind]; // NOLINT - cmd.output_file_name = argv[optind + 1]; // NOLINT - return cmd; + settings.input_file_name = argv[optind]; // NOLINT + settings.output_file_name = argv[optind + 1]; // NOLINT + return settings; } diff --git a/bin/ftsort/tape_config.h b/bin/ftsort/tape_config.h index fd5f95b..def0d3c 100644 --- a/bin/ftsort/tape_config.h +++ b/bin/ftsort/tape_config.h @@ -41,16 +41,18 @@ const static std::string HELP_MSG = const static std::string VERSION_MSG = "ftsort ver. " xstr(VERSION); -struct CmdArgs { +struct AppSettings { std::string config_file_path; std::string input_file_name; std::string output_file_name; size_t memory_limit; bool version; bool help; - tape::FileTapeSettings settings; + tape::FileTapeSettings ft_settings; }; -CmdArgs parse_command_line(int argc, char **argv); +AppSettings parse_command_line(int argc, char **argv); + +void read_settings_from_file(AppSettings &settings); #endif // !TAPE_CONFIG_H