diff options
author | jsing <> | 2014-08-28 14:15:28 +0000 |
---|---|---|
committer | jsing <> | 2014-08-28 14:15:28 +0000 |
commit | 31c9e04aeb255ae1ae51c6f06be5e4714c9e9054 (patch) | |
tree | 7ad8821d2764d0d699b6be9caad478781a13d65f /src | |
parent | f430ac8944374866d079eae7d55e530af6edae73 (diff) | |
download | openbsd-31c9e04aeb255ae1ae51c6f06be5e4714c9e9054.tar.gz openbsd-31c9e04aeb255ae1ae51c6f06be5e4714c9e9054.tar.bz2 openbsd-31c9e04aeb255ae1ae51c6f06be5e4714c9e9054.zip |
Add option handling with a callback function for argument processing.
Diffstat (limited to 'src')
-rw-r--r-- | src/usr.bin/openssl/apps.c | 8 | ||||
-rw-r--r-- | src/usr.bin/openssl/apps.h | 4 |
2 files changed, 10 insertions, 2 deletions
diff --git a/src/usr.bin/openssl/apps.c b/src/usr.bin/openssl/apps.c index 76977ec44a..7a5def5007 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.7 2014/08/28 13:55:19 jsing Exp $ */ | 1 | /* $OpenBSD: apps.c,v 1.8 2014/08/28 14:15:28 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -2280,6 +2280,7 @@ options_parse(int argc, char **argv, struct option *opts, char **unnamed) | |||
2280 | 2280 | ||
2281 | if (opt->type == OPTION_ARG || | 2281 | if (opt->type == OPTION_ARG || |
2282 | opt->type == OPTION_ARG_FORMAT || | 2282 | opt->type == OPTION_ARG_FORMAT || |
2283 | opt->type == OPTION_ARG_FUNC || | ||
2283 | opt->type == OPTION_ARG_INT) { | 2284 | opt->type == OPTION_ARG_INT) { |
2284 | if (++i >= argc) { | 2285 | if (++i >= argc) { |
2285 | fprintf(stderr, | 2286 | fprintf(stderr, |
@@ -2305,6 +2306,11 @@ options_parse(int argc, char **argv, struct option *opts, char **unnamed) | |||
2305 | *opt->opt.value = fmt; | 2306 | *opt->opt.value = fmt; |
2306 | break; | 2307 | break; |
2307 | 2308 | ||
2309 | case OPTION_ARG_FUNC: | ||
2310 | if (opt->opt.func(opt, argv[i]) != 0) | ||
2311 | return (1); | ||
2312 | break; | ||
2313 | |||
2308 | case OPTION_ARG_INT: | 2314 | case OPTION_ARG_INT: |
2309 | val = strtonum(argv[i], 0, INT_MAX, &errstr); | 2315 | val = strtonum(argv[i], 0, INT_MAX, &errstr); |
2310 | if (errstr != NULL) { | 2316 | if (errstr != NULL) { |
diff --git a/src/usr.bin/openssl/apps.h b/src/usr.bin/openssl/apps.h index 3ea855f684..277dcc3699 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.5 2014/08/28 13:39:07 jsing Exp $ */ | 1 | /* $OpenBSD: apps.h,v 1.6 2014/08/28 14:15:28 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 | * |
@@ -289,6 +289,7 @@ struct option { | |||
289 | enum { | 289 | enum { |
290 | OPTION_ARG, | 290 | OPTION_ARG, |
291 | OPTION_ARG_FORMAT, | 291 | OPTION_ARG_FORMAT, |
292 | OPTION_ARG_FUNC, | ||
292 | OPTION_ARG_INT, | 293 | OPTION_ARG_INT, |
293 | OPTION_FLAG, | 294 | OPTION_FLAG, |
294 | OPTION_FLAG_ORD, | 295 | OPTION_FLAG_ORD, |
@@ -297,6 +298,7 @@ struct option { | |||
297 | union { | 298 | union { |
298 | char **arg; | 299 | char **arg; |
299 | int *flag; | 300 | int *flag; |
301 | int (*func)(struct option *opt, char *arg); | ||
300 | int *value; | 302 | int *value; |
301 | } opt; | 303 | } opt; |
302 | const int value; | 304 | const int value; |