Thread
Commits
-
Automatically count the number of output lines in psql/help.c.
- f00a4f02ac2e 15.0 landed
-
Count output lines automatically in psql/help.c
Tom Lane <tgl@sss.pgh.pa.us> — 2022-06-03T20:51:30Z
I finally reached the point of being fed up with our inability to maintain the number of lines output by psql's usage() and sibling functions. Almost every year, we find ourselves updating those magic constants sometime late in the dev cycle, and I just had to do it again today. So, attached is a patch to remove that maintenance chore by constructing the output in a PQExpBuffer and then counting the lines automatically. While I was at it, I introduced a couple of macros to make the code shorter rather than longer. We could alternatively decide that we've blown past whatever vertical screen space anybody has and just use 1000 or something like that as the PageOutput count. However, that's a somewhat dicey proposition for usage() itself, which is at 63 lines today; that's well within reach of larger monitors. Thoughts? regards, tom lane
-
Re: Count output lines automatically in psql/help.c
Robert Haas <robertmhaas@gmail.com> — 2022-06-04T12:55:25Z
On Fri, Jun 3, 2022 at 4:51 PM Tom Lane <tgl@sss.pgh.pa.us> wrote: > Thoughts? +1 from me. Wish we'd done this years ago. -- Robert Haas EDB: http://www.enterprisedb.com
-
Re: Count output lines automatically in psql/help.c
Tom Lane <tgl@sss.pgh.pa.us> — 2022-06-04T15:54:42Z
Robert Haas <robertmhaas@gmail.com> writes: > On Fri, Jun 3, 2022 at 4:51 PM Tom Lane <tgl@sss.pgh.pa.us> wrote: >> Thoughts? > +1 from me. Wish we'd done this years ago. Pushed, thanks for looking at it. regards, tom lane
-
Re: Count output lines automatically in psql/help.c
Alvaro Herrera <alvherre@alvh.no-ip.org> — 2022-06-04T16:18:20Z
On 2022-Jun-03, Tom Lane wrote: > So, attached is a patch to remove that maintenance chore by > constructing the output in a PQExpBuffer and then counting the > lines automatically. While I was at it, I introduced a couple of > macros to make the code shorter rather than longer. What about adding stringInfoCountLines or something like that? -- Álvaro Herrera
-
Re: Count output lines automatically in psql/help.c
Tom Lane <tgl@sss.pgh.pa.us> — 2022-06-04T16:56:59Z
Alvaro Herrera <alvherre@alvh.no-ip.org> writes: > What about adding stringInfoCountLines or something like that? If we have other use-cases, maybe that'd be worthwhile. (In the committed patch, I dumbed it down to a plain per-char loop without the strchr() complication. So it's very little code. I'm not real sure that strchr would make it faster.) regards, tom lane
-
Re: Count output lines automatically in psql/help.c
Peter Eisentraut <peter.eisentraut@enterprisedb.com> — 2022-06-10T10:16:32Z
On 03.06.22 22:51, Tom Lane wrote: > + HELP0(" -c, --command=COMMAND run only single command (SQL or internal) and exit\n"); > + HELP(" -d, --dbname=DBNAME database name to connect to (default: \"%s\")\n", > + env); I wonder whether this mix of HELP0 and HELP is necessary. The original code didn't care about calling fprintf even if there are no substitutions. I think this could lead to misalignment errors. I vaguely recall we once had mixes of fprintf and fputs and got rid of them for this reason. -
Re: Count output lines automatically in psql/help.c
Tom Lane <tgl@sss.pgh.pa.us> — 2022-06-10T11:50:37Z
Peter Eisentraut <peter.eisentraut@enterprisedb.com> writes: > I wonder whether this mix of HELP0 and HELP is necessary. The original > code didn't care about calling fprintf even if there are no > substitutions. I think this could lead to misalignment errors. I > vaguely recall we once had mixes of fprintf and fputs and got rid of > them for this reason. In the committed patch, I changed HELP to HELPN exactly so that the strings would still line up. regards, tom lane