Commit 92d4294d authored by Peter Eisentraut's avatar Peter Eisentraut

psql: Fix some strange code in SQL help creation

Struct QL_HELP used to be defined as static in the sql_help.h header
file, which is included in sql_help.c and help.c, thus creating two
separate instances of the struct.  This causes a warning from GCC 6,
because the struct is not used in sql_help.c.

Instead, declare the struct as extern in the header file and define it
in sql_help.c.  This also allows making a bunch of functions static
because they are no longer needed outside of sql_help.c.
Reviewed-by: default avatarThomas Munro <thomas.munro@enterprisedb.com>
parent 0d0644dc
...@@ -59,8 +59,6 @@ print HFILE "/* ...@@ -59,8 +59,6 @@ print HFILE "/*
#ifndef $define #ifndef $define
#define $define #define $define
#define N_(x) (x) /* gettext noop */
#include \"postgres_fe.h\" #include \"postgres_fe.h\"
#include \"pqexpbuffer.h\" #include \"pqexpbuffer.h\"
...@@ -72,6 +70,7 @@ struct _helpStruct ...@@ -72,6 +70,7 @@ struct _helpStruct
int nl_count; /* number of newlines in syntax (for pager) */ int nl_count; /* number of newlines in syntax (for pager) */
}; };
extern const struct _helpStruct QL_HELP[];
"; ";
print CFILE "/* print CFILE "/*
...@@ -83,6 +82,8 @@ print CFILE "/* ...@@ -83,6 +82,8 @@ print CFILE "/*
* *
*/ */
#define N_(x) (x) /* gettext noop */
#include \"$hfile\" #include \"$hfile\"
"; ";
...@@ -170,8 +171,7 @@ foreach (sort keys %entries) ...@@ -170,8 +171,7 @@ foreach (sort keys %entries)
$synopsis =~ s/\\n/\\n"\n$prefix"/g; $synopsis =~ s/\\n/\\n"\n$prefix"/g;
my @args = my @args =
("buf", $synopsis, map("_(\"$_\")", @{ $entries{$_}{params} })); ("buf", $synopsis, map("_(\"$_\")", @{ $entries{$_}{params} }));
print HFILE "extern void sql_help_$id(PQExpBuffer buf);\n"; print CFILE "static void
print CFILE "void
sql_help_$id(PQExpBuffer buf) sql_help_$id(PQExpBuffer buf)
{ {
\tappendPQExpBuffer(" . join(",\n$prefix", @args) . "); \tappendPQExpBuffer(" . join(",\n$prefix", @args) . ");
...@@ -180,15 +180,14 @@ sql_help_$id(PQExpBuffer buf) ...@@ -180,15 +180,14 @@ sql_help_$id(PQExpBuffer buf)
"; ";
} }
print HFILE " print CFILE "
const struct _helpStruct QL_HELP[] = {
static const struct _helpStruct QL_HELP[] = {
"; ";
foreach (sort keys %entries) foreach (sort keys %entries)
{ {
my $id = $_; my $id = $_;
$id =~ s/ /_/g; $id =~ s/ /_/g;
print HFILE " { \"$_\", print CFILE " { \"$_\",
N_(\"$entries{$_}{cmddesc}\"), N_(\"$entries{$_}{cmddesc}\"),
sql_help_$id, sql_help_$id,
$entries{$_}{nl_count} }, $entries{$_}{nl_count} },
...@@ -196,11 +195,12 @@ foreach (sort keys %entries) ...@@ -196,11 +195,12 @@ foreach (sort keys %entries)
"; ";
} }
print HFILE " print CFILE "
{ NULL, NULL, NULL } /* End of list marker */ { NULL, NULL, NULL } /* End of list marker */
}; };
";
print HFILE "
#define QL_HELP_COUNT " #define QL_HELP_COUNT "
. scalar(keys %entries) . " /* number of help items */ . scalar(keys %entries) . " /* number of help items */
#define QL_MAX_CMD_LEN $maxlen /* largest strlen(cmd) */ #define QL_MAX_CMD_LEN $maxlen /* largest strlen(cmd) */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment