diff options
author | Joel Sing <jsing@cvs.openbsd.org> | 2014-12-28 16:22:38 +0000 |
---|---|---|
committer | Joel Sing <jsing@cvs.openbsd.org> | 2014-12-28 16:22:38 +0000 |
commit | aec002be9e98a9b250be62a66f544c498e942d19 (patch) | |
tree | ccc6779a9a37ca805a498ac7d06489d3657f7108 /usr.bin/openssl | |
parent | 70f6f6575dea03b43f5f8f1671d1fce1d7399ce6 (diff) |
Provide an option type that allows for a callback function to consume an
arbitrary number of arguments. This will allow for more complex option
handling as required by some of the openssl(1) applications.
Diffstat (limited to 'usr.bin/openssl')
-rw-r--r-- | usr.bin/openssl/apps.c | 11 | ||||
-rw-r--r-- | usr.bin/openssl/apps.h | 4 |
2 files changed, 12 insertions, 3 deletions
diff --git a/usr.bin/openssl/apps.c b/usr.bin/openssl/apps.c index 4640519cf1d..1155278b791 100644 --- a/usr.bin/openssl/apps.c +++ b/usr.bin/openssl/apps.c @@ -1,4 +1,4 @@ -/* $OpenBSD: apps.c,v 1.19 2014/12/28 16:10:33 jsing Exp $ */ +/* $OpenBSD: apps.c,v 1.20 2014/12/28 16:22:37 jsing Exp $ */ /* * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> * @@ -2249,9 +2249,9 @@ options_parse(int argc, char **argv, struct option *opts, char **unnamed, struct option *opt; long long val; char *arg, *p; + int fmt, used; int ord = 0; int i, j; - int fmt; if (unnamed != NULL) *unnamed = NULL; @@ -2286,6 +2286,7 @@ options_parse(int argc, char **argv, struct option *opts, char **unnamed, goto unknown; } + /* See if there is a matching option... */ for (j = 0; opts[j].name != NULL; j++) { opt = &opts[j]; if (strcmp(p, opt->name) == 0) @@ -2310,6 +2311,12 @@ options_parse(int argc, char **argv, struct option *opts, char **unnamed, *opt->opt.arg = argv[i]; break; + case OPTION_ARGV_FUNC: + if (opt->opt.argvfunc(argc - i, &argv[i], &used) != 0) + return (1); + i += used - 1; + break; + case OPTION_ARG_FORMAT: fmt = str2fmt(argv[i]); if (fmt == FORMAT_UNDEF) { diff --git a/usr.bin/openssl/apps.h b/usr.bin/openssl/apps.h index c448e85d879..f0571480e28 100644 --- a/usr.bin/openssl/apps.h +++ b/usr.bin/openssl/apps.h @@ -1,4 +1,4 @@ -/* $OpenBSD: apps.h,v 1.11 2014/12/28 15:48:52 jsing Exp $ */ +/* $OpenBSD: apps.h,v 1.12 2014/12/28 16:22:37 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -286,6 +286,7 @@ struct option { const char *desc; enum { OPTION_ARG, + OPTION_ARGV_FUNC, OPTION_ARG_FORMAT, OPTION_ARG_FUNC, OPTION_ARG_INT, @@ -297,6 +298,7 @@ struct option { union { char **arg; int (*argfunc)(char *arg); + int (*argvfunc)(int argc, char **argv, int *argsused); int *flag; int (*func)(void); int *value; |