12
12
*
13
13
*
14
14
* IDENTIFICATION
15
- * $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.104 2003/02/14 13:17:13 meskes Exp $
15
+ * $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.105 2003/02/14 16:40:01 meskes Exp $
16
16
*
17
17
*-------------------------------------------------------------------------
18
18
*/
@@ -43,6 +43,7 @@ static int literalalloc; /* current allocated buffer size */
43
43
#define startlit () (literalbuf[0 ] = ' \0 ' , literallen = 0 )
44
44
static void addlit (char *ytext, int yleng);
45
45
static void addlitchar (unsigned char );
46
+ static void string_unput (char *);
46
47
47
48
char *token_start;
48
49
int state_before;
@@ -701,12 +702,67 @@ cppline {space}*#(.*\\{space})*.*
701
702
<C >{other } { return S_ANYTHING; }
702
703
703
704
<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
+ }
704
719
<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
+ }
707
734
<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
+ }
708
750
<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
+ }
710
766
<C ,xskip >{exec_sql }{elif }{space }* { /* pop stack */
711
767
if ( preproc_tos == 0 ) {
712
768
mmerror (PARSE_ERROR, ET_FATAL, " Missing matching 'EXEC SQL IFDEF / EXEC SQL IFNDEF'" );
@@ -718,6 +774,28 @@ cppline {space}*#(.*\\{space})*.*
718
774
719
775
ifcond = TRUE ; BEGIN (xcond);
720
776
}
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
+ else if ( 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
+ }
721
799
722
800
<C ,xskip >{exec_sql }{else }{space }* " ;" { /* only exec sql endif pops the stack, so take care of duplicated 'else' */
723
801
if ( stacked_if_value[preproc_tos].else_branch ) {
@@ -735,6 +813,33 @@ cppline {space}*#(.*\\{space})*.*
735
813
BEGIN (xskip);
736
814
}
737
815
}
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
+ }
738
843
<C ,xskip >{exec_sql }{endif }{space }* " ;" {
739
844
if ( preproc_tos == 0 )
740
845
mmerror (PARSE_ERROR, ET_FATAL, " Unmatched 'EXEC SQL ENDIF;'" );
@@ -746,6 +851,28 @@ cppline {space}*#(.*\\{space})*.*
746
851
else
747
852
BEGIN (xskip);
748
853
}
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
+ }
749
876
750
877
<xskip >{other } { /* ignore */ }
751
878
@@ -983,3 +1110,14 @@ addlitchar(unsigned char ychar)
983
1110
literallen += 1 ;
984
1111
literalbuf[literallen] = ' \0 ' ;
985
1112
}
1113
+
1114
+ /* put string back on stack */
1115
+ static void
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