Thread: Patch for BUG #6480, psql incorrect indent for inherited tables names with UTF-8 NLS
Patch for BUG #6480, psql incorrect indent for inherited tables names with UTF-8 NLS
From
Sergey Burladyan
Date:
See http://archives.postgresql.org/pgsql-bugs/2012-02/msg00164.php This need function for count characters, not bytes. I find this pg_wcswidth but it is not used anywhere and broken. So, I fix it and also change it prototype for remove type casting. PS: Please help, next week release will be with Russian translation again (thank you, Alexander!) and this tiny bug is slightly annoying. >From aaa828e05691ca58067d74cea43dabe8863ccdf7 Mon Sep 17 00:00:00 2001 From: Sergey Burladyan <eshkinkot@gmail.com> Date: Thu, 23 Feb 2012 04:09:10 +0400 Subject: [PATCH] Fix NLS text width and pg_wcswidth function --- src/bin/psql/describe.c | 4 ++-- src/bin/psql/mbprint.c | 7 ++++--- src/bin/psql/mbprint.h | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index b2c54b5..2b63df4 100644 *** a/src/bin/psql/describe.c --- b/src/bin/psql/describe.c *************** describeOneTableDetails(const char *sche *** 2068,2074 **** if (i == 0) printfPQExpBuffer(&buf, "%s: %s", s, PQgetvalue(result, i, 0)); else ! printfPQExpBuffer(&buf, "%*s %s", (int) strlen(s), "", PQgetvalue(result, i, 0)); if (i < tuples - 1) appendPQExpBuffer(&buf, ","); --- 2068,2074 ---- if (i == 0) printfPQExpBuffer(&buf, "%s: %s", s, PQgetvalue(result, i, 0)); else ! printfPQExpBuffer(&buf, "%*s %s", pg_wcswidth(s, strlen(s), pset.encoding), "", PQgetvalue(result, i,0)); if (i < tuples - 1) appendPQExpBuffer(&buf, ","); *************** describeOneTableDetails(const char *sche *** 2109,2115 **** ct, PQgetvalue(result, i, 0)); else printfPQExpBuffer(&buf, "%*s %s", ! (int) strlen(ct), "", PQgetvalue(result, i, 0)); if (i < tuples - 1) appendPQExpBuffer(&buf, ","); --- 2109,2115 ---- ct, PQgetvalue(result, i, 0)); else printfPQExpBuffer(&buf, "%*s %s", ! pg_wcswidth(ct, strlen(ct), pset.encoding), "", PQgetvalue(result, i, 0)); if (i < tuples - 1) appendPQExpBuffer(&buf, ","); diff --git a/src/bin/psql/mbprint.c b/src/bin/psql/mbprint.c index 248a4db..477e35d 100644 *** a/src/bin/psql/mbprint.c --- b/src/bin/psql/mbprint.c *************** mb_utf_validate(unsigned char *pwcs) *** 173,179 **** * only appear on one line. OTOH it is easier to use if this applies to you. */ int ! pg_wcswidth(const unsigned char *pwcs, size_t len, int encoding) { int width = 0; --- 173,179 ---- * only appear on one line. OTOH it is easier to use if this applies to you. */ int ! pg_wcswidth(const char *pwcs, size_t len, int encoding) { int width = 0; *************** pg_wcswidth(const unsigned char *pwcs, s *** 182,196 **** int chlen, chwidth; ! chlen = PQmblen((const char *) pwcs, encoding); if (chlen > len) break; /* Invalid string */ ! chwidth = PQdsplen((const char *) pwcs, encoding); if (chwidth > 0) width += chwidth; pwcs += chlen; } return width; } --- 182,197 ---- int chlen, chwidth; ! chlen = PQmblen(pwcs, encoding); if (chlen > len) break; /* Invalid string */ ! chwidth = PQdsplen(pwcs, encoding); if (chwidth > 0) width += chwidth; pwcs += chlen; + len -= chlen; } return width; } diff --git a/src/bin/psql/mbprint.h b/src/bin/psql/mbprint.h index f729ef0..5c13d97 100644 *** a/src/bin/psql/mbprint.h --- b/src/bin/psql/mbprint.h *************** struct lineptr *** 10,16 **** }; extern unsigned char *mbvalidate(unsigned char *pwcs, int encoding); ! extern int pg_wcswidth(const unsigned char *pwcs, size_t len, int encoding); extern void pg_wcsformat(unsigned char *pwcs, size_t len, int encoding, struct lineptr * lines, int count); extern void pg_wcssize(unsigned char *pwcs, size_t len, int encoding, int *width, int *height, int *format_size); --- 10,16 ---- }; extern unsigned char *mbvalidate(unsigned char *pwcs, int encoding); ! extern int pg_wcswidth(const char *pwcs, size_t len, int encoding); extern void pg_wcsformat(unsigned char *pwcs, size_t len, int encoding, struct lineptr * lines, int count); extern void pg_wcssize(unsigned char *pwcs, size_t len, int encoding, int *width, int *height, int *format_size); -- 1.7.9 -- Sergey Burladyan
Re: Patch for BUG #6480, psql incorrect indent for inherited tables names with UTF-8 NLS
From
Alvaro Herrera
Date:
Excerpts from Sergey Burladyan's message of vie feb 24 19:43:10 -0300 2012: > > See http://archives.postgresql.org/pgsql-bugs/2012-02/msg00164.php > > This need function for count characters, not bytes. I find this pg_wcswidth but > it is not used anywhere and broken. So, I fix it and also change it prototype > for remove type casting. > > PS: Please help, next week release will be with Russian translation again (thank you, > Alexander!) and this tiny bug is slightly annoying. I'm sorry, but the releases are already tagged :-( So they will contain the buggy output for a while yet. -- Álvaro Herrera <alvherre@commandprompt.com> The PostgreSQL Company - Command Prompt, Inc. PostgreSQL Replication, Consulting, Custom Development, 24x7 support
Re: Patch for BUG #6480, psql incorrect indent for inherited tables names with UTF-8 NLS
From
Sergey Burladyan
Date:
Alvaro Herrera <alvherre@commandprompt.com> writes: > I'm sorry, but the releases are already tagged :-( So they will contain > the buggy output for a while yet. Ah, I see, ok, wait next! :) -- Sergey Burladyan