summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorJoel Sing <jsing@cvs.openbsd.org>2014-12-28 15:48:53 +0000
committerJoel Sing <jsing@cvs.openbsd.org>2014-12-28 15:48:53 +0000
commit2a00c3ba2d6dd23ec91a9bd0bfe23c815c7ea804 (patch)
treeec5cb2c17afb9b4b72d4181bf6f0be7965d66ce3 /usr.bin
parent70224308c131509e526e86c51cb3143582e529a4 (diff)
Provide a mechanism for option parsing to return the number of arguments
that it has consumed. This allows for the handling of multiple unnamed arguments, including lists of filenames.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/openssl/apps.c11
-rw-r--r--usr.bin/openssl/apps.h5
-rw-r--r--usr.bin/openssl/crl.c4
-rw-r--r--usr.bin/openssl/ecparam.c4
-rw-r--r--usr.bin/openssl/prime.c4
-rw-r--r--usr.bin/openssl/rand.c4
-rw-r--r--usr.bin/openssl/version.c4
7 files changed, 22 insertions, 14 deletions
diff --git a/usr.bin/openssl/apps.c b/usr.bin/openssl/apps.c
index 506e421cc12..7c774e40776 100644
--- a/usr.bin/openssl/apps.c
+++ b/usr.bin/openssl/apps.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: apps.c,v 1.17 2014/12/28 15:05:38 jsing Exp $ */
+/* $OpenBSD: apps.c,v 1.18 2014/12/28 15:48:52 jsing Exp $ */
/*
* Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
*
@@ -2242,7 +2242,8 @@ options_usage(struct option *opts)
}
int
-options_parse(int argc, char **argv, struct option *opts, char **unnamed)
+options_parse(int argc, char **argv, struct option *opts, char **unnamed,
+ int *argsused)
{
const char *errstr;
struct option *opt;
@@ -2260,6 +2261,8 @@ options_parse(int argc, char **argv, struct option *opts, char **unnamed)
/* Single unnamed argument (without leading hyphen). */
if (*p++ != '-') {
+ if (argsused != NULL)
+ goto done;
if (unnamed == NULL)
goto unknown;
if (*unnamed != NULL)
@@ -2344,6 +2347,10 @@ options_parse(int argc, char **argv, struct option *opts, char **unnamed)
}
}
+done:
+ if (argsused != NULL)
+ *argsused = i;
+
return (0);
toomany:
diff --git a/usr.bin/openssl/apps.h b/usr.bin/openssl/apps.h
index b069d2d29bf..c448e85d879 100644
--- a/usr.bin/openssl/apps.h
+++ b/usr.bin/openssl/apps.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: apps.h,v 1.10 2014/12/28 14:21:42 jsing Exp $ */
+/* $OpenBSD: apps.h,v 1.11 2014/12/28 15:48:52 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -305,6 +305,7 @@ struct option {
};
void options_usage(struct option *opts);
-int options_parse(int argc, char **argv, struct option *opts, char **unnamed);
+int options_parse(int argc, char **argv, struct option *opts, char **unnamed,
+ int *argsused);
#endif
diff --git a/usr.bin/openssl/crl.c b/usr.bin/openssl/crl.c
index 0391e6e4dc0..2b6a4a3e5df 100644
--- a/usr.bin/openssl/crl.c
+++ b/usr.bin/openssl/crl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: crl.c,v 1.5 2014/10/13 02:46:14 bcook Exp $ */
+/* $OpenBSD: crl.c,v 1.6 2014/12/28 15:48:52 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -244,7 +244,7 @@ crl_main(int argc, char **argv)
crl_config.informat = FORMAT_PEM;
crl_config.outformat = FORMAT_PEM;
- if (options_parse(argc, argv, crl_options, &digest_name) != 0) {
+ if (options_parse(argc, argv, crl_options, &digest_name, NULL) != 0) {
crl_usage();
goto end;
}
diff --git a/usr.bin/openssl/ecparam.c b/usr.bin/openssl/ecparam.c
index 57797a8e4e6..c958c1f51b2 100644
--- a/usr.bin/openssl/ecparam.c
+++ b/usr.bin/openssl/ecparam.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ecparam.c,v 1.7 2014/12/28 14:21:42 jsing Exp $ */
+/* $OpenBSD: ecparam.c,v 1.8 2014/12/28 15:48:52 jsing Exp $ */
/*
* Written by Nils Larsch for the OpenSSL project.
*/
@@ -277,7 +277,7 @@ ecparam_main(int argc, char **argv)
ecparam_config.informat = FORMAT_PEM;
ecparam_config.outformat = FORMAT_PEM;
- if (options_parse(argc, argv, ecparam_options, NULL) != 0) {
+ if (options_parse(argc, argv, ecparam_options, NULL, NULL) != 0) {
ecparam_usage();
goto end;
}
diff --git a/usr.bin/openssl/prime.c b/usr.bin/openssl/prime.c
index d9237f9070a..fca3701632c 100644
--- a/usr.bin/openssl/prime.c
+++ b/usr.bin/openssl/prime.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: prime.c,v 1.3 2014/10/13 02:46:14 bcook Exp $ */
+/* $OpenBSD: prime.c,v 1.4 2014/12/28 15:48:52 jsing Exp $ */
/* ====================================================================
* Copyright (c) 2004 The OpenSSL Project. All rights reserved.
*
@@ -123,7 +123,7 @@ prime_main(int argc, char **argv)
/* Default iterations for Miller-Rabin probabilistic primality test. */
prime_config.checks = 20;
- if (options_parse(argc, argv, prime_options, &prime) != 0) {
+ if (options_parse(argc, argv, prime_options, &prime, NULL) != 0) {
prime_usage();
return (1);
}
diff --git a/usr.bin/openssl/rand.c b/usr.bin/openssl/rand.c
index 6de2208b425..eccf4dee866 100644
--- a/usr.bin/openssl/rand.c
+++ b/usr.bin/openssl/rand.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rand.c,v 1.5 2014/10/22 13:54:03 jsing Exp $ */
+/* $OpenBSD: rand.c,v 1.6 2014/12/28 15:48:52 jsing Exp $ */
/* ====================================================================
* Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
*
@@ -123,7 +123,7 @@ rand_main(int argc, char **argv)
memset(&rand_config, 0, sizeof(rand_config));
- if (options_parse(argc, argv, rand_options, &num_bytes) != 0) {
+ if (options_parse(argc, argv, rand_options, &num_bytes, NULL) != 0) {
rand_usage();
return (1);
}
diff --git a/usr.bin/openssl/version.c b/usr.bin/openssl/version.c
index 953d0c3afea..2e28fa4345b 100644
--- a/usr.bin/openssl/version.c
+++ b/usr.bin/openssl/version.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: version.c,v 1.4 2014/12/28 14:21:42 jsing Exp $ */
+/* $OpenBSD: version.c,v 1.5 2014/12/28 15:48:52 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -217,7 +217,7 @@ version_main(int argc, char **argv)
{
memset(&version_config, 0, sizeof(version_config));
- if (options_parse(argc, argv, version_options, NULL) != 0) {
+ if (options_parse(argc, argv, version_options, NULL, NULL) != 0) {
version_usage();
return (1);
}