mirror of https://git.tukaani.org/xz.git
Refactored option parsing.
This commit is contained in:
parent
25adaaa56e
commit
319a0fd7d7
|
@ -87,28 +87,34 @@ parse_options(const char *str, const option_map *opts,
|
||||||
"pairs separated with commas"), str);
|
"pairs separated with commas"), str);
|
||||||
|
|
||||||
// Look for the option name from the option map.
|
// Look for the option name from the option map.
|
||||||
bool found = false;
|
size_t i = 0;
|
||||||
for (size_t i = 0; opts[i].name != NULL; ++i) {
|
while (true) {
|
||||||
if (strcmp(name, opts[i].name) != 0)
|
if (opts[i].name == NULL)
|
||||||
continue;
|
message_fatal(_("%s: Invalid option name"),
|
||||||
|
name);
|
||||||
|
|
||||||
|
if (strcmp(name, opts[i].name) == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Option was found from the map. See how we should handle it.
|
||||||
if (opts[i].map != NULL) {
|
if (opts[i].map != NULL) {
|
||||||
// value is a string which we should map
|
// value is a string which we should map
|
||||||
// to an integer.
|
// to an integer.
|
||||||
size_t j;
|
size_t j;
|
||||||
for (j = 0; opts[i].map[j].name != NULL; ++j) {
|
for (j = 0; opts[i].map[j].name != NULL; ++j) {
|
||||||
if (strcmp(opts[i].map[j].name, value)
|
if (strcmp(opts[i].map[j].name, value) == 0)
|
||||||
== 0)
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts[i].map[j].name == NULL)
|
if (opts[i].map[j].name == NULL)
|
||||||
message_fatal(_("%s: Invalid option "
|
message_fatal(_("%s: Invalid option value"),
|
||||||
"value"), value);
|
|
||||||
|
|
||||||
set(filter_options, i, opts[i].map[j].id,
|
|
||||||
value);
|
value);
|
||||||
|
|
||||||
|
set(filter_options, i, opts[i].map[j].id, value);
|
||||||
|
|
||||||
} else if (opts[i].min == UINT64_MAX) {
|
} else if (opts[i].min == UINT64_MAX) {
|
||||||
// value is a special string that will be
|
// value is a special string that will be
|
||||||
// parsed by set().
|
// parsed by set().
|
||||||
|
@ -121,13 +127,7 @@ parse_options(const char *str, const option_map *opts,
|
||||||
set(filter_options, i, v, value);
|
set(filter_options, i, v, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
found = true;
|
// Check if it was the last option.
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!found)
|
|
||||||
message_fatal(_("%s: Invalid option name"), name);
|
|
||||||
|
|
||||||
if (split == NULL)
|
if (split == NULL)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue