silently accept multiple unnamed arguments, ignoring all except the last.
This behaviour was already inconsistent between openssl(1) applications;
apply the principal of least surprise. This will also simplify the addition
of upcoming functionality.
-/* $OpenBSD: apps.c,v 1.16 2014/12/28 14:50:15 jsing Exp $ */
+/* $OpenBSD: apps.c,v 1.17 2014/12/28 15:05:38 jsing Exp $ */
/*
* Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
*
int i, j;
int fmt;
+ if (unnamed != NULL)
+ *unnamed = NULL;
+
for (i = 1; i < argc; i++) {
p = arg = argv[i];
+ /* Single unnamed argument (without leading hyphen). */
if (*p++ != '-') {
if (unnamed == NULL)
goto unknown;
+ if (*unnamed != NULL)
+ goto toomany;
*unnamed = arg;
continue;
}
+
if (*p == '\0') /* XXX - end of named options. */
goto unknown;
return (0);
+toomany:
+ fprintf(stderr, "too many arguments\n");
+ return (1);
+
unknown:
fprintf(stderr, "unknown option '%s'\n", arg);
return (1);