pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Automatically count the number of output lines in psql/help.c.
Date: Sat, 04 Jun 2022 15:54:19 +0000
Message-ID: <E1nxW6V-002gq1-KG@gemulon.postgresql.org> (raw)

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(-)



Message-ID: <E1nxW6V-002gq1-KG@gemulon.postgresql.org>
Permalink:  ../E1nxW6V-002gq1-KG@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1nxW6V-002gq1-KG@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Automatically count the number of output lines in psql/help.c.
  In-Reply-To: <E1nxW6V-002gq1-KG@gemulon.postgresql.org>
  References: <E1nxW6V-002gq1-KG@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox