This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH PR/42686] Align the help text output
- From: Shujing Zhao <pearly dot zhao at oracle dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: "Joseph S. Myers" <joseph at codesourcery dot com>, Paolo Carlini <paolo dot carlini at oracle dot com>
- Date: Thu, 25 Feb 2010 16:31:21 +0800
- Subject: [PATCH PR/42686] Align the help text output
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
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.
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