mirror of
https://github.com/3lswear/webserv.git
synced 2025-10-29 05:17:59 +03:00
feat(parser): get config file from arg
This commit is contained in:
@@ -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; */
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
namespace config
|
||||
{
|
||||
|
||||
TOMLParser::TOMLParser(const std::string filename) : tokenizer(filename)
|
||||
TOMLParser::TOMLParser(char *filename) : tokenizer(filename)
|
||||
{};
|
||||
|
||||
void TOMLParser::processMap(void)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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); */
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "TOMLNode.hpp"
|
||||
#include "TOMLParser.hpp"
|
||||
|
||||
TOMLMap *parse(void);
|
||||
TOMLMap *parse(char *filename);
|
||||
void display(TOMLMap *config);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -10,7 +10,7 @@ int main(int argc, char **argv)
|
||||
|
||||
Server server;
|
||||
|
||||
server.readConfig();
|
||||
server.readConfig(argv[1]);
|
||||
server.setupConfig();
|
||||
server.start();
|
||||
server.end();
|
||||
|
||||
Reference in New Issue
Block a user