From 4c4bae99e00961e8d37e98a49174f7a389695caa Mon Sep 17 00:00:00 2001 From: Joel Sing Date: Thu, 28 Aug 2014 14:15:29 +0000 Subject: Add option handling with a callback function for argument processing. --- usr.bin/openssl/apps.c | 8 +++++++- usr.bin/openssl/apps.h | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/usr.bin/openssl/apps.c b/usr.bin/openssl/apps.c index 76977ec44ab..7a5def5007d 100644 --- a/usr.bin/openssl/apps.c +++ b/usr.bin/openssl/apps.c @@ -1,4 +1,4 @@ -/* $OpenBSD: apps.c,v 1.7 2014/08/28 13:55:19 jsing Exp $ */ +/* $OpenBSD: apps.c,v 1.8 2014/08/28 14:15:28 jsing Exp $ */ /* * Copyright (c) 2014 Joel Sing * @@ -2280,6 +2280,7 @@ options_parse(int argc, char **argv, struct option *opts, char **unnamed) if (opt->type == OPTION_ARG || opt->type == OPTION_ARG_FORMAT || + opt->type == OPTION_ARG_FUNC || opt->type == OPTION_ARG_INT) { if (++i >= argc) { fprintf(stderr, @@ -2305,6 +2306,11 @@ options_parse(int argc, char **argv, struct option *opts, char **unnamed) *opt->opt.value = fmt; break; + case OPTION_ARG_FUNC: + if (opt->opt.func(opt, argv[i]) != 0) + return (1); + break; + case OPTION_ARG_INT: val = strtonum(argv[i], 0, INT_MAX, &errstr); if (errstr != NULL) { diff --git a/usr.bin/openssl/apps.h b/usr.bin/openssl/apps.h index 3ea855f6848..277dcc36997 100644 --- a/usr.bin/openssl/apps.h +++ b/usr.bin/openssl/apps.h @@ -1,4 +1,4 @@ -/* $OpenBSD: apps.h,v 1.5 2014/08/28 13:39:07 jsing Exp $ */ +/* $OpenBSD: apps.h,v 1.6 2014/08/28 14:15:28 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -289,6 +289,7 @@ struct option { enum { OPTION_ARG, OPTION_ARG_FORMAT, + OPTION_ARG_FUNC, OPTION_ARG_INT, OPTION_FLAG, OPTION_FLAG_ORD, @@ -297,6 +298,7 @@ struct option { union { char **arg; int *flag; + int (*func)(struct option *opt, char *arg); int *value; } opt; const int value; -- cgit v1.2.3