pgsql: Automatically count the number of output lines in psql/help.c. - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Automatically count the number of output lines in psql/help.c.
Date
Msg-id E1nxW6V-002gq1-KG@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Automatically count the number of output lines in psql/help.c.

The hard-wired PageOutput arguments in usage() and sibling functions
have been a perennial maintenance gotcha, and there's no reason to
think we'll ever get any better about that.  Let's get rid of those
magic constants by constructing the output in a buffer where we can
count the newlines before calling PageOutput.  (Perhaps this is
microscopically slower; but none of these functions are performance
critical, and anyway we might well be buying back all the cost by
avoiding having to pass most of the data through snprintf.c.  I could
not detect any speed difference in a desultory check.)  This also
gets rid of the need to assume that platform-specific variations in
the output are insignificant.

While at it, make the code shorter and more abstract by inventing
helper macros HELP0() and HELPN() to encapsulate the specific
output actions being invoked.

Discussion: https://postgr.es/m/365160.1654289490@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/f00a4f02ac2e31aaa6f74f8ef916624b9018370f

Modified Files
--------------
src/bin/psql/help.c | 845 ++++++++++++++++++++++++++++------------------------
src/bin/psql/nls.mk |   2 +-
2 files changed, 450 insertions(+), 397 deletions(-)


pgsql-committers by date:

Previous
From: Michael Paquier
Date:
Subject: pgsql: Force run of pg_upgrade in the build directory in its TAP test
Next
From: Michael Paquier
Date:
Subject: pgsql: Fix psql's single transaction mode on client-side errors with -c