Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This is a comment
- log =/var/log/secure
- max_tries=5
- max_reports=2
- std::string buf;
- smatch matches;
- int line_number = 0; // keeping track of the line number allows for error identification
- std::unordered_map<std::string, std::string> parsed_options;
- while (std::getline(is, buf)) {
- // is the line a comment or blank?
- if ((buf.find_first_of('#') == 0) || (std::all_of(buf.begin(), buf.end(), isspace)) || (buf.empty())) {
- } else {
- std::istringstream configs(buf);
- std::string option;
- if (std::getline(configs, option, '=')) {
- std::string val;
- if (std::getline(configs, val)) {
- option.erase(std::remove_if(option.begin(), option.end(), isspace), option.end());
- val.erase(std::remove_if(val.begin(), val.end(), isspace), val.end());
- parsed_options.emplace(std::make_pair(option, val));
- }
- } else {
- std::stringstream se;
- se << "Coud not parse option at line " << line_number;
- throw std::runtime_error(se.str());
- }
- }
- ++line_number;
- }
- for (auto i : parsed_options) {
- if (i.first == "log") {
- auth_log_ = i.second;
- } else if (i.first == "max_tries") {
- max_attempts_ = std::stoi(i.second);
- } else if (i.first == "max_reports") {
- max_reports_ = std::stoi(i.second);
- } else if (i.first == "interval") {
- interval_ == std::stoi(i.second);
- } else {
- std::cout << """ << i.first << "" " << i.second << 'n';
- std::stringstream ss1;
- ss1 << "Invalid option at line " << line_number;
- throw std::runtime_error(ss1.str());
- }
- }
- # This is a comment
- [section1]
- log =/var/log/secure
- max_tries=5
- max_reports=2
- [section2]
- log =/var/log/secure
- max_tries=5
- max_reports=2
Add Comment
Please, Sign In to add comment