public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH PR/42686] Align the help text output
@ 2010-02-25 10:32 Shujing Zhao
  2010-02-25 16:34 ` Joseph S. Myers
  0 siblings, 1 reply; 20+ messages in thread
From: Shujing Zhao @ 2010-02-25 10:32 UTC (permalink / raw)
  To: GCC Patches; +Cc: Joseph S. Myers, Paolo Carlini

[-- Attachment #1: Type: text/plain, Size: 433 bytes --]

Hi,

This patch is to align the help text output when it includes the characters that 
use three bytes in UTF-8 in some languages, such as Chinese.
The option name is left-aligned with the width 27 or the length of itself from 
the 3th column. The help text is left-aligned with the width 50 (default) from 
the 31th column.
Tested on i686-pc-linux-gnu with no regression to the "C" locale environment.

OK for trunk?

Thanks
Pearly

[-- Attachment #2: ChangeLog --]
[-- Type: text/plain, Size: 261 bytes --]

2010-02-25  Shujing Zhao  <pearly.zhao@oracle.com>

	PR translation/42686
	* opts.c (wrap_help): Align the help output when it includes the
	characters that use three bytes in UTF-8.
	(print_filtered_help): Split the help string to option name and help
	text.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: pr42686.patch --]
[-- Type: text/x-patch; name="pr42686.patch", Size: 1668 bytes --]

Index: opts.c
===================================================================
--- opts.c	(修订版 157061)
+++ opts.c	(工作拷贝)
@@ -1158,8 +1158,9 @@ wrap_help (const char *help,
 	   unsigned int columns)
 {
   unsigned int col_width = LEFT_COLUMN;
-  unsigned int remaining, room, len;
+  unsigned int remaining, room, len, width_diff;
 
+  width_diff = item_width - gcc_gettext_width(item);
   remaining = strlen (help);
 
   do
@@ -1183,10 +1184,20 @@ wrap_help (const char *help,
 		       && help[i + 1] != ' '
 		       && i > 0 && ISALPHA (help[i - 1]))
 		len = i + 1;
+	      /* For the characters use three bytes in UTF-8 in some languages,
+ 		 such as Chinese, move three bytes everytime. */
+	      else if (help[i] < 0 && help[i + 1] < 0 && help[i + 2] < 0)
+		{
+		  i = i + 2;
+		  len = i + 1;
+		  room = room + 1;
+		}
 	    }
 	}
 
-      printf( "  %-*.*s %.*s\n", col_width, item_width, item, len, help);
+      printf ("  %-*.*s %.*s\n", 
+	      col_width + width_diff, item_width, item, len, help);
+      width_diff = 0;
       item_width = 0;
       while (help[len] == ' ')
 	len++;
@@ -1242,6 +1253,7 @@ print_filtered_help (unsigned int includ
       unsigned int len;
       const char *opt;
       const char *tab;
+      char *buf;
 
       if (include_flags == 0
 	  || ((option->flags & include_flags) != include_flags))
@@ -1278,7 +1290,10 @@ print_filtered_help (unsigned int includ
       if (tab)
 	{
 	  len = tab - help;
-	  opt = help;
+	  buf = (char *)alloca (len + 1);
+	  strncpy (buf, help, len);
+	  buf[len] = '\0';
+	  opt = buf;
 	  help = tab + 1;
 	}
       else

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2010-04-15 21:51 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-25 10:32 [PATCH PR/42686] Align the help text output 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
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

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).