summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Meskes2007-08-29 13:59:04 +0000
committerMichael Meskes2007-08-29 13:59:04 +0000
commit17984443003005a5b2707e85ff39cf73494b087d (patch)
tree06e2a62f42ec0e3d5f6b4754b839ea70ad43a145
parent28b17705200d31fd2e8d2d3be4605c1e6c912dca (diff)
Fixed bug in Informix define handling.
-rw-r--r--src/interfaces/ecpg/preproc/ecpg.c7
-rw-r--r--src/interfaces/ecpg/preproc/pgc.l121
2 files changed, 67 insertions, 61 deletions
diff --git a/src/interfaces/ecpg/preproc/ecpg.c b/src/interfaces/ecpg/preproc/ecpg.c
index d106928d58b..7bb20e6256c 100644
--- a/src/interfaces/ecpg/preproc/ecpg.c
+++ b/src/interfaces/ecpg/preproc/ecpg.c
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.91 2004/11/09 15:57:55 petere Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.91.4.1 2007/08/29 13:59:04 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);
diff --git a/src/interfaces/ecpg/preproc/pgc.l b/src/interfaces/ecpg/preproc/pgc.l
index fad995fbd72..b6e0301ac3c 100644
--- a/src/interfaces/ecpg/preproc/pgc.l
+++ b/src/interfaces/ecpg/preproc/pgc.l
@@ -12,7 +12,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.134 2004/12/31 22:03:48 pgsql Exp $
+ * $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.134.4.1 2007/08/29 13:59:04 meskes Exp $
*
*-------------------------------------------------------------------------
*/
@@ -44,6 +44,8 @@ static int literalalloc; /* current allocated buffer size */
static void addlit(char *ytext, int yleng);
static void addlitchar (unsigned char);
static void parse_include (void);
+static bool isdefine(void);
+static bool isinformixdefine(void);
char *token_start;
int state_before;
@@ -597,29 +599,8 @@ cppline {space}*#(.*\\{space})+.*
}
<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);
@@ -691,38 +672,10 @@ cppline {space}*#(.*\\{space})+.*
}
<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)
@@ -1187,3 +1140,61 @@ parse_include(void)
BEGIN C;
}
+
+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;
+}