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