fix(core): Nullptr checks

This commit is contained in:
Michael Carlberg 2016-06-01 16:59:03 +02:00
parent a410e182a9
commit b63e25d6e7
3 changed files with 18 additions and 15 deletions

View File

@ -48,7 +48,7 @@ namespace config
void set_bar_path(const std::string& path); void set_bar_path(const std::string& path);
void load(const std::string& path) throw(UnexistingFileError, ParseError); void load(const std::string& path) throw(UnexistingFileError, ParseError);
void load(char *dir, const std::string& path); void load(const char *dir, const std::string& path);
void reload() throw(ParseError); void reload() throw(ParseError);
boost::property_tree::ptree get_tree(); boost::property_tree::ptree get_tree();

View File

@ -93,19 +93,22 @@ int main(int argc, char **argv)
/** /**
* Load configuration file * Load configuration file
*/ */
if (cli::has_option("config")) { const char *env_home = std::getenv("HOME");
config::load(string::replace(cli::get_option_value("config"), "~", std::getenv("HOME"))); const char *env_xdg_config_home = std::getenv("XDG_CONFIG_HOME");
} else {
auto xdg_config_home = std::getenv("XDG_CONFIG_HOME");
auto home = std::getenv("HOME");
if (xdg_config_home != nullptr) if (cli::has_option("config")) {
config::load(xdg_config_home, "lemonbuddy/config"); auto config_file = cli::get_option_value("config");
else if (home != nullptr)
config::load(home, ".config/lemonbuddy/config"); if (env_home != nullptr)
else config_file = string::replace(cli::get_option_value("config"), "~", std::string(env_home));
throw ApplicationError("Could not find config file. Specify the location using --config=PATH");
} config::load(config_file);
} else if (env_xdg_config_home != nullptr)
config::load(env_xdg_config_home, "lemonbuddy/config");
else if (env_home != nullptr)
config::load(env_home, ".config/lemonbuddy/config");
else
throw ApplicationError("Could not find config file. Specify the location using --config=PATH");
/** /**
* Check if the specified bar exist * Check if the specified bar exist

View File

@ -34,8 +34,8 @@ namespace config
file_path = path; file_path = path;
} }
void load(char *dir, const std::string& path) { void load(const char *dir, const std::string& path) {
load(std::string(dir) +"/"+ path); load(std::string(dir != nullptr ? dir : "") +"/"+ path);
} }
void reload() throw(ParseError) void reload() throw(ParseError)