Commit 4e1ed3da authored by Michael Meskes's avatar Michael Meskes

- Added more compatibility functions.

	- Accept CPP defines for type definitions.
	- Do not parse system include files automatically for Informix mode
parent 78b08584
......@@ -1408,6 +1408,12 @@ Tue May 6 11:51:33 CEST 2003
Tue May 13 13:34:12 CEST 2003
- Fixed order of include search path.
Wed May 14 13:05:49 CEST 2003
- Added more compatibility functions.
- Accept CPP defines for type definitions.
- Do not parse system include files automatically for Informix mode
- Set ecpg version to 2.12.0.
- Set ecpg library to 3.4.2.
- Set pgtypes library to 1.0.0
......
......@@ -609,6 +609,28 @@ rfmtlong(long lng_val, char *fmt, char *outbuf)
return 0;
}
void
rupshift(char *str)
{
for (; *str != '\0'; str++)
if (islower(*str)) *str = toupper(*str);
return;
}
int
byleng(char *str, int len)
{
for (len--; str[len] && str[len] == ' '; len--);
return (len+1);
}
void
ldchar(char *src, int len, char *dest)
{
memmove(dest, src, len);
dest[len]=0;
}
int
rgetmsg(int msgnum, char *s, int maxsize)
{
......@@ -639,13 +661,15 @@ rtypmsize(int type, int len)
return 0;
}
void
rupshift(char *str)
int
rtypwidth(int sqltype, int sqllen)
{
for (; *str != '\0'; str++)
if (islower(*str)) *str = toupper(*str);
return;
return 0;
}
int
dtcvfmtasc (char *inbuf, char *fmtstr, dtime_t *dtvalue)
{
return 0;
}
......@@ -15,4 +15,4 @@ extern int dtsub (dtime_t *, dtime_t *, intrvl_t *);
extern int dttoasc (dtime_t *, char *);
extern int dttofmtasc (dtime_t *, char *, int, char *);
extern int intoasc(intrvl_t *, char *);
extern int dtcvfmtasc(char *, char *, dtime_t *);
......@@ -26,6 +26,9 @@ extern int risnull(int, char *);
extern int rsetnull(int, char *);
extern int rtypalign(int, int);
extern int rtypmsize(int, int);
extern int rtypwidth(int, int);
extern void rupshift(char *);
extern int byleng(char *, int);
extern void ldchar(char *, int, char *);
......@@ -192,7 +192,7 @@ output_get_descr(char *desc_name, char *index)
break;
}
fprintf(yyout, "%s,", get_dtype(results->value));
ECPGdump_a_type(yyout, v->name, v->type, NULL, NULL, NULL, NULL, 0L, NULL, NULL);
ECPGdump_a_type(yyout, v->name, v->type, NULL, NULL, NULL, NULL, make_str("0"), NULL, NULL);
}
drop_assignments();
fputs("ECPGd_EODT);\n", yyout);
......
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.69 2003/05/13 11:29:14 meskes Exp $ */
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.70 2003/05/14 14:37:35 meskes Exp $ */
/* New main for ecpg, the PostgreSQL embedded SQL precompiler. */
/* (C) Michael Meskes <meskes@postgresql.org> Feb 5th, 1998 */
......@@ -162,7 +162,7 @@ main(int argc, char *const argv[])
if (strcmp(optarg, "INFORMIX") == 0)
{
compat = ECPG_COMPAT_INFORMIX;
system_includes = true;
/* system_includes = true; */
add_preprocessor_define("dec_t=Numeric");
add_preprocessor_define("intrvl_t=Interval");
}
......
......@@ -77,7 +77,7 @@ extern void add_variable(struct arguments **, struct variable *, struct variable
extern void append_variable(struct arguments **, struct variable *, struct variable *);
extern void dump_variables(struct arguments *, int);
extern struct typedefs *get_typedef(char *);
extern void adjust_array(enum ECPGttype, int *, int *, int, int, int);
extern void adjust_array(enum ECPGttype, char **, char **, char *, char *, int);
extern void reset_variables(void);
extern void check_indicator(struct ECPGtype *);
extern void remove_variables(int);
......
This diff is collapsed.
......@@ -83,7 +83,7 @@ ECPGmake_struct_member(char *name, struct ECPGtype * type, struct ECPGstruct_mem
}
struct ECPGtype *
ECPGmake_simple_type(enum ECPGttype type, long size)
ECPGmake_simple_type(enum ECPGttype type, char *size)
{
struct ECPGtype *ne = (struct ECPGtype *) mm_alloc(sizeof(struct ECPGtype));
......@@ -96,7 +96,7 @@ ECPGmake_simple_type(enum ECPGttype type, long size)
}
struct ECPGtype *
ECPGmake_array_type(struct ECPGtype * type, long size)
ECPGmake_array_type(struct ECPGtype * type, char *size)
{
struct ECPGtype *ne = ECPGmake_simple_type(ECPGt_array, size);
......@@ -108,7 +108,7 @@ ECPGmake_array_type(struct ECPGtype * type, long size)
struct ECPGtype *
ECPGmake_struct_type(struct ECPGstruct_member * rm, enum ECPGttype type, char *struct_sizeof)
{
struct ECPGtype *ne = ECPGmake_simple_type(type, 1);
struct ECPGtype *ne = ECPGmake_simple_type(type, make_str("1"));
ne->u.members = ECPGstruct_member_dup(rm);
ne->struct_sizeof = struct_sizeof;
......@@ -207,13 +207,17 @@ get_type(enum ECPGttype type)
the variable (required to do array fetches of structs).
*/
static void ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
long varcharsize,
long arrsiz, const char *siz, const char *prefix);
static void ECPGdump_a_struct(FILE *o, const char *name, const char *ind_name, long arrsiz,
char *varcharsize,
char *arrsiz, const char *siz, const char *prefix);
static void ECPGdump_a_struct(FILE *o, const char *name, const char *ind_name, char *arrsiz,
struct ECPGtype * type, struct ECPGtype * ind_type, const char *offset, const char *prefix, const char *ind_prefix);
void
ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * type, const char *ind_name, struct ECPGtype * ind_type, const char *prefix, const char *ind_prefix, const long arr_str_siz, const char *struct_sizeof, const char *ind_struct_sizeof)
ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * type,
const char *ind_name, struct ECPGtype * ind_type,
const char *prefix, const char *ind_prefix,
char *arr_str_siz, const char *struct_sizeof,
const char *ind_struct_sizeof)
{
switch (type->type)
{
......@@ -239,7 +243,7 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * type, const char *i
if (ind_type != NULL)
{
if (ind_type->type == ECPGt_NO_INDICATOR)
ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, -1, NULL, ind_prefix);
ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, make_str("-1"), NULL, ind_prefix);
else
ECPGdump_a_simple(o, ind_name, ind_type->u.element->type,
ind_type->u.element->size, ind_type->size, NULL, prefix);
......@@ -250,7 +254,7 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * type, const char *i
if (indicator_set && ind_type->type != ECPGt_struct)
mmerror(INDICATOR_NOT_STRUCT, ET_FATAL, "Indicator for struct has to be struct.\n");
ECPGdump_a_struct(o, name, ind_name, 1, type, ind_type, NULL, prefix, ind_prefix);
ECPGdump_a_struct(o, name, ind_name, make_str("1"), type, ind_type, NULL, prefix, ind_prefix);
break;
case ECPGt_union: /* cannot dump a complete union */
yyerror("Type of union has to be specified");
......@@ -259,23 +263,23 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * type, const char *i
if (indicator_set && (ind_type->type == ECPGt_struct || ind_type->type == ECPGt_array))
mmerror(INDICATOR_NOT_SIMPLE, ET_FATAL, "Indicator for simple datatype has to be simple.\n");
ECPGdump_a_simple(o, name, type->type, 1, arr_str_siz ? arr_str_siz : 1, struct_sizeof, prefix);
ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, arr_str_siz ? arr_str_siz : -1, ind_struct_sizeof, ind_prefix);
ECPGdump_a_simple(o, name, type->type, make_str("1"), (arr_str_siz && strcmp(arr_str_siz, "0") != 0) ? arr_str_siz : make_str("1"), struct_sizeof, prefix);
ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, (arr_str_siz && strcmp(arr_str_siz, "0") != 0) ? arr_str_siz : make_str("-1"), ind_struct_sizeof, ind_prefix);
break;
case ECPGt_descriptor:
if (indicator_set && (ind_type->type == ECPGt_struct || ind_type->type == ECPGt_array))
mmerror(INDICATOR_NOT_SIMPLE, ET_FATAL, "Indicator for simple datatype has to be simple.\n");
ECPGdump_a_simple(o, name, type->type, 0, -1, NULL, prefix);
ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, -1, NULL, ind_prefix);
ECPGdump_a_simple(o, name, type->type, 0, make_str("-1"), NULL, prefix);
ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, make_str("-1"), NULL, ind_prefix);
break;
default:
if (indicator_set && (ind_type->type == ECPGt_struct || ind_type->type == ECPGt_array))
mmerror(INDICATOR_NOT_SIMPLE, ET_FATAL, "Indicator for simple datatype has to be simple.\n");
ECPGdump_a_simple(o, name, type->type, type->size, arr_str_siz ? arr_str_siz : -1, struct_sizeof, prefix);
ECPGdump_a_simple(o, name, type->type, type->size, (arr_str_siz && strcmp(arr_str_siz, "0") != 0) ? arr_str_siz : make_str("-1"), struct_sizeof, prefix);
if (ind_type != NULL)
ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, arr_str_siz ? arr_str_siz : -1, ind_struct_sizeof, ind_prefix);
ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, (arr_str_siz && strcmp(arr_str_siz, "0") != 0) ? arr_str_siz : make_str("-1"), ind_struct_sizeof, ind_prefix);
break;
}
}
......@@ -285,8 +289,8 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * type, const char *i
string, it represents the offset needed if we are in an array of structs. */
static void
ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
long varcharsize,
long arrsize,
char *varcharsize,
char *arrsize,
const char *siz,
const char *prefix
)
......@@ -309,7 +313,9 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
* we have to use the pointer except for arrays with given
* bounds
*/
if (arrsize > 0 && siz == NULL)
if (((atoi(arrsize) > 0) ||
(atoi(arrsize) == 0) && strcmp(arrsize, "0") != 0) &&
siz == NULL)
sprintf(variable, "(%s%s)", prefix ? prefix : "", name);
else
sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
......@@ -324,12 +330,16 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
* we have to use the pointer except for arrays with given
* bounds
*/
if ((varcharsize > 1 || arrsize > 0) && siz == NULL)
if ((atoi(varcharsize) > 1 ||
(atoi(arrsize) > 0) ||
(atoi(varcharsize) == 0 && strcmp(varcharsize, "0") != 0) ||
(atoi(arrsize) == 0 && strcmp(arrsize, "0") != 0))
&& siz == NULL)
sprintf(variable, "(%s%s)", prefix ? prefix : "", name);
else
sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
sprintf(offset, "%ld*sizeof(char)", varcharsize == 0 ? 1 : varcharsize);
sprintf(offset, "%s*sizeof(char)", strcmp(varcharsize, "0") == 0 ? "1" : varcharsize);
break;
case ECPGt_numeric:
......@@ -369,7 +379,9 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
* we have to use the pointer except for arrays with given
* bounds
*/
if (arrsize > 0 && siz == NULL)
if (((atoi(arrsize) > 0) ||
(atoi(arrsize) == 0) && strcmp(arrsize, "0") != 0) &&
siz == NULL)
sprintf(variable, "(%s%s)", prefix ? prefix : "", name);
else
sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
......@@ -378,13 +390,13 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
break;
}
if (arrsize < 0)
arrsize = 1;
if (siz == NULL || arrsize <= 1)
fprintf(o, "\n\t%s,%s,%ldL,%ldL,%s, ", get_type(type), variable, varcharsize, arrsize, offset);
if (atoi(arrsize) < 0)
strcpy(arrsize, "1");
if (siz == NULL || strcmp(arrsize, "0") == 0 || strcmp(arrsize, "1") == 0)
fprintf(o, "\n\t%s,%s,(long)%s,(long)%s,%s, ", get_type(type), variable, varcharsize, arrsize, offset);
else
fprintf(o, "\n\t%s,%s,%ldL,%ldL,%s, ", get_type(type), variable, varcharsize, arrsize, siz);
fprintf(o, "\n\t%s,%s,(long)%s,(long)%s,%s, ", get_type(type), variable, varcharsize, arrsize, siz);
free(variable);
free(offset);
......@@ -394,7 +406,7 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
/* Penetrate a struct and dump the contents. */
static void
ECPGdump_a_struct(FILE *o, const char *name, const char *ind_name, long arrsiz, struct ECPGtype * type, struct ECPGtype * ind_type, const char *offsetarg, const char *prefix, const char *ind_prefix)
ECPGdump_a_struct(FILE *o, const char *name, const char *ind_name, char *arrsiz, struct ECPGtype * type, struct ECPGtype * ind_type, const char *offsetarg, const char *prefix, const char *ind_prefix)
{
/*
* If offset is NULL, then this is the first recursive level. If not
......@@ -416,7 +428,7 @@ ECPGdump_a_struct(FILE *o, const char *name, const char *ind_name, long arrsiz,
else
offset = offsetarg;
if (arrsiz == 1)
if (atoi(arrsiz) == 1)
sprintf(pbuf, "%s%s.", prefix ? prefix : "", name);
else
sprintf(pbuf, "%s%s->", prefix ? prefix : "", name);
......@@ -427,7 +439,7 @@ ECPGdump_a_struct(FILE *o, const char *name, const char *ind_name, long arrsiz,
ind_p = &struct_no_indicator;
else if (ind_type != NULL)
{
if (arrsiz == 1)
if (atoi(arrsiz) == 1)
sprintf(ind_pbuf, "%s%s.", ind_prefix ? ind_prefix : "", ind_name);
else
sprintf(ind_pbuf, "%s%s->", ind_prefix ? ind_prefix : "", ind_name);
......
......@@ -14,26 +14,24 @@ struct ECPGstruct_member
struct ECPGtype
{
enum ECPGttype type;
long size; /* For array it is the number of elements.
* For varchar it is the maxsize of the
* area. */
char *struct_sizeof; /* For a struct this is the sizeof() type
* as string */
char *size; /* For array it is the number of elements.
* For varchar it is the maxsize of the
* area. */
char *struct_sizeof; /* For a struct this is the sizeof() type
* as string */
union
{
struct ECPGtype *element; /* For an array this is the type
* of the element */
struct ECPGstruct_member *members;
/* A pointer to a list of members. */
* of the element */
struct ECPGstruct_member *members; /* A pointer to a list of members. */
} u;
};
/* Everything is malloced. */
void ECPGmake_struct_member(char *, struct ECPGtype *, struct ECPGstruct_member **);
struct ECPGtype *ECPGmake_simple_type(enum ECPGttype, long);
struct ECPGtype *ECPGmake_simple_type(enum ECPGttype, char *);
struct ECPGtype *ECPGmake_varchar_type(enum ECPGttype, long);
struct ECPGtype *ECPGmake_array_type(struct ECPGtype *, long);
struct ECPGtype *ECPGmake_array_type(struct ECPGtype *, char *);
struct ECPGtype *ECPGmake_struct_type(struct ECPGstruct_member *, enum ECPGttype, char *);
struct ECPGstruct_member *ECPGstruct_member_dup(struct ECPGstruct_member *);
......@@ -51,7 +49,9 @@ void ECPGfree_type(struct ECPGtype *);
size is the maxsize in case it is a varchar. Otherwise it is the size of
the variable (required to do array fetches of structs).
*/
void ECPGdump_a_type(FILE *, const char *, struct ECPGtype *, const char *, struct ECPGtype *, const char *, const char *, const long, const char *, const char *);
void ECPGdump_a_type(FILE *, const char *, struct ECPGtype *, const char *,
struct ECPGtype *, const char *, const char *, char *,
const char *, const char *);
/* A simple struct to keep a variable and its type. */
struct ECPGtemp_type
......@@ -83,18 +83,18 @@ struct when
struct index
{
int index1;
int index2;
char *str;
char *index1;
char *index2;
char *str;
};
struct this_type
{
enum ECPGttype type_enum;
char *type_str;
int type_dimension;
int type_index;
char *type_sizeof;
char *type_str;
char *type_dimension;
char *type_index;
char *type_sizeof;
};
struct _include_path
......
......@@ -298,22 +298,22 @@ get_typedef(char *name)
}
void
adjust_array(enum ECPGttype type_enum, int *dimension, int *length, int type_dimension, int type_index, int pointer_len)
adjust_array(enum ECPGttype type_enum, char **dimension, char **length, char *type_dimension, char *type_index, int pointer_len)
{
if (type_index >= 0)
if (atoi(type_index) >= 0)
{
if (*length >= 0)
if (atoi(*length) >= 0)
mmerror(PARSE_ERROR, ET_FATAL, "No multi-dimensional array support");
*length = type_index;
}
if (type_dimension >= 0)
if (atoi(type_dimension) >= 0)
{
if (*dimension >= 0 && *length >= 0)
if (atoi(*dimension) >= 0 && atoi(*length) >= 0)
mmerror(PARSE_ERROR, ET_FATAL, "No multi-dimensional array support");
if (*dimension >= 0)
if (atoi(*dimension) >= 0)
*length = *dimension;
*dimension = type_dimension;
......@@ -328,10 +328,10 @@ adjust_array(enum ECPGttype type_enum, int *dimension, int *length, int type_dim
if (pointer_len > 1 && type_enum != ECPGt_char && type_enum != ECPGt_unsigned_char)
mmerror(PARSE_ERROR, ET_FATAL, "No pointer to pointer supported for this type");
if (pointer_len > 1 && (*length >= 0 || *dimension >= 0))
if (pointer_len > 1 && (atoi(*length) >= 0 || atoi(*dimension) >= 0))
mmerror(PARSE_ERROR, ET_FATAL, "No multi-dimensional array support");
if (*length >= 0 && *dimension >= 0 && pointer_len)
if (atoi(*length) >= 0 && atoi(*dimension) >= 0 && pointer_len)
mmerror(PARSE_ERROR, ET_FATAL, "No multi-dimensional array support");
switch (type_enum)
......@@ -342,23 +342,23 @@ adjust_array(enum ECPGttype type_enum, int *dimension, int *length, int type_dim
if (pointer_len)
{
*length = *dimension;
*dimension = 0;
*dimension = make_str("0");
}
if (*length >= 0)
if (atoi(*length) >= 0)
mmerror(PARSE_ERROR, ET_FATAL, "No multi-dimensional array support for structures");
break;
case ECPGt_varchar:
/* pointer has to get dimension 0 */
if (pointer_len)
*dimension = 0;
*dimension = make_str("0");
/* one index is the string length */
if (*length < 0)
if (atoi(*length) < 0)
{
*length = *dimension;
*dimension = -1;
*dimension = make_str("-1");
}
break;
......@@ -367,19 +367,19 @@ adjust_array(enum ECPGttype type_enum, int *dimension, int *length, int type_dim
/* char ** */
if (pointer_len == 2)
{
*length = *dimension = 0;
*length = *dimension = make_str("0");
break;
}
/* pointer has to get length 0 */
if (pointer_len == 1)
*length = 0;
*length = make_str("0");
/* one index is the string length */
if (*length < 0)
if (atoi(*length) < 0)
{
*length = (*dimension < 0) ? 1 : *dimension;
*dimension = -1;
*length = (atoi(*dimension) < 0) ? make_str("1") : *dimension;
*dimension = make_str("-1");
}
break;
default:
......@@ -387,10 +387,10 @@ adjust_array(enum ECPGttype type_enum, int *dimension, int *length, int type_dim
if (pointer_len)
{
*length = *dimension;
*dimension = 0;
*dimension = make_str("0");
}
if (*length >= 0)
if (atoi(*length) >= 0)
mmerror(PARSE_ERROR, ET_FATAL, "No multi-dimensional array support for simple data types");
break;
......
......@@ -9,7 +9,8 @@ typedef char* c;
exec sql type ind is union { int integer; short smallint; };
typedef union { int integer; short smallint; } ind;
exec sql type str is varchar[8];
#define BUFSIZ 8
exec sql type str is varchar[BUFSIZ];
int
main ()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment