Update README.md
[miniREPL.git] / Sources / os.cpp
blobcce99141a69b5f047042cbf22d3aceb77050f59c
1 /*
2 * miniREPL
3 * https://github.com/vrmiguel/minirepl
5 * Copyright (c) 2020 Vinícius R. Miguel <vinicius.miguel at unifesp.br>
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
26 #include "Headers/os.h"
28 bool is_verbose;
29 std::unordered_map<std::string, std::string> var_list; // extern variable
31 void signal_handler(int s)
33 if (s==SIGINT)
35 cout << "\nSIGINT (Ctrl+C) received. Code " << s << ". Exiting.\n";
36 exit(s);
39 if (s==SIGHUP)
41 cout << "\nSIGHUP received. Code " << s << ". Exiting.\n";
42 exit(s);
46 SignalHandler::SignalHandler()
48 signal_action.sa_handler = signal_handler;
49 sigemptyset(&signal_action.sa_mask);
50 signal_action.sa_flags = 0;
51 sigaction(SIGINT, &signal_action, NULL);
54 CLIInputs::CLIInputs(int argc, char **argv)
56 if(argc > 1)
58 for(short unsigned int i = 1; i < argc; i++)
60 string s_argv = argv[i];
61 if (!s_argv.compare("-h") || !s_argv.compare("--help"))
63 printf("%-20s\tObtain help.\n", "-h, --help");
64 printf("%-20s\tShows additional execution data.\n", "-v, --verbose");
65 exit(0);
67 if (!s_argv.compare("-v") || !s_argv.compare("--verbose"))
69 printf("Executing in verbose mode.\n");
70 is_verbose = true;
76 findres_t var_find(string var_name)
78 auto res = var_list.find(var_name);
79 if (res != var_list.end()) {
80 return {res->second, true};
82 return {"unused", false}; // In case the variable was not found.