Re: Count output lines automatically in psql/help.c

2022-06-10 Thread Tom Lane
Peter Eisentraut 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 r

Re: Count output lines automatically in psql/help.c

2022-06-10 Thread Peter Eisentraut
On 03.06.22 22:51, Tom Lane wrote: + HELP0(" -c, --command=COMMANDrun 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

Re: Count output lines automatically in psql/help.c

2022-06-04 Thread Tom Lane
Alvaro Herrera 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

Re: Count output lines automatically in psql/help.c

2022-06-04 Thread Alvaro Herrera
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 addin

Re: Count output lines automatically in psql/help.c

2022-06-04 Thread Tom Lane
Robert Haas writes: > On Fri, Jun 3, 2022 at 4:51 PM Tom Lane 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

2022-06-04 Thread Robert Haas
On Fri, Jun 3, 2022 at 4:51 PM Tom Lane wrote: > Thoughts? +1 from me. Wish we'd done this years ago. -- Robert Haas EDB: http://www.enterprisedb.com