recognize startup parameters

Usage: winix [options]
  -c             : a path to the config file
  --config       : a path to the config file
  -h             : print usage information
  --help         : print usage information
  -?             : print usage information

While here:
- let it be possible to parse multiple configs,
- fix: some error messages were not printed at startup.
This commit is contained in:
2022-04-16 18:38:30 +02:00
parent e0d9989d74
commit 4f8b5e649a
3 changed files with 120 additions and 48 deletions

View File

@@ -45,7 +45,6 @@ namespace Winix
Config::Config()
{
errors_to_stdout = true;
}
@@ -61,27 +60,19 @@ void Config::SetLogBuffer(pt::WTextStream * log_buffer)
}
void Config::ShowError()
void Config::ShowError(const std::wstring & config_file)
{
switch( parser.status )
{
case pt::SpaceParser::ok:
log << log2 << "Config: syntax ok" << logend;
break;
case pt::SpaceParser::cant_open_file:
if( errors_to_stdout )
std::wcout << L"Config: I cannot open a config file: " << config_file << std::endl;
log << log1 << "Config: cant open a config file: " << config_file << logend;
log << log1 << "Config: I cannot open a config file: " << config_file << logend;
break;
case pt::SpaceParser::syntax_error:
if( errors_to_stdout )
std::wcout << "Config: syntax error, line: " << parser.get_last_parsed_line() << std::endl;
log << log1 << "Config: syntax error, line: " << parser.get_last_parsed_line() << logend;
log << log1 << "Config: syntax error in file: " << config_file << ", line: " << parser.get_last_parsed_line() << logend;
break;
}
}
@@ -91,28 +82,26 @@ void Config::ShowError()
bool Config::ReadConfig(bool errors_to_stdout_, bool stdout_is_closed)
bool Config::ReadConfig(const std::wstring & config_file)
{
errors_to_stdout = errors_to_stdout_;
if( config_file.empty() )
{
log << log2 << "Config: name of the config file is empty" << logend;
return false;
}
log << log2 << "Config: reading a config file" << logend;
pt::SpaceParser::Status status = parser.parse_space_file(config_file, space);
log << log2 << "Config: reading a config file: " << config_file << logend;
pt::SpaceParser::Status status = parser.parse_space_file(config_file, space, false);
if( status == pt::SpaceParser::ok )
{
AssignValues(stdout_is_closed);
AssignValues();
SetAdditionalVariables();
return true;
}
else
{
ShowError();
ShowError(config_file);
return false;
}
}
@@ -120,7 +109,7 @@ bool Config::ReadConfig(bool errors_to_stdout_, bool stdout_is_closed)
void Config::AssignValues(bool stdout_is_closed)
void Config::AssignValues()
{
server_mode = Text(L"server_mode");
demonize = Bool(L"demonize", true);