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
17
int
main
(
int
argc,
char
*argv[])
18
{
19
if
(argc < 2)
20
{
21
Program::print_usage
();
22
return
EXIT_FAILURE;
23
}
24
25
Program::Options
options;
26
Program::parse_args
(argc, argv, options);
27
28
if
(options.
show_help
)
29
{
30
Program::print_help
();
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
}
Project
Orchestrates configuration ingestion and state saves, abstraction layer bridging core computation wit...
Definition
project.hpp:31
Project::load_project
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
Project::get_machine
std::shared_ptr< TuringMachine > get_machine() noexcept
Retrieves the pointer to the active Turing Machine instance.
Definition
project.hpp:59
Project::save_project
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
run_cli_session
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
cli.hpp
Header definition for the interactive CLI dashboard interface.
main
int main(int argc, char *argv[])
Definition
main.cpp:17
Program::parse_args
void parse_args(int argc, char *argv[], Program::Options &options)
Definition
program.cpp:42
Program::print_help
void print_help()
Definition
program.cpp:25
Program::print_usage
void print_usage()
Definition
program.cpp:17
program.hpp
Dedicated header for the main CLI functions.
Program::Options
Definition
program.hpp:16
Program::Options::config_file
std::string config_file
Definition
program.hpp:21
Program::Options::err_code
int err_code
Definition
program.hpp:19
Program::Options::input
std::string input
Definition
program.hpp:23
Program::Options::output_file
std::string output_file
Definition
program.hpp:22
Program::Options::err_msg
std::string err_msg
Definition
program.hpp:20
Program::Options::batch_exec
bool batch_exec
Definition
program.hpp:17
Program::Options::show_help
bool show_help
Definition
program.hpp:18
src
cli
main.cpp
Generated by
1.9.8