Count output lines automatically in psql/help.c
Count output lines automatically in psql/help.c
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
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
diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index 81a4739cda..c784f4a959 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -36,20 +36,25 @@
* know how to do it, please find someone who can help you.
*/
+/* Some helper macros to make the code less verbose */
+#define HELP0(str) appendPQExpBufferStr(&buf, _(str))
+#define HELP(str,...) appendPQExpBuffer(&buf, _(str), __VA_ARGS__)
+#define ON(var) (var ? _("on") : _("off"))
+
/*
* usage
*
* print out command line arguments
*/
-#define ON(var) (var ? _("on") : _("off"))
-
void
usage(unsigned short int pager)
{
const char *env;
const char *user;
char *errstr;
+ PQExpBufferData buf;
+ int nlcount;
FILE *output;
/* Find default user, in case we need it. */
@@ -62,86 +67,102 @@ usage(unsigned short int pager)
}
/*
- * Keep this line count in sync with the number of lines printed below!
- * Use "psql --help=options | wc" to count correctly.
+ * To avoid counting the output lines manually, build the output in "buf"
+ * and then count them.
*/
- output = PageOutput(63, pager ? &(pset.popt.topt) : NULL);
+ initPQExpBuffer(&buf);
- fprintf(output, _("psql is the PostgreSQL interactive terminal.\n\n"));
- fprintf(output, _("Usage:\n"));
- fprintf(output, _(" psql [OPTION]... [DBNAME [USERNAME]]\n\n"));
+ HELP0("psql is the PostgreSQL interactive terminal.\n\n");
+ HELP0("Usage:\n");
+ HELP0(" psql [OPTION]... [DBNAME [USERNAME]]\n\n");
- fprintf(output, _("General options:\n"));
+ HELP0("General options:\n");
/* Display default database */
env = getenv("PGDATABASE");
if (!env)
env = user;
- fprintf(output, _(" -c, --command=COMMAND run only single command (SQL or internal) and exit\n"));
- fprintf(output, _(" -d, --dbname=DBNAME database name to connect to (default: \"%s\")\n"), env);
- fprintf(output, _(" -f, --file=FILENAME execute commands from file, then exit\n"));
- fprintf(output, _(" -l, --list list available databases, then exit\n"));
- fprintf(output, _(" -v, --set=, --variable=NAME=VALUE\n"
- " set psql variable NAME to VALUE\n"
- " (e.g., -v ON_ERROR_STOP=1)\n"));
- fprintf(output, _(" -V, --version output version information, then exit\n"));
- fprintf(output, _(" -X, --no-psqlrc do not read startup file (~/.psqlrc)\n"));
- fprintf(output, _(" -1 (\"one\"), --single-transaction\n"
- " execute as a single transaction (if non-interactive)\n"));
- fprintf(output, _(" -?, --help[=options] show this help, then exit\n"));
- fprintf(output, _(" --help=commands list backslash commands, then exit\n"));
- fprintf(output, _(" --help=variables list special variables, then exit\n"));
-
- fprintf(output, _("\nInput and output options:\n"));
- fprintf(output, _(" -a, --echo-all echo all input from script\n"));
- fprintf(output, _(" -b, --echo-errors echo failed commands\n"));
- fprintf(output, _(" -e, --echo-queries echo commands sent to server\n"));
- fprintf(output, _(" -E, --echo-hidden display queries that internal commands generate\n"));
- fprintf(output, _(" -L, --log-file=FILENAME send session log to file\n"));
- fprintf(output, _(" -n, --no-readline disable enhanced command line editing (readline)\n"));
- fprintf(output, _(" -o, --output=FILENAME send query results to file (or |pipe)\n"));
- fprintf(output, _(" -q, --quiet run quietly (no messages, only query output)\n"));
- fprintf(output, _(" -s, --single-step single-step mode (confirm each query)\n"));
- fprintf(output, _(" -S, --single-line single-line mode (end of line terminates SQL command)\n"));
-
- fprintf(output, _("\nOutput format options:\n"));
- fprintf(output, _(" -A, --no-align unaligned table output mode\n"));
- fprintf(output, _(" --csv CSV (Comma-Separated Values) table output mode\n"));
- fprintf(output, _(" -F, --field-separator=STRING\n"
- " field separator for unaligned output (default: \"%s\")\n"),
- DEFAULT_FIELD_SEP);
- fprintf(output, _(" -H, --html HTML table output mode\n"));
- fprintf(output, _(" -P, --pset=VAR[=ARG] set printing option VAR to ARG (see \\pset command)\n"));
- fprintf(output, _(" -R, --record-separator=STRING\n"
- " record separator for unaligned output (default: newline)\n"));
- fprintf(output, _(" -t, --tuples-only print rows only\n"));
- fprintf(output, _(" -T, --table-attr=TEXT set HTML table tag attributes (e.g., width, border)\n"));
- fprintf(output, _(" -x, --expanded turn on expanded table output\n"));
- fprintf(output, _(" -z, --field-separator-zero\n"
- " set field separator for unaligned output to zero byte\n"));
- fprintf(output, _(" -0, --record-separator-zero\n"
- " set record separator for unaligned output to zero byte\n"));
-
- fprintf(output, _("\nConnection options:\n"));
+ 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);
+ HELP0(" -f, --file=FILENAME execute commands from file, then exit\n");
+ HELP0(" -l, --list list available databases, then exit\n");
+ HELP0(" -v, --set=, --variable=NAME=VALUE\n"
+ " set psql variable NAME to VALUE\n"
+ " (e.g., -v ON_ERROR_STOP=1)\n");
+ HELP0(" -V, --version output version information, then exit\n");
+ HELP0(" -X, --no-psqlrc do not read startup file (~/.psqlrc)\n");
+ HELP0(" -1 (\"one\"), --single-transaction\n"
+ " execute as a single transaction (if non-interactive)\n");
+ HELP0(" -?, --help[=options] show this help, then exit\n");
+ HELP0(" --help=commands list backslash commands, then exit\n");
+ HELP0(" --help=variables list special variables, then exit\n");
+
+ HELP0("\nInput and output options:\n");
+ HELP0(" -a, --echo-all echo all input from script\n");
+ HELP0(" -b, --echo-errors echo failed commands\n");
+ HELP0(" -e, --echo-queries echo commands sent to server\n");
+ HELP0(" -E, --echo-hidden display queries that internal commands generate\n");
+ HELP0(" -L, --log-file=FILENAME send session log to file\n");
+ HELP0(" -n, --no-readline disable enhanced command line editing (readline)\n");
+ HELP0(" -o, --output=FILENAME send query results to file (or |pipe)\n");
+ HELP0(" -q, --quiet run quietly (no messages, only query output)\n");
+ HELP0(" -s, --single-step single-step mode (confirm each query)\n");
+ HELP0(" -S, --single-line single-line mode (end of line terminates SQL command)\n");
+
+ HELP0("\nOutput format options:\n");
+ HELP0(" -A, --no-align unaligned table output mode\n");
+ HELP0(" --csv CSV (Comma-Separated Values) table output mode\n");
+ HELP(" -F, --field-separator=STRING\n"
+ " field separator for unaligned output (default: \"%s\")\n",
+ DEFAULT_FIELD_SEP);
+ HELP0(" -H, --html HTML table output mode\n");
+ HELP0(" -P, --pset=VAR[=ARG] set printing option VAR to ARG (see \\pset command)\n");
+ HELP0(" -R, --record-separator=STRING\n"
+ " record separator for unaligned output (default: newline)\n");
+ HELP0(" -t, --tuples-only print rows only\n");
+ HELP0(" -T, --table-attr=TEXT set HTML table tag attributes (e.g., width, border)\n");
+ HELP0(" -x, --expanded turn on expanded table output\n");
+ HELP0(" -z, --field-separator-zero\n"
+ " set field separator for unaligned output to zero byte\n");
+ HELP0(" -0, --record-separator-zero\n"
+ " set record separator for unaligned output to zero byte\n");
+
+ HELP0("\nConnection options:\n");
/* Display default host */
env = getenv("PGHOST");
- fprintf(output, _(" -h, --host=HOSTNAME database server host or socket directory (default: \"%s\")\n"),
- env ? env : _("local socket"));
+ HELP(" -h, --host=HOSTNAME database server host or socket directory (default: \"%s\")\n",
+ env ? env : _("local socket"));
/* Display default port */
env = getenv("PGPORT");
- fprintf(output, _(" -p, --port=PORT database server port (default: \"%s\")\n"),
- env ? env : DEF_PGPORT_STR);
+ HELP(" -p, --port=PORT database server port (default: \"%s\")\n",
+ env ? env : DEF_PGPORT_STR);
/* Display default user */
- fprintf(output, _(" -U, --username=USERNAME database user name (default: \"%s\")\n"), user);
- fprintf(output, _(" -w, --no-password never prompt for password\n"));
- fprintf(output, _(" -W, --password force password prompt (should happen automatically)\n"));
+ HELP(" -U, --username=USERNAME database user name (default: \"%s\")\n",
+ user);
+ HELP0(" -w, --no-password never prompt for password\n");
+ HELP0(" -W, --password force password prompt (should happen automatically)\n");
+
+ HELP0("\nFor more information, type \"\\?\" (for internal commands) or \"\\help\" (for SQL\n"
+ "commands) from within psql, or consult the psql section in the PostgreSQL\n"
+ "documentation.\n\n");
+ HELP("Report bugs to <%s>.\n", PACKAGE_BUGREPORT);
+ HELP("%s home page: <%s>\n", PACKAGE_NAME, PACKAGE_URL);
+
+ /* Now we can count the lines. */
+ nlcount = 0;
+ for (const char *ptr = strchr(buf.data, '\n');
+ ptr != NULL;
+ ptr = strchr(ptr + 1, '\n'))
+ nlcount++;
+
+ /* And dump the output, with appropriate pagination. */
+ output = PageOutput(nlcount, pager ? &(pset.popt.topt) : NULL);
- fprintf(output, _("\nFor more information, type \"\\?\" (for internal commands) or \"\\help\" (for SQL\n"
- "commands) from within psql, or consult the psql section in the PostgreSQL\n"
- "documentation.\n\n"));
- fprintf(output, _("Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
- fprintf(output, _("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
+ fputs(buf.data, output);
ClosePager(output);
+
+ termPQExpBuffer(&buf);
}
@@ -153,181 +174,196 @@ usage(unsigned short int pager)
void
slashUsage(unsigned short int pager)
{
+ PQExpBufferData buf;
+ int nlcount;
FILE *output;
char *currdb;
currdb = PQdb(pset.db);
/*
- * Keep this line count in sync with the number of lines printed below!
- * Use "psql --help=commands | wc" to count correctly. It's okay to count
- * the USE_READLINE line even in builds without that.
+ * To avoid counting the output lines manually, build the output in "buf"
+ * and then count them.
*/
- output = PageOutput(139, pager ? &(pset.popt.topt) : NULL);
-
- fprintf(output, _("General\n"));
- fprintf(output, _(" \\copyright show PostgreSQL usage and distribution terms\n"));
- fprintf(output, _(" \\crosstabview [COLUMNS] execute query and display result in crosstab\n"));
- fprintf(output, _(" \\errverbose show most recent error message at maximum verbosity\n"));
- fprintf(output, _(" \\g [(OPTIONS)] [FILE] execute query (and send result to file or |pipe);\n"
- " \\g with no arguments is equivalent to a semicolon\n"));
- fprintf(output, _(" \\gdesc describe result of query, without executing it\n"));
- fprintf(output, _(" \\gexec execute query, then execute each value in its result\n"));
- fprintf(output, _(" \\gset [PREFIX] execute query and store result in psql variables\n"));
- fprintf(output, _(" \\gx [(OPTIONS)] [FILE] as \\g, but forces expanded output mode\n"));
- fprintf(output, _(" \\q quit psql\n"));
- fprintf(output, _(" \\watch [SEC] execute query every SEC seconds\n"));
- fprintf(output, "\n");
-
- fprintf(output, _("Help\n"));
-
- fprintf(output, _(" \\? [commands] show help on backslash commands\n"));
- fprintf(output, _(" \\? options show help on psql command-line options\n"));
- fprintf(output, _(" \\? variables show help on special variables\n"));
- fprintf(output, _(" \\h [NAME] help on syntax of SQL commands, * for all commands\n"));
- fprintf(output, "\n");
-
- fprintf(output, _("Query Buffer\n"));
- fprintf(output, _(" \\e [FILE] [LINE] edit the query buffer (or file) with external editor\n"));
- fprintf(output, _(" \\ef [FUNCNAME [LINE]] edit function definition with external editor\n"));
- fprintf(output, _(" \\ev [VIEWNAME [LINE]] edit view definition with external editor\n"));
- fprintf(output, _(" \\p show the contents of the query buffer\n"));
- fprintf(output, _(" \\r reset (clear) the query buffer\n"));
+ initPQExpBuffer(&buf);
+
+ HELP0("General\n");
+ HELP0(" \\copyright show PostgreSQL usage and distribution terms\n");
+ HELP0(" \\crosstabview [COLUMNS] execute query and display result in crosstab\n");
+ HELP0(" \\errverbose show most recent error message at maximum verbosity\n");
+ HELP0(" \\g [(OPTIONS)] [FILE] execute query (and send result to file or |pipe);\n"
+ " \\g with no arguments is equivalent to a semicolon\n");
+ HELP0(" \\gdesc describe result of query, without executing it\n");
+ HELP0(" \\gexec execute query, then execute each value in its result\n");
+ HELP0(" \\gset [PREFIX] execute query and store result in psql variables\n");
+ HELP0(" \\gx [(OPTIONS)] [FILE] as \\g, but forces expanded output mode\n");
+ HELP0(" \\q quit psql\n");
+ HELP0(" \\watch [SEC] execute query every SEC seconds\n");
+ HELP0("\n");
+
+ HELP0("Help\n");
+
+ HELP0(" \\? [commands] show help on backslash commands\n");
+ HELP0(" \\? options show help on psql command-line options\n");
+ HELP0(" \\? variables show help on special variables\n");
+ HELP0(" \\h [NAME] help on syntax of SQL commands, * for all commands\n");
+ HELP0("\n");
+
+ HELP0("Query Buffer\n");
+ HELP0(" \\e [FILE] [LINE] edit the query buffer (or file) with external editor\n");
+ HELP0(" \\ef [FUNCNAME [LINE]] edit function definition with external editor\n");
+ HELP0(" \\ev [VIEWNAME [LINE]] edit view definition with external editor\n");
+ HELP0(" \\p show the contents of the query buffer\n");
+ HELP0(" \\r reset (clear) the query buffer\n");
#ifdef USE_READLINE
- fprintf(output, _(" \\s [FILE] display history or save it to file\n"));
+ HELP0(" \\s [FILE] display history or save it to file\n");
#endif
- fprintf(output, _(" \\w FILE write query buffer to file\n"));
- fprintf(output, "\n");
-
- fprintf(output, _("Input/Output\n"));
- fprintf(output, _(" \\copy ... perform SQL COPY with data stream to the client host\n"));
- fprintf(output, _(" \\echo [-n] [STRING] write string to standard output (-n for no newline)\n"));
- fprintf(output, _(" \\i FILE execute commands from file\n"));
- fprintf(output, _(" \\ir FILE as \\i, but relative to location of current script\n"));
- fprintf(output, _(" \\o [FILE] send all query results to file or |pipe\n"));
- fprintf(output, _(" \\qecho [-n] [STRING] write string to \\o output stream (-n for no newline)\n"));
- fprintf(output, _(" \\warn [-n] [STRING] write string to standard error (-n for no newline)\n"));
- fprintf(output, "\n");
-
- fprintf(output, _("Conditional\n"));
- fprintf(output, _(" \\if EXPR begin conditional block\n"));
- fprintf(output, _(" \\elif EXPR alternative within current conditional block\n"));
- fprintf(output, _(" \\else final alternative within current conditional block\n"));
- fprintf(output, _(" \\endif end conditional block\n"));
- fprintf(output, "\n");
-
- fprintf(output, _("Informational\n"));
- fprintf(output, _(" (options: S = show system objects, + = additional detail)\n"));
- fprintf(output, _(" \\d[S+] list tables, views, and sequences\n"));
- fprintf(output, _(" \\d[S+] NAME describe table, view, sequence, or index\n"));
- fprintf(output, _(" \\da[S] [PATTERN] list aggregates\n"));
- fprintf(output, _(" \\dA[+] [PATTERN] list access methods\n"));
- fprintf(output, _(" \\dAc[+] [AMPTRN [TYPEPTRN]] list operator classes\n"));
- fprintf(output, _(" \\dAf[+] [AMPTRN [TYPEPTRN]] list operator families\n"));
- fprintf(output, _(" \\dAo[+] [AMPTRN [OPFPTRN]] list operators of operator families\n"));
- fprintf(output, _(" \\dAp[+] [AMPTRN [OPFPTRN]] list support functions of operator families\n"));
- fprintf(output, _(" \\db[+] [PATTERN] list tablespaces\n"));
- fprintf(output, _(" \\dc[S+] [PATTERN] list conversions\n"));
- fprintf(output, _(" \\dconfig[+] [PATTERN] list configuration parameters\n"));
- fprintf(output, _(" \\dC[+] [PATTERN] list casts\n"));
- fprintf(output, _(" \\dd[S] [PATTERN] show object descriptions not displayed elsewhere\n"));
- fprintf(output, _(" \\dD[S+] [PATTERN] list domains\n"));
- fprintf(output, _(" \\ddp [PATTERN] list default privileges\n"));
- fprintf(output, _(" \\dE[S+] [PATTERN] list foreign tables\n"));
- fprintf(output, _(" \\des[+] [PATTERN] list foreign servers\n"));
- fprintf(output, _(" \\det[+] [PATTERN] list foreign tables\n"));
- fprintf(output, _(" \\deu[+] [PATTERN] list user mappings\n"));
- fprintf(output, _(" \\dew[+] [PATTERN] list foreign-data wrappers\n"));
- fprintf(output, _(" \\df[anptw][S+] [FUNCPTRN [TYPEPTRN ...]]\n"
- " list [only agg/normal/procedure/trigger/window] functions\n"));
- fprintf(output, _(" \\dF[+] [PATTERN] list text search configurations\n"));
- fprintf(output, _(" \\dFd[+] [PATTERN] list text search dictionaries\n"));
- fprintf(output, _(" \\dFp[+] [PATTERN] list text search parsers\n"));
- fprintf(output, _(" \\dFt[+] [PATTERN] list text search templates\n"));
- fprintf(output, _(" \\dg[S+] [PATTERN] list roles\n"));
- fprintf(output, _(" \\di[S+] [PATTERN] list indexes\n"));
- fprintf(output, _(" \\dl[+] list large objects, same as \\lo_list\n"));
- fprintf(output, _(" \\dL[S+] [PATTERN] list procedural languages\n"));
- fprintf(output, _(" \\dm[S+] [PATTERN] list materialized views\n"));
- fprintf(output, _(" \\dn[S+] [PATTERN] list schemas\n"));
- fprintf(output, _(" \\do[S+] [OPPTRN [TYPEPTRN [TYPEPTRN]]]\n"
- " list operators\n"));
- fprintf(output, _(" \\dO[S+] [PATTERN] list collations\n"));
- fprintf(output, _(" \\dp [PATTERN] list table, view, and sequence access privileges\n"));
- fprintf(output, _(" \\dP[itn+] [PATTERN] list [only index/table] partitioned relations [n=nested]\n"));
- fprintf(output, _(" \\drds [ROLEPTRN [DBPTRN]] list per-database role settings\n"));
- fprintf(output, _(" \\dRp[+] [PATTERN] list replication publications\n"));
- fprintf(output, _(" \\dRs[+] [PATTERN] list replication subscriptions\n"));
- fprintf(output, _(" \\ds[S+] [PATTERN] list sequences\n"));
- fprintf(output, _(" \\dt[S+] [PATTERN] list tables\n"));
- fprintf(output, _(" \\dT[S+] [PATTERN] list data types\n"));
- fprintf(output, _(" \\du[S+] [PATTERN] list roles\n"));
- fprintf(output, _(" \\dv[S+] [PATTERN] list views\n"));
- fprintf(output, _(" \\dx[+] [PATTERN] list extensions\n"));
- fprintf(output, _(" \\dX [PATTERN] list extended statistics\n"));
- fprintf(output, _(" \\dy[+] [PATTERN] list event triggers\n"));
- fprintf(output, _(" \\l[+] [PATTERN] list databases\n"));
- fprintf(output, _(" \\sf[+] FUNCNAME show a function's definition\n"));
- fprintf(output, _(" \\sv[+] VIEWNAME show a view's definition\n"));
- fprintf(output, _(" \\z [PATTERN] same as \\dp\n"));
- fprintf(output, "\n");
-
- fprintf(output, _("Large Objects\n"));
- fprintf(output, _(" \\lo_export LOBOID FILE write large object to file\n"));
- fprintf(output, _(" \\lo_import FILE [COMMENT]\n"
- " read large object from file\n"));
- fprintf(output, _(" \\lo_list[+] list large objects\n"));
- fprintf(output, _(" \\lo_unlink LOBOID delete a large object\n"));
- fprintf(output, "\n");
-
- fprintf(output, _("Formatting\n"));
- fprintf(output, _(" \\a toggle between unaligned and aligned output mode\n"));
- fprintf(output, _(" \\C [STRING] set table title, or unset if none\n"));
- fprintf(output, _(" \\f [STRING] show or set field separator for unaligned query output\n"));
- fprintf(output, _(" \\H toggle HTML output mode (currently %s)\n"),
- ON(pset.popt.topt.format == PRINT_HTML));
- fprintf(output, _(" \\pset [NAME [VALUE]] set table output option\n"
- " (border|columns|csv_fieldsep|expanded|fieldsep|\n"
- " fieldsep_zero|footer|format|linestyle|null|\n"
- " numericlocale|pager|pager_min_lines|recordsep|\n"
- " recordsep_zero|tableattr|title|tuples_only|\n"
- " unicode_border_linestyle|unicode_column_linestyle|\n"
- " unicode_header_linestyle)\n"));
- fprintf(output, _(" \\t [on|off] show only rows (currently %s)\n"),
- ON(pset.popt.topt.tuples_only));
- fprintf(output, _(" \\T [STRING] set HTML Re: Count output lines automatically in psql/help.c
От:
Robert Haas <robertmhaas@gmail.com>
Дата:
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
Re: Count output lines automatically in psql/help.c
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
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
От:
Alvaro Herrera <alvherre@alvh.no-ip.org>
Дата:
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>
Дата:
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 strchr would make it faster.) regards, tom lane
Re: Count output lines automatically in psql/help.c
От:
Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Дата:
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>
Дата:
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 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