summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Sing <jsing@cvs.openbsd.org>2014-08-28 14:15:29 +0000
committerJoel Sing <jsing@cvs.openbsd.org>2014-08-28 14:15:29 +0000
commit4c4bae99e00961e8d37e98a49174f7a389695caa (patch)
treefc93003eff74f6f8a5e5c2a1b9c1aa1828125a6f
parentce33da722b62f52a567c8b5eaa6c92a193da27ca (diff)
Add option handling with a callback function for argument processing.
-rw-r--r--usr.bin/openssl/apps.c8
-rw-r--r--usr.bin/openssl/apps.h4
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 <jsing@openbsd.org>
*
@@ -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;