yadro-task/bin/ftsort/tape_config.h

79 lines
2.6 KiB
C
Raw Permalink Normal View History

#ifndef TAPE_CONFIG_H
#define TAPE_CONFIG_H
#include "tapelib/filetape.h"
#include <cstddef>
#include <string>
// stringizing opearator to convert macro into string literal
#define xstr(s) str(s)
#define str(s) #s
const static std::string HELP_MSG =
"Usage: ftsort [OPTIONS...] INPUT_FILE OUTPUT_FILE\n"
"Sorts a Tape provided by the INPUT_FILE into the OUTPUT_FILE\n\n"
"Options:\n"
"-w, --write-delay VALUE\t\t\t"
"Sets the delay of write operations to VALUE milliseconds\n"
"-r, --read-delay VALUE\t\t\t"
"Sets the delay of read operations to VALUE milliseconds\n"
"-f, --seek-forward-delay VALUE\t\t"
"Sets the delay of seeking forward operations to VALUE milliseconds\n"
"-b, --seek-backwards-delay VALUE\t"
"Sets the delay of seeking backwards operations to VALUE milliseconds\n"
"-m, --memory-limit VALUE\t\t"
"Sets the amount of cells that the program can store in its memory during "
"sorting to VALUE\n"
"-c, --config-file FILE\t\t\t"
"Applies options from the FILE, config shoud be a simple KEY=VALUE list\n"
"-v, --version\t\t\t\t"
"Print out version of the program\n"
"-h, --help\t\t\t\t"
"Print help message\n\n"
"Exmaple of valid input Tape file with values 1, 1234 and 2222222222:\n\n"
"0000000001\n"
"0000001234\n"
"2222222222\n\n"
"Example of a valid config file:\n\n"
"write-delay=100\n"
"read-delay=100\n"
"seek-forward-delay=100\n"
"seek-backwards-delay=100\n"
"memory-limit=1024\n";
const static std::string VERSION_MSG = "ftsort ver. " xstr(VERSION);
2024-10-27 15:53:34 +00:00
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;
2024-10-27 15:53:34 +00:00
tape::FileTapeSettings ft_settings;
};
/**
* Parses command line arguments (from main) and creates an instance of
* AppSettings from them
*
* @param argc Args count from main
* @param argv Args array from main
* @return Instance of AppSettings filled with values from command line
*/
2024-10-27 15:53:34 +00:00
AppSettings parse_command_line(int argc, char **argv);
/**
* Accepts AppSettings prefilled with settings from command line, tries to open
* the file specified in the config_file_path field and reads values from the
* supplied config files into provided AppSettings, overwriting the settings.
*
* @param settings AppSettings, values of which will be overwritten by configs
* values
* @return true, if config file was opened and read successfully, otherwise
* false
*/
bool read_settings_from_file(AppSettings &settings);
#endif // !TAPE_CONFIG_H