diff --git a/include/setup.h b/include/setup.h index e74b3403..1bb5c3eb 100644 --- a/include/setup.h +++ b/include/setup.h @@ -111,14 +111,20 @@ private: class Property { public: - struct Changeable { enum Value {Always, WhenIdle,OnlyAtStart};}; + struct Changeable { + enum Value { Always, WhenIdle, OnlyAtStart, Deprecated }; + }; const std::string propname; Property(std::string const& _propname, Changeable::Value when):propname(_propname),change(when) { } + virtual ~Property() = default; + void Set_values(const char * const * in); void Set_values(const std::vector &in); void Set_help(std::string const& str); - char const* Get_help(); + + const char* GetHelp() const; + virtual bool SetValue(std::string const& str)=0; Value const& GetValue() const { return value;} Value const& Get_Default_Value() const { return default_value; } @@ -126,11 +132,12 @@ public: //Type specific properties are encouraged to override this and check for type //specific features. virtual bool CheckValue(Value const& in, bool warn); -public: - virtual ~Property(){ } + + Changeable::Value GetChange() const { return change; } + bool IsDeprecated() const { return (change == Changeable::Value::Deprecated); } + virtual const std::vector& GetValues() const; Value::Etype Get_type(){return default_value.type;} - Changeable::Value getChange() {return change;} protected: //Set interval value to in or default if in is invalid. force always sets the value. diff --git a/src/misc/programs.cpp b/src/misc/programs.cpp index d47fb9fc..0a48877d 100644 --- a/src/misc/programs.cpp +++ b/src/misc/programs.cpp @@ -525,11 +525,11 @@ void CONFIG::Run(void) { WriteOut(MSG_Get("PROGRAM_CONFIG_HLP_PROPHLP"), p->propname.c_str(), sec->GetName(), - p->Get_help(),propvalues.c_str(), + p->GetHelp(), propvalues.c_str(), p->Get_Default_Value().ToString().c_str(), p->GetValue().ToString().c_str()); // print 'changability' - if (p->getChange()==Property::Changeable::OnlyAtStart) { + if (p->GetChange() == Property::Changeable::OnlyAtStart) { WriteOut(MSG_Get("PROGRAM_CONFIG_HLP_NOCHANGE")); } return; diff --git a/src/misc/setup.cpp b/src/misc/setup.cpp index c12f280f..b2eecb8f 100644 --- a/src/misc/setup.cpp +++ b/src/misc/setup.cpp @@ -239,8 +239,9 @@ void Property::Set_help(string const& in) { MSG_Add(result.c_str(),in.c_str()); } -char const* Property::Get_help() { - string result = string("CONFIG_") + propname; +const char * Property::GetHelp() const +{ + std::string result = "CONFIG_" + propname; upcase(result); return MSG_Get(result.c_str()); } @@ -654,13 +655,24 @@ bool Section_prop::HandleInputline(string const& gegevens){ ((val[0] == '\"' && val[length - 1] == '\"' ) || (val[0] == '\'' && val[length - 1] == '\'')) ) val = val.substr(1,length - 2); + /* trim the results incase there were spaces somewhere */ - trim(name);trim(val); - for(it tel = properties.begin();tel != properties.end();++tel){ - if (!strcasecmp((*tel)->propname.c_str(),name.c_str())){ - return (*tel)->SetValue(val); + trim(name); + trim(val); + for (auto &p : properties) { + + if (strcasecmp(p->propname.c_str(), name.c_str()) != 0) + continue; + + if (p->IsDeprecated()) { + LOG_MSG("CONFIG: Deprecated option '%s'", name.c_str()); + LOG_MSG("CONFIG: %s", p->GetHelp()); + return false; } + + return p->SetValue(val); } + LOG_MSG("CONFIG: Unknown option %s", name.c_str()); return false; } @@ -673,6 +685,10 @@ void Section_prop::PrintData(FILE* outfile) const { len = std::max(len, tel->propname.length()); for (const auto &tel : properties) { + + if (tel->IsDeprecated()) + continue; + fprintf(outfile, "%-*s = %s\n", std::min(40, len), tel->propname.c_str(), @@ -731,7 +747,11 @@ bool Config::PrintConfig(char const * const configfilename) const { int intmaxwidth = std::min(60, maxwidth); snprintf(prefix, sizeof(prefix), "\n# %*s ", intmaxwidth , ""); while ((p = sec->Get_prop(i++))) { - std::string help = p->Get_help(); + + if (p->IsDeprecated()) + continue; + + std::string help = p->GetHelp(); std::string::size_type pos = std::string::npos; while ((pos = help.find('\n', pos+1)) != std::string::npos) { help.replace(pos, 1, prefix); @@ -871,11 +891,11 @@ bool Config::ParseConfigFile(char const * const configfilename) { //static bool first_configfile = true; ifstream in(configfilename); if (!in) return false; - const char * settings_type; - settings_type = (configfiles.size() == 0)? "primary":"additional"; configfiles.push_back(configfilename); - LOG_MSG("CONFIG: Loading %s settings from config file %s", settings_type,configfilename); + LOG_MSG("CONFIG: Loading %s config file %s", + configfiles.size() == 1 ? "primary" : "additional", + configfilename); //Get directory from configfilename, used with relative paths. current_config_dir=configfilename;