feat(parser): get config file from arg

This commit is contained in:
3lswear
2022-02-12 00:30:50 +03:00
parent 4c7712eac1
commit 29ae04e40d
10 changed files with 14 additions and 13 deletions

View File

@@ -41,6 +41,6 @@ re:
$(MAKE) all
run: $(NAME)
ASAN_OPTIONS=detect_leaks=0 ./$(NAME)
ASAN_OPTIONS=detect_leaks=0 ./$(NAME) $(filter-out $@,$(MAKECMDGOALS))
.PHONY: all clean fclean re

View File

@@ -34,9 +34,9 @@ void Server::print_epoll_events(unsigned int events)
//----------------------------------------------Send--------------------------------------------------------------------------------------------
//----------------------------------------------Configuration-----------------------------------------------------------------------------------
void Server::readConfig(void)
void Server::readConfig(char *filename)
{
TOMLMap *root = parse();
TOMLMap *root = parse(filename);
/* TOMLMap *map; */

View File

@@ -56,7 +56,7 @@ class Server
Server();
Server(std::string path);
void readConfig(void);
void readConfig(char *filename);
void setupConfig(void);
void start(void);
void end(void);

View File

@@ -25,7 +25,7 @@
namespace config
{
TOMLParser::TOMLParser(const std::string filename) : tokenizer(filename)
TOMLParser::TOMLParser(char *filename) : tokenizer(filename)
{};
void TOMLParser::processMap(void)

View File

@@ -23,7 +23,7 @@ namespace config
toml_node *map_node, toml_node::e_type type);
public:
TOMLParser(const std::string filename);
TOMLParser(char *filename);
TOMLMap *parse(void);
toml_node *parseMap(void);

View File

@@ -38,12 +38,13 @@ namespace config
else
return (false);
}
Tokenizer::Tokenizer(std::string filename)
Tokenizer::Tokenizer(char *filename)
{
file.open(filename.c_str(), std::ios::in);
file.open(filename, std::ios::in);
if (!file.good())
{
std::cerr << "file didn't open" << std::endl;
throw std::logic_error("file didnt open");
}
}
bool Tokenizer::firstToken()

View File

@@ -49,7 +49,7 @@ namespace config
e_token last_token;
public:
Tokenizer(std::string filename);
Tokenizer(char *filename);
char getWithoutWhiteSpace();
struct s_token getToken();
bool hasMoreTokens();

View File

@@ -38,9 +38,9 @@ namespace config
}
}
TOMLMap *parse(void)
TOMLMap *parse(char *filename)
{
std::string filename = "config/tester.toml";
// std::string fiцename = "config/simple.toml";
config::TOMLParser parser(filename);
TOMLMap *root = parser.parse();
/* config::display(root); */

View File

@@ -7,7 +7,7 @@
#include "TOMLNode.hpp"
#include "TOMLParser.hpp"
TOMLMap *parse(void);
TOMLMap *parse(char *filename);
void display(TOMLMap *config);
#endif

View File

@@ -10,7 +10,7 @@ int main(int argc, char **argv)
Server server;
server.readConfig();
server.readConfig(argv[1]);
server.setupConfig();
server.start();
server.end();