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

Commit1d66a1c

Browse files
author
Michael Meskes
committed
ECPG only copied #include statements instead of processing them according to
commandline option "-i". This change fixes this and adds a test case. It alsohonors #include_next, although this is probably never used for embedded SQL.
1 parent6ad4249 commit1d66a1c

File tree

10 files changed

+72
-43
lines changed

10 files changed

+72
-43
lines changed

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

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
*
1414
* IDENTIFICATION
15-
* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.172 2010/01/26 09:07:31 meskes Exp $
15+
* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.173 2010/03/21 10:49:51 meskes Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -44,6 +44,9 @@ static intliteralalloc;/* current allocated buffer size */
4444
/* Used for detecting global state together with braces_open*/
4545
staticintparenths_open;
4646

47+
/* Used to tell parse_include() whether the command was #include or #include_next*/
48+
staticboolinclude_next;
49+
4750
#definestartlit()(literalbuf[0] ='\0', literallen =0)
4851
staticvoidaddlit(char *ytext,int yleng);
4952
staticvoidaddlitchar (unsignedchar);
@@ -310,11 +313,14 @@ other.
310313

311314
/* some stuff needed for ecpg */
312315
exec[eE][xX][eE][cC]
313-
sql[sS][qQ][lL]
316+
sql[sS][qQ][lL]
314317
define[dD][eE][fF][iI][nN][eE]
315318
include [iI][nN][cC][lL][uU][dD][eE]
319+
include_next [iI][nN][cC][lL][uU][dD][eE]_[nN][eE][xX][tT]
320+
import [iI][mM][pP][oO][rR][tT]
316321
undef[uU][nN][dD][eE][fF]
317322

323+
if[iI][fF]
318324
ifdef[iI][fF][dD][eE][fF]
319325
ifndef[iI][fF][nN][dD][eE][fF]
320326
else[eE][lL][sS][eE]
@@ -325,13 +331,17 @@ struct[sS][tT][rR][uU][cC][tT]
325331

326332
exec_sql{exec}{space}*{sql}{space}*
327333
ipdigit({digit}|{digit}{digit}|{digit}{digit}{digit})
328-
ip{ipdigit}\.{ipdigit}\.{ipdigit}\.{ipdigit}
334+
ip{ipdigit}\.{ipdigit}\.{ipdigit}\.{ipdigit}
329335

330336
/* we might want to parse all cpp include files */
331337
cppinclude {space}*#{include}{space}*
338+
cppinclude_next{space}*#{include_next}{space}*
332339

333-
/* Take care of cpp lines, they may also be continuated */
334-
cppline{space}*#(.*\\{space})*.*{newline}
340+
/* take care of cpp lines, they may also be continuated */
341+
/* first a general line for all commands not starting with "i" */
342+
/* and then the other commands starting with "i", we have to add these
343+
* seperately because the cppline production would match on "include" too */
344+
cppline{space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})(.*\\{space})*.*{newline}
335345

336346
/*
337347
* Dollar quoted strings are totally opaque, and no escaping is done on them.
@@ -777,6 +787,19 @@ cppline{space}*#(.*\\{space})*.*{newline}
777787
<C>{cppinclude}{
778788
if (system_includes)
779789
{
790+
include_next =false;
791+
BEGIN(incl);
792+
}
793+
else
794+
{
795+
yylval.str =mm_strdup(yytext);
796+
return(CPP_LINE);
797+
}
798+
}
799+
<C>{cppinclude_next}{
800+
if (system_includes)
801+
{
802+
include_next =true;
780803
BEGIN(incl);
781804
}
782805
else
@@ -1322,6 +1345,12 @@ parse_include(void)
13221345
yyin =fopen( inc_file,"r" );
13231346
}
13241347
}
1348+
/* if the command was "include_next" we have to disregard the first hit */
1349+
if (yyin && include_next)
1350+
{
1351+
yyin =NULL;
1352+
include_next =false;
1353+
}
13251354
}
13261355
}
13271356
if (!yyin)

‎src/interfaces/ecpg/test/compat_informix/rnull.pgc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "sqltypes.h"
22
#include <stdlib.h>
3-
#
3+
44
$include ../regression;
55
$define NUMBER 12;
66

‎src/interfaces/ecpg/test/compat_informix/test_informix.pgc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "sqltypes.h"
22
#include <stdlib.h>
3-
#
3+
44
$include ../regression;
55
$define NUMBER 12;
66

‎src/interfaces/ecpg/test/expected/compat_informix-rnull.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#line 1 "rnull.pgc"
1212
#include"sqltypes.h"
1313
#include<stdlib.h>
14-
#
14+
1515

1616
#line 1 "regression.h"
1717

‎src/interfaces/ecpg/test/expected/compat_informix-test_informix.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#line 1 "test_informix.pgc"
1212
#include"sqltypes.h"
1313
#include<stdlib.h>
14-
#
14+
1515

1616
#line 1 "regression.h"
1717

‎src/interfaces/ecpg/test/expected/preproc-strings.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
#defineECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
88

99
#line 1 "strings.pgc"
10-
#include<stdlib.h>
11-
1210

1311
#line 1 "regression.h"
1412

@@ -18,27 +16,28 @@
1816

1917

2018
#line 3 "strings.pgc"
21-
22-
2319
/* exec sql begin declare section */
20+
#line 1 "strings.h"
2421

2522

26-
#line 6 "strings.pgc"
23+
#line 5 "strings.pgc"
24+
25+
#line 1 "strings.h"
2726
char*s1 ,*s2 ,*s3 ,*s4 ,*s5 ,*s6 ;
2827
/* exec sql end declare section */
29-
#line7 "strings.pgc"
28+
#line5 "strings.pgc"
3029

3130

3231
intmain(void)
3332
{
3433
ECPGdebug(1,stderr);
3534

3635
{ECPGconnect(__LINE__,0,"regress1" ,NULL,NULL ,NULL,0); }
37-
#line13 "strings.pgc"
36+
#line11 "strings.pgc"
3837

3938

4039
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"set standard_conforming_strings to on",ECPGt_EOIT,ECPGt_EORT);}
41-
#line15 "strings.pgc"
40+
#line13 "strings.pgc"
4241

4342

4443
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"select 'abcdef' , N'abcdef' as foo , E'abc\\bdef' as \"foo\" , U&'d\\0061t\\0061' as U&\"foo\" , U&'d!+000061t!+000061' uescape '!' , $foo$abc$def$foo$",ECPGt_EOIT,
@@ -54,13 +53,13 @@ int main(void)
5453
ECPGt_NO_INDICATOR,NULL ,0L,0L,0L,
5554
ECPGt_char,&(s6),(long)0,(long)1,(1)*sizeof(char),
5655
ECPGt_NO_INDICATOR,NULL ,0L,0L,0L,ECPGt_EORT);}
57-
#line23 "strings.pgc"
56+
#line21 "strings.pgc"
5857

5958

6059
printf("%s %s %s %s %s %s\n",s1,s2,s3,s4,s5,s6);
6160

6261
{ECPGdisconnect(__LINE__,"CURRENT");}
63-
#line27 "strings.pgc"
62+
#line25 "strings.pgc"
6463

65-
exit (0);
64+
return (0);
6665
}

‎src/interfaces/ecpg/test/expected/preproc-strings.stderr

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,41 @@
22
[NO_PID]: sqlca: code: 0, state: 00000
33
[NO_PID]: ECPGconnect: opening database regress1 on <DEFAULT> port <DEFAULT>
44
[NO_PID]: sqlca: code: 0, state: 00000
5-
[NO_PID]: ecpg_execute on line15: query: set standard_conforming_strings to on; with 0 parameter(s) on connection regress1
5+
[NO_PID]: ecpg_execute on line13: query: set standard_conforming_strings to on; with 0 parameter(s) on connection regress1
66
[NO_PID]: sqlca: code: 0, state: 00000
7-
[NO_PID]: ecpg_execute on line15: using PQexec
7+
[NO_PID]: ecpg_execute on line13: using PQexec
88
[NO_PID]: sqlca: code: 0, state: 00000
9-
[NO_PID]: ecpg_execute on line15: OK: SET
9+
[NO_PID]: ecpg_execute on line13: OK: SET
1010
[NO_PID]: sqlca: code: 0, state: 00000
11-
[NO_PID]: ecpg_execute on line17: query: select 'abcdef' , N'abcdef' as foo , E'abc\bdef' as "foo" , U&'d\0061t\0061' as U&"foo" , U&'d!+000061t!+000061' uescape '!' , $foo$abc$def$foo$; with 0 parameter(s) on connection regress1
11+
[NO_PID]: ecpg_execute on line15: query: select 'abcdef' , N'abcdef' as foo , E'abc\bdef' as "foo" , U&'d\0061t\0061' as U&"foo" , U&'d!+000061t!+000061' uescape '!' , $foo$abc$def$foo$; with 0 parameter(s) on connection regress1
1212
[NO_PID]: sqlca: code: 0, state: 00000
13-
[NO_PID]: ecpg_execute on line17: using PQexec
13+
[NO_PID]: ecpg_execute on line15: using PQexec
1414
[NO_PID]: sqlca: code: 0, state: 00000
15-
[NO_PID]: ecpg_execute on line17: correctly got 1 tuples with 6 fields
15+
[NO_PID]: ecpg_execute on line15: correctly got 1 tuples with 6 fields
1616
[NO_PID]: sqlca: code: 0, state: 00000
17-
[NO_PID]: ecpg_store_result on line17: allocating memory for 1 tuples
17+
[NO_PID]: ecpg_store_result on line15: allocating memory for 1 tuples
1818
[NO_PID]: sqlca: code: 0, state: 00000
19-
[NO_PID]: ecpg_get_data on line17: RESULT: abcdef offset: -1; array: no
19+
[NO_PID]: ecpg_get_data on line15: RESULT: abcdef offset: -1; array: no
2020
[NO_PID]: sqlca: code: 0, state: 00000
21-
[NO_PID]: ecpg_store_result on line17: allocating memory for 1 tuples
21+
[NO_PID]: ecpg_store_result on line15: allocating memory for 1 tuples
2222
[NO_PID]: sqlca: code: 0, state: 00000
23-
[NO_PID]: ecpg_get_data on line17: RESULT: abcdef offset: -1; array: no
23+
[NO_PID]: ecpg_get_data on line15: RESULT: abcdef offset: -1; array: no
2424
[NO_PID]: sqlca: code: 0, state: 00000
25-
[NO_PID]: ecpg_store_result on line17: allocating memory for 1 tuples
25+
[NO_PID]: ecpg_store_result on line15: allocating memory for 1 tuples
2626
[NO_PID]: sqlca: code: 0, state: 00000
27-
[NO_PID]: ecpg_get_data on line17: RESULT: abcdef offset: -1; array: no
27+
[NO_PID]: ecpg_get_data on line15: RESULT: abcdef offset: -1; array: no
2828
[NO_PID]: sqlca: code: 0, state: 00000
29-
[NO_PID]: ecpg_store_result on line17: allocating memory for 1 tuples
29+
[NO_PID]: ecpg_store_result on line15: allocating memory for 1 tuples
3030
[NO_PID]: sqlca: code: 0, state: 00000
31-
[NO_PID]: ecpg_get_data on line17: RESULT: data offset: -1; array: no
31+
[NO_PID]: ecpg_get_data on line15: RESULT: data offset: -1; array: no
3232
[NO_PID]: sqlca: code: 0, state: 00000
33-
[NO_PID]: ecpg_store_result on line17: allocating memory for 1 tuples
33+
[NO_PID]: ecpg_store_result on line15: allocating memory for 1 tuples
3434
[NO_PID]: sqlca: code: 0, state: 00000
35-
[NO_PID]: ecpg_get_data on line17: RESULT: data offset: -1; array: no
35+
[NO_PID]: ecpg_get_data on line15: RESULT: data offset: -1; array: no
3636
[NO_PID]: sqlca: code: 0, state: 00000
37-
[NO_PID]: ecpg_store_result on line17: allocating memory for 1 tuples
37+
[NO_PID]: ecpg_store_result on line15: allocating memory for 1 tuples
3838
[NO_PID]: sqlca: code: 0, state: 00000
39-
[NO_PID]: ecpg_get_data on line17: RESULT: abc$def offset: -1; array: no
39+
[NO_PID]: ecpg_get_data on line15: RESULT: abc$def offset: -1; array: no
4040
[NO_PID]: sqlca: code: 0, state: 00000
4141
[NO_PID]: ecpg_finish: connection regress1 closed
4242
[NO_PID]: sqlca: code: 0, state: 00000

‎src/interfaces/ecpg/test/preproc/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ array_of_struct.c:array_of_struct.pgc ../regression.h
2424
autoprep.c: autoprep.pgc ../regression.h
2525
$(ECPG) -r prepare -o$@ -I$(srcdir)$<
2626

27+
strings.c: strings.pgc strings.h ../regression.h
28+
$(ECPG) -i -o$@ -I$(srcdir)$<
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
char*s1,*s2,*s3,*s4,*s5,*s6;

‎src/interfaces/ecpg/test/preproc/strings.pgc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
#include <stdlib.h>
2-
3-
exec sql include ../regression;
1+
#include "../regression.h"
42

53
exec sql begin declare section;
6-
char *s1, *s2, *s3, *s4, *s5, *s6;
4+
#include "strings.h"
75
exec sql end declare section;
86

97
int main(void)
@@ -25,5 +23,5 @@ int main(void)
2523
printf("%s %s %s %s %s %s\n", s1, s2, s3, s4, s5, s6);
2624

2725
exec sql disconnect;
28-
exit (0);
26+
return (0);
2927
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp