1
- /* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.98 2007/03/17 19:25:23 meskes Exp $ */
1
+ /* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.99 2007/06/11 11:52:08 meskes Exp $ */
2
2
3
3
/* New main for ecpg, the PostgreSQL embedded SQL precompiler. */
4
4
/* (C) Michael Meskes <meskes@postgresql.org> Feb 5th, 1998 */
@@ -20,6 +20,8 @@ int ret_value = 0,
20
20
header_mode = false,
21
21
regression_mode = false;
22
22
23
+ char * output_filename ;
24
+
23
25
enum COMPAT_MODE compat = ECPG_COMPAT_PGSQL ;
24
26
25
27
struct _include_path * include_paths = NULL ;
@@ -135,6 +137,7 @@ main(int argc, char *const argv[])
135
137
136
138
find_my_exec (argv [0 ], my_exec_path );
137
139
140
+ output_filename = NULL ;
138
141
while ((c = getopt_long (argc , argv , "vcio:I:tD:dC:r:h?" , ecpg_options , NULL )) != -1 )
139
142
{
140
143
switch (c )
@@ -163,14 +166,18 @@ main(int argc, char *const argv[])
163
166
regression_mode = true;
164
167
break ;
165
168
case 'o' :
166
- if (strcmp (optarg , "-" ) == 0 )
169
+ output_filename = optarg ;
170
+ if (strcmp (output_filename , "-" ) == 0 )
167
171
yyout = stdout ;
168
172
else
169
- yyout = fopen (optarg , PG_BINARY_W );
173
+ yyout = fopen (output_filename , PG_BINARY_W );
170
174
171
- if (yyout == NULL )
175
+ if (yyout == NULL )
176
+ {
172
177
fprintf (stderr , "%s: could not open file \"%s\": %s\n" ,
173
- progname , optarg , strerror (errno ));
178
+ progname , output_filename , strerror (errno ));
179
+ output_filename = NULL ;
180
+ }
174
181
else
175
182
out_option = 1 ;
176
183
break ;
@@ -269,8 +276,7 @@ main(int argc, char *const argv[])
269
276
/* after the options there must not be anything but filenames */
270
277
for (fnr = optind ; fnr < argc ; fnr ++ )
271
278
{
272
- char * output_filename = NULL ,
273
- * ptr2ext ;
279
+ char * ptr2ext ;
274
280
275
281
/* If argv[fnr] is "-" we have to read from stdin */
276
282
if (strcmp (argv [fnr ], "-" ) == 0 )
@@ -467,7 +473,7 @@ main(int argc, char *const argv[])
467
473
fclose (yyout );
468
474
}
469
475
470
- if (output_filename )
476
+ if (output_filename && out_option == 0 )
471
477
free (output_filename );
472
478
473
479
free (input_filename );
0 commit comments