diff options
| author | jsing <> | 2014-12-28 16:22:37 +0000 |
|---|---|---|
| committer | jsing <> | 2014-12-28 16:22:37 +0000 |
| commit | 4eb0a7a0a04348c425df5fc594de04a50beb7f6a (patch) | |
| tree | 7c2d7055314f7a997398ccc4d632a9e294f88b81 | |
| parent | 7f2737fdac1da5c9ccdfadd17f52ea59bf546ff1 (diff) | |
| download | openbsd-4eb0a7a0a04348c425df5fc594de04a50beb7f6a.tar.gz openbsd-4eb0a7a0a04348c425df5fc594de04a50beb7f6a.tar.bz2 openbsd-4eb0a7a0a04348c425df5fc594de04a50beb7f6a.zip | |
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 '')
| -rw-r--r-- | src/usr.bin/openssl/apps.c | 11 | ||||
| -rw-r--r-- | src/usr.bin/openssl/apps.h | 4 |
2 files changed, 12 insertions, 3 deletions
diff --git a/src/usr.bin/openssl/apps.c b/src/usr.bin/openssl/apps.c index 4640519cf1..1155278b79 100644 --- a/src/usr.bin/openssl/apps.c +++ b/src/usr.bin/openssl/apps.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: apps.c,v 1.19 2014/12/28 16:10:33 jsing Exp $ */ | 1 | /* $OpenBSD: apps.c,v 1.20 2014/12/28 16:22:37 jsing Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
| 4 | * | 4 | * |
| @@ -2249,9 +2249,9 @@ options_parse(int argc, char **argv, struct option *opts, char **unnamed, | |||
| 2249 | struct option *opt; | 2249 | struct option *opt; |
| 2250 | long long val; | 2250 | long long val; |
| 2251 | char *arg, *p; | 2251 | char *arg, *p; |
| 2252 | int fmt, used; | ||
| 2252 | int ord = 0; | 2253 | int ord = 0; |
| 2253 | int i, j; | 2254 | int i, j; |
| 2254 | int fmt; | ||
| 2255 | 2255 | ||
| 2256 | if (unnamed != NULL) | 2256 | if (unnamed != NULL) |
| 2257 | *unnamed = NULL; | 2257 | *unnamed = NULL; |
| @@ -2286,6 +2286,7 @@ options_parse(int argc, char **argv, struct option *opts, char **unnamed, | |||
| 2286 | goto unknown; | 2286 | goto unknown; |
| 2287 | } | 2287 | } |
| 2288 | 2288 | ||
| 2289 | /* See if there is a matching option... */ | ||
| 2289 | for (j = 0; opts[j].name != NULL; j++) { | 2290 | for (j = 0; opts[j].name != NULL; j++) { |
| 2290 | opt = &opts[j]; | 2291 | opt = &opts[j]; |
| 2291 | if (strcmp(p, opt->name) == 0) | 2292 | if (strcmp(p, opt->name) == 0) |
| @@ -2310,6 +2311,12 @@ options_parse(int argc, char **argv, struct option *opts, char **unnamed, | |||
| 2310 | *opt->opt.arg = argv[i]; | 2311 | *opt->opt.arg = argv[i]; |
| 2311 | break; | 2312 | break; |
| 2312 | 2313 | ||
| 2314 | case OPTION_ARGV_FUNC: | ||
| 2315 | if (opt->opt.argvfunc(argc - i, &argv[i], &used) != 0) | ||
| 2316 | return (1); | ||
| 2317 | i += used - 1; | ||
| 2318 | break; | ||
| 2319 | |||
| 2313 | case OPTION_ARG_FORMAT: | 2320 | case OPTION_ARG_FORMAT: |
| 2314 | fmt = str2fmt(argv[i]); | 2321 | fmt = str2fmt(argv[i]); |
| 2315 | if (fmt == FORMAT_UNDEF) { | 2322 | if (fmt == FORMAT_UNDEF) { |
diff --git a/src/usr.bin/openssl/apps.h b/src/usr.bin/openssl/apps.h index c448e85d87..f0571480e2 100644 --- a/src/usr.bin/openssl/apps.h +++ b/src/usr.bin/openssl/apps.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: apps.h,v 1.11 2014/12/28 15:48:52 jsing Exp $ */ | 1 | /* $OpenBSD: apps.h,v 1.12 2014/12/28 16:22:37 jsing Exp $ */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -286,6 +286,7 @@ struct option { | |||
| 286 | const char *desc; | 286 | const char *desc; |
| 287 | enum { | 287 | enum { |
| 288 | OPTION_ARG, | 288 | OPTION_ARG, |
| 289 | OPTION_ARGV_FUNC, | ||
| 289 | OPTION_ARG_FORMAT, | 290 | OPTION_ARG_FORMAT, |
| 290 | OPTION_ARG_FUNC, | 291 | OPTION_ARG_FUNC, |
| 291 | OPTION_ARG_INT, | 292 | OPTION_ARG_INT, |
| @@ -297,6 +298,7 @@ struct option { | |||
| 297 | union { | 298 | union { |
| 298 | char **arg; | 299 | char **arg; |
| 299 | int (*argfunc)(char *arg); | 300 | int (*argfunc)(char *arg); |
| 301 | int (*argvfunc)(int argc, char **argv, int *argsused); | ||
| 300 | int *flag; | 302 | int *flag; |
| 301 | int (*func)(void); | 303 | int (*func)(void); |
| 302 | int *value; | 304 | int *value; |
