public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Joseph S. Myers" <joseph@codesourcery.com>
To: Shujing Zhao <pearly.zhao@oracle.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>,
	     Paolo Carlini <paolo.carlini@oracle.com>
Subject: Re: [PATCH PR/42686] Align the help text output
Date: Wed, 17 Mar 2010 12:50:00 -0000	[thread overview]
Message-ID: <Pine.LNX.4.64.1003171201450.2148@digraph.polyomino.org.uk> (raw)
In-Reply-To: <4BA07D89.3040406@oracle.com>

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

  reply	other threads:[~2010-03-17 12:05 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-25 10:32 Shujing Zhao
2010-02-25 16:34 ` Joseph S. Myers
2010-03-10 10:26   ` Shujing Zhao
2010-03-10 17:19     ` Joseph S. Myers
2010-03-12 11:34       ` Shujing Zhao
2010-03-12 17:09         ` Joseph S. Myers
2010-03-15  9:28           ` Shujing Zhao
2010-03-15 10:58             ` Shujing Zhao
2010-03-15 11:42             ` Joseph S. Myers
2010-03-17  7:57               ` Shujing Zhao
2010-03-17 12:50                 ` Joseph S. Myers [this message]
2010-03-18 11:48                   ` Shujing Zhao
2010-03-18 17:54                     ` Joseph S. Myers
2010-03-19 11:43                       ` Shujing Zhao
2010-03-19 13:44                         ` Joseph S. Myers
2010-03-22  9:17                           ` Shujing Zhao
2010-03-31  7:03                             ` Shujing Zhao
2010-04-06 16:56                               ` Joseph S. Myers
2010-04-13 11:32                                 ` Shujing Zhao
2010-04-15 21:54                                   ` Joseph S. Myers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.64.1003171201450.2148@digraph.polyomino.org.uk \
    --to=joseph@codesourcery.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=paolo.carlini@oracle.com \
    --cc=pearly.zhao@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).