1 //===-- Options.cpp ---------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/lldb-python.h"
12 #include "lldb/Interpreter/Options.h"
20 // Other libraries and framework includes
22 #include "lldb/Interpreter/CommandObject.h"
23 #include "lldb/Interpreter/CommandReturnObject.h"
24 #include "lldb/Interpreter/CommandCompletions.h"
25 #include "lldb/Interpreter/CommandInterpreter.h"
26 #include "lldb/Core/StreamString.h"
27 #include "lldb/Target/Target.h"
30 using namespace lldb_private;
32 //-------------------------------------------------------------------------
34 //-------------------------------------------------------------------------
35 Options::Options (CommandInterpreter &interpreter) :
36 m_interpreter (interpreter),
39 BuildValidOptionSets();
47 Options::NotifyOptionParsingStarting ()
49 m_seen_options.clear();
50 // Let the subclass reset its option values
51 OptionParsingStarting ();
55 Options::NotifyOptionParsingFinished ()
57 return OptionParsingFinished ();
61 Options::OptionSeen (int option_idx)
63 m_seen_options.insert (option_idx);
66 // Returns true is set_a is a subset of set_b; Otherwise returns false.
69 Options::IsASubset (const OptionSet& set_a, const OptionSet& set_b)
71 bool is_a_subset = true;
72 OptionSet::const_iterator pos_a;
73 OptionSet::const_iterator pos_b;
75 // set_a is a subset of set_b if every member of set_a is also a member of set_b
77 for (pos_a = set_a.begin(); pos_a != set_a.end() && is_a_subset; ++pos_a)
79 pos_b = set_b.find(*pos_a);
80 if (pos_b == set_b.end())
87 // Returns the set difference set_a - set_b, i.e. { x | ElementOf (x, set_a) && !ElementOf (x, set_b) }
90 Options::OptionsSetDiff (const OptionSet& set_a, const OptionSet& set_b, OptionSet& diffs)
93 OptionSet::const_iterator pos_a;
94 OptionSet::const_iterator pos_b;
96 for (pos_a = set_a.begin(); pos_a != set_a.end(); ++pos_a)
98 pos_b = set_b.find(*pos_a);
99 if (pos_b == set_b.end())
102 diffs.insert(*pos_a);
109 // Returns the union of set_a and set_b. Does not put duplicate members into the union.
112 Options::OptionsSetUnion (const OptionSet &set_a, const OptionSet &set_b, OptionSet &union_set)
114 OptionSet::const_iterator pos;
115 OptionSet::iterator pos_union;
117 // Put all the elements of set_a into the union.
119 for (pos = set_a.begin(); pos != set_a.end(); ++pos)
120 union_set.insert(*pos);
122 // Put all the elements of set_b that are not already there into the union.
123 for (pos = set_b.begin(); pos != set_b.end(); ++pos)
125 pos_union = union_set.find(*pos);
126 if (pos_union == union_set.end())
127 union_set.insert(*pos);
132 Options::VerifyOptions (CommandReturnObject &result)
134 bool options_are_valid = false;
136 int num_levels = GetRequiredOptions().size();
139 for (int i = 0; i < num_levels && !options_are_valid; ++i)
141 // This is the correct set of options if: 1). m_seen_options contains all of m_required_options[i]
142 // (i.e. all the required options at this level are a subset of m_seen_options); AND
143 // 2). { m_seen_options - m_required_options[i] is a subset of m_options_options[i] (i.e. all the rest of
144 // m_seen_options are in the set of optional options at this level.
146 // Check to see if all of m_required_options[i] are a subset of m_seen_options
147 if (IsASubset (GetRequiredOptions()[i], m_seen_options))
149 // Construct the set difference: remaining_options = {m_seen_options} - {m_required_options[i]}
150 OptionSet remaining_options;
151 OptionsSetDiff (m_seen_options, GetRequiredOptions()[i], remaining_options);
152 // Check to see if remaining_options is a subset of m_optional_options[i]
153 if (IsASubset (remaining_options, GetOptionalOptions()[i]))
154 options_are_valid = true;
160 options_are_valid = true;
163 if (options_are_valid)
165 result.SetStatus (eReturnStatusSuccessFinishNoResult);
169 result.AppendError ("invalid combination of options for the given command");
170 result.SetStatus (eReturnStatusFailed);
173 return options_are_valid;
176 // This is called in the Options constructor, though we could call it lazily if that ends up being
177 // a performance problem.
180 Options::BuildValidOptionSets ()
182 // Check to see if we already did this.
183 if (m_required_options.size() != 0)
186 // Check to see if there are any options.
187 int num_options = NumCommandOptions ();
188 if (num_options == 0)
191 const OptionDefinition *opt_defs = GetDefinitions();
192 m_required_options.resize(1);
193 m_optional_options.resize(1);
195 // First count the number of option sets we've got. Ignore LLDB_ALL_OPTION_SETS...
197 uint32_t num_option_sets = 0;
199 for (int i = 0; i < num_options; i++)
201 uint32_t this_usage_mask = opt_defs[i].usage_mask;
202 if (this_usage_mask == LLDB_OPT_SET_ALL)
204 if (num_option_sets == 0)
209 for (uint32_t j = 0; j < LLDB_MAX_NUM_OPTION_SETS; j++)
211 if (this_usage_mask & (1 << j))
213 if (num_option_sets <= j)
214 num_option_sets = j + 1;
220 if (num_option_sets > 0)
222 m_required_options.resize(num_option_sets);
223 m_optional_options.resize(num_option_sets);
225 for (int i = 0; i < num_options; ++i)
227 for (uint32_t j = 0; j < num_option_sets; j++)
229 if (opt_defs[i].usage_mask & 1 << j)
231 if (opt_defs[i].required)
232 m_required_options[j].insert(opt_defs[i].short_option);
234 m_optional_options[j].insert(opt_defs[i].short_option);
242 Options::NumCommandOptions ()
244 const OptionDefinition *opt_defs = GetDefinitions ();
245 if (opt_defs == NULL)
250 if (opt_defs != NULL)
252 while (opt_defs[i].long_option != NULL)
260 Options::GetLongOptions ()
262 // Check to see if this has already been done.
263 if (m_getopt_table.empty())
265 // Check to see if there are any options.
266 const uint32_t num_options = NumCommandOptions();
267 if (num_options == 0)
271 const OptionDefinition *opt_defs = GetDefinitions();
273 std::map<int, uint32_t> option_seen;
275 m_getopt_table.resize(num_options + 1);
276 for (i = 0; i < num_options; ++i)
278 const int short_opt = opt_defs[i].short_option;
280 m_getopt_table[i].name = opt_defs[i].long_option;
281 m_getopt_table[i].has_arg = opt_defs[i].option_has_arg;
282 m_getopt_table[i].flag = NULL;
283 m_getopt_table[i].val = short_opt;
285 if (option_seen.find(short_opt) == option_seen.end())
287 option_seen[short_opt] = i;
291 m_getopt_table[i].val = 0;
292 std::map<int, uint32_t>::const_iterator pos = option_seen.find(short_opt);
294 if (isprint8(short_opt))
295 Host::SystemLog (Host::eSystemLogError, "option[%u] --%s has a short option -%c that conflicts with option[%u] --%s, short option won't be used for --%s\n",
297 opt_defs[i].long_option,
300 m_getopt_table[pos->second].name,
301 opt_defs[i].long_option);
303 Host::SystemLog (Host::eSystemLogError, "option[%u] --%s has a short option 0x%x that conflicts with option[%u] --%s, short option won't be used for --%s\n",
305 opt_defs[i].long_option,
308 m_getopt_table[pos->second].name,
309 opt_defs[i].long_option);
313 //getopt_long_only requires a NULL final entry in the table:
315 m_getopt_table[i].name = NULL;
316 m_getopt_table[i].has_arg = 0;
317 m_getopt_table[i].flag = NULL;
318 m_getopt_table[i].val = 0;
321 if (m_getopt_table.empty())
324 return &m_getopt_table.front();
328 // This function takes INDENT, which tells how many spaces to output at the front of each line; SPACES, which is
329 // a string containing 80 spaces; and TEXT, which is the text that is to be output. It outputs the text, on
330 // multiple lines if necessary, to RESULT, with INDENT spaces at the front of each line. It breaks lines on spaces,
331 // tabs or newlines, shortening the line if necessary to not break in the middle of a word. It assumes that each
332 // output line should contain a maximum of OUTPUT_MAX_COLUMNS characters.
336 Options::OutputFormattedUsageText
340 uint32_t output_max_columns
343 int len = strlen (text);
345 // Will it all fit on one line?
347 if ((len + strm.GetIndentLevel()) < output_max_columns)
349 // Output it as a single line.
355 // We need to break it up into multiple lines.
357 int text_width = output_max_columns - strm.GetIndentLevel() - 1;
360 int final_end = strlen (text);
363 while (end < final_end)
365 // Don't start the 'text' on a space, since we're already outputting the indentation.
366 while ((start < final_end) && (text[start] == ' '))
369 end = start + text_width;
374 // If we're not at the end of the text, make sure we break the line on white space.
376 && text[end] != ' ' && text[end] != '\t' && text[end] != '\n')
380 sub_len = end - start;
384 assert (start < final_end);
385 assert (start + sub_len <= final_end);
386 strm.Write(text + start, sub_len);
394 Options::SupportsLongOption (const char *long_option)
396 if (long_option && long_option[0])
398 const OptionDefinition *opt_defs = GetDefinitions ();
401 const char *long_option_name = long_option;
402 if (long_option[0] == '-' && long_option[1] == '-')
403 long_option_name += 2;
405 for (uint32_t i = 0; opt_defs[i].long_option; ++i)
407 if (strcmp(opt_defs[i].long_option, long_option_name) == 0)
415 enum OptionDisplayType
423 PrintOption (const OptionDefinition &opt_def,
424 OptionDisplayType display_type,
430 const bool has_short_option = isprint8(opt_def.short_option) != 0;
432 if (display_type == eDisplayShortOption && !has_short_option)
435 if (header && header[0])
436 strm.PutCString(header);
438 if (show_optional && !opt_def.required)
440 const bool show_short_option = has_short_option && display_type != eDisplayLongOption;
441 if (show_short_option)
442 strm.Printf ("-%c", opt_def.short_option);
444 strm.Printf ("--%s", opt_def.long_option);
445 switch (opt_def.option_has_arg)
447 case OptionParser::eNoArgument:
449 case OptionParser::eRequiredArgument:
450 strm.Printf (" <%s>", CommandObject::GetArgumentName (opt_def.argument_type));
453 case OptionParser::eOptionalArgument:
454 strm.Printf ("%s[<%s>]",
455 show_short_option ? "" : "=",
456 CommandObject::GetArgumentName (opt_def.argument_type));
459 if (show_optional && !opt_def.required)
461 if (footer && footer[0])
462 strm.PutCString(footer);
467 Options::GenerateOptionUsage
473 const uint32_t screen_width = m_interpreter.GetDebugger().GetTerminalWidth();
475 const OptionDefinition *opt_defs = GetDefinitions();
476 const uint32_t save_indent_level = strm.GetIndentLevel();
479 StreamString arguments_str;
483 name = cmd->GetCommandName();
484 cmd->GetFormattedCommandArguments (arguments_str);
489 strm.PutCString ("\nCommand Options Usage:\n");
493 // First, show each usage level set of options, e.g. <cmd> [options-for-level-0]
494 // <cmd> [options-for-level-1]
497 const uint32_t num_options = NumCommandOptions();
498 if (num_options == 0)
501 uint32_t num_option_sets = GetRequiredOptions().size();
505 for (uint32_t opt_set = 0; opt_set < num_option_sets; ++opt_set)
507 uint32_t opt_set_mask;
509 opt_set_mask = 1 << opt_set;
514 // Different option sets may require different args.
515 StreamString args_str;
517 cmd->GetFormattedCommandArguments(args_str, opt_set_mask);
519 // First go through and print all options that take no arguments as
520 // a single string. If a command has "-a" "-b" and "-c", this will show
523 std::set<int> options;
524 std::set<int>::const_iterator options_pos, options_end;
525 for (i = 0; i < num_options; ++i)
527 if (opt_defs[i].usage_mask & opt_set_mask && isprint8(opt_defs[i].short_option))
529 // Add current option to the end of out_stream.
531 if (opt_defs[i].required == true &&
532 opt_defs[i].option_has_arg == OptionParser::eNoArgument)
534 options.insert (opt_defs[i].short_option);
539 if (options.empty() == false)
541 // We have some required options with no arguments
542 strm.PutCString(" -");
544 for (options_pos = options.begin(), options_end = options.end();
545 options_pos != options_end;
548 if (i==0 && ::islower (*options_pos))
550 if (i==1 && ::isupper (*options_pos))
552 strm << (char)*options_pos;
556 for (i = 0, options.clear(); i < num_options; ++i)
558 if (opt_defs[i].usage_mask & opt_set_mask && isprint8(opt_defs[i].short_option))
560 // Add current option to the end of out_stream.
562 if (opt_defs[i].required == false &&
563 opt_defs[i].option_has_arg == OptionParser::eNoArgument)
565 options.insert (opt_defs[i].short_option);
570 if (options.empty() == false)
572 // We have some required options with no arguments
573 strm.PutCString(" [-");
575 for (options_pos = options.begin(), options_end = options.end();
576 options_pos != options_end;
579 if (i==0 && ::islower (*options_pos))
581 if (i==1 && ::isupper (*options_pos))
583 strm << (char)*options_pos;
588 // First go through and print the required options (list them up front).
590 for (i = 0; i < num_options; ++i)
592 if (opt_defs[i].usage_mask & opt_set_mask && isprint8(opt_defs[i].short_option))
594 if (opt_defs[i].required && opt_defs[i].option_has_arg != OptionParser::eNoArgument)
595 PrintOption (opt_defs[i], eDisplayBestOption, " ", NULL, true, strm);
599 // Now go through again, and this time only print the optional options.
601 for (i = 0; i < num_options; ++i)
603 if (opt_defs[i].usage_mask & opt_set_mask)
605 // Add current option to the end of out_stream.
607 if (!opt_defs[i].required && opt_defs[i].option_has_arg != OptionParser::eNoArgument)
608 PrintOption (opt_defs[i], eDisplayBestOption, " ", NULL, true, strm);
612 if (args_str.GetSize() > 0)
614 if (cmd->WantsRawCommandString())
617 strm.Printf (" %s", args_str.GetData());
622 cmd->WantsRawCommandString() &&
623 arguments_str.GetSize() > 0)
627 strm.Printf(" %s", arguments_str.GetData());
630 strm.Printf ("\n\n");
632 // Now print out all the detailed information about the various options: long form, short form and help text:
633 // --long_name <argument> ( -short <argument> )
636 // This variable is used to keep track of which options' info we've printed out, because some options can be in
637 // more than one usage level, but we only want to print the long form of its information once.
639 std::multimap<int, uint32_t> options_seen;
642 // Put the unique command options in a vector & sort it, so we can output them alphabetically (by short_option)
643 // when writing out detailed help for each option.
645 for (i = 0; i < num_options; ++i)
646 options_seen.insert(std::make_pair(opt_defs[i].short_option, i));
648 // Go through the unique'd and alphabetically sorted vector of options, find the table entry for each option
649 // and write out the detailed help information for that option.
651 bool first_option_printed = false;;
653 for (auto pos : options_seen)
656 //Print out the help information for this option.
658 // Put a newline separation between arguments
659 if (first_option_printed)
662 first_option_printed = true;
664 CommandArgumentType arg_type = opt_defs[i].argument_type;
666 StreamString arg_name_str;
667 arg_name_str.Printf ("<%s>", CommandObject::GetArgumentName (arg_type));
670 if (opt_defs[i].short_option && isprint8(opt_defs[i].short_option))
672 PrintOption (opt_defs[i], eDisplayShortOption, NULL, NULL, false, strm);
673 PrintOption (opt_defs[i], eDisplayLongOption, " ( ", " )", false, strm);
677 // Short option is not printable, just print long option
678 PrintOption (opt_defs[i], eDisplayLongOption, NULL, NULL, false, strm);
684 if (opt_defs[i].usage_text)
685 OutputFormattedUsageText (strm,
686 opt_defs[i].usage_text,
688 if (opt_defs[i].enum_values != NULL)
691 strm.Printf("Values: ");
692 for (int k = 0; opt_defs[i].enum_values[k].string_value != NULL; k++)
695 strm.Printf("%s", opt_defs[i].enum_values[k].string_value);
697 strm.Printf(" | %s", opt_defs[i].enum_values[k].string_value);
704 // Restore the indent level
705 strm.SetIndentLevel (save_indent_level);
708 // This function is called when we have been given a potentially incomplete set of
709 // options, such as when an alias has been defined (more options might be added at
710 // at the time the alias is invoked). We need to verify that the options in the set
711 // m_seen_options are all part of a set that may be used together, but m_seen_options
712 // may be missing some of the "required" options.
715 Options::VerifyPartialOptions (CommandReturnObject &result)
717 bool options_are_valid = false;
719 int num_levels = GetRequiredOptions().size();
722 for (int i = 0; i < num_levels && !options_are_valid; ++i)
724 // In this case we are treating all options as optional rather than required.
725 // Therefore a set of options is correct if m_seen_options is a subset of the
726 // union of m_required_options and m_optional_options.
728 OptionsSetUnion (GetRequiredOptions()[i], GetOptionalOptions()[i], union_set);
729 if (IsASubset (m_seen_options, union_set))
730 options_are_valid = true;
734 return options_are_valid;
738 Options::HandleOptionCompletion
741 OptionElementVector &opt_element_vector,
744 int match_start_point,
745 int max_return_elements,
747 lldb_private::StringList &matches
750 word_complete = true;
752 // For now we just scan the completions to see if the cursor position is in
753 // an option or its argument. Otherwise we'll call HandleArgumentCompletion.
754 // In the future we can use completion to validate options as well if we want.
756 const OptionDefinition *opt_defs = GetDefinitions();
758 std::string cur_opt_std_str (input.GetArgumentAtIndex(cursor_index));
759 cur_opt_std_str.erase(char_pos);
760 const char *cur_opt_str = cur_opt_std_str.c_str();
762 for (size_t i = 0; i < opt_element_vector.size(); i++)
764 int opt_pos = opt_element_vector[i].opt_pos;
765 int opt_arg_pos = opt_element_vector[i].opt_arg_pos;
766 int opt_defs_index = opt_element_vector[i].opt_defs_index;
767 if (opt_pos == cursor_index)
769 // We're completing the option itself.
771 if (opt_defs_index == OptionArgElement::eBareDash)
773 // We're completing a bare dash. That means all options are open.
774 // FIXME: We should scan the other options provided and only complete options
775 // within the option group they belong to.
776 char opt_str[3] = {'-', 'a', '\0'};
778 for (int j = 0 ; opt_defs[j].short_option != 0 ; j++)
780 opt_str[1] = opt_defs[j].short_option;
781 matches.AppendString (opt_str);
785 else if (opt_defs_index == OptionArgElement::eBareDoubleDash)
787 std::string full_name ("--");
788 for (int j = 0 ; opt_defs[j].short_option != 0 ; j++)
790 full_name.erase(full_name.begin() + 2, full_name.end());
791 full_name.append (opt_defs[j].long_option);
792 matches.AppendString (full_name.c_str());
796 else if (opt_defs_index != OptionArgElement::eUnrecognizedArg)
798 // We recognized it, if it an incomplete long option, complete it anyway (getopt_long_only is
799 // happy with shortest unique string, but it's still a nice thing to do.) Otherwise return
800 // The string so the upper level code will know this is a full match and add the " ".
801 if (cur_opt_str && strlen (cur_opt_str) > 2
802 && cur_opt_str[0] == '-' && cur_opt_str[1] == '-'
803 && strcmp (opt_defs[opt_defs_index].long_option, cur_opt_str) != 0)
805 std::string full_name ("--");
806 full_name.append (opt_defs[opt_defs_index].long_option);
807 matches.AppendString(full_name.c_str());
812 matches.AppendString(input.GetArgumentAtIndex(cursor_index));
818 // FIXME - not handling wrong options yet:
819 // Check to see if they are writing a long option & complete it.
820 // I think we will only get in here if the long option table has two elements
821 // that are not unique up to this point. getopt_long_only does shortest unique match
822 // for long options already.
824 if (cur_opt_str && strlen (cur_opt_str) > 2
825 && cur_opt_str[0] == '-' && cur_opt_str[1] == '-')
827 for (int j = 0 ; opt_defs[j].short_option != 0 ; j++)
829 if (strstr(opt_defs[j].long_option, cur_opt_str + 2) == opt_defs[j].long_option)
831 std::string full_name ("--");
832 full_name.append (opt_defs[j].long_option);
833 // The options definitions table has duplicates because of the
834 // way the grouping information is stored, so only add once.
835 bool duplicate = false;
836 for (size_t k = 0; k < matches.GetSize(); k++)
838 if (matches.GetStringAtIndex(k) == full_name)
845 matches.AppendString(full_name.c_str());
854 else if (opt_arg_pos == cursor_index)
856 // Okay the cursor is on the completion of an argument.
857 // See if it has a completion, otherwise return no matches.
859 if (opt_defs_index != -1)
861 HandleOptionArgumentCompletion (input,
863 strlen (input.GetArgumentAtIndex(cursor_index)),
874 // No completion callback means no completions...
881 // Not the last element, keep going.
889 Options::HandleOptionArgumentCompletion
894 OptionElementVector &opt_element_vector,
895 int opt_element_index,
896 int match_start_point,
897 int max_return_elements,
899 lldb_private::StringList &matches
902 const OptionDefinition *opt_defs = GetDefinitions();
903 std::unique_ptr<SearchFilter> filter_ap;
905 int opt_arg_pos = opt_element_vector[opt_element_index].opt_arg_pos;
906 int opt_defs_index = opt_element_vector[opt_element_index].opt_defs_index;
908 // See if this is an enumeration type option, and if so complete it here:
910 OptionEnumValueElement *enum_values = opt_defs[opt_defs_index].enum_values;
911 if (enum_values != NULL)
913 bool return_value = false;
914 std::string match_string(input.GetArgumentAtIndex (opt_arg_pos), input.GetArgumentAtIndex (opt_arg_pos) + char_pos);
915 for (int i = 0; enum_values[i].string_value != NULL; i++)
917 if (strstr(enum_values[i].string_value, match_string.c_str()) == enum_values[i].string_value)
919 matches.AppendString (enum_values[i].string_value);
926 // If this is a source file or symbol type completion, and there is a
927 // -shlib option somewhere in the supplied arguments, then make a search filter
928 // for that shared library.
929 // FIXME: Do we want to also have an "OptionType" so we don't have to match string names?
931 uint32_t completion_mask = opt_defs[opt_defs_index].completion_type;
933 if (completion_mask == 0)
935 lldb::CommandArgumentType option_arg_type = opt_defs[opt_defs_index].argument_type;
936 if (option_arg_type != eArgTypeNone)
938 CommandObject::ArgumentTableEntry *arg_entry = CommandObject::FindArgumentDataByType (opt_defs[opt_defs_index].argument_type);
940 completion_mask = arg_entry->completion_type;
944 if (completion_mask & CommandCompletions::eSourceFileCompletion
945 || completion_mask & CommandCompletions::eSymbolCompletion)
947 for (size_t i = 0; i < opt_element_vector.size(); i++)
949 int cur_defs_index = opt_element_vector[i].opt_defs_index;
950 int cur_arg_pos = opt_element_vector[i].opt_arg_pos;
951 const char *cur_opt_name = opt_defs[cur_defs_index].long_option;
953 // If this is the "shlib" option and there was an argument provided,
954 // restrict it to that shared library.
955 if (cur_opt_name && strcmp(cur_opt_name, "shlib") == 0 && cur_arg_pos != -1)
957 const char *module_name = input.GetArgumentAtIndex(cur_arg_pos);
960 FileSpec module_spec(module_name, false);
961 lldb::TargetSP target_sp = m_interpreter.GetDebugger().GetSelectedTarget();
962 // Search filters require a target...
964 filter_ap.reset (new SearchFilterByModule (target_sp, module_spec));
971 return CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
973 input.GetArgumentAtIndex (opt_arg_pos),
984 OptionGroupOptions::Append (OptionGroup* group)
986 const OptionDefinition* group_option_defs = group->GetDefinitions ();
987 const uint32_t group_option_count = group->GetNumDefinitions();
988 for (uint32_t i=0; i<group_option_count; ++i)
990 m_option_infos.push_back (OptionInfo (group, i));
991 m_option_defs.push_back (group_option_defs[i]);
996 OptionGroupOptions::GetGroupWithOption (char short_opt)
998 for (uint32_t i = 0; i < m_option_defs.size(); i++)
1000 OptionDefinition opt_def = m_option_defs[i];
1001 if (opt_def.short_option == short_opt)
1002 return m_option_infos[i].option_group;
1008 OptionGroupOptions::Append (OptionGroup* group,
1012 const OptionDefinition* group_option_defs = group->GetDefinitions ();
1013 const uint32_t group_option_count = group->GetNumDefinitions();
1014 for (uint32_t i=0; i<group_option_count; ++i)
1016 if (group_option_defs[i].usage_mask & src_mask)
1018 m_option_infos.push_back (OptionInfo (group, i));
1019 m_option_defs.push_back (group_option_defs[i]);
1020 m_option_defs.back().usage_mask = dst_mask;
1026 OptionGroupOptions::Finalize ()
1028 m_did_finalize = true;
1029 OptionDefinition empty_option_def = { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL };
1030 m_option_defs.push_back (empty_option_def);
1034 OptionGroupOptions::SetOptionValue (uint32_t option_idx,
1035 const char *option_value)
1037 // After calling OptionGroupOptions::Append(...), you must finalize the groups
1038 // by calling OptionGroupOptions::Finlize()
1039 assert (m_did_finalize);
1040 assert (m_option_infos.size() + 1 == m_option_defs.size());
1042 if (option_idx < m_option_infos.size())
1044 error = m_option_infos[option_idx].option_group->SetOptionValue (m_interpreter,
1045 m_option_infos[option_idx].option_index,
1051 error.SetErrorString ("invalid option index"); // Shouldn't happen...
1057 OptionGroupOptions::OptionParsingStarting ()
1059 std::set<OptionGroup*> group_set;
1060 OptionInfos::iterator pos, end = m_option_infos.end();
1061 for (pos = m_option_infos.begin(); pos != end; ++pos)
1063 OptionGroup* group = pos->option_group;
1064 if (group_set.find(group) == group_set.end())
1066 group->OptionParsingStarting (m_interpreter);
1067 group_set.insert(group);
1072 OptionGroupOptions::OptionParsingFinished ()
1074 std::set<OptionGroup*> group_set;
1076 OptionInfos::iterator pos, end = m_option_infos.end();
1077 for (pos = m_option_infos.begin(); pos != end; ++pos)
1079 OptionGroup* group = pos->option_group;
1080 if (group_set.find(group) == group_set.end())
1082 error = group->OptionParsingFinished (m_interpreter);
1083 group_set.insert(group);