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: Thu, 18 Mar 2010 17:54:00 -0000	[thread overview]
Message-ID: <Pine.LNX.4.64.1003181650570.19807@digraph.polyomino.org.uk> (raw)
In-Reply-To: <4BA2010C.9030103@oracle.com>

On Thu, 18 Mar 2010, Shujing Zhao wrote:

>  
> +static wchar_t *
> +get_sub_wstr (wchar_t *wstr, int len)

Needs comment explaining semantics of parameters and return value.

> +/* Return the number of bytes in the multibyte representation of the wide 
> +   character WC. */
> +
> +static int
> +wctomb_nbytes (wchar_t wc)
> +{

This code is heavily assuming that converting from multibyte to wide 
characters and back again yields exactly the same multibyte characters.  
This is more likely in the Unicode world than it used to be, but it's not 
clear we should be presuming it.  I think code without this presumption 
would be simpler than code with it; rather than converting the whole 
string at once and then repeatedly extracting substrings, you'd convert 
one character at a time, keeping track of the width at each point 
(computing the width of one character at a time) and of the byte count to 
the last possible point for a line break.  (That way, you could also 
easily allow for encodings with shift sequences, keeping an mbstate_t in 
the course of processing the string.)

> +/* Return the length of multibyte string MSGSTR that can be printed within the

"length" = number of bytes?

> +    { 
> +      nbytes = wctomb_nbytes (wmsgstr [i]);
> +      colwidth ++;

Why this increment?  Characters may have width 0 (combining characters) or 
more than 1 and it's not clear why adding 1 should be the correct thing to 
do here.

> +      else if (nbytes > 1)

Why this conditional?  Whatever the number of bytes is, you need to update 
the width appropriately.

> +          {
> +	    if (colwidth > room)	
> +              len = len_bk;
> +            break;

Indentation seems very confused.  Make sure that new code consistently 
uses TABs for indenting source code lines.

> +      int n_spaces = item_width <= item_col_width 
> +                     ? col_width - item_width
> +                     : col_width - item_col_width;

I don't see why this conditional is here.  For printing spaces, it's 
always the number of columns that's relevant; the number of bytes is 
irrelevant.

-- 
Joseph S. Myers
joseph@codesourcery.com

  reply	other threads:[~2010-03-18 17:04 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
2010-03-18 11:48                   ` Shujing Zhao
2010-03-18 17:54                     ` Joseph S. Myers [this message]
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.1003181650570.19807@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).