From b1649c7e203ad5ad9f94d93eb3ff3a0298301bf6 Mon Sep 17 00:00:00 2001 From: jsing Date: Sun, 28 Dec 2014 16:22:37 +0000 Subject: [PATCH] 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. --- usr.bin/openssl/apps.c | 11 +++++++++-- 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 * @@ -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; -- 2.20.1