From 87093f538625055e90dd47dbfbb5df747f56591a Mon Sep 17 00:00:00 2001 From: Morten Welinder Date: Mon, 18 Dec 2000 03:49:49 +0000 Subject: [PATCH] (parse_options): Allow GNU-like option arguments like "--desktop=800x600". (Not perfect -- we don't allow shorthands.) --- misc/options.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/misc/options.c b/misc/options.c index cae462fda77..ca8d99a8556 100644 --- a/misc/options.c +++ b/misc/options.c @@ -248,6 +248,7 @@ static void parse_options( char *argv[] ) for (i = 0; argv[i]; i++) { + const char *equalarg = NULL; char *p = argv[i]; if (*p++ != '-') continue; /* not an option */ if (*p && !p[1]) /* short name */ @@ -257,14 +258,31 @@ static void parse_options( char *argv[] ) } else /* long name */ { + const char *equal = strchr (p, '='); if (*p == '-') p++; /* check for the long name */ - for (opt = option_table; opt->longname; opt++) + for (opt = option_table; opt->longname; opt++) { + /* Plain --option */ if (!strcmp( p, opt->longname )) break; + + /* --option=value */ + if (opt->has_arg && + equal && + strlen (opt->longname) == equal - p && + !strncmp (p, opt->longname, equal - p)) { + equalarg = equal + 1; + break; + } + } } if (!opt->longname) continue; - if (opt->has_arg && argv[i+1]) + if (equalarg) + { + opt->func( equalarg ); + remove_options( argv, i, 1, opt->inherit ); + } + else if (opt->has_arg && argv[i+1]) { opt->func( argv[i+1] ); remove_options( argv, i, 2, opt->inherit );