guck

Vim-like QtWebEngine-powered browser, written in C++
git clone git://git.deurzen.net/guck
Log | Files | Refs | LICENSE

parse.cc (1167B)


      1 #include "parse.hh"
      2 #include "util.hh"
      3 
      4 
      5 void
      6 parser_t::parse()
      7 {
      8     for (size_t i = 0; i < m_opts.size(); ++i) {
      9         if (m_opts[i].rfind("--", 0) != std::string::npos) {
     10             std::string optflag = m_opts[i].substr(2);
     11             if (!m_optmap.count(optflag)) continue;
     12             option_t opt = m_optmap[optflag];
     13             if (opt.has_value && i+1 < m_opts.size()) {
     14                 setopt(optflag, m_opts[i+1]);
     15                 ++i;
     16             } else if (!opt.flag.empty() && !opt.has_value)
     17                 setopt(optflag);
     18         } else if (m_opts[i].rfind("-", 0) != std::string::npos) {
     19             std::string optflags = m_opts[i].substr(1);
     20             for (auto& optflag : optflags)
     21                 setopt(std::string(1, optflag));
     22         }
     23     }
     24 }
     25 
     26 void
     27 parser_t::setopt(std::string flag, std::string value)
     28 {
     29     for (auto& opt : m_optlist)
     30         if (!opt.flag.compare(flag)) {
     31             opt.set = true;
     32             opt.value = value;
     33         }
     34 }
     35 
     36 std::pair<int, std::vector<char*>>
     37 parser_t::getargs()
     38 {
     39     std::vector<char*> raw;
     40     for (auto& s : m_args)
     41         raw.push_back(convert_new(s));
     42 
     43     return {raw.size(), raw};
     44 }