]> granicus.if.org Git - postgresql/commitdiff
When a macro is replaced by the preprocessor, pgc.l reaches a end of
authorBruce Momjian <bruce@momjian.us>
Fri, 5 Apr 2002 11:39:47 +0000 (11:39 +0000)
committerBruce Momjian <bruce@momjian.us>
Fri, 5 Apr 2002 11:39:47 +0000 (11:39 +0000)
file, which is not the actual end of the file. One side effect of that
is that if you are i n a ifdef block, you get a wrong error telling you
that a endif is missing.

This patch corrects pgc.l and also adds a test of this problem to
test1.pgc. To  convince you apply the patch to test1.pgc first then try
to compile the test the n apply the patch to pgc.l.

The patch moves the test of the scope of an ifdef block to the end of
the file b eeing parsed, including all includes files, ... .

Nicolas Bazin

src/interfaces/ecpg/preproc/pgc.l
src/interfaces/ecpg/test/test1.pgc

index 5341d0930188a7cdbbbce39e6a37c210beb76d6b..27ba1c9375a9c8cbe2935b2cec918b34fadda241 100644 (file)
@@ -12,7 +12,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.89 2002/03/24 18:22:21 tgl Exp $
+ *       $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.90 2002/04/05 11:39:45 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -837,14 +837,14 @@ cppline                   {space}*#(.*\\{space})*.*
                                        }
 
 <<EOF>>                                {
+                                               if (yy_buffer == NULL) {
                                                if ( preproc_tos > 0 ) 
                                                {
                                                        preproc_tos = 0;
                                                        mmerror(PARSE_ERROR, ET_FATAL, "Missing 'EXEC SQL ENDIF;'");
                                                }
-
-                                               if (yy_buffer == NULL)
                                                        yyterminate();
+                                                       }
                                                else
                                                {
                                                        struct _yy_buffer *yb = yy_buffer;
index 0c23f240f60edfedc96031ef7716e8131e94e150..8eb27c3a2788f3732c07fb5a5503aa8fec378135 100644 (file)
@@ -17,9 +17,9 @@ static void warn(void)
 
 /* comment */
 exec sql define AMOUNT 6;
+exec sql define NAMELEN 8;
 
 exec sql type intarray is int[AMOUNT];
-exec sql type string is char(8); 
 
 typedef int intarray[AMOUNT];
 
@@ -27,16 +27,19 @@ int
 main ()
 {
 exec sql begin declare section;
+exec sql ifdef NAMELEN;
+       typedef char string[NAMELEN];
         intarray amount;
        int increment=100;
-        char name[AMOUNT][8];
+        char name[AMOUNT][NAMELEN];
        char letter[AMOUNT][1];
        struct name_letter_struct
        {
-               char name[8];
+               char name[NAMELEN];
                int amount;
                char letter;
        } name_letter[AMOUNT];
+exec sql endif;
         struct ind_struct
         {
                 short a;
@@ -62,8 +65,8 @@ exec sql end declare section;
         exec sql connect to pm;
 
        strcpy(msg, "create");
-       exec sql at main create table "Test" (name char(8), amount int, letter char(1));
-       exec sql create table "Test" (name char(8), amount int, letter char(1));
+       exec sql at main create table "Test" (name char(NAMELEN), amount int, letter char(1));
+       exec sql create table "Test" (name char(NAMELEN), amount int, letter char(1));
 
        strcpy(msg, "commit");
        exec sql at main commit;
@@ -115,7 +118,7 @@ exec sql end declare section;
            int a = amount[i];
            exec sql end declare section;
 
-           strncpy(n, name[i], 8);
+           strncpy(n, name[i], NAMELEN);
             printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l);
            amount[i]+=1000;