// static
int OptionParser::Match(const char* s, const std::string& full, bool has_argument) {
int i;
for (i = 0;; i++) {
if (full[i] == '\0') { // Perfect match. Return +1, so it will be preferred over a longer option // with the same prefix.
if (s[i] == '\0') { return i + 1;
}
// We want to fail if s is longer than full, e.g. --foobar vs. --foo. // However, if s ends with an '=', it's OK.
if (!(has_argument && s[i] == '=')) { return -1;
} break;
}
if (s[i] == '\0') { break;
}
if (s[i] != full[i]) { return -1;
}
} return i;
}
void OptionParser::Errorf(const char* format, ...) {
WABT_SNPRINTF_ALLOCA(buffer, length, format);
std::string msg(program_name_);
msg += ": ";
msg += buffer;
msg += "\nTry '--help' for more information.";
on_error_(msg.c_str());
}
const Option& best_option = options_[best_index]; const char* option_argument = nullptr;
if (best_option.has_argument) {
if (arg[best_length + 1] != 0 && // This byte is 0 on a full match.
arg[best_length + 2] == '=') { // +2 to skip "--".
option_argument = &arg[best_length + 3];
} else {
if (i + 1 == argc || argv[i + 1][0] == '-') {
Errorf("option '--%s' requires argument",
best_option.long_name.c_str()); continue;
}
++i;
option_argument = argv[i];
}
}
best_option.callback(option_argument);
} else { // Short option.
if (arg[1] == '\0') { // Just "-".
HandleArgument(&arg_index, arg); continue;
}
// Allow short names to be combined, e.g. "-d -v" => "-dv".
for (int k = 1; arg[k]; ++k) { bool matched = false;
for (const Option& option : options_) {
if (option.short_name && arg[k] == option.short_name) { const char* option_argument = nullptr;
if (option.has_argument) { // A short option with a required argument cannot be followed // by other short options_.
if (arg[k + 1] != '\0') {
Errorf("option '-%c' requires argument", option.short_name); break;
}
// For now, all arguments must be provided. Check that the last Argument was // handled at least once.
if (!arguments_.empty() && arguments_.back().handled_count == 0) {
for (size_t i = arg_index; i < arguments_.size(); ++i) {
if (arguments_[i].count != ArgumentCount::ZeroOrMore) {
Errorf("expected %s argument.", arguments_[i].name.c_str());
}
}
}
}
if (length > longest_name_length) {
longest_name_length = length;
}
}
for (const Option& option : options_) {
if (!option.short_name && option.long_name.empty()) { continue;
}
std::string line;
if (option.short_name) {
line += std::string(" -") + option.short_name + ", ";
} else {
line += " ";
}
std::string flag;
if (!option.long_name.empty()) {
flag = "--";
if (!option.metavar.empty()) {
flag += option.long_name + '=' + option.metavar;
} else {
flag += option.long_name;
}
}
// +2 for "--" of the long flag name.
size_t remaining = longest_name_length + kExtraSpace + 2 - flag.size();
line += flag + std::string(remaining, ' ');
if (!option.help.empty()) {
line += option.help;
}
printf("%s\n", line.c_str());
}
}
} // namespace wabt
Messung V0.5 in Prozent
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.15Angebot
(Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-08-28)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.