72
72
#endif
73
73
74
74
#include < boost/interprocess/sync/file_lock.hpp>
75
- #include < boost/program_options/detail/config_file.hpp>
76
75
#include < boost/thread.hpp>
77
76
#include < openssl/crypto.h>
78
77
#include < openssl/rand.h>
@@ -811,17 +810,47 @@ fs::path GetConfigFile(const std::string& confPath)
811
810
return AbsPathForConfigVal (fs::path (confPath), false );
812
811
}
813
812
813
+ static std::string TrimString (const std::string& str, const std::string& pattern)
814
+ {
815
+ std::string::size_type front = str.find_first_not_of (pattern);
816
+ if (front == std::string::npos) {
817
+ return std::string ();
818
+ }
819
+ std::string::size_type end = str.find_last_not_of (pattern);
820
+ return str.substr (front, end - front + 1 );
821
+ }
822
+
823
+ static std::vector<std::pair<std::string, std::string>> GetConfigOptions (std::istream& stream)
824
+ {
825
+ std::vector<std::pair<std::string, std::string>> options;
826
+ std::string str, prefix;
827
+ std::string::size_type pos;
828
+ while (std::getline (stream, str)) {
829
+ if ((pos = str.find (' #' )) != std::string::npos) {
830
+ str = str.substr (0 , pos);
831
+ }
832
+ const static std::string pattern = " \t\r\n " ;
833
+ str = TrimString (str, pattern);
834
+ if (!str.empty ()) {
835
+ if (*str.begin () == ' [' && *str.rbegin () == ' ]' ) {
836
+ prefix = str.substr (1 , str.size () - 2 ) + ' .' ;
837
+ } else if ((pos = str.find (' =' )) != std::string::npos) {
838
+ std::string name = prefix + TrimString (str.substr (0 , pos), pattern);
839
+ std::string value = TrimString (str.substr (pos + 1 ), pattern);
840
+ options.emplace_back (name, value);
841
+ }
842
+ }
843
+ }
844
+ return options;
845
+ }
846
+
814
847
bool ArgsManager::ReadConfigStream (std::istream& stream, std::string& error, bool ignore_invalid_keys)
815
848
{
816
849
LOCK (cs_args);
817
850
818
- std::set<std::string> setOptions;
819
- setOptions.insert (" *" );
820
-
821
- for (boost::program_options::detail::config_file_iterator it (stream, setOptions), end; it != end; ++it)
822
- {
823
- std::string strKey = std::string (" -" ) + it->string_key ;
824
- std::string strValue = it->value [0 ];
851
+ for (const std::pair<std::string, std::string>& option : GetConfigOptions (stream)) {
852
+ std::string strKey = std::string (" -" ) + option.first ;
853
+ std::string strValue = option.second ;
825
854
826
855
if (InterpretNegatedOption (strKey, strValue)) {
827
856
m_config_args[strKey].clear ();
@@ -831,7 +860,7 @@ bool ArgsManager::ReadConfigStream(std::istream& stream, std::string& error, boo
831
860
832
861
// Check that the arg is known
833
862
if (!IsArgKnown (strKey, error) && !ignore_invalid_keys) {
834
- error = strprintf (" Invalid configuration value %s" , it-> string_key .c_str ());
863
+ error = strprintf (" Invalid configuration value %s" , option. first .c_str ());
835
864
return false ;
836
865
}
837
866
}
0 commit comments