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

Commite185583

Browse files
author
Michael Meskes
committed
Allow input from stdin and output to stdout.
1 parent6778445 commite185583

File tree

3 files changed

+59
-44
lines changed

3 files changed

+59
-44
lines changed

‎src/interfaces/ecpg/ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,6 +1445,10 @@ Fri May 23 11:46:15 CEST 2003
14451445
Tue May 27 13:29:28 CEST 2003
14461446

14471447
- Fixed incorrect output for some structs.
1448+
1449+
Tue May 27 16:33:36 CEST 2003
1450+
1451+
- Accept stdin/stdout as input/output file.
14481452
- Set ecpg version to 2.12.0.
14491453
- Set ecpg library to 3.4.2.
14501454
- Set pgtypes library to 1.0.0

‎src/interfaces/ecpg/preproc/ecpg.c

Lines changed: 54 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.70 2003/05/14 14:37:35 meskes Exp $ */
1+
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.71 2003/05/27 14:36:00 meskes Exp $ */
22

33
/* New main for ecpg, the PostgreSQL embedded SQL precompiler. */
44
/* (C) Michael Meskes <meskes@postgresql.org> Feb 5th, 1998 */
@@ -137,7 +137,11 @@ main(int argc, char *const argv[])
137137
switch (c)
138138
{
139139
case'o':
140-
yyout=fopen(optarg,PG_BINARY_W);
140+
if (strcmp(optarg,"-")==0)
141+
yyout=stdout;
142+
else
143+
yyout=fopen(optarg,PG_BINARY_W);
144+
141145
if (yyout==NULL)
142146
perror(optarg);
143147
else
@@ -219,47 +223,62 @@ main(int argc, char *const argv[])
219223
char*output_filename=NULL,
220224
*ptr2ext;
221225

222-
input_filename=mm_alloc(strlen(argv[fnr])+5);
223-
224-
strcpy(input_filename,argv[fnr]);
226+
/* If argv[fnr] is "-" we have to read from stdin */
227+
if (strcmp(argv[fnr],"-")==0)
228+
{
229+
input_filename=mm_alloc(strlen("stdin")+1);
230+
strcpy(input_filename,"stdin");
231+
yyin=stdin;
232+
}
233+
else
234+
{
235+
input_filename=mm_alloc(strlen(argv[fnr])+5);
236+
strcpy(input_filename,argv[fnr]);
225237

226-
/* take care of relative paths */
227-
ptr2ext=last_path_separator(input_filename);
228-
ptr2ext= (ptr2ext ?strrchr(ptr2ext,'.') :strrchr(input_filename,'.'));
238+
/* take care of relative paths */
239+
ptr2ext=last_path_separator(input_filename);
240+
ptr2ext= (ptr2ext ?strrchr(ptr2ext,'.') :strrchr(input_filename,'.'));
229241

230-
/* no extension? */
231-
if (ptr2ext==NULL)
232-
{
233-
ptr2ext=input_filename+strlen(input_filename);
234-
235-
/* no extension => add .pgc */
236-
ptr2ext[0]='.';
237-
ptr2ext[1]='p';
238-
ptr2ext[2]='g';
239-
ptr2ext[3]='c';
240-
ptr2ext[4]='\0';
242+
/* no extension? */
243+
if (ptr2ext==NULL)
244+
{
245+
ptr2ext=input_filename+strlen(input_filename);
246+
247+
/* no extension => add .pgc */
248+
ptr2ext[0]='.';
249+
ptr2ext[1]='p';
250+
ptr2ext[2]='g';
251+
ptr2ext[3]='c';
252+
ptr2ext[4]='\0';
253+
}
254+
255+
yyin=fopen(input_filename,PG_BINARY_R);
241256
}
242257

243258
if (out_option==0)/* calculate the output name */
244259
{
245-
output_filename=strdup(input_filename);
260+
if (strcmp(input_filename,"stdin")==0)
261+
yyout=stdout;
262+
else
263+
{
264+
output_filename=strdup(input_filename);
246265

247-
ptr2ext=strrchr(output_filename,'.');
248-
/* make extension = .c */
249-
ptr2ext[1]='c';
250-
ptr2ext[2]='\0';
266+
ptr2ext=strrchr(output_filename,'.');
267+
/* make extension = .c */
268+
ptr2ext[1]='c';
269+
ptr2ext[2]='\0';
251270

252-
yyout=fopen(output_filename,PG_BINARY_W);
253-
if (yyout==NULL)
254-
{
255-
perror(output_filename);
256-
free(output_filename);
257-
free(input_filename);
258-
continue;
271+
yyout=fopen(output_filename,PG_BINARY_W);
272+
if (yyout==NULL)
273+
{
274+
perror(output_filename);
275+
free(output_filename);
276+
free(input_filename);
277+
continue;
278+
}
259279
}
260280
}
261281

262-
yyin=fopen(input_filename,PG_BINARY_R);
263282
if (yyin==NULL)
264283
perror(argv[fnr]);
265284
else
@@ -341,7 +360,7 @@ main(int argc, char *const argv[])
341360

342361
/* finally the actual connection */
343362
connection=NULL;
344-
363+
345364
/* initialize lex */
346365
lex_init();
347366

@@ -355,9 +374,9 @@ main(int argc, char *const argv[])
355374
/* and parse the source */
356375
yyparse();
357376

358-
if (yyin!=NULL)
377+
if (yyin!=NULL&&yyin!=stdin)
359378
fclose(yyin);
360-
if (out_option==0)
379+
if (out_option==0&&yyout!=stdout)
361380
fclose(yyout);
362381
}
363382

‎src/interfaces/ecpg/preproc/pgc.l

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
*
1414
* IDENTIFICATION
15-
* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.110 2003/05/22 07:58:41 meskes Exp $
15+
* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.111 2003/05/27 14:36:00 meskes Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -399,14 +399,6 @@ cppline{space}*#(.*\\{space})+.*
399399
BEGIN(state_before);
400400
if (literallen ==0)
401401
mmerror(PARSE_ERROR, ET_ERROR,"zero-length delimited identifier");
402-
if (literallen >= NAMEDATALEN)
403-
{
404-
snprintf(errortext,sizeof(errortext),"identifier\"%s\" will be truncated to\"%.*s\"",
405-
literalbuf, NAMEDATALEN-1, literalbuf);
406-
literalbuf[NAMEDATALEN-1] ='\0';
407-
mmerror(PARSE_ERROR, ET_WARNING, errortext);
408-
}
409-
410402
yylval.str =mm_strdup(literalbuf);
411403
return CSTRING;
412404
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp