option-parser: Add support for the '--' options

This toggles parse_options to ignore the rest of the remaining
options.

Signed-off-by: Nicholas Niro <blowfist@xroutine.net>
This commit is contained in:
Nicholas Niro 2023-10-21 15:59:00 -04:00 committed by Pekka Paalanen
parent 7e150101ba
commit 10a455f2ba
1 changed files with 8 additions and 1 deletions

View File

@ -167,10 +167,17 @@ parse_options(const struct weston_option *options,
int count, int *argc, char *argv[])
{
int i, j;
int ignore_options = 0;
for (i = 1, j = 1; i < *argc; i++) {
if (argv[i][0] == '-') {
if (argv[i][0] == '-' && ignore_options == 0) {
if (argv[i][1] == '-') {
if (strlen(argv[i]) == 2) {
/* '--' to ignore the remaining options */
i--; /* reinsert the '--' entry */
ignore_options = 1;
continue;
}
/* Long option, e.g. --foo or --foo=bar */
if (long_option(options, count, argv[i]))
continue;