Eric Blake wrote:
> 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.
Good idea.
That is cleaner.
Do you feel like adjusting that patch, and listing yourself as the author?
If so, please note in the log that the bug was introduced by my
Mar 6 2009 commit: a4053c5291d5797734b3e4f042f9e1adf3944fd6