aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bin/psql/describe.c32
-rw-r--r--src/bin/psql/mbprint.c16
-rw-r--r--src/bin/psql/mbprint.h2
3 files changed, 29 insertions, 21 deletions
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index 4eee4be96e0..75709afedec 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -2156,22 +2156,28 @@ describeOneTableDetails(const char *schemaname,
if (!result)
goto error_return;
else
- tuples = PQntuples(result);
-
- for (i = 0; i < tuples; i++)
{
const char *s = _("Inherits");
+ int sw = pg_wcswidth(s, strlen(s), pset.encoding);
- 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, ",");
+ tuples = PQntuples(result);
- printTableAddFooter(&cont, buf.data);
+ for (i = 0; i < tuples; i++)
+ {
+ if (i == 0)
+ printfPQExpBuffer(&buf, "%s: %s",
+ s, PQgetvalue(result, i, 0));
+ else
+ printfPQExpBuffer(&buf, "%*s %s",
+ sw, "", PQgetvalue(result, i, 0));
+ if (i < tuples - 1)
+ appendPQExpBuffer(&buf, ",");
+
+ printTableAddFooter(&cont, buf.data);
+ }
+
+ PQclear(result);
}
- PQclear(result);
/* print child tables */
if (pset.sversion >= 80300)
@@ -2198,6 +2204,7 @@ describeOneTableDetails(const char *schemaname,
{
/* display the list of child tables */
const char *ct = _("Child tables");
+ int ctw = pg_wcswidth(ct, strlen(ct), pset.encoding);
for (i = 0; i < tuples; i++)
{
@@ -2206,8 +2213,7 @@ describeOneTableDetails(const char *schemaname,
ct, PQgetvalue(result, i, 0));
else
printfPQExpBuffer(&buf, "%*s %s",
- (int) strlen(ct), "",
- PQgetvalue(result, i, 0));
+ ctw, "", 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 32fc756efe5..d43973e96a0 100644
--- a/src/bin/psql/mbprint.c
+++ b/src/bin/psql/mbprint.c
@@ -168,11 +168,12 @@ mb_utf_validate(unsigned char *pwcs)
*/
/*
- * pg_wcswidth is the dumb width function. It assumes that everything will
- * only appear on one line. OTOH it is easier to use if this applies to you.
+ * pg_wcswidth is the dumb display-width function.
+ * It assumes that everything will appear on one line.
+ * OTOH it is easier to use than pg_wcssize if this applies to you.
*/
int
-pg_wcswidth(const unsigned char *pwcs, size_t len, int encoding)
+pg_wcswidth(const char *pwcs, size_t len, int encoding)
{
int width = 0;
@@ -181,15 +182,16 @@ pg_wcswidth(const unsigned char *pwcs, size_t len, int encoding)
int chlen,
chwidth;
- chlen = PQmblen((const char *) pwcs, encoding);
- if (chlen > len)
+ chlen = PQmblen(pwcs, encoding);
+ if (len < (size_t) chlen)
break; /* Invalid string */
- chwidth = PQdsplen((const char *) pwcs, encoding);
-
+ 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 83050ffcd7e..01064d31007 100644
--- a/src/bin/psql/mbprint.h
+++ b/src/bin/psql/mbprint.h
@@ -10,7 +10,7 @@ struct lineptr
};
extern unsigned char *mbvalidate(unsigned char *pwcs, int encoding);
-extern int pg_wcswidth(const unsigned char *pwcs, size_t len, int encoding);
+extern int pg_wcswidth(const char *pwcs, size_t len, int encoding);
extern void pg_wcsformat(const unsigned char *pwcs, size_t len, int encoding, struct lineptr * lines, int count);
extern void pg_wcssize(const unsigned char *pwcs, size_t len, int encoding,
int *width, int *height, int *format_size);