Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit980a70b

Browse files
committed
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 itas an unrecognized switch. This is unhelpful; better is to treat suchan item as a non-switch argument. That behavior is what we find inGNU's getopt_long(); it's what src/port/getopt.c does; and it isrequired by POSIX for getopt(), which getopt_long() ought to begenerally a superset of. Moreover, it's expected by ecpg, whichintends an argument of "-" to mean "read from stdin". So fix it.Also add some documentation about ecpg's behavior in this area, sincethat was miserably underdocumented. I had to reverse-engineer itfrom 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
1 parentc81bd3b commit980a70b

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

‎doc/src/sgml/ref/ecpg-ref.sgml

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,21 @@ PostgreSQL documentation
4141

4242
<para>
4343
<command>ecpg</command> will convert each input file given on the
44-
command line to the corresponding C output file.Input files
45-
preferablyhavethe extension <filename>.pgc</filename>.
46-
The extension will be replaced by <filename>.c</filename> to
47-
determine the output file name.
48-
Theoutput file name can also be overridden using the
44+
command line to the corresponding C output file.If an input file
45+
name does nothaveany extension, <filename>.pgc</filename> is
46+
assumed.Thefile'sextension will be replaced
47+
by <filename>.c</filename> to construct the output file name.
48+
But theoutput file name can be overridden using the
4949
<option>-o</option> option.
5050
</para>
5151

52+
<para>
53+
If an input file name is just <literal>-</literal>,
54+
<command>ecpg</command> reads the program from standard input
55+
(and writes to standard output, unless that is overridden
56+
with <option>-o</option>).
57+
</para>
58+
5259
<para>
5360
This reference page does not describe the embedded SQL language.
5461
See <xref linkend="ecpg"/> for more information on that topic.
@@ -94,6 +101,19 @@ PostgreSQL documentation
94101
</listitem>
95102
</varlistentry>
96103

104+
<varlistentry>
105+
<term><option>-h</option></term>
106+
<listitem>
107+
<para>
108+
Process header files. When this option is specified, the output file
109+
extension becomes <literal>.h</literal> not <literal>.c</literal>,
110+
and the default input file extension is <literal>.pgh</literal>
111+
not <literal>.pgc</literal>. Also, the <option>-c</option> option is
112+
forced on.
113+
</para>
114+
</listitem>
115+
</varlistentry>
116+
97117
<varlistentry>
98118
<term><option>-i</option></term>
99119
<listitem>
@@ -125,6 +145,7 @@ PostgreSQL documentation
125145
<para>
126146
Specifies that <command>ecpg</command> should write all
127147
its output to the given <replaceable>filename</replaceable>.
148+
Write <literal>-o -</literal> to send all output to standard output.
128149
</para>
129150
</listitem>
130151
</varlistentry>

‎src/port/getopt_long.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,22 @@ getopt_long(int argc, char *const argv[],
7979

8080
place++;
8181

82-
if (place[0]&&place[0]=='-'&&place[1]=='\0')
83-
{/* found "--" */
82+
if (!*place)
83+
{
84+
/* treat "-" as not being an option */
85+
place=EMSG;
86+
return-1;
87+
}
88+
89+
if (place[0]=='-'&&place[1]=='\0')
90+
{
91+
/* found "--", treat it as end of options */
8492
++optind;
8593
place=EMSG;
8694
return-1;
8795
}
8896

89-
if (place[0]&&place[0]=='-'&&place[1])
97+
if (place[0]=='-'&&place[1])
9098
{
9199
/* long option */
92100
size_tnamelen;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp