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

Commitb57b0e0

Browse files
committed
The first fix is to allow an input file with a relative path and without
a ".pgc " extension. The second patch fixes a coredump when there ismore than one input file (in that case, cur and types were not set toNULL before processing the second f ile)The patch below modifies the accepted grammar of ecpg to accept FETCH [direction] [amount] cursor namei.e. the IN|FROM clause becomes optional (as in Oracle and Informix).This removes the incompatibility mentioned in section "Porting FromOther RDBMS Packages" p169, PostgreSQL Programmer's Guide. The grammaris modified in such a way as to avoid shift/reduce conflicts. It doesnot accept the statement "EXEC SQL FETCH;" anymore, as the old grammardid (this seems to be a bug of the old grammar anyway).This patch cleans up the handling of space characters in the scanner;some patte rns require \n to be in {space}, some do not. A second fix isthe handling of cpp continuati on lines; the old pattern did not matchthese. The parser is patched to fix an off-by-one error in the #linedirectives. The pa rser is also enhanced to report the correct locationof errors in declarations in the "E XEC SQL DECLARE SECTION". Finally,some right recursions in the parser were replaced by left-recursions.This patch adds preprocessor directives to ecpg; in particularEXEC SQL IFDEF, EXEC SQL IFNDEF, EXEC SQL ELSE, EXEC SQL ELIF and EXEC SQL ENDIF"EXEC SQL IFDEF" is used with defines made with "EXEC SQL DEFINE" anddefines, specified on the command line with -D. Defines, specified onthe command line are persistent across multiple input files. Defines canbe nested up to a maximum level of 128 (see patch). There is a fairamount of error checking to make sure directives are matched properly. Ineed preprocessor directives for porting code, that is written for anInformix database, to a PostgreSQL database, while maintainingcompatibility with the original code. I decided not to extend thealready large ecpg grammar. Everything is done in the scanner by addingsome states, e.g. to skip all input except newlines and directives. Thepreprocessor commands are compatible with Informix. Oracle uses a cppreplacement.Rene Hogendoorn
1 parenta0fa26b commitb57b0e0

File tree

4 files changed

+238
-61
lines changed

4 files changed

+238
-61
lines changed

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

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@
1212
#include"extern.h"
1313

1414
struct_include_path*include_paths;
15-
intret_value=OK,autocommit=0;
15+
struct_defines*defines=NULL;
16+
intautocommit=0;
17+
intret_value=OK;
1618
structcursor*cur=NULL;
1719
structtypedefs*types=NULL;
1820

1921
staticvoid
2022
usage(char*progname)
2123
{
2224
fprintf(stderr,"ecpg - the postgresql preprocessor, version: %d.%d.%d\n",MAJOR_VERSION,MINOR_VERSION,PATCHLEVEL);
23-
fprintf(stderr,"Usage: %s: [-v] [-t] [-I include path] [ -o output file name] file1 [file2] ...\n",progname);
25+
fprintf(stderr,"Usage: %s: [-v] [-t] [-I include path] [ -o output file name][-D define name]file1 [file2] ...\n",progname);
2426
}
2527

2628
staticvoid
@@ -33,6 +35,18 @@ add_include_path(char *path)
3335
include_paths->next=ip;
3436
}
3537

38+
staticvoid
39+
add_preprocessor_define(char*define)
40+
{
41+
struct_defines*pd=defines;
42+
43+
defines=mm_alloc(sizeof(struct_defines));
44+
defines->old=strdup(define);
45+
defines->new=strdup("");
46+
defines->pertinent= true;
47+
defines->next=pd;
48+
}
49+
3650
int
3751
main(intargc,char*constargv[])
3852
{
@@ -46,7 +60,7 @@ main(int argc, char *const argv[])
4660
add_include_path("/usr/local/include");
4761
add_include_path(".");
4862

49-
while ((c=getopt(argc,argv,"vo:I:t"))!=EOF)
63+
while ((c=getopt(argc,argv,"vo:I:tD:"))!=EOF)
5064
{
5165
switch (c)
5266
{
@@ -74,6 +88,9 @@ main(int argc, char *const argv[])
7488
fprintf(stderr," %s\n",ip->path);
7589
fprintf(stderr,"End of search list.\n");
7690
returnOK;
91+
case'D':
92+
add_preprocessor_define(optarg);
93+
break;
7794
default:
7895
usage(argv[0]);
7996
returnILLEGAL_OPTION;
@@ -97,7 +114,9 @@ main(int argc, char *const argv[])
97114

98115
strcpy(input_filename,argv[fnr]);
99116

100-
ptr2ext=strrchr(input_filename,'.');
117+
/* take care of relative paths */
118+
ptr2ext=strrchr(input_filename,'/');
119+
ptr2ext= (ptr2ext ?strrchr(ptr2ext,'.') :strrchr(input_filename,'.'));
101120
/* no extension? */
102121
if (ptr2ext==NULL)
103122
{
@@ -170,16 +189,29 @@ main(int argc, char *const argv[])
170189
ptr=ptr->next;
171190
free(this);
172191
}
192+
cur=NULL;
193+
194+
/* remove non-pertinent old defines as well */
195+
while (defines&& !defines->pertinent ) {
196+
defptr=defines;
197+
defines=defines->next;
198+
199+
free(defptr->new);
200+
free(defptr->old);
201+
free(defptr);
202+
}
173203

174-
/* remove old defines as well */
175-
for (defptr=defines;defptr!=NULL;)
204+
for (defptr=defines;defptr!=NULL;defptr=defptr->next )
176205
{
177-
struct_defines*this=defptr;
206+
struct_defines*this=defptr->next;
207+
208+
if (this&& !this->pertinent ) {
209+
defptr->next=this->next;
178210

179-
free(defptr->new);
180-
free(defptr->old);
181-
defptr=defptr->next;
211+
free(this->new);
212+
free(this->old);
182213
free(this);
214+
}
183215
}
184216

185217
/* and old typedefs */
@@ -193,12 +225,13 @@ main(int argc, char *const argv[])
193225
typeptr=typeptr->next;
194226
free(this);
195227
}
228+
types=NULL;
196229

197230
/* initialize lex */
198231
lex_init();
199232

200233
/* we need two includes */
201-
fprintf(yyout,"/* Processed by ecpg (%d.%d.%d) */\n/* These two include files are added by the preprocessor */\n#include <ecpgtype.h>\n#include <ecpglib.h>\n\n",MAJOR_VERSION,MINOR_VERSION,PATCHLEVEL);
234+
fprintf(yyout,"/* Processed by ecpg (%d.%d.%d) */\n/* These two include files are added by the preprocessor */\n#include <ecpgtype.h>\n#include <ecpglib.h>\n#line 1 \"%s\"\n",MAJOR_VERSION,MINOR_VERSION,PATCHLEVEL,input_filename);
202235

203236
/* and parse the source */
204237
yyparse();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp