[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: [PATCH] Lining up option descriptions in cmdline binary help

From: Karl Fogel <kfogel_at_newton.ch.collab.net>
Date: 2002-04-14 10:02:50 CEST

cmpilato@collab.net writes:
> My brain feels super-mushy right now, so rather than commit this chunk
> of elementary code, I'll send it to the list for review. I feel sure
> that there's some better way to do what I did here (hopefully not
> involving a series of single-space apr_pstrcat's) but the old
> Thinker's coming up shorthanded. At any rate, the SEGFAULT protection
> code needs to be committed.

After your instantaneous tweaks to my patch for text base checksums, I
feel I owe you one :-). My contribution here is relatively minor, but
you're welcome to it...

> 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. */

There's some C syntax for initializing the whole array to the same
value, right? I'm thinking spaces (' '), fwiw. Don't have my K&R
here, and google is not as forthcoming as I expected.

If there's not a way, just init by hand I suppose, no big deal.

> 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);
> + }
>

Then here, I'm thinking everything between the curly braces can be
replaced with just this:

   opts = apr_psprintf (pool, "%s%s : %s",
                        opts, optsw + strlen (ops), opt->description);

Untested, and I hereby disclaim all o.b.o.e. playing in this area. :-)
("off by one error", for those not familiar)

-Karl

---------------------------------------------------------------------
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:58:38 2002

This is an archived mail posted to the Subversion Dev mailing list.