This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH PR/42686] Align the help text output
On Wed, 17 Mar 2010, Shujing Zhao wrote:
> > > + if (item_width == item_col_width
> > > + || item_width == 0)
> > > + printf (" %-*.*s", col_width, item_width, item);
> > > + /* Handle the item that includes wide character. */
> > > + else
> >
> > I think the code would be a lot clearer with fewer conditionals. Why do you
> > need to handle specially the case where item_width == item_col_width? Can't
> > you just use the logic below unconditionally?
> The conditional item_width == item_col_width is used to handle the ITEM
> without wide characters. As your suggestion, I simplify the logic as
But you should be able to treat all ITEMs as if they have wide characters;
there should be no need to do something special for the case of no wide
characters.
> > > + if (len != gcc_gettext_width (help))
> > > + len = get_aligned_len (help, room, remaining);
> >
> > Again, I'd like to avoid conditionals if possible.
> After the logic is moved to intl.c, the conditional is still kept to tell
> calling get_str_aligned_len or get_wcs_aligned_len.
>
> + if (gcc_gettext_width (msgstr) == remaining)
> + return get_str_aligned_len (msgstr, room, remaining);
> + else
> + return get_wcs_aligned_len (msgstr, room, remaining);
>
> Is it ok or any suggestion?
The check still isn't appropriate. The width might equal the number of
bytes even when wide characters are present. I think the logic should be:
if NLS enabled and the relevant wide character functions available, use
get_wcs_aligned_len, otherwise use get_str_aligned_len. This means only
one of those functions is used in any compiler configuration, so you can
just make them two different implementations of get_aligned_len depending
on the configuration, rather than having three function names involved.
--
Joseph S. Myers
joseph@codesourcery.com