cURL / Mailing Lists / curl-users / Single Mail


Re: patch to enhance --progress-bar

From: Dan Fandrich <>
Date: Sun, 23 Nov 2008 09:38:14 -0800

On Sun, Nov 23, 2008 at 01:59:19PM +0100, Björn Schlögl wrote:
> attached is a small patch that adds a new command line option to curl to allow
> the user to specify a prefix that will be displays in front of the progress
> bar:

Sounds like a good idea--the user can be give a bit of information to look
at while a download occurs.

> + int length = strlen(config->progress_prefix);

There's a minor problem in this line in that in multibyte locales (like UTF-8)
strlen doesn't necessarily give the number of characters displayed on the
screen. It's a minor problem because the progress bar will just be a little
shorter than it could be in that case, and the solution would require a
new library dependency. And even then, the length of terminal escape
sequences wouldn't be taken into account.

> + snprintf( format, sizeof(format), "%%s%%-%ds %%5.1f%%%%", barwidth );
> + snprintf( outline, sizeof(outline), format, bar->prefix, line, percent );

This is a bit odd, too. I know it's just a cut and paste of the original code,
but why not combine them into a single line, like this:

      snprintf( outline, sizeof(outline), "%s%-*s %5.1f%%",
                bar->prefix, barwidth, line, percent );

The * syntax seems to be pretty portable, although I haven't verified that
it's part of C89 (I suspect it is).

>>> Dan

--              The web change of address service
          Let webmasters know that your web site has moved

List admin:

  • application/pgp-signature attachment: stored
Received on 2008-11-23