[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: Sander Striker <striker_at_apache.org>
Date: 2002-04-14 10:14:28 CEST

> From: Karl Fogel [mailto:kfogel@newton.ch.collab.net]
> Sent: 14 April 2002 10:03

> 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?

Not that I know of. Or at least, I've never seen it ;)

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

A simple memset would do the trick:

  memset (optsw, ' ', sizeof(optsw));
  optsw[sizeof(optsw) - 1] = '\0';

Or something like that. Ofcourse some simple for loop will suffice.
It's only 20 bytes ;)

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

Yes, nice ;)

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

*grin*
 
> -Karl

Sander

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Sun Apr 14 10:08:09 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.