From 3016f0d916cff2fa5c93e769e25ded6c34e7fb73 Mon Sep 17 00:00:00 2001 From: jsing <> Date: Sat, 30 Aug 2014 15:14:03 +0000 Subject: Move the callback function pointer outside the opt union so that the option values are useable by the function. Also provide an option type that calls a function without consuming/passing an argument. --- src/usr.bin/openssl/apps.c | 9 +++++++-- src/usr.bin/openssl/apps.h | 5 +++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/usr.bin/openssl/apps.c b/src/usr.bin/openssl/apps.c index 7a5def5007..4aac0ff6d2 100644 --- a/src/usr.bin/openssl/apps.c +++ b/src/usr.bin/openssl/apps.c @@ -1,4 +1,4 @@ -/* $OpenBSD: apps.c,v 1.8 2014/08/28 14:15:28 jsing Exp $ */ +/* $OpenBSD: apps.c,v 1.9 2014/08/30 15:14:03 jsing Exp $ */ /* * Copyright (c) 2014 Joel Sing * @@ -2307,7 +2307,7 @@ options_parse(int argc, char **argv, struct option *opts, char **unnamed) break; case OPTION_ARG_FUNC: - if (opt->opt.func(opt, argv[i]) != 0) + if (opt->func(opt, argv[i]) != 0) return (1); break; @@ -2322,6 +2322,11 @@ options_parse(int argc, char **argv, struct option *opts, char **unnamed) *opt->opt.value = (int)val; break; + case OPTION_FUNC: + if (opt->func(opt, NULL) != 0) + return (1); + break; + case OPTION_FLAG: *opt->opt.flag = 1; break; diff --git a/src/usr.bin/openssl/apps.h b/src/usr.bin/openssl/apps.h index 277dcc3699..ea6be60a44 100644 --- a/src/usr.bin/openssl/apps.h +++ b/src/usr.bin/openssl/apps.h @@ -1,4 +1,4 @@ -/* $OpenBSD: apps.h,v 1.6 2014/08/28 14:15:28 jsing Exp $ */ +/* $OpenBSD: apps.h,v 1.7 2014/08/30 15:14:03 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -291,6 +291,7 @@ struct option { OPTION_ARG_FORMAT, OPTION_ARG_FUNC, OPTION_ARG_INT, + OPTION_FUNC, OPTION_FLAG, OPTION_FLAG_ORD, OPTION_VALUE, @@ -298,9 +299,9 @@ struct option { union { char **arg; int *flag; - int (*func)(struct option *opt, char *arg); int *value; } opt; + int (*func)(struct option *opt, char *arg); const int value; }; -- cgit v1.2.3-55-g6feb