mirror of
https://github.com/postgres/postgres.git
synced 2025-05-28 05:21:27 +03:00
Fix our getopt_long's behavior for a command line argument of just "-".
src/port/getopt_long.c failed on such an argument, always seeing it as an unrecognized switch. This is unhelpful; better is to treat such an item as a non-switch argument. That behavior is what we find in GNU's getopt_long(); it's what src/port/getopt.c does; and it is required by POSIX for getopt(), which getopt_long() ought to be generally a superset of. Moreover, it's expected by ecpg, which intends an argument of "-" to mean "read from stdin". So fix it. Also add some documentation about ecpg's behavior in this area, since that was miserably underdocumented. I had to reverse-engineer it from the code. Per bug #16304 from James Gray. Back-patch to all supported branches, since this has been broken forever. Discussion: https://postgr.es/m/16304-c662b00a1322db7f@postgresql.org
This commit is contained in:
parent
48f57efa49
commit
ef7d6d79af
@ -41,14 +41,21 @@ PostgreSQL documentation
|
|||||||
|
|
||||||
<para>
|
<para>
|
||||||
<command>ecpg</command> will convert each input file given on the
|
<command>ecpg</command> will convert each input file given on the
|
||||||
command line to the corresponding C output file. Input files
|
command line to the corresponding C output file. If an input file
|
||||||
preferably have the extension <filename>.pgc</filename>.
|
name does not have any extension, <filename>.pgc</filename> is
|
||||||
The extension will be replaced by <filename>.c</filename> to
|
assumed. The file's extension will be replaced
|
||||||
determine the output file name.
|
by <filename>.c</filename> to construct the output file name.
|
||||||
The output file name can also be overridden using the
|
But the output file name can be overridden using the
|
||||||
<option>-o</option> option.
|
<option>-o</option> option.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
If an input file name is just <literal>-</literal>,
|
||||||
|
<command>ecpg</command> reads the program from standard input
|
||||||
|
(and writes to standard output, unless that is overridden
|
||||||
|
with <option>-o</option>).
|
||||||
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
This reference page does not describe the embedded SQL language.
|
This reference page does not describe the embedded SQL language.
|
||||||
See <xref linkend="ecpg"> for more information on that topic.
|
See <xref linkend="ecpg"> for more information on that topic.
|
||||||
@ -94,6 +101,19 @@ PostgreSQL documentation
|
|||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term><option>-h</option></term>
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
Process header files. When this option is specified, the output file
|
||||||
|
extension becomes <literal>.h</literal> not <literal>.c</literal>,
|
||||||
|
and the default input file extension is <literal>.pgh</literal>
|
||||||
|
not <literal>.pgc</literal>. Also, the <option>-c</option> option is
|
||||||
|
forced on.
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><option>-i</option></term>
|
<term><option>-i</option></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
@ -125,6 +145,7 @@ PostgreSQL documentation
|
|||||||
<para>
|
<para>
|
||||||
Specifies that <command>ecpg</command> should write all
|
Specifies that <command>ecpg</command> should write all
|
||||||
its output to the given <replaceable>filename</replaceable>.
|
its output to the given <replaceable>filename</replaceable>.
|
||||||
|
Write <literal>-o -</literal> to send all output to standard output.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
@ -79,14 +79,22 @@ getopt_long(int argc, char *const argv[],
|
|||||||
|
|
||||||
place++;
|
place++;
|
||||||
|
|
||||||
if (place[0] && place[0] == '-' && place[1] == '\0')
|
if (!*place)
|
||||||
{ /* found "--" */
|
{
|
||||||
|
/* treat "-" as not being an option */
|
||||||
|
place = EMSG;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (place[0] == '-' && place[1] == '\0')
|
||||||
|
{
|
||||||
|
/* found "--", treat it as end of options */
|
||||||
++optind;
|
++optind;
|
||||||
place = EMSG;
|
place = EMSG;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (place[0] && place[0] == '-' && place[1])
|
if (place[0] == '-' && place[1])
|
||||||
{
|
{
|
||||||
/* long option */
|
/* long option */
|
||||||
size_t namelen;
|
size_t namelen;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user