-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
74 lines (59 loc) · 1.82 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* @file main.cpp
* @author UnknownRori (68576836+UnknownRori@users.noreply.github.com)
* @brief A simple program to solve simple math expressions
* @version 1.0
* @date 2022-12-24
*
* @copyright Copyright (c) 2022
*
*/
#include <iostream>
#include <csignal>
#include "./include/erebus.hpp"
#ifdef _WIN32
#include <Windows.h>
#endif
#define loop while (true)
#define THANK_YOU "\n===Thank you for using this tool!===\n"
#define EXIT_SUCCESS 0
auto signal_handler(int) -> void;
auto main(i32 argc, char **argv) -> i32
{
#ifdef _WIN32
if (!SetConsoleOutputCP(CP_UTF8) && setvbuf(stdout, nullptr, _IOFBF, 1000) != 0)
{
std::cout << "[Warning]: Failed to change terminal into UTF-8\n";
}
#endif
signal(SIGINT, signal_handler);
std::cout << "===== Project Ἔρεβος - Simple Math Solver =====\n"
<< "Usage : Write math expression, invalid keyword will trigger Syntax Error!\n\n";
auto solver = Rori::Math::MathSolver();
loop
{
std::string buffer;
Rori::Math::input(buffer, ">> ");
if (buffer.find("exit") != std::string::npos || (buffer.find("q") != std::string::npos && buffer.size() == 1))
break;
if (buffer.find("help") != std::string::npos)
{
Rori::Math::print_help();
continue;
}
auto [result, err] = solver.evaluate(buffer);
if (err == Rori::Math::ErrorKind::SyntaxError)
std::cout << "Error: Syntax Error\n\n";
else if (err == Rori::Math::ErrorKind::ParseIntError)
std::cout << "Error: Failed to parse integer value\n\n";
else
std::cout << "Result\t: " << result << "\n\n";
}
std::cout << THANK_YOU;
return EXIT_SUCCESS;
}
auto signal_handler(int __signum) -> void
{
std::cout << THANK_YOU;
exit(__signum);
}