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

Commit1005c99

Browse files
author
Michael Meskes
committed
In Informix mode ecpg should still be able to parse preprocessor directives.
1 parente955121 commit1005c99

File tree

1 file changed

+142
-4
lines changed
  • src/interfaces/ecpg/preproc

1 file changed

+142
-4
lines changed

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

Lines changed: 142 additions & 4 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.104 2003/02/1413:17:13 meskes Exp $
15+
* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.105 2003/02/1416:40:01 meskes Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -43,6 +43,7 @@ static intliteralalloc;/* current allocated buffer size */
4343
#definestartlit()(literalbuf[0] ='\0', literallen =0)
4444
staticvoidaddlit(char *ytext,int yleng);
4545
staticvoidaddlitchar (unsignedchar);
46+
staticvoidstring_unput (char *);
4647

4748
char *token_start;
4849
int state_before;
@@ -701,12 +702,67 @@ cppline{space}*#(.*\\{space})*.*
701702
<C>{other}{return S_ANYTHING; }
702703

703704
<C>{exec_sql}{define}{space}*{BEGIN(def_ident); }
705+
<C>{informix_special}{define}{space}*{
706+
/* are we simulating Informix? */
707+
if (compat == ECPG_COMPAT_INFORMIX)
708+
{
709+
BEGIN(def_ident);
710+
}
711+
else
712+
{
713+
string_unput("define");
714+
/* remove the "define " part of the text */
715+
yytext[1] ='\0';
716+
return (S_ANYTHING);
717+
}
718+
}
704719
<C>{exec_sql}{include}{space}*{BEGIN(incl); }
705-
<C>{informix_special}{include}{space}*{BEGIN(incl); }
706-
720+
<C>{informix_special}{include}{space}* {
721+
/* are we simulating Informix? */
722+
if (compat == ECPG_COMPAT_INFORMIX)
723+
{
724+
BEGIN(incl);
725+
}
726+
else
727+
{
728+
string_unput("include");
729+
/* remove the "include " part of the text */
730+
yytext[1] ='\0';
731+
return (S_ANYTHING);
732+
}
733+
}
707734
<C,xskip>{exec_sql}{ifdef}{space}*{ ifcond =TRUE;BEGIN(xcond); }
735+
<C,xskip>{informix_special}{ifdef}{space}* {
736+
/* are we simulating Informix? */
737+
if (compat == ECPG_COMPAT_INFORMIX)
738+
{
739+
ifcond =TRUE;
740+
BEGIN(xcond);
741+
}
742+
else
743+
{
744+
string_unput("ifdef");
745+
/* remove the "ifdef " part of the text */
746+
yytext[1] ='\0';
747+
return (S_ANYTHING);
748+
}
749+
}
708750
<C,xskip>{exec_sql}{ifndef}{space}* { ifcond =FALSE;BEGIN(xcond); }
709-
751+
<C,xskip>{informix_special}{ifndef}{space}* {
752+
/* are we simulating Informix? */
753+
if (compat == ECPG_COMPAT_INFORMIX)
754+
{
755+
ifcond =FALSE;
756+
BEGIN(xcond);
757+
}
758+
else
759+
{
760+
string_unput("ifndef");
761+
/* remove the "ifndef " part of the text */
762+
yytext[1] ='\0';
763+
return (S_ANYTHING);
764+
}
765+
}
710766
<C,xskip>{exec_sql}{elif}{space}*{/* pop stack */
711767
if ( preproc_tos ==0 ) {
712768
mmerror(PARSE_ERROR, ET_FATAL,"Missing matching 'EXEC SQL IFDEF / EXEC SQL IFNDEF'");
@@ -718,6 +774,28 @@ cppline{space}*#(.*\\{space})*.*
718774

719775
ifcond =TRUE;BEGIN(xcond);
720776
}
777+
<C,xskip>{informix_special}{elif}{space}* {
778+
/* are we simulating Informix? */
779+
if (compat == ECPG_COMPAT_INFORMIX)
780+
{
781+
if ( preproc_tos ==0 ) {
782+
mmerror(PARSE_ERROR, ET_FATAL,"Missing matching 'EXEC SQL IFDEF / EXEC SQL IFNDEF'");
783+
}
784+
elseif ( stacked_if_value[preproc_tos].else_branch )
785+
mmerror(PARSE_ERROR, ET_FATAL,"Missing 'EXEC SQL ENDIF;'");
786+
else
787+
preproc_tos--;
788+
789+
ifcond =TRUE;BEGIN(xcond);
790+
}
791+
else
792+
{
793+
string_unput("elif");
794+
/* remove the "elif " part of the text */
795+
yytext[1] ='\0';
796+
return (S_ANYTHING);
797+
}
798+
}
721799

722800
<C,xskip>{exec_sql}{else}{space}*";" {/* only exec sql endif pops the stack, so take care of duplicated 'else' */
723801
if ( stacked_if_value[preproc_tos].else_branch ) {
@@ -735,6 +813,33 @@ cppline{space}*#(.*\\{space})*.*
735813
BEGIN(xskip);
736814
}
737815
}
816+
<C,xskip>{informix_special}{else}{space}*{
817+
/* are we simulating Informix? */
818+
if (compat == ECPG_COMPAT_INFORMIX)
819+
{
820+
if ( stacked_if_value[preproc_tos].else_branch ) {
821+
mmerror(PARSE_ERROR, ET_FATAL,"Duplicated 'EXEC SQL ELSE;'");
822+
}
823+
else {
824+
stacked_if_value[preproc_tos].else_branch =TRUE;
825+
stacked_if_value[preproc_tos].condition =
826+
(stacked_if_value[preproc_tos-1].condition &&
827+
! stacked_if_value[preproc_tos].condition);
828+
829+
if ( stacked_if_value[preproc_tos].condition )
830+
BEGIN(C);
831+
else
832+
BEGIN(xskip);
833+
}
834+
}
835+
else
836+
{
837+
string_unput("else");
838+
/* remove the "else " part of the text */
839+
yytext[1] ='\0';
840+
return (S_ANYTHING);
841+
}
842+
}
738843
<C,xskip>{exec_sql}{endif}{space}*";" {
739844
if ( preproc_tos ==0 )
740845
mmerror(PARSE_ERROR, ET_FATAL,"Unmatched 'EXEC SQL ENDIF;'");
@@ -746,6 +851,28 @@ cppline{space}*#(.*\\{space})*.*
746851
else
747852
BEGIN(xskip);
748853
}
854+
<C,xskip>{informix_special}{endif}{space}*{
855+
/* are we simulating Informix? */
856+
if (compat == ECPG_COMPAT_INFORMIX)
857+
{
858+
if ( preproc_tos ==0 )
859+
mmerror(PARSE_ERROR, ET_FATAL,"Unmatched 'EXEC SQL ENDIF;'");
860+
else
861+
preproc_tos--;
862+
863+
if ( stacked_if_value[preproc_tos].condition )
864+
BEGIN(C);
865+
else
866+
BEGIN(xskip);
867+
}
868+
else
869+
{
870+
string_unput("endif");
871+
/* remove the "endif " part of the text */
872+
yytext[1] ='\0';
873+
return (S_ANYTHING);
874+
}
875+
}
749876

750877
<xskip>{other}{/* ignore */ }
751878

@@ -983,3 +1110,14 @@ addlitchar(unsigned char ychar)
9831110
literallen +=1;
9841111
literalbuf[literallen] ='\0';
9851112
}
1113+
1114+
/* put string back on stack */
1115+
staticvoid
1116+
string_unput (char *string)
1117+
{
1118+
int i;
1119+
1120+
for (i =strlen(string)-1; i>=0; i--)
1121+
unput(string[i]);
1122+
}
1123+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp