MTMS main
Modern Turing Machine Simulator
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1
10#include "../core/project.hpp"
11#include "cli.hpp"
12#include "program.hpp"
13
14#include <cstdlib>
15#include <print>
16
17int main(int argc, char *argv[])
18{
19 if (argc < 2)
20 {
22 return EXIT_FAILURE;
23 }
24
25 Program::Options options;
26 Program::parse_args(argc, argv, options);
27
28 if (options.show_help)
29 {
31 return EXIT_SUCCESS;
32 }
33
34 if (options.err_code != EXIT_SUCCESS)
35 {
36 std::println(stderr, "\033[1;31m[!] {}\033[0m", options.err_msg);
37 return options.err_code;
38 }
39
40 Project project;
41 if (!project.load_project(options.config_file))
42 {
43 std::println(
44 stderr,
45 "\033[1;31m[!] Blueprint compilation or validation failed for: {}\033[0m",
46 options.config_file
47 );
48 return EXIT_FAILURE;
49 }
50
51 auto machine_ptr = project.get_machine();
52 int exit_code = run_cli_session(*machine_ptr, options.input, !options.batch_exec);
53
54 if (exit_code == EXIT_SUCCESS && !options.output_file.empty())
55 {
56 std::println("[-] Exporting current blueprint layout to {}...", options.output_file);
57 if (project.save_project(options.output_file))
58 {
59 std::println("\033[1;32m[*] Project successfully exported to disk.\033[0m");
60 }
61 else
62 {
63 std::println(
64 stderr,
65 "\033[1;31m[!] Serialization pipeline failed to write destination file.\033[0m"
66 );
67 }
68 }
69
70 return exit_code;
71}
Orchestrates configuration ingestion and state saves, abstraction layer bridging core computation wit...
Definition project.hpp:31
bool load_project(const std::filesystem::path &filepath) noexcept(false)
Parses a TM configuration file using toml++ and instantiates the TuringMachine.
Definition project.cpp:265
std::shared_ptr< TuringMachine > get_machine() noexcept
Retrieves the pointer to the active Turing Machine instance.
Definition project.hpp:59
bool save_project(const std::filesystem::path &filepath) const noexcept(false)
Exports the current machine configuration snapshot back to a TOML file.
Definition project.cpp:331
int run_cli_session(TuringMachine &machine, std::string_view input_word, bool interactive)
Executes the simulation via the terminal view layer.
Definition cli.cpp:53
Header definition for the interactive CLI dashboard interface.
int main(int argc, char *argv[])
Definition main.cpp:17
void parse_args(int argc, char *argv[], Program::Options &options)
Definition program.cpp:42
void print_help()
Definition program.cpp:25
void print_usage()
Definition program.cpp:17
Dedicated header for the main CLI functions.
std::string config_file
Definition program.hpp:21
std::string input
Definition program.hpp:23
std::string output_file
Definition program.hpp:22
std::string err_msg
Definition program.hpp:20