]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fixed bug in Informix define handling.
authorMichael Meskes <meskes@postgresql.org>
Wed, 29 Aug 2007 13:58:34 +0000 (13:58 +0000)
committerMichael Meskes <meskes@postgresql.org>
Wed, 29 Aug 2007 13:58:34 +0000 (13:58 +0000)
src/interfaces/ecpg/preproc/ecpg.c
src/interfaces/ecpg/preproc/pgc.l

index c06075ad5f962c32d3decca1e25c32659abef28c..5c236da475690a61913261dd331cc25cd2b95d5d 100644 (file)
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.94 2006/02/08 09:10:04 meskes Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.94.2.1 2007/08/29 13:58:34 meskes Exp $ */
 
 /* New main for ecpg, the PostgreSQL embedded SQL precompiler. */
 /* (C) Michael Meskes <meskes@postgresql.org> Feb 5th, 1998 */
@@ -185,11 +185,6 @@ main(int argc, char *const argv[])
                                        char            informix_path[MAXPGPATH];
 
                                        compat = (strcmp(optarg, "INFORMIX") == 0) ? ECPG_COMPAT_INFORMIX : ECPG_COMPAT_INFORMIX_SE;
-                                       /* system_includes = true; */
-                                       add_preprocessor_define("dec_t=decimal");
-                                       add_preprocessor_define("intrvl_t=interval");
-                                       add_preprocessor_define("dtime_t=timestamp");
-
                                        get_pkginclude_path(my_exec_path, pkginclude_path);
                                        snprintf(informix_path, MAXPGPATH, "%s/informix/esql", pkginclude_path);
                                        add_include_path(informix_path);
index 1af79f8e9e41903d3899083c7b1a80124d9eaf86..2a3cba547ff848e95bdfb993ececa31400e7062e 100644 (file)
@@ -12,7 +12,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.150 2006/09/22 21:39:58 tgl Exp $
+ *       $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.150.2.1 2007/08/29 13:58:34 meskes Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -48,6 +48,8 @@ static void addlitchar (unsigned char);
 static void parse_include (void);
 static void check_escape_warning(void);
 static bool ecpg_isspace(char ch);
+static bool isdefine(void);
+static bool isinformixdefine(void);
 
 char *token_start;
 int state_before;
@@ -671,29 +673,8 @@ cppline                    {space}*#(.*\\{space})*.*{newline}
                                        }
 <SQL>{identifier}      {
                                                ScanKeyword    *keyword;
-                                               struct _defines *ptr;
-                                               
-                                               /* How about a DEFINE? */
-                                               for (ptr = defines; ptr; ptr = ptr->next)
-                                               {
-                                                       if (strcmp(yytext, ptr->old) == 0 && ptr->used == NULL)
-                                                       {
-                                                               struct _yy_buffer *yb;
-
-                                                               yb = mm_alloc(sizeof(struct _yy_buffer));
-
-                                                               yb->buffer =  YY_CURRENT_BUFFER;
-                                                               yb->lineno = yylineno;
-                                                               yb->filename = mm_strdup(input_filename);
-                                                               yb->next = yy_buffer;
-                                                               
-                                                               ptr->used = yy_buffer = yb;
 
-                                                               yy_scan_string(ptr->new);
-                                                               break;
-                                                       }
-                                               }
-                                               if (ptr == NULL)
+                                               if (!isdefine())
                                                {
                                                        /* Is it an SQL keyword? */
                                                        keyword = ScanKeywordLookup(yytext);
@@ -765,38 +746,10 @@ cppline                   {space}*#(.*\\{space})*.*{newline}
                                        }
 <C>{identifier}        {
                                                ScanKeyword             *keyword;
-                                               struct _defines *ptr;
-
-                                               if (INFORMIX_MODE)
-                                               {
-                                                       /* Informix uses SQL defines only in SQL space */
-                                                       ptr = NULL;
-                                               }
-                                               else
-                                               {
-                                                       /* is it a define? */
-                                                       for (ptr = defines; ptr; ptr = ptr->next)
-                                                       {
-                                                               if (strcmp(yytext, ptr->old) == 0 && ptr->used == NULL)
-                                                               {
-                                                                       struct _yy_buffer *yb;
-
-                                                                       yb = mm_alloc(sizeof(struct _yy_buffer));
 
-                                                                       yb->buffer =  YY_CURRENT_BUFFER;
-                                                                       yb->lineno = yylineno;
-                                                                       yb->filename = mm_strdup(input_filename);
-                                                                       yb->next = yy_buffer;
-
-                                                                       ptr->used = yy_buffer = yb;
-
-                                                                       yy_scan_string(ptr->new);
-                                                                       break;
-                                                               }
-                                                       }
-                                               }
-
-                                               if (ptr == NULL)
+                                               /* Informix uses SQL defines only in SQL space */
+                                               /* however, some defines have to be taken care of for compatibility */
+                                               if ((!INFORMIX_MODE || !isinformixdefine()) && !isdefine())
                                                {
                                                        keyword = ScanCKeywordLookup(yytext);
                                                        if (keyword != NULL)
@@ -1347,3 +1300,61 @@ ecpg_isspace(char ch)
                return true;
        return false;
 }
+
+static bool isdefine(void)
+{
+       struct _defines *ptr;
+
+       /* is it a define? */
+       for (ptr = defines; ptr; ptr = ptr->next)
+       {
+               if (strcmp(yytext, ptr->old) == 0 && ptr->used == NULL)
+               {
+                       struct _yy_buffer *yb;
+
+                       yb = mm_alloc(sizeof(struct _yy_buffer));
+
+                       yb->buffer =  YY_CURRENT_BUFFER;
+                       yb->lineno = yylineno;
+                       yb->filename = mm_strdup(input_filename);
+                       yb->next = yy_buffer;
+
+                       ptr->used = yy_buffer = yb;
+
+                       yy_scan_string(ptr->new);
+                       return true;
+               }
+       }
+
+       return false;
+}
+
+static bool isinformixdefine(void)
+{
+       const char *new = NULL;
+
+       if (strcmp(yytext, "dec_t") == 0)
+               new = "decimal";
+       else if (strcmp(yytext, "intrvl_t") == 0)
+               new = "interval";
+       else if (strcmp(yytext, "dtime_t") == 0)
+                new = "timestamp";
+
+       if (new)
+       {
+               struct _yy_buffer *yb;
+
+               yb = mm_alloc(sizeof(struct _yy_buffer));
+
+               yb->buffer =  YY_CURRENT_BUFFER;
+               yb->lineno = yylineno;
+               yb->filename = mm_strdup(input_filename);
+               yb->next = yy_buffer;
+               yy_buffer = yb;
+
+               yy_scan_string(new);
+               return true;
+       }
+
+       return false;
+}