bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] pr: ensure the page header line is of the required format


From: Eric Blake
Subject: Re: [PATCH] pr: ensure the page header line is of the required format
Date: Wed, 6 Jan 2010 20:54:59 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

Jim Meyering <jim <at> meyering.net> writes:

>    lhs_spaces = available_width >> 1;
>    rhs_spaces = available_width - lhs_spaces;
> 
> +  lhs_spaces = 0 < lhs_spaces ? lhs_spaces : 1;
> +  rhs_spaces = 0 < rhs_spaces ? rhs_spaces : 1;
> +
>    printf ("\n\n%*.*s%s%*.*s%s%*.*s%s\n\n\n",
>            chars_per_margin, chars_per_margin, " ",
>            date_text, lhs_spaces, lhs_spaces, " ",
>            file_text, rhs_spaces, rhs_spaces, " ", page_text);


Why not this instead:

   lhs_spaces = available_width >> 1;
   rhs_spaces = available_width - lhs_spaces;

   printf ("\n\n%*.*s%s%*s%s%*s%s\n\n\n",
           chars_per_margin, chars_per_margin, " ",
           date_text, lhs_spaces, " ",
           file_text, rhs_spaces, " ", page_text);

In other words, instead of specifying both minimum width and precision, and 
manually tweaking the result to be 1 if it was 0, what if we instead specify 
only minimum width, and let the " " provide the guarantee of a width of 1 if 
lhs_spaces is 0.

-- 
Eric Blake







reply via email to

[Prev in Thread] Current Thread [Next in Thread]