diff options
author | jsing <> | 2014-09-01 14:21:06 +0000 |
---|---|---|
committer | jsing <> | 2014-09-01 14:21:06 +0000 |
commit | 6ba9e33f75744ee0b55d3b232099cde23f66eea7 (patch) | |
tree | aeca9fb859f91c93d0a80c1879bec27ac8d1ba43 /src | |
parent | 306fc7823dc8064742f82e15e8fbf1e49eefdf4a (diff) | |
download | openbsd-6ba9e33f75744ee0b55d3b232099cde23f66eea7.tar.gz openbsd-6ba9e33f75744ee0b55d3b232099cde23f66eea7.tar.bz2 openbsd-6ba9e33f75744ee0b55d3b232099cde23f66eea7.zip |
Improve option usage output.
If the option/argument string exceeds the given width, add a hanging indent
prior to displaying the description. Also, if the description includes
newlines, wrap and indent for each newline so that the indentation is
correctly maintained.
Diffstat (limited to 'src')
-rw-r--r-- | src/usr.bin/openssl/apps.c | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/src/usr.bin/openssl/apps.c b/src/usr.bin/openssl/apps.c index 4aac0ff6d2..c4ab7c8350 100644 --- a/src/usr.bin/openssl/apps.c +++ b/src/usr.bin/openssl/apps.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: apps.c,v 1.9 2014/08/30 15:14:03 jsing Exp $ */ | 1 | /* $OpenBSD: apps.c,v 1.10 2014/09/01 14:21:06 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -2234,19 +2234,32 @@ app_isdir(const char *name) | |||
2234 | return -1; | 2234 | return -1; |
2235 | } | 2235 | } |
2236 | 2236 | ||
2237 | #define OPTION_WIDTH 18 | ||
2238 | |||
2237 | void | 2239 | void |
2238 | options_usage(struct option *opts) | 2240 | options_usage(struct option *opts) |
2239 | { | 2241 | { |
2240 | const char *argname; | 2242 | const char *p, *q; |
2241 | char buf[32]; | 2243 | char optstr[32]; |
2242 | int i; | 2244 | int i; |
2243 | 2245 | ||
2244 | for (i = 0; opts[i].name != NULL; i++) { | 2246 | for (i = 0; opts[i].name != NULL; i++) { |
2245 | if (opts[i].desc == NULL) | 2247 | if (opts[i].desc == NULL) |
2246 | continue; | 2248 | continue; |
2247 | argname = (opts[i].argname != NULL) ? opts[i].argname : ""; | 2249 | |
2248 | snprintf(buf, sizeof(buf), "-%s %s", opts[i].name, argname); | 2250 | snprintf(optstr, sizeof(optstr), "-%s %s", opts[i].name, |
2249 | fprintf(stderr, " %-*s %s\n", 16, buf, opts[i].desc); | 2251 | (opts[i].argname != NULL) ? opts[i].argname : ""); |
2252 | fprintf(stderr, " %-*s", OPTION_WIDTH, optstr); | ||
2253 | if (strlen(optstr) > OPTION_WIDTH) | ||
2254 | fprintf(stderr, "\n %-*s", OPTION_WIDTH, ""); | ||
2255 | |||
2256 | p = opts[i].desc; | ||
2257 | while ((q = strchr(p, '\n')) != NULL) { | ||
2258 | fprintf(stderr, " %.*s", (int)(q - p), p); | ||
2259 | fprintf(stderr, "\n %-*s", OPTION_WIDTH, ""); | ||
2260 | p = q + 1; | ||
2261 | } | ||
2262 | fprintf(stderr, " %s\n", p); | ||
2250 | } | 2263 | } |
2251 | } | 2264 | } |
2252 | 2265 | ||
@@ -2270,7 +2283,7 @@ options_parse(int argc, char **argv, struct option *opts, char **unnamed) | |||
2270 | *unnamed = arg; | 2283 | *unnamed = arg; |
2271 | continue; | 2284 | continue; |
2272 | } | 2285 | } |
2273 | if (*p == '\0') | 2286 | if (*p == '\0') /* XXX - end of named options. */ |
2274 | goto unknown; | 2287 | goto unknown; |
2275 | 2288 | ||
2276 | for (j = 0; opts[j].name != NULL; j++) { | 2289 | for (j = 0; opts[j].name != NULL; j++) { |