Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1ed7f0e

Browse files
committed
Fix indentation of \d footers for non-ASCII cases.
Multi-line "Inherits:" and "Child tables:" footers were misindented when those strings' translations involved multibyte characters, because we were using strlen() instead of an appropriate display width measurement. In passing, avoid doing gettext() more than once per loop in these places. While at it, fix pg_wcswidth(), which has been entirely broken since about 8.2, but fortunately has been unused for the same length of time. Report and patch by Sergey Burladyan (bug #6480)
1 parent 9088d1b commit 1ed7f0e

File tree

3 files changed

+29
-21
lines changed

3 files changed

+29
-21
lines changed

src/bin/psql/describe.c

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2156,22 +2156,28 @@ describeOneTableDetails(const char *schemaname,
21562156
if (!result)
21572157
goto error_return;
21582158
else
2159-
tuples = PQntuples(result);
2160-
2161-
for (i = 0; i < tuples; i++)
21622159
{
21632160
const char *s = _("Inherits");
2161+
int sw = pg_wcswidth(s, strlen(s), pset.encoding);
21642162

2165-
if (i == 0)
2166-
printfPQExpBuffer(&buf, "%s: %s", s, PQgetvalue(result, i, 0));
2167-
else
2168-
printfPQExpBuffer(&buf, "%*s %s", (int) strlen(s), "", PQgetvalue(result, i, 0));
2169-
if (i < tuples - 1)
2170-
appendPQExpBuffer(&buf, ",");
2163+
tuples = PQntuples(result);
21712164

2172-
printTableAddFooter(&cont, buf.data);
2165+
for (i = 0; i < tuples; i++)
2166+
{
2167+
if (i == 0)
2168+
printfPQExpBuffer(&buf, "%s: %s",
2169+
s, PQgetvalue(result, i, 0));
2170+
else
2171+
printfPQExpBuffer(&buf, "%*s %s",
2172+
sw, "", PQgetvalue(result, i, 0));
2173+
if (i < tuples - 1)
2174+
appendPQExpBuffer(&buf, ",");
2175+
2176+
printTableAddFooter(&cont, buf.data);
2177+
}
2178+
2179+
PQclear(result);
21732180
}
2174-
PQclear(result);
21752181

21762182
/* print child tables */
21772183
if (pset.sversion >= 80300)
@@ -2198,6 +2204,7 @@ describeOneTableDetails(const char *schemaname,
21982204
{
21992205
/* display the list of child tables */
22002206
const char *ct = _("Child tables");
2207+
int ctw = pg_wcswidth(ct, strlen(ct), pset.encoding);
22012208

22022209
for (i = 0; i < tuples; i++)
22032210
{
@@ -2206,8 +2213,7 @@ describeOneTableDetails(const char *schemaname,
22062213
ct, PQgetvalue(result, i, 0));
22072214
else
22082215
printfPQExpBuffer(&buf, "%*s %s",
2209-
(int) strlen(ct), "",
2210-
PQgetvalue(result, i, 0));
2216+
ctw, "", PQgetvalue(result, i, 0));
22112217
if (i < tuples - 1)
22122218
appendPQExpBuffer(&buf, ",");
22132219

src/bin/psql/mbprint.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,12 @@ mb_utf_validate(unsigned char *pwcs)
168168
*/
169169

170170
/*
171-
* pg_wcswidth is the dumb width function. It assumes that everything will
172-
* only appear on one line. OTOH it is easier to use if this applies to you.
171+
* pg_wcswidth is the dumb display-width function.
172+
* It assumes that everything will appear on one line.
173+
* OTOH it is easier to use than pg_wcssize if this applies to you.
173174
*/
174175
int
175-
pg_wcswidth(const unsigned char *pwcs, size_t len, int encoding)
176+
pg_wcswidth(const char *pwcs, size_t len, int encoding)
176177
{
177178
int width = 0;
178179

@@ -181,15 +182,16 @@ pg_wcswidth(const unsigned char *pwcs, size_t len, int encoding)
181182
int chlen,
182183
chwidth;
183184

184-
chlen = PQmblen((const char *) pwcs, encoding);
185-
if (chlen > len)
185+
chlen = PQmblen(pwcs, encoding);
186+
if (len < (size_t) chlen)
186187
break; /* Invalid string */
187188

188-
chwidth = PQdsplen((const char *) pwcs, encoding);
189-
189+
chwidth = PQdsplen(pwcs, encoding);
190190
if (chwidth > 0)
191191
width += chwidth;
192+
192193
pwcs += chlen;
194+
len -= chlen;
193195
}
194196
return width;
195197
}

src/bin/psql/mbprint.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ struct lineptr
1010
};
1111

1212
extern unsigned char *mbvalidate(unsigned char *pwcs, int encoding);
13-
extern int pg_wcswidth(const unsigned char *pwcs, size_t len, int encoding);
13+
extern int pg_wcswidth(const char *pwcs, size_t len, int encoding);
1414
extern void pg_wcsformat(const unsigned char *pwcs, size_t len, int encoding, struct lineptr * lines, int count);
1515
extern void pg_wcssize(const unsigned char *pwcs, size_t len, int encoding,
1616
int *width, int *height, int *format_size);

0 commit comments

Comments
 (0)