[PATCH] Lining up option descriptions in cmdline binary help
From: <cmpilato_at_collab.net>
Date: 2002-04-14 09:04:23 CEST
My brain feels super-mushy right now, so rather than commit this chunk
--
* subversion/clients/cmdline/main.c
(format_option): Fix potential segfault when OPT is NULL. Also,
stop using tabs to supposedly attempt to line up the documentation
strings ... it just doesn't work.
Index: ./subversion/clients/cmdline/main.c
===================================================================
--- ./subversion/clients/cmdline/main.c
+++ ./subversion/clients/cmdline/main.c Sun Apr 14 01:58:22 2002
@@ -351,20 +351,43 @@
apr_pool_t *pool)
{
char *opts;
+ char optsw[24]; /* ### this needs to be at least as long as the
+ longest option string up to the optional ARG. */
+ /* If there is no option, just return a '?' string. */
if (opt == NULL)
- *string = apr_psprintf (pool, "?");
+ {
+ *string = apr_psprintf (pool, "?");
+ return;
+ }
+ /* Else, we have a valid option which may or may not have a "short
+ name" (a single-character alias for the long option). */
if (opt->optch <= 255)
opts = apr_psprintf (pool, "-%c [--%s]", opt->optch, opt->name);
else
opts = apr_psprintf (pool, "--%s", opt->name);
+ /* If option takes an argument, specify this in the string. */
if (opt->has_arg)
opts = apr_pstrcat (pool, opts, " arg", NULL);
+ /* If there exists documentation for the option, add this to the
+ string as well, starting at the sizeof(optsw)'th column. */
if (doc)
- opts = apr_pstrcat (pool, opts, ":\t", opt->description, NULL);
+ {
+ int opts_len = strlen (opts);
+ int optsw_len = sizeof (optsw) / sizeof (*optsw);
+ int i;
+
+ /* Pad the existing OPTS string up to sizeof(optsw) with, well,
+ spaces. */
+ for (i = 0; i < (optsw_len - 1); i++)
+ optsw[i] = ((i < opts_len) ? opts[i] : ' ');
+
+ optsw[optsw_len - 1] = 0;
+ opts = apr_psprintf (pool, "%s : %s", optsw, opt->description);
+ }
*string = opts;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Sun Apr 14 09:07:08 2002
|
This is an archived mail posted to the Subversion Dev mailing list.
This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.