1/*******************************************************************\
5Author: Daniel Kroening, kroening@kroening.com
7\*******************************************************************/
57 if(i.has_value() && !
options[*i].values.empty())
58 return options[*i].values.front();
72 "unknown command line option", option);
83 options[*i].values.push_back(value);
88 "unknown command line option", option);
99 options[*i].values.push_back(value);
104 "unknown command line option", std::string(1, option));
129 if(i.has_value() && !
options[*i].values.empty())
130 return options[*i].values.front();
136 const std::string &option)
const
146std::list<std::string>
163 for(std::size_t i=0; i<
options.size(); i++)
167 return std::optional<std::size_t>();
172 for(std::size_t i=0; i<
options.size(); i++)
173 if(
options[i].optstring==option)
176 return std::optional<std::size_t>();
193 while(optstring[0] != 0)
198 optstring[0] !=
':',
"cmdlinet::parse: Invalid option string\n");
200 if(optstring[0] ==
'(')
204 option.
isset =
false;
207 for(optstring++; optstring[0] !=
')' && optstring[0] != 0; optstring++)
210 if(optstring[0] ==
')')
218 option.
isset =
false;
223 if(optstring[0] ==
':')
235std::vector<std::string>
240 std::size_t distance;
245 return distance < other.distance;
250 // We allow 3 errors here. This can lead to the output being a bit chatty,
251 // which we mitigate by reducing suggestions to those with the minimum
252 // distance further down below
254 for(
const auto &option :
options)
258 const auto long_name =
"--" + option.optstring;
266 const auto short_name = std::string{
"-"} + option.optchar;
277 // we only want to keep suggestions with the minimum distance
278 // because otherwise they become quickly too noisy to be useful
279 auto min = std::min_element(
283 "there is a minimum because it's not empty");
297 for(
int i = 1; i < argc; i++)
299 if(argv[i][0] !=
'-')
300 args.push_back(argv[i]);
303 std::optional<std::size_t>
optnr;
305 if(argv[i][1] != 0 && argv[i][2] == 0)
307 else if(argv[i][1] ==
'-')
308 optnr =
getoptnr(argv[i] + 2);
// multi-letter option with --XXX
311 // Multi-letter option -XXX, or single-letter with argument -Xval
312 // We first try single-letter.
315 if(!
optnr.has_value())
// try multi-letter
319 if(!
optnr.has_value())
334 if(argv[i][0] ==
'-' && argv[i][1] != 0)
349 : command_line(command_line), index(index)
359 goto_next_valid_index();
395 return index == other.
index;
402 return index != other.
index;
virtual void clear()
Reset the abstract state.
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
std::string get_value(char option) const
virtual bool isset(char option) const
std::list< std::string > get_comma_separated_values(const char *option) const
Collect all occurrences of option option and split their values on each comma, merging them into a si...
std::optional< std::size_t > getoptnr(char option) const
std::optional< std::string > value_opt(char option) const
bool parse_arguments(int argc, const char **argv)
Parses a commandline according to a previously parsed optstring and writes the result to cmdlinet::op...
std::vector< optiont > options
virtual void set(const std::string &option, bool value=true)
Set option option to value, or true if the value is omitted.
virtual bool parse(int argc, const char **argv, const char *optstring)
Parses a commandline according to a specification given in optstring.
std::vector< std::string > get_argument_suggestions(const std::string &unknown_argument)
void parse_optstring(const char *optstring)
Parses an optstring and writes the result to cmdlinet::options.
option_namest option_names() const
Pseudo-object that can be used to iterate over options in this cmdlinet (should not outlive this)
const std::list< std::string > & get_values(const std::string &option) const
Thrown when users pass incorrect command line arguments, for example passing no files to analysis or ...
static std::list< std::string > immutable_empty_list
bool operator<(const reaching_definitiont &a, const reaching_definitiont &b)
In order to use instances of this structure as keys in ordered containers, such as std::map,...
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
#define PRECONDITION(CONDITION)
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
void split_string(std::string_view s, char delim, std::vector< std::string > &result, bool strip, bool remove_empty)
bool is_valid_index() const
const std::string & operator*()
const cmdlinet * command_line
bool operator==(const option_names_iteratort &other)
void goto_next_valid_index()
bool operator!=(const option_names_iteratort &other)
option_names_iteratort()=default
option_names_iteratort & operator++()
option_names_iteratort end()
option_names_iteratort begin()
option_namest(const cmdlinet &command_line)
const cmdlinet & command_line
Simple automaton that can detect whether a string can be transformed into another with a limited numb...